From 5697bf17387e5b985fc37347fa9e2713468f50d2 Mon Sep 17 00:00:00 2001 From: Pritesh Lahoti Date: Mon, 23 Sep 2024 14:36:40 +0530 Subject: [PATCH] ccl/oidcccl: TestOIDCEnabled failed under stress TestOIDCEnabled used to update the OIDC related cluster settings via SQL. This takes time to get reflected within the application handler and flakes the test under stress. Updated the unit test to directly override cluster setting values within the application. Fixes: #130637 Release note: None --- pkg/ccl/oidcccl/authentication_oidc_test.go | 23 ++++++++------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/pkg/ccl/oidcccl/authentication_oidc_test.go b/pkg/ccl/oidcccl/authentication_oidc_test.go index 51aeb62b7b28..43a5d29803c7 100644 --- a/pkg/ccl/oidcccl/authentication_oidc_test.go +++ b/pkg/ccl/oidcccl/authentication_oidc_test.go @@ -126,22 +126,17 @@ func TestOIDCEnabled(t *testing.T) { NewOIDCManager = realNewManager }() - // Set minimum settings to successfully enable the OIDC client sqlDB := sqlutils.MakeSQLRunner(db) sqlDB.Exec(t, fmt.Sprintf(`CREATE USER %s with password 'unused'`, usernameUnderTest)) - sqlDB.Exec(t, `SET CLUSTER SETTING server.oidc_authentication.provider_url = "providerURL"`) - sqlDB.Exec(t, `SET CLUSTER SETTING server.oidc_authentication.client_id = "fake_client_id"`) - sqlDB.Exec(t, `SET CLUSTER SETTING server.oidc_authentication.client_secret = "fake_client_secret"`) - sqlDB.Exec(t, `SET CLUSTER SETTING server.oidc_authentication.redirect_url = "https://cockroachlabs.com/oidc/v1/callback"`) - sqlDB.Exec(t, `set cluster setting server.oidc_authentication.claim_json_key = "email"`) - sqlDB.Exec(t, `set cluster setting server.oidc_authentication.principal_regex = '^([^@]+)@[^@]+$'`) - sqlDB.Exec(t, fmt.Sprintf(`SET CLUSTER SETTING server.http.base_path = "%s"`, basePath)) - // Setting the `server.oidc_authentication.enabled` cluster setting through - // SQL command adds an overhead in updating the `OIDCEnabled` var. - // This fails the test under stress as the value of `OIDCEnabled` var - // determines the response to the `/oidc/v1/login` API handler. - // Hence, it is recommended to override the value directly. - // TODO(pritesh-lahoti): Refactor the above OIDC cluster setting statements. + + // Set minimum settings to successfully enable the OIDC client + OIDCProviderURL.Override(ctx, &s.ClusterSettings().SV, "providerURL") + OIDCClientID.Override(ctx, &s.ClusterSettings().SV, "fake_client_id") + OIDCClientSecret.Override(ctx, &s.ClusterSettings().SV, "fake_client_secret") + OIDCRedirectURL.Override(ctx, &s.ClusterSettings().SV, "https://cockroachlabs.com/oidc/v1/callback") + OIDCClaimJSONKey.Override(ctx, &s.ClusterSettings().SV, "email") + OIDCPrincipalRegex.Override(ctx, &s.ClusterSettings().SV, "^([^@]+)@[^@]+$") + server.ServerHTTPBasePath.Override(ctx, &s.ClusterSettings().SV, basePath) OIDCEnabled.Override(ctx, &s.ClusterSettings().SV, true) testCertsContext := s.NewClientRPCContext(ctx, username.TestUserName())