From 6f0d88467c040280f6c34e763f1a9b1a87d99482 Mon Sep 17 00:00:00 2001 From: spbsoluble <1661003+spbsoluble@users.noreply.github.com> Date: Wed, 16 Oct 2024 17:16:06 -0700 Subject: [PATCH] fix(tests): Only run basic auth tests against basic auth environment and oauth tests against an oauth environment --- auth_providers/auth_basic_test.go | 28 ++++++++++++++++++++++++++++ auth_providers/auth_oauth_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/auth_providers/auth_basic_test.go b/auth_providers/auth_basic_test.go index 50dcff9..d95f0d9 100644 --- a/auth_providers/auth_basic_test.go +++ b/auth_providers/auth_basic_test.go @@ -9,6 +9,12 @@ import ( ) func TestBasicAuthAuthenticator_GetHttpClient(t *testing.T) { + // Skip test if TEST_KEYFACTOR_KC_AUTH is set to 1 or true + if os.Getenv("TEST_KEYFACTOR_KC_AUTH") == "1" || os.Getenv("TEST_KEYFACTOR_KC_AUTH") == "true" { + t.Skip("Skipping TestBasicAuthAuthenticator_GetHttpClient") + return + } + auth := &auth_providers.BasicAuthAuthenticator{ Client: &http.Client{}, } @@ -24,6 +30,11 @@ func TestBasicAuthAuthenticator_GetHttpClient(t *testing.T) { } func TestCommandAuthConfigBasic_ValidateAuthConfig(t *testing.T) { + // Skip test if TEST_KEYFACTOR_KC_AUTH is set to 1 or true + if os.Getenv("TEST_KEYFACTOR_KC_AUTH") == "1" || os.Getenv("TEST_KEYFACTOR_KC_AUTH") == "true" { + t.Skip("Skipping TestBasicAuthAuthenticator_GetHttpClient") + return + } config := &auth_providers.CommandAuthConfigBasic{ Username: os.Getenv(auth_providers.EnvKeyfactorUsername), Password: os.Getenv(auth_providers.EnvKeyfactorPassword), @@ -36,6 +47,12 @@ func TestCommandAuthConfigBasic_ValidateAuthConfig(t *testing.T) { } func TestCommandAuthConfigBasic_GetHttpClient(t *testing.T) { + // Skip test if TEST_KEYFACTOR_KC_AUTH is set to 1 or true + if os.Getenv("TEST_KEYFACTOR_KC_AUTH") == "1" || os.Getenv("TEST_KEYFACTOR_KC_AUTH") == "true" { + t.Skip("Skipping TestBasicAuthAuthenticator_GetHttpClient") + return + } + config := &auth_providers.CommandAuthConfigBasic{ Username: os.Getenv(auth_providers.EnvKeyfactorUsername), Password: os.Getenv(auth_providers.EnvKeyfactorPassword), @@ -52,6 +69,12 @@ func TestCommandAuthConfigBasic_GetHttpClient(t *testing.T) { } func TestCommandAuthConfigBasic_Authenticate(t *testing.T) { + // Skip test if TEST_KEYFACTOR_KC_AUTH is set to 1 or true + if os.Getenv("TEST_KEYFACTOR_KC_AUTH") == "1" || os.Getenv("TEST_KEYFACTOR_KC_AUTH") == "true" { + t.Skip("Skipping TestBasicAuthAuthenticator_GetHttpClient") + return + } + config := &auth_providers.CommandAuthConfigBasic{} err := config.Authenticate() @@ -61,6 +84,11 @@ func TestCommandAuthConfigBasic_Authenticate(t *testing.T) { } func TestCommandAuthConfigBasic_Build(t *testing.T) { + // Skip test if TEST_KEYFACTOR_KC_AUTH is set to 1 or true + if os.Getenv("TEST_KEYFACTOR_KC_AUTH") == "1" || os.Getenv("TEST_KEYFACTOR_KC_AUTH") == "true" { + t.Skip("Skipping TestBasicAuthAuthenticator_GetHttpClient") + return + } config := &auth_providers.CommandAuthConfigBasic{ Username: os.Getenv(auth_providers.EnvKeyfactorUsername), Password: os.Getenv(auth_providers.EnvKeyfactorPassword), diff --git a/auth_providers/auth_oauth_test.go b/auth_providers/auth_oauth_test.go index 5b17147..82a79a8 100644 --- a/auth_providers/auth_oauth_test.go +++ b/auth_providers/auth_oauth_test.go @@ -9,6 +9,11 @@ import ( ) func TestOAuthAuthenticator_GetHttpClient(t *testing.T) { + // Skip test if TEST_KEYFACTOR_AD_AUTH is set to 1 or true + if os.Getenv("TEST_KEYFACTOR_AD_AUTH") == "1" || os.Getenv("TEST_KEYFACTOR_AD_AUTH") == "true" { + t.Skip("Skipping TestOAuthAuthenticator_GetHttpClient") + return + } auth := &auth_providers.OAuthAuthenticator{ Client: &http.Client{}, } @@ -24,6 +29,11 @@ func TestOAuthAuthenticator_GetHttpClient(t *testing.T) { } func TestCommandConfigOauth_ValidateAuthConfig(t *testing.T) { + // Skip test if TEST_KEYFACTOR_AD_AUTH is set to 1 or true + if os.Getenv("TEST_KEYFACTOR_AD_AUTH") == "1" || os.Getenv("TEST_KEYFACTOR_AD_AUTH") == "true" { + t.Skip("Skipping TestOAuthAuthenticator_GetHttpClient") + return + } config := &auth_providers.CommandConfigOauth{ ClientID: os.Getenv(auth_providers.EnvKeyfactorClientID), ClientSecret: os.Getenv(auth_providers.EnvKeyfactorClientSecret), @@ -37,6 +47,11 @@ func TestCommandConfigOauth_ValidateAuthConfig(t *testing.T) { } func TestCommandConfigOauth_GetHttpClient(t *testing.T) { + // Skip test if TEST_KEYFACTOR_AD_AUTH is set to 1 or true + if os.Getenv("TEST_KEYFACTOR_AD_AUTH") == "1" || os.Getenv("TEST_KEYFACTOR_AD_AUTH") == "true" { + t.Skip("Skipping TestOAuthAuthenticator_GetHttpClient") + return + } config := &auth_providers.CommandConfigOauth{ ClientID: os.Getenv(auth_providers.EnvKeyfactorClientID), ClientSecret: os.Getenv(auth_providers.EnvKeyfactorClientSecret), @@ -55,6 +70,11 @@ func TestCommandConfigOauth_GetHttpClient(t *testing.T) { } func TestCommandConfigOauth_Authenticate(t *testing.T) { + // Skip test if TEST_KEYFACTOR_AD_AUTH is set to 1 or true + if os.Getenv("TEST_KEYFACTOR_AD_AUTH") == "1" || os.Getenv("TEST_KEYFACTOR_AD_AUTH") == "true" { + t.Skip("Skipping TestOAuthAuthenticator_GetHttpClient") + return + } config := &auth_providers.CommandConfigOauth{ ClientID: os.Getenv(auth_providers.EnvKeyfactorClientID), ClientSecret: os.Getenv(auth_providers.EnvKeyfactorClientSecret), @@ -69,6 +89,11 @@ func TestCommandConfigOauth_Authenticate(t *testing.T) { } func TestCommandConfigOauth_Build(t *testing.T) { + // Skip test if TEST_KEYFACTOR_AD_AUTH is set to 1 or true + if os.Getenv("TEST_KEYFACTOR_AD_AUTH") == "1" || os.Getenv("TEST_KEYFACTOR_AD_AUTH") == "true" { + t.Skip("Skipping TestOAuthAuthenticator_GetHttpClient") + return + } config := &auth_providers.CommandConfigOauth{ ClientID: os.Getenv(auth_providers.EnvKeyfactorClientID), ClientSecret: os.Getenv(auth_providers.EnvKeyfactorClientSecret),