From d6203fb0d57b90780b9831ff899f89775b5ae05c Mon Sep 17 00:00:00 2001 From: Livio Amstutz Date: Wed, 7 Oct 2020 08:49:23 +0200 Subject: [PATCH] chore: move CAOS_OIDC_DEV to const (and ensure TestValidateIssuer runs (even on machines with env set)) --- pkg/op/config.go | 4 +++- pkg/op/config_test.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/op/config.go b/pkg/op/config.go index b3df943..d64c0ee 100644 --- a/pkg/op/config.go +++ b/pkg/op/config.go @@ -7,6 +7,8 @@ import ( "strings" ) +const OidcDevMode = "CAOS_OIDC_DEV" + type Configuration interface { Issuer() string AuthorizationEndpoint() Endpoint @@ -42,7 +44,7 @@ func ValidateIssuer(issuer string) error { } func devLocalAllowed(url *url.URL) bool { - _, b := os.LookupEnv("CAOS_OIDC_DEV") + _, b := os.LookupEnv(OidcDevMode) if !b { return b } diff --git a/pkg/op/config_test.go b/pkg/op/config_test.go index 79173fb..e140074 100644 --- a/pkg/op/config_test.go +++ b/pkg/op/config_test.go @@ -60,6 +60,8 @@ func TestValidateIssuer(t *testing.T) { true, }, } + //ensure env is not set + os.Unsetenv(OidcDevMode) for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if err := ValidateIssuer(tt.args.issuer); (err != nil) != tt.wantErr { @@ -84,7 +86,7 @@ func TestValidateIssuerDevLocalAllowed(t *testing.T) { false, }, } - os.Setenv("CAOS_OIDC_DEV", "") + os.Setenv(OidcDevMode, "true") for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if err := ValidateIssuer(tt.args.issuer); (err != nil) != tt.wantErr {