Skip to content

Commit c60d745

Browse files
committed
fix(test): Toggle tests against Command environments with non-trusted CA certs.
1 parent 9b3cefa commit c60d745

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

.github/workflows/go_tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@ jobs:
4646
KEYFACTOR_SKIP_VERIFY: ${{ vars.KEYFACTOR_SKIP_VERIFY }}
4747
TEST_KEYFACTOR_AD_AUTH: ${{ vars.TEST_KEYFACTOR_AD_AUTH }}
4848
TEST_KEYFACTOR_OAUTH: ${{ vars.TEST_KEYFACTOR_OAUTH }}
49+
TEST_UNTRUSTED_CERT: ${{ vars.TEST_UNTRUSTED_CERT }}
4950
KEYFACTOR_API_PATH: ${{ vars.KEYFACTOR_API_PATH }}

auth_providers/auth_oauth_test.go

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,22 @@ func TestCommandConfigOauth_Authenticate(t *testing.T) {
188188
// end test case
189189

190190
// Begin test case
191-
noParamsConfig = &auth_providers.CommandConfigOauth{}
192-
httpsFailEnvExpected := []string{"tls: failed to verify certificate"}
193-
authOauthTest(
194-
t,
195-
fmt.Sprintf("w/o env %s", auth_providers.EnvKeyfactorCACert),
196-
true,
197-
noParamsConfig,
198-
httpsFailEnvExpected...,
199-
)
191+
192+
if os.Getenv("TEST_UNTRUSTED_CERT") == "1" || os.Getenv("TEST_UNTRUSTED_CERT") == "true" {
193+
noParamsConfig = &auth_providers.CommandConfigOauth{}
194+
httpsFailEnvExpected := []string{"tls: failed to verify certificate"}
195+
t.Log("Testing oAuth with https fail env")
196+
t.Logf("Setting environment variable %s", auth_providers.EnvKeyfactorSkipVerify)
197+
os.Setenv(auth_providers.EnvKeyfactorSkipVerify, "false")
198+
authOauthTest(
199+
t,
200+
fmt.Sprintf("w/o env %s", auth_providers.EnvKeyfactorCACert),
201+
true,
202+
noParamsConfig,
203+
httpsFailEnvExpected...,
204+
)
205+
}
206+
200207
// end test case
201208

202209
t.Log("Testing oAuth with invalid config file path")
@@ -314,15 +321,17 @@ func TestCommandConfigOauth_Authenticate(t *testing.T) {
314321
t.Logf("Unsetting environment variable %s", auth_providers.EnvKeyfactorSkipVerify)
315322
os.Unsetenv(auth_providers.EnvKeyfactorSkipVerify)
316323

317-
t.Log("Testing oAuth with valid implicit config file https fail")
318-
httpsFailConfigFile := &auth_providers.CommandConfigOauth{}
319-
httpsFailConfigFile.
320-
WithConfigProfile("oauth")
321-
httpsFailConfigFileExpected := []string{"tls: failed to verify certificate"}
322-
authOauthTest(
323-
t, "oAuth with valid implicit config file https fail", true, httpsFailConfigFile,
324-
httpsFailConfigFileExpected...,
325-
)
324+
if os.Getenv("TEST_UNTRUSTED_CERT") == "1" || os.Getenv("TEST_UNTRUSTED_CERT") == "true" {
325+
t.Log("Testing oAuth with valid implicit config file https fail")
326+
httpsFailConfigFile := &auth_providers.CommandConfigOauth{}
327+
httpsFailConfigFile.
328+
WithConfigProfile("oauth")
329+
httpsFailConfigFileExpected := []string{"tls: failed to verify certificate"}
330+
authOauthTest(
331+
t, "oAuth with valid implicit config file https fail", true, httpsFailConfigFile,
332+
httpsFailConfigFileExpected...,
333+
)
334+
}
326335

327336
t.Log("Testing oAuth with invalid profile implicit config file")
328337
invProfile := &auth_providers.CommandConfigOauth{}

0 commit comments

Comments
 (0)