From ac72ee494c81b62d19e2369cee0f2e4abb37823f Mon Sep 17 00:00:00 2001 From: James Elliott Date: Sun, 26 Feb 2023 13:22:22 +1100 Subject: [PATCH] ci: fix misc and refactorings (#4994) * ci: fix misc and refactorings * ci: additional fix --- internal/server/public_html/index.html | 2 ++ internal/suites/const.go | 4 +-- internal/suites/suite_activedirectory.go | 8 ++--- internal/suites/suite_bypass_all.go | 8 ++--- internal/suites/suite_caddy.go | 8 ++--- internal/suites/suite_cli.go | 4 +-- internal/suites/suite_docker.go | 8 ++--- internal/suites/suite_duo_push.go | 8 ++--- internal/suites/suite_envoy.go | 8 ++--- internal/suites/suite_haproxy.go | 8 ++--- internal/suites/suite_high_availability.go | 8 ++--- internal/suites/suite_ldap.go | 8 ++--- internal/suites/suite_mariadb.go | 8 ++--- internal/suites/suite_multi_cookie_domain.go | 11 ++++--- internal/suites/suite_mysql.go | 8 ++--- internal/suites/suite_network_acl.go | 8 ++--- internal/suites/suite_oidc.go | 11 +++---- internal/suites/suite_oidc_traefik.go | 11 +++---- internal/suites/suite_one_factor_only.go | 8 ++--- internal/suites/suite_pathprefix.go | 8 ++--- internal/suites/suite_postgres.go | 8 ++--- internal/suites/suite_short_timeouts.go | 8 ++--- internal/suites/suite_standalone.go | 8 ++--- internal/suites/suite_traefik.go | 8 ++--- internal/suites/suite_traefik2.go | 8 ++--- internal/suites/utils.go | 34 +++++++++++--------- 26 files changed, 96 insertions(+), 133 deletions(-) diff --git a/internal/server/public_html/index.html b/internal/server/public_html/index.html index 5e384f70f..ca923626d 100644 --- a/internal/server/public_html/index.html +++ b/internal/server/public_html/index.html @@ -5,5 +5,7 @@ "RememberMe":"{{ .RememberMe }}", "ResetPassword":"{{ .ResetPassword }}", "ResetPasswordCustomURL":"{{ .ResetPasswordCustomURL }}", + "PrivacyPolicyURL":"{{ .PrivacyPolicyURL }}", + "PrivacyPolicyAccept":"{{ .PrivacyPolicyAccept }}", "Theme":"{{ .Theme }}" } diff --git a/internal/suites/const.go b/internal/suites/const.go index 5cd016775..3deddf064 100644 --- a/internal/suites/const.go +++ b/internal/suites/const.go @@ -83,8 +83,8 @@ const ( ) const ( - envFileProd = "./web/.env.production" - envFileDev = "./web/.env.development" + envFileProd = "/web/.env.production" + envFileDev = "/web/.env.development" namespaceAuthelia = "authelia" namespaceDashboard = "kubernetes-dashboard" namespaceKube = "kube-system" diff --git a/internal/suites/suite_activedirectory.go b/internal/suites/suite_activedirectory.go index 2446e8e1b..eac3af473 100644 --- a/internal/suites/suite_activedirectory.go +++ b/internal/suites/suite_activedirectory.go @@ -19,14 +19,12 @@ func init() { "internal/suites/example/compose/samba/docker-compose.yml", }) - setup := func(suitePath string) error { - err := dockerEnvironment.Up() - if err != nil { + setup := func(suitePath string) (err error) { + if err = dockerEnvironment.Up(); err != nil { return err } - err = waitUntilAutheliaIsReady(dockerEnvironment, activedirectorySuiteName) - if err != nil { + if err = waitUntilAutheliaIsReady(dockerEnvironment, activedirectorySuiteName); err != nil { return err } diff --git a/internal/suites/suite_bypass_all.go b/internal/suites/suite_bypass_all.go index d593dc8f9..d27b4079e 100644 --- a/internal/suites/suite_bypass_all.go +++ b/internal/suites/suite_bypass_all.go @@ -19,14 +19,12 @@ func init() { "internal/suites/example/compose/smtp/docker-compose.yml", }) - setup := func(suitePath string) error { - err := dockerEnvironment.Up() - if err != nil { + setup := func(suitePath string) (err error) { + if err = dockerEnvironment.Up(); err != nil { return err } - err = waitUntilAutheliaIsReady(dockerEnvironment, bypassAllSuiteName) - if err != nil { + if err = waitUntilAutheliaIsReady(dockerEnvironment, bypassAllSuiteName); err != nil { return err } diff --git a/internal/suites/suite_caddy.go b/internal/suites/suite_caddy.go index 90df0786d..60b1d1ac7 100644 --- a/internal/suites/suite_caddy.go +++ b/internal/suites/suite_caddy.go @@ -32,14 +32,12 @@ func init() { }) } - setup := func(suitePath string) error { - err := dockerEnvironment.Up() - if err != nil { + setup := func(suitePath string) (err error) { + if err = dockerEnvironment.Up(); err != nil { return err } - err = waitUntilAutheliaIsReady(dockerEnvironment, caddySuiteName) - if err != nil { + if err = waitUntilAutheliaIsReady(dockerEnvironment, caddySuiteName); err != nil { return err } diff --git a/internal/suites/suite_cli.go b/internal/suites/suite_cli.go index 7a81f088b..095c4d9e3 100644 --- a/internal/suites/suite_cli.go +++ b/internal/suites/suite_cli.go @@ -15,8 +15,8 @@ func init() { "internal/suites/example/compose/authelia/docker-compose.backend.{}.yml", }) - setup := func(suitePath string) error { - if err := dockerEnvironment.Up(); err != nil { + setup := func(suitePath string) (err error) { + if err = dockerEnvironment.Up(); err != nil { return err } diff --git a/internal/suites/suite_docker.go b/internal/suites/suite_docker.go index 3eeaa9889..d083be134 100644 --- a/internal/suites/suite_docker.go +++ b/internal/suites/suite_docker.go @@ -18,14 +18,12 @@ func init() { "internal/suites/example/compose/smtp/docker-compose.yml", }) - setup := func(suitePath string) error { - err := dockerEnvironment.Up() - if err != nil { + setup := func(suitePath string) (err error) { + if err = dockerEnvironment.Up(); err != nil { return err } - err = waitUntilAutheliaIsReady(dockerEnvironment, dockerSuiteName) - if err != nil { + if err = waitUntilAutheliaIsReady(dockerEnvironment, dockerSuiteName); err != nil { return err } diff --git a/internal/suites/suite_duo_push.go b/internal/suites/suite_duo_push.go index 8a363b1c6..aa5b6484c 100644 --- a/internal/suites/suite_duo_push.go +++ b/internal/suites/suite_duo_push.go @@ -19,14 +19,12 @@ func init() { "internal/suites/example/compose/duo-api/docker-compose.yml", }) - setup := func(suitePath string) error { - err := dockerEnvironment.Up() - if err != nil { + setup := func(suitePath string) (err error) { + if err = dockerEnvironment.Up(); err != nil { return err } - err = waitUntilAutheliaIsReady(dockerEnvironment, duoPushSuiteName) - if err != nil { + if err = waitUntilAutheliaIsReady(dockerEnvironment, duoPushSuiteName); err != nil { return err } diff --git a/internal/suites/suite_envoy.go b/internal/suites/suite_envoy.go index 70a79e86b..f20e3a5ab 100644 --- a/internal/suites/suite_envoy.go +++ b/internal/suites/suite_envoy.go @@ -32,14 +32,12 @@ func init() { }) } - setup := func(suitePath string) error { - err := dockerEnvironment.Up() - if err != nil { + setup := func(suitePath string) (err error) { + if err = dockerEnvironment.Up(); err != nil { return err } - err = waitUntilAutheliaIsReady(dockerEnvironment, envoySuiteName) - if err != nil { + if err = waitUntilAutheliaIsReady(dockerEnvironment, envoySuiteName); err != nil { return err } diff --git a/internal/suites/suite_haproxy.go b/internal/suites/suite_haproxy.go index e65337bef..0ff031c1f 100644 --- a/internal/suites/suite_haproxy.go +++ b/internal/suites/suite_haproxy.go @@ -32,14 +32,12 @@ func init() { }) } - setup := func(suitePath string) error { - err := dockerEnvironment.Up() - if err != nil { + setup := func(suitePath string) (err error) { + if err = dockerEnvironment.Up(); err != nil { return err } - err = waitUntilAutheliaIsReady(dockerEnvironment, haproxySuiteName) - if err != nil { + if err = waitUntilAutheliaIsReady(dockerEnvironment, haproxySuiteName); err != nil { return err } diff --git a/internal/suites/suite_high_availability.go b/internal/suites/suite_high_availability.go index 815125743..b70c7b23b 100644 --- a/internal/suites/suite_high_availability.go +++ b/internal/suites/suite_high_availability.go @@ -23,14 +23,12 @@ var haDockerEnvironment = NewDockerEnvironment([]string{ }) func init() { - setup := func(suitePath string) error { - err := haDockerEnvironment.Up() - if err != nil { + setup := func(suitePath string) (err error) { + if err = haDockerEnvironment.Up(); err != nil { return err } - err = waitUntilAutheliaIsReady(haDockerEnvironment, highAvailabilitySuiteName) - if err != nil { + if err = waitUntilAutheliaIsReady(haDockerEnvironment, highAvailabilitySuiteName); err != nil { return err } diff --git a/internal/suites/suite_ldap.go b/internal/suites/suite_ldap.go index 1d5fcd32e..80b247374 100644 --- a/internal/suites/suite_ldap.go +++ b/internal/suites/suite_ldap.go @@ -20,14 +20,12 @@ func init() { "internal/suites/example/compose/ldap/docker-compose.admin.yml", }) - setup := func(suitePath string) error { - err := dockerEnvironment.Up() - if err != nil { + setup := func(suitePath string) (err error) { + if err = dockerEnvironment.Up(); err != nil { return err } - err = waitUntilAutheliaIsReady(dockerEnvironment, ldapSuiteName) - if err != nil { + if err = waitUntilAutheliaIsReady(dockerEnvironment, ldapSuiteName); err != nil { return err } diff --git a/internal/suites/suite_mariadb.go b/internal/suites/suite_mariadb.go index 51a070607..57c4ef2ee 100644 --- a/internal/suites/suite_mariadb.go +++ b/internal/suites/suite_mariadb.go @@ -20,14 +20,12 @@ func init() { "internal/suites/example/compose/ldap/docker-compose.yml", }) - setup := func(suitePath string) error { - err := dockerEnvironment.Up() - if err != nil { + setup := func(suitePath string) (err error) { + if err = dockerEnvironment.Up(); err != nil { return err } - err = waitUntilAutheliaIsReady(dockerEnvironment, mariadbSuiteName) - if err != nil { + if err = waitUntilAutheliaIsReady(dockerEnvironment, mariadbSuiteName); err != nil { return err } diff --git a/internal/suites/suite_multi_cookie_domain.go b/internal/suites/suite_multi_cookie_domain.go index a6d627864..7506487f3 100644 --- a/internal/suites/suite_multi_cookie_domain.go +++ b/internal/suites/suite_multi_cookie_domain.go @@ -18,13 +18,16 @@ var multiCookieDomainDockerEnvironment = NewDockerEnvironment([]string{ }) func init() { - setup := func(suitePath string) error { - err := multiCookieDomainDockerEnvironment.Up() - if err != nil { + setup := func(suitePath string) (err error) { + if err = multiCookieDomainDockerEnvironment.Up(); err != nil { return err } - return waitUntilAutheliaIsReady(multiCookieDomainDockerEnvironment, multiCookieDomainSuiteName) + if err = waitUntilAutheliaIsReady(multiCookieDomainDockerEnvironment, multiCookieDomainSuiteName); err != nil { + return err + } + + return updateDevEnvFileForDomain(BaseDomain, true) } displayAutheliaLogs := func() error { diff --git a/internal/suites/suite_mysql.go b/internal/suites/suite_mysql.go index ee6d4ebbd..e45119c62 100644 --- a/internal/suites/suite_mysql.go +++ b/internal/suites/suite_mysql.go @@ -20,14 +20,12 @@ func init() { "internal/suites/example/compose/ldap/docker-compose.yml", }) - setup := func(suitePath string) error { - err := dockerEnvironment.Up() - if err != nil { + setup := func(suitePath string) (err error) { + if err = dockerEnvironment.Up(); err != nil { return err } - err = waitUntilAutheliaIsReady(dockerEnvironment, mysqlSuiteName) - if err != nil { + if err = waitUntilAutheliaIsReady(dockerEnvironment, mysqlSuiteName); err != nil { return err } diff --git a/internal/suites/suite_network_acl.go b/internal/suites/suite_network_acl.go index f0a4276ca..6753353e6 100644 --- a/internal/suites/suite_network_acl.go +++ b/internal/suites/suite_network_acl.go @@ -21,14 +21,12 @@ func init() { "internal/suites/example/compose/httpbin/docker-compose.yml", }) - setup := func(suitePath string) error { - err := dockerEnvironment.Up() - if err != nil { + setup := func(suitePath string) (err error) { + if err = dockerEnvironment.Up(); err != nil { return err } - err = waitUntilAutheliaIsReady(dockerEnvironment, networkACLSuiteName) - if err != nil { + if err = waitUntilAutheliaIsReady(dockerEnvironment, networkACLSuiteName); err != nil { return err } diff --git a/internal/suites/suite_oidc.go b/internal/suites/suite_oidc.go index 3f1768697..59ceb8805 100644 --- a/internal/suites/suite_oidc.go +++ b/internal/suites/suite_oidc.go @@ -20,21 +20,18 @@ func init() { "internal/suites/example/compose/redis/docker-compose.yml", }) - setup := func(suitePath string) error { + setup := func(suitePath string) (err error) { // TODO(c.michaud): use version in tags for oidc-client but in the meantime we pull the image to make sure it's // up to date. - err := dockerEnvironment.Pull("oidc-client") - if err != nil { + if err = dockerEnvironment.Pull("oidc-client"); err != nil { return err } - err = dockerEnvironment.Up() - if err != nil { + if err = dockerEnvironment.Up(); err != nil { return err } - err = waitUntilAutheliaIsReady(dockerEnvironment, oidcSuiteName) - if err != nil { + if err = waitUntilAutheliaIsReady(dockerEnvironment, oidcSuiteName); err != nil { return err } diff --git a/internal/suites/suite_oidc_traefik.go b/internal/suites/suite_oidc_traefik.go index 91446986c..5652455e3 100644 --- a/internal/suites/suite_oidc_traefik.go +++ b/internal/suites/suite_oidc_traefik.go @@ -34,21 +34,18 @@ func init() { }) } - setup := func(suitePath string) error { + setup := func(suitePath string) (err error) { // TODO(c.michaud): use version in tags for oidc-client but in the meantime we pull the image to make sure it's // up to date. - err := dockerEnvironment.Pull("oidc-client") - if err != nil { + if err = dockerEnvironment.Pull("oidc-client"); err != nil { return err } - err = dockerEnvironment.Up() - if err != nil { + if err = dockerEnvironment.Up(); err != nil { return err } - err = waitUntilAutheliaIsReady(dockerEnvironment, oidcTraefikSuiteName) - if err != nil { + if err = waitUntilAutheliaIsReady(dockerEnvironment, oidcTraefikSuiteName); err != nil { return err } diff --git a/internal/suites/suite_one_factor_only.go b/internal/suites/suite_one_factor_only.go index 8dcba2f8b..dd12b58ad 100644 --- a/internal/suites/suite_one_factor_only.go +++ b/internal/suites/suite_one_factor_only.go @@ -17,14 +17,12 @@ func init() { "internal/suites/example/compose/nginx/portal/docker-compose.yml", }) - setup := func(suitePath string) error { - err := dockerEnvironment.Up() - if err != nil { + setup := func(suitePath string) (err error) { + if err = dockerEnvironment.Up(); err != nil { return err } - err = waitUntilAutheliaIsReady(dockerEnvironment, oneFactorOnlySuiteName) - if err != nil { + if err = waitUntilAutheliaIsReady(dockerEnvironment, oneFactorOnlySuiteName); err != nil { return err } diff --git a/internal/suites/suite_pathprefix.go b/internal/suites/suite_pathprefix.go index 76cd24fdc..839280403 100644 --- a/internal/suites/suite_pathprefix.go +++ b/internal/suites/suite_pathprefix.go @@ -32,14 +32,12 @@ func init() { }) } - setup := func(suitePath string) error { - err := dockerEnvironment.Up() - if err != nil { + setup := func(suitePath string) (err error) { + if err = dockerEnvironment.Up(); err != nil { return err } - err = waitUntilAutheliaIsReady(dockerEnvironment, pathPrefixSuiteName) - if err != nil { + if err = waitUntilAutheliaIsReady(dockerEnvironment, pathPrefixSuiteName); err != nil { return err } diff --git a/internal/suites/suite_postgres.go b/internal/suites/suite_postgres.go index 7c6042ce1..0512f3294 100644 --- a/internal/suites/suite_postgres.go +++ b/internal/suites/suite_postgres.go @@ -20,14 +20,12 @@ func init() { "internal/suites/example/compose/ldap/docker-compose.yml", }) - setup := func(suitePath string) error { - err := dockerEnvironment.Up() - if err != nil { + setup := func(suitePath string) (err error) { + if err = dockerEnvironment.Up(); err != nil { return err } - err = waitUntilAutheliaIsReady(dockerEnvironment, postgresSuiteName) - if err != nil { + if err = waitUntilAutheliaIsReady(dockerEnvironment, postgresSuiteName); err != nil { return err } diff --git a/internal/suites/suite_short_timeouts.go b/internal/suites/suite_short_timeouts.go index 4d6b4d390..4650e06df 100644 --- a/internal/suites/suite_short_timeouts.go +++ b/internal/suites/suite_short_timeouts.go @@ -18,14 +18,12 @@ func init() { "internal/suites/example/compose/smtp/docker-compose.yml", }) - setup := func(suitePath string) error { - err := dockerEnvironment.Up() - if err != nil { + setup := func(suitePath string) (err error) { + if err = dockerEnvironment.Up(); err != nil { return err } - err = waitUntilAutheliaIsReady(dockerEnvironment, shortTimeoutsSuiteName) - if err != nil { + if err = waitUntilAutheliaIsReady(dockerEnvironment, shortTimeoutsSuiteName); err != nil { return err } diff --git a/internal/suites/suite_standalone.go b/internal/suites/suite_standalone.go index 7125e2d4c..88d4d9f6e 100644 --- a/internal/suites/suite_standalone.go +++ b/internal/suites/suite_standalone.go @@ -23,14 +23,12 @@ func init() { "internal/suites/example/compose/smtp/docker-compose.yml", }) - setup := func(suitePath string) error { - err := dockerEnvironment.Up() - if err != nil { + setup := func(suitePath string) (err error) { + if err = dockerEnvironment.Up(); err != nil { return err } - err = waitUntilAutheliaIsReady(dockerEnvironment, standaloneSuiteName) - if err != nil { + if err = waitUntilAutheliaIsReady(dockerEnvironment, standaloneSuiteName); err != nil { return err } diff --git a/internal/suites/suite_traefik.go b/internal/suites/suite_traefik.go index ffdbb4442..a1cd06267 100644 --- a/internal/suites/suite_traefik.go +++ b/internal/suites/suite_traefik.go @@ -32,14 +32,12 @@ func init() { }) } - setup := func(suitePath string) error { - err := dockerEnvironment.Up() - if err != nil { + setup := func(suitePath string) (err error) { + if err = dockerEnvironment.Up(); err != nil { return err } - err = waitUntilAutheliaIsReady(dockerEnvironment, traefikSuiteName) - if err != nil { + if err = waitUntilAutheliaIsReady(dockerEnvironment, traefikSuiteName); err != nil { return err } diff --git a/internal/suites/suite_traefik2.go b/internal/suites/suite_traefik2.go index 585f8f341..747ef2030 100644 --- a/internal/suites/suite_traefik2.go +++ b/internal/suites/suite_traefik2.go @@ -34,14 +34,12 @@ func init() { }) } - setup := func(suitePath string) error { - err := traefik2DockerEnvironment.Up() - if err != nil { + setup := func(suitePath string) (err error) { + if err = traefik2DockerEnvironment.Up(); err != nil { return err } - err = waitUntilAutheliaIsReady(traefik2DockerEnvironment, traefik2SuiteName) - if err != nil { + if err = waitUntilAutheliaIsReady(traefik2DockerEnvironment, traefik2SuiteName); err != nil { return err } diff --git a/internal/suites/utils.go b/internal/suites/utils.go index 4ed46ad91..c7491e0c7 100644 --- a/internal/suites/utils.go +++ b/internal/suites/utils.go @@ -241,8 +241,8 @@ func fixCoveragePath(path string, file os.FileInfo, err error) error { // getEnvInfoFromURL gets environments variables for specified cookie domain // this func makes a http call to https://login./devworkflow and is only useful for suite tests. -func getDomainEnvInfo(domain string) (map[string]string, error) { - info := make(map[string]string) +func getDomainEnvInfo(domain string) (info map[string]string, err error) { + info = make(map[string]string) client := &http.Client{ Transport: &http.Transport{ @@ -256,7 +256,6 @@ func getDomainEnvInfo(domain string) (map[string]string, error) { req *http.Request resp *http.Response body []byte - err error ) targetURL := LoginBaseURLFmt(domain) + "/devworkflow" @@ -285,16 +284,20 @@ func getDomainEnvInfo(domain string) (map[string]string, error) { } // generateDevEnvFile generates web/.env.development based on opts. -func generateDevEnvFile(opts map[string]string) error { - tmpl, err := template.ParseFiles(envFileProd) - if err != nil { +func generateDevEnvFile(info map[string]string) (err error) { + base, _ := os.Getwd() + base = strings.TrimSuffix(base, "/internal/suites") + + var tmpl *template.Template + + if tmpl, err = template.ParseFiles(base + envFileProd); err != nil { return err } - file, _ := os.Create(envFileDev) + file, _ := os.Create(base + envFileDev) defer file.Close() - if err := tmpl.Execute(file, opts); err != nil { + if err = tmpl.Execute(file, info); err != nil { return err } @@ -303,29 +306,28 @@ func generateDevEnvFile(opts map[string]string) error { // updateDevEnvFileForDomain updates web/.env.development. // this function only affects local dev environments. -func updateDevEnvFileForDomain(domain string, setup bool) error { +func updateDevEnvFileForDomain(domain string, setup bool) (err error) { if os.Getenv("CI") == t { return nil } - if _, err := os.Stat(envFileDev); err != nil && os.IsNotExist(err) { + if _, err = os.Stat(envFileDev); err != nil && os.IsNotExist(err) { file, _ := os.Create(envFileDev) file.Close() } - info, err := getDomainEnvInfo(domain) - if err != nil { + var info map[string]string + + if info, err = getDomainEnvInfo(domain); err != nil { return err } - err = generateDevEnvFile(info) - if err != nil { + if err = generateDevEnvFile(info); err != nil { return err } if !setup { - err = waitUntilAutheliaFrontendIsReady(multiCookieDomainDockerEnvironment) - if err != nil { + if err = waitUntilAutheliaFrontendIsReady(multiCookieDomainDockerEnvironment); err != nil { return err } }