From fd92acef46a0c83b8c7e24d6dffae0e7e3084951 Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 15 Jul 2022 15:09:32 +0200 Subject: [PATCH] Fixed tests Removed unused issuer key in tests and generate-appini-env. Combined host and port keys for ease of programming. --- src/main/cljc/dda/c4k_gitea/gitea.cljc | 11 ++- .../resources/gitea/appini-env-configmap.yaml | 2 +- src/test/cljc/dda/c4k_gitea/gitea_test.cljc | 70 +++++++++++++------ 3 files changed, 56 insertions(+), 27 deletions(-) diff --git a/src/main/cljc/dda/c4k_gitea/gitea.cljc b/src/main/cljc/dda/c4k_gitea/gitea.cljc index c3f3c7e..1cffaf3 100644 --- a/src/main/cljc/dda/c4k_gitea/gitea.cljc +++ b/src/main/cljc/dda/c4k_gitea/gitea.cljc @@ -12,15 +12,15 @@ (s/def ::fqdn pred/fqdn-string?) (s/def ::issuer pred/letsencrypt-issuer?) -(s/def ::maileruser pred/bash-env-string?) -(s/def ::mailerpw pred/bash-env-string?) +(s/def ::mailer-user pred/bash-env-string?) +(s/def ::mailer-pw pred/bash-env-string?) (def config-defaults {:issuer "staging"}) (def config? (s/keys :req-un [::fqdn] :opt-un [::issuer])) -(def auth? (s/keys :req-un [::postgres/postgres-db-user ::postgres/postgres-db-password ::maileruser ::mailerpw])) +(def auth? (s/keys :req-un [::postgres/postgres-db-user ::postgres/postgres-db-password ::mailer-user ::mailer-pw])) #?(:cljs (defmethod yaml/load-resource :gitea [resource-name] @@ -43,14 +43,13 @@ (defn-spec generate-appini-env pred/map-or-seq? ; TODO: fix this to require the merged spec of auth and config instead of any [config any?] - (let [{:keys [fqdn mailer-from mailer-host mailer-port service-whitelist-domains]} config] + (let [{:keys [fqdn mailer-from mailer-host-port service-whitelist-domains]} config] (-> (yaml/load-as-edn "gitea/appini-env-configmap.yaml") (cm/replace-all-matching-values-by-new-value "FQDN" fqdn) (cm/replace-all-matching-values-by-new-value "URL" (str "https://" fqdn)) (cm/replace-all-matching-values-by-new-value "FROM" mailer-from) - (cm/replace-all-matching-values-by-new-value "HOST" mailer-host) - (cm/replace-all-matching-values-by-new-value "PORT" mailer-port) + (cm/replace-all-matching-values-by-new-value "HOSTANDPORT" mailer-host-port) (cm/replace-all-matching-values-by-new-value "WHITELISTDOMAINS" service-whitelist-domains) ))) diff --git a/src/main/resources/gitea/appini-env-configmap.yaml b/src/main/resources/gitea/appini-env-configmap.yaml index e7e75a0..d836d8e 100644 --- a/src/main/resources/gitea/appini-env-configmap.yaml +++ b/src/main/resources/gitea/appini-env-configmap.yaml @@ -14,7 +14,7 @@ data: GITEA__mailer__ENABLED: "true" GITEA__mailer__FROM: FROM GITEA__mailer__MAILER_TYPE: smtp - GITEA__mailer__HOST: HOST:PORT + GITEA__mailer__HOST: HOSTANDPORT GITEA__mailer__IS_TLS_ENABLED: "true" GITEA__service__DISABLE_REGISTRATION: "true" diff --git a/src/test/cljc/dda/c4k_gitea/gitea_test.cljc b/src/test/cljc/dda/c4k_gitea/gitea_test.cljc index a0f0b8f..19b02b4 100644 --- a/src/test/cljc/dda/c4k_gitea/gitea_test.cljc +++ b/src/test/cljc/dda/c4k_gitea/gitea_test.cljc @@ -12,19 +12,25 @@ (st/instrument `cut/generate-secrets) (deftest should-generate-appini-env - (is (= {:GITEA__database__USER-c1 nil, - :GITEA__database__USER-c2 "pg-user", - :GITEA__database__PASSWD-c1 nil, - :GITEA__database__PASSWD-c2 "pg-pw", - :GITEA__server__DOMAIN-c1 nil, + (is (= {:GITEA__server__DOMAIN-c1 "", :GITEA__server__DOMAIN-c2 "test.com", :GITEA__server__ROOT_URL-c1 "https://", - :GITEA__server__ROOT_URL-c2 "https://test.com"} - (ct/map-diff (cut/generate-appini-env {}) - (cut/generate-appini-env {:fqdn "test.com" - :issuer "staging" - :postgres-db-user "pg-user" - :postgres-db-password "pg-pw"}))))) + :GITEA__server__ROOT_URL-c2 "https://test.com", + :GITEA__mailer__FROM-c1 "", + :GITEA__mailer__FROM-c2 "test@test.com", + :GITEA__mailer__HOST-c1 "", + :GITEA__mailer__HOST-c2 "mail.test.com:123", + :GITEA__service__EMAIL_DOMAIN_WHITELIST-c1 "", + :GITEA__service__EMAIL_DOMAIN_WHITELIST-c2 "abc.com,def.com"} + (ct/map-diff (cut/generate-appini-env {:fqdn "" + :mailer-from "" + :mailer-host-port "" + :service-whitelist-domains ""}) + (cut/generate-appini-env {:fqdn "test.com" + :mailer-from "test@test.com" + :mailer-host-port "mail.test.com:123" + :service-whitelist-domains "abc.com,def.com" + }))))) (deftest should-generate-certificate (is (= {:name-c2 "prod", :name-c1 "staging"} @@ -32,15 +38,39 @@ (cut/generate-certificate {:issuer "prod"}))))) (deftest should-generate-secret - (is (= {:GITEA__mailer__USER-c1 "", - :GITEA__mailer__USER-c2 (b64/encode "mailuser"), + (is (= {:GITEA__database__USER-c1 "", + :GITEA__database__USER-c2 "pg-user", + :GITEA__database__PASSWD-c1 "", + :GITEA__database__PASSWD-c2 "pg-pw", + :GITEA__mailer__USER-c1 "", + :GITEA__mailer__USER-c2 (b64/encode "maileruser"), :GITEA__mailer__PASSWD-c1 "", - :GITEA__mailer__PASSWD-c2 (b64/encode "mailpw")} + :GITEA__mailer__PASSWD-c2 (b64/encode "mailerpw")} (ct/map-diff (cut/generate-secrets {:postgres-db-user "" :postgres-db-password "" - :maileruser "" - :mailerpw ""}) - (cut/generate-secrets {:postgres-db-user "" - :postgres-db-password "" - :maileruser "mailuser" - :mailerpw "mailpw"}))))) \ No newline at end of file + :mailer-user "" + :mailer-pw ""}) + (cut/generate-secrets {:postgres-db-user "pg-user" + :postgres-db-password "pg-pw" + :mailer-user "maileruser" + :mailer-pw "mailerpw"}))))) + + +(not + (= + {:GITEA__server__DOMAIN-c2 "test.com", + :GITEA__mailer__FROM-c1 "", + :GITEA__service__EMAIL_DOMAIN_WHITELIST-c2 "abc.com,def.com", + :GITEA__service__EMAIL_DOMAIN_WHITELIST-c1 "", + :GITEA__mailer__HOST-c1 ":", + :GITEA__mailer__FROM-c2 "test@test.com", + :GITEA__mailer__HOST-c2 "mail.test.com:123", + :GITEA__server__ROOT_URL-c2 "https://test.com", + :GITEA__server__ROOT_URL-c1 "https://", + :GITEA__server__DOMAIN-c1 ""} + {:GITEA__server__DOMAIN-c1 "", + :GITEA__server__DOMAIN-c2 "test.com", + :GITEA__server__ROOT_URL-c1 "https://", + :GITEA__server__ROOT_URL-c2 "https://test.com", + :GITEA__service__EMAIL_DOMAIN_WHITELIST-c1 "", + :GITEA__service__EMAIL_DOMAIN_WHITELIST-c2 "abc.com,def.com"})) \ No newline at end of file