(t *testing.T)
| 3264 | } |
| 3265 | |
| 3266 | func TestNewDatabaseContextWithOIDCProviderOptions(t *testing.T) { |
| 3267 | tests := []struct { |
| 3268 | name string |
| 3269 | inputOptions *auth.OIDCOptions |
| 3270 | expectedError string |
| 3271 | }{ |
| 3272 | // Mock valid OIDCOptions |
| 3273 | { |
| 3274 | name: "TestWithValidOptions", |
| 3275 | inputOptions: mockOIDCOptions(), |
| 3276 | expectedError: "", |
| 3277 | }, |
| 3278 | // If Validation Key not defined in config for provider, it should warn auth code flow will not be |
| 3279 | // supported for this provider. |
| 3280 | { |
| 3281 | name: "TestWithNoValidationKey", |
| 3282 | inputOptions: mockOIDCOptionsWithNoValidationKey(), |
| 3283 | expectedError: "", |
| 3284 | }, |
| 3285 | |
| 3286 | // Input to simulate the scenario where the current provider is the default provider, or there's are |
| 3287 | // providers defined, don't set IsDefault. |
| 3288 | { |
| 3289 | name: "TestWithMultipleProviders", |
| 3290 | inputOptions: mockOIDCOptionsWithMultipleProviders(), |
| 3291 | expectedError: "", |
| 3292 | }, |
| 3293 | // Input to simulate the scenario where the current provider isn't the default provider, add the provider |
| 3294 | // to the callback URL (needed to identify provider to _oidc_callback) |
| 3295 | { |
| 3296 | name: "TestWithMultipleProvidersAndCustomCallbackURL", |
| 3297 | inputOptions: mockOIDCOptionsWithMultipleProvidersCBQ(), |
| 3298 | expectedError: "", |
| 3299 | }, |
| 3300 | } |
| 3301 | |
| 3302 | for _, tc := range tests { |
| 3303 | t.Run(tc.name, func(t *testing.T) { |
| 3304 | tBucket := base.GetTestBucket(t) |
| 3305 | options := DatabaseContextOptions{ |
| 3306 | OIDCOptions: tc.inputOptions, |
| 3307 | Scopes: GetScopesOptions(t, tBucket, 1), |
| 3308 | } |
| 3309 | AddOptionsFromEnvironmentVariables(&options) |
| 3310 | |
| 3311 | ctx := base.TestCtx(t) |
| 3312 | dbCtx, err := NewDatabaseContext(ctx, "db", tBucket, false, options) |
| 3313 | assert.NoError(t, err, "Couldn't create context for database 'db'") |
| 3314 | defer dbCtx.Close(ctx) |
| 3315 | assert.NotNil(t, dbCtx, "Database context should be created") |
| 3316 | |
| 3317 | database, err := CreateDatabase(dbCtx) |
| 3318 | assert.NotNil(t, database, "Database should be created with context options") |
| 3319 | assert.NoError(t, err, "Couldn't create database 'db'") |
| 3320 | }) |
| 3321 | } |
| 3322 | } |
| 3323 |
nothing calls this directly
no test coverage detected