Fixed tests

Removed unused issuer key in tests and generate-appini-env.
Combined host and port keys for ease of programming.
This commit is contained in:
erik 2022-07-15 15:09:32 +02:00
parent 9113bc2677
commit fd92acef46
3 changed files with 56 additions and 27 deletions

View file

@ -12,15 +12,15 @@
(s/def ::fqdn pred/fqdn-string?) (s/def ::fqdn pred/fqdn-string?)
(s/def ::issuer pred/letsencrypt-issuer?) (s/def ::issuer pred/letsencrypt-issuer?)
(s/def ::maileruser pred/bash-env-string?) (s/def ::mailer-user pred/bash-env-string?)
(s/def ::mailerpw pred/bash-env-string?) (s/def ::mailer-pw pred/bash-env-string?)
(def config-defaults {:issuer "staging"}) (def config-defaults {:issuer "staging"})
(def config? (s/keys :req-un [::fqdn] (def config? (s/keys :req-un [::fqdn]
:opt-un [::issuer])) :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 #?(:cljs
(defmethod yaml/load-resource :gitea [resource-name] (defmethod yaml/load-resource :gitea [resource-name]
@ -43,14 +43,13 @@
(defn-spec generate-appini-env pred/map-or-seq? (defn-spec generate-appini-env pred/map-or-seq?
; TODO: fix this to require the merged spec of auth and config instead of any ; TODO: fix this to require the merged spec of auth and config instead of any
[config 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") (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 "FQDN" fqdn)
(cm/replace-all-matching-values-by-new-value "URL" (str "https://" 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 "FROM" mailer-from)
(cm/replace-all-matching-values-by-new-value "HOST" mailer-host) (cm/replace-all-matching-values-by-new-value "HOSTANDPORT" mailer-host-port)
(cm/replace-all-matching-values-by-new-value "PORT" mailer-port)
(cm/replace-all-matching-values-by-new-value "WHITELISTDOMAINS" service-whitelist-domains) (cm/replace-all-matching-values-by-new-value "WHITELISTDOMAINS" service-whitelist-domains)
))) )))

View file

@ -14,7 +14,7 @@ data:
GITEA__mailer__ENABLED: "true" GITEA__mailer__ENABLED: "true"
GITEA__mailer__FROM: FROM GITEA__mailer__FROM: FROM
GITEA__mailer__MAILER_TYPE: smtp GITEA__mailer__MAILER_TYPE: smtp
GITEA__mailer__HOST: HOST:PORT GITEA__mailer__HOST: HOSTANDPORT
GITEA__mailer__IS_TLS_ENABLED: "true" GITEA__mailer__IS_TLS_ENABLED: "true"
GITEA__service__DISABLE_REGISTRATION: "true" GITEA__service__DISABLE_REGISTRATION: "true"

View file

@ -12,19 +12,25 @@
(st/instrument `cut/generate-secrets) (st/instrument `cut/generate-secrets)
(deftest should-generate-appini-env (deftest should-generate-appini-env
(is (= {:GITEA__database__USER-c1 nil, (is (= {:GITEA__server__DOMAIN-c1 "",
:GITEA__database__USER-c2 "pg-user",
:GITEA__database__PASSWD-c1 nil,
:GITEA__database__PASSWD-c2 "pg-pw",
:GITEA__server__DOMAIN-c1 nil,
:GITEA__server__DOMAIN-c2 "test.com", :GITEA__server__DOMAIN-c2 "test.com",
:GITEA__server__ROOT_URL-c1 "https://", :GITEA__server__ROOT_URL-c1 "https://",
:GITEA__server__ROOT_URL-c2 "https://test.com"} :GITEA__server__ROOT_URL-c2 "https://test.com",
(ct/map-diff (cut/generate-appini-env {}) :GITEA__mailer__FROM-c1 "",
(cut/generate-appini-env {:fqdn "test.com" :GITEA__mailer__FROM-c2 "test@test.com",
:issuer "staging" :GITEA__mailer__HOST-c1 "",
:postgres-db-user "pg-user" :GITEA__mailer__HOST-c2 "mail.test.com:123",
:postgres-db-password "pg-pw"}))))) :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 (deftest should-generate-certificate
(is (= {:name-c2 "prod", :name-c1 "staging"} (is (= {:name-c2 "prod", :name-c1 "staging"}
@ -32,15 +38,39 @@
(cut/generate-certificate {:issuer "prod"}))))) (cut/generate-certificate {:issuer "prod"})))))
(deftest should-generate-secret (deftest should-generate-secret
(is (= {:GITEA__mailer__USER-c1 "", (is (= {:GITEA__database__USER-c1 "",
:GITEA__mailer__USER-c2 (b64/encode "mailuser"), :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-c1 "",
:GITEA__mailer__PASSWD-c2 (b64/encode "mailpw")} :GITEA__mailer__PASSWD-c2 (b64/encode "mailerpw")}
(ct/map-diff (cut/generate-secrets {:postgres-db-user "" (ct/map-diff (cut/generate-secrets {:postgres-db-user ""
:postgres-db-password "" :postgres-db-password ""
:maileruser "" :mailer-user ""
:mailerpw ""}) :mailer-pw ""})
(cut/generate-secrets {:postgres-db-user "" (cut/generate-secrets {:postgres-db-user "pg-user"
:postgres-db-password "" :postgres-db-password "pg-pw"
:maileruser "mailuser" :mailer-user "maileruser"
:mailerpw "mailpw"}))))) :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"}))