diff of 553f06c46b5c57cf8b351ccd8d0fdbd0d56de6e3
553f06c46b5c57cf8b351ccd8d0fdbd0d56de6e3
diff --git a/resources/sql/e2e-migration.sql b/resources/sql/e2e-migration.sql
new file mode 100644
index 0000000..7297928
--- /dev/null
+++ b/resources/sql/e2e-migration.sql
@@ -0,0 +1,5 @@
+DELETE FROM blog.Users;
+DELETE FROM blog.Media;
+
+INSERT INTO blog.Users (username, nickname, img_location, password)
+VALUES ('Playwright-user', 'playwrighte', '', 'fe1c94d7b0ac51013b944b84cd1fd40111421684f857ebf2eaaf494014007e3068ea25ed03c4c8155b33c1271742db38dcf3059096ad2b859b44ed2b9ae5d10f');
diff --git a/src/local-lib/lisp-fixup.lisp b/src/local-lib/lisp-fixup.lisp
index e8f47c8..5989790 100644
--- a/src/local-lib/lisp-fixup.lisp
+++ b/src/local-lib/lisp-fixup.lisp
@@ -1,9 +1,13 @@
(defpackage lisp-fixup
(:use :cl)
- (:export :partial :compose :drop :slurp-bytes :slurp-utf-8))
+ (:export :sha-512 :partial :compose :drop :slurp-bytes :slurp-utf-8))
(in-package :lisp-fixup)
+(defun sha-512 (str)
+ (ironclad:byte-array-to-hex-string
+ (ironclad:digest-sequence :sha512
+ (ironclad:ascii-string-to-byte-array str))))
;; https://www.n16f.net/blog/reading-files-faster-in-common-lisp/
(defun slurp-bytes (path)
diff --git a/src/local-lib/migrations.lisp b/src/local-lib/migrations.lisp
index 261e9cd..b2b670a 100644
--- a/src/local-lib/migrations.lisp
+++ b/src/local-lib/migrations.lisp
@@ -1,7 +1,7 @@
(defpackage murja.migrations
(:use :halisql)
(:use :cl)
- (:export :defmigration :migrate))
+ (:export :deflispmigration :defmigration :migrate))
(in-package :murja.migrations)
@@ -43,6 +43,34 @@
(unless found-migration?
(push (cons path fn) *migrations*))))
+(defmacro deflispmigration (filename-sym path &rest body)
+ `(let* ((,filename-sym (asdf:system-relative-pathname *system-name*
+ (format nil "resources/sql/~a.sql" ,path)))
+ ;; ragtime legacy, migration filenames are named .up.sql but they were saved into the public.ragtime_migrations without the .up.sql postfix
+ ;; and murja.migrations/halisql system drops the .sql extension, but halisql functions don't handle the .up. string correctly
+ (path (str:replace-all ".up" "" ,path))
+ (fn (lambda ()
+ ,@body))
+ (found-migration? nil))
+ (dolist (mig *migrations*)
+ (when (string= (first mig) path)
+ (setf (cdr mig) fn)
+ (setf found-migration? t)
+ (return)))
+
+ (unless found-migration?
+ (push (cons path fn) *migrations*))))
+
+(defun defmigration (file-path &key initial)
+ (deflispmigration filename file-path
+ (cond ((and initial (not (migration-table-exists)))
+ (postmodern:execute-file filename))
+
+ ((and (migration-table-exists) (not (migration-does-exist path)))
+ (postmodern:execute-file filename))
+
+ (t (log:info "Didn't run ~a" path)))))
+
(defun migrate ()
(postmodern:with-transaction ()
(dolist (mig (reverse *migrations*))
diff --git a/src/migration-list.lisp b/src/migration-list.lisp
index 8c20fbd..53e52d2 100644
--- a/src/migration-list.lisp
+++ b/src/migration-list.lisp
@@ -1,6 +1,7 @@
(defpackage murja.migration-list
(:use :cl)
- (:import-from :murja.migrations :defmigration))
+ (:import-from :lisp-fixup :sha-512)
+ (:import-from :murja.migrations :defmigration :deflispmigration))
(in-package :murja.migration-list)
@@ -20,4 +21,16 @@
(defmigration "014-tag-hidden-unlisted-validator.up")
(defmigration "015-image-post-pairing-view.up")
+(deflispmigration _ "e2e-migration"
+ (declare (ignore _))
+ (log:info "Running e2e-migration")
+ (when (sb-ext:posix-getenv "MURJA_E2E")
+ (let ((user-id (caar (postmodern:query "INSERT INTO blog.Users (username, nickname, img_location, password) VALUES ($1, $2, $3, $4) returning id"
+ "Playwright-user"
+ "playwrighte"
+ ""
+ (sha-512 "p4ssw0rd")))))
+ (postmodern:execute "insert into blog.groupmapping (userid, groupid, primarygroup) values ($1, $2, $3)"
+ user-id 1 t))))
+
;; (murja.migrations:migrate)
diff --git a/src/routes/login-routes.lisp b/src/routes/login-routes.lisp
index 7f87f58..20a24fc 100644
--- a/src/routes/login-routes.lisp
+++ b/src/routes/login-routes.lisp
@@ -1,5 +1,6 @@
(defpackage murja.routes.login-routes
(:use :cl)
+ (:import-from :lisp-fixup :sha-512)
(:import-from :murja.middleware.auth :@authenticated :*user*)
(:import-from :murja.middleware.db :@transaction)
@@ -9,11 +10,6 @@
(in-package :murja.routes.login-routes)
-(defun sha-512 (str)
- (ironclad:byte-array-to-hex-string
- (ironclad:digest-sequence :sha512
- (ironclad:ascii-string-to-byte-array str))))
-
(defroute post-login ("/api/login/login" :method :post :decorators (@transaction @json)) ()
(let* ((body-params (parse (hunchentoot:raw-post-data :force-text t)))
(username (gethash "username" body-params))
diff --git a/src/users/user-db.lisp b/src/users/user-db.lisp
index b234b4a..1286293 100644
--- a/src/users/user-db.lisp
+++ b/src/users/user-db.lisp
@@ -24,7 +24,13 @@
(defun select-user-by-login (username password-sha)
(let ((usr (first (coerce (query-users* username password-sha) 'list))))
- (when usr
- (jsonize-key usr "permissions"))))
+ (if usr
+ (jsonize-key usr "permissions")
+ (let ((usrs (coerce (postmodern:query "SELECT * FROM blog.Users" :alists) 'list)))
+ (unless usrs
+ (log:error "There are no users in the db"))
+
+ (log:warn "login failed with params ~a, ~a. Users in db: ~{~a~%~}" username password-sha usrs)
+ nil))))
;;(postmodern:connect-toplevel "blogdb" "blogadmin" "blog" "localhost")