From 5c1838b347feffe348b3ce8b342f3dccc5f8e6fa Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Tue, 13 Aug 2024 16:38:39 +0200 Subject: [PATCH] auth test, work in progress: get static login data from config / .env --- config.lisp | 1 - core/core.lisp | 1 + lib/auth/auth.lisp | 12 +++++++++--- lib/auth/test/.test.env | 4 ++-- lib/auth/test/config.lisp | 1 + lib/auth/test/test-auth.lisp | 7 ++++--- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/config.lisp b/config.lisp index 7d47e72..ea0972c 100644 --- a/config.lisp +++ b/config.lisp @@ -49,7 +49,6 @@ (let* ((key (str:concat prefix (string sl))) (env-val (uiop:getenv key)) (dotenv-val (if dotenv-data (gethash key dotenv-data)))) - ;(format t "~&init after config:root key: ~s, env-val ~s~%" key dotenv-val) (if env-val (setf (gethash sl data) env-val) (setf (gethash sl data) dotenv-val)))))) diff --git a/core/core.lisp b/core/core.lisp index 887d34a..7c1ff5d 100644 --- a/core/core.lisp +++ b/core/core.lisp @@ -5,6 +5,7 @@ (:local-nicknames (:config :scopes/config) (:message :scopes/core/message) (:shape :scopes/shape) + (:util :scopes/util) (:alx :alexandria)) (:export #:*root* #:default-setup #:default-actions #:find-service #:setup-services diff --git a/lib/auth/auth.lisp b/lib/auth/auth.lisp index c3400a7..3900ea0 100644 --- a/lib/auth/auth.lisp +++ b/lib/auth/auth.lisp @@ -3,15 +3,21 @@ (defpackage :scopes-auth (:use :common-lisp) (:local-nicknames (:config :scopes/config) + (:core :scopes/core) (:util :scopes/util)) (:import-from :scopes/web/dom #:div #:label) - (:export #:config + (:export #:config #:setup #:login)) (in-package :scopes-auth) (defclass config (config:base) - ((admin-credentials :initarg :admin-credentials))) + ((admin-credentials :reader admin-credentials :initarg :admin-credentials))) + +(defun setup (cfg) + (core:default-setup cfg)) (defun login (cred) - (util:lgi cred)) + (let ((srv (core:find-service :auth))) + (util:lgi cred (admin-credentials (core:config srv))))) + diff --git a/lib/auth/test/.test.env b/lib/auth/test/.test.env index a7d2279..77631e5 100644 --- a/lib/auth/test/.test.env +++ b/lib/auth/test/.test.env @@ -1,4 +1,4 @@ # lib/auth/test/.test.env - environment file for overriding config settings -SCOPES_ADMIN_LOGIN=admin -SCOPES_ADMIN_PASSWORD=sc0pes +SCOPES_ADMIN-LOGIN=admin +SCOPES_ADMIN-PASSWORD=sc0pes diff --git a/lib/auth/test/config.lisp b/lib/auth/test/config.lisp index aac6ec1..7c81456 100644 --- a/lib/auth/test/config.lisp +++ b/lib/auth/test/config.lisp @@ -16,6 +16,7 @@ :console nil) (config:add :auth :class 'auth:config + :setup #'auth:setup :admin-credentials `(:login ,(config:from-env :admin-login "admin") :password ,(config:from-env :admin-password "secret"))) diff --git a/lib/auth/test/test-auth.lisp b/lib/auth/test/test-auth.lisp index 3268421..e6c645f 100644 --- a/lib/auth/test/test-auth.lisp +++ b/lib/auth/test/test-auth.lisp @@ -21,13 +21,14 @@ (let ((t:*current-system* :scopes-auth) (t:*test-suite* (t:test-suite "auth"))) (load (t:test-path "config" "")) - (unwind-protect + ;(unwind-protect (progn (core:setup-services) (let ((server (core:find-service :server)) (client (core:find-service :client))) - (test-login)) - (t:show-result))))) + (test-login))) + (core:shutdown) + (t:show-result))) (deftest test-login () (let ((cred '(:login "admin" :password "secret")))