(t *testing.T)
| 358 | } |
| 359 | |
| 360 | func TestMCPServerConfigsUserOIDCClearsFields(t *testing.T) { |
| 361 | t.Parallel() |
| 362 | |
| 363 | ctx := testutil.Context(t, testutil.WaitLong) |
| 364 | client := newMCPClient(t) |
| 365 | _ = coderdtest.CreateFirstUser(t, client) |
| 366 | |
| 367 | // Start with an oauth2 config that has a client secret, then |
| 368 | // switch the auth_type to user_oidc and verify all auth-specific |
| 369 | // fields are cleared. |
| 370 | created, err := client.CreateMCPServerConfig(ctx, codersdk.CreateMCPServerConfigRequest{ |
| 371 | DisplayName: "Switch Server", |
| 372 | Slug: "switch-server", |
| 373 | Transport: "streamable_http", |
| 374 | URL: "https://mcp.example.com/v1", |
| 375 | AuthType: "oauth2", |
| 376 | OAuth2ClientID: "cid", |
| 377 | OAuth2ClientSecret: "secret-value", |
| 378 | OAuth2AuthURL: "https://auth.example.com/authorize", |
| 379 | OAuth2TokenURL: "https://auth.example.com/token", |
| 380 | OAuth2Scopes: "read write", |
| 381 | Availability: "default_off", |
| 382 | Enabled: true, |
| 383 | ToolAllowList: []string{}, |
| 384 | ToolDenyList: []string{}, |
| 385 | }) |
| 386 | require.NoError(t, err) |
| 387 | require.True(t, created.HasOAuth2Secret) |
| 388 | require.Equal(t, "cid", created.OAuth2ClientID) |
| 389 | |
| 390 | newAuth := "user_oidc" |
| 391 | updated, err := client.UpdateMCPServerConfig(ctx, created.ID, codersdk.UpdateMCPServerConfigRequest{ |
| 392 | AuthType: &newAuth, |
| 393 | }) |
| 394 | require.NoError(t, err) |
| 395 | require.Equal(t, "user_oidc", updated.AuthType) |
| 396 | require.False(t, updated.HasOAuth2Secret, "oauth2 secret should be cleared") |
| 397 | require.False(t, updated.HasAPIKey, "api key should remain unset") |
| 398 | require.False(t, updated.HasCustomHeaders, "custom headers should remain unset") |
| 399 | require.Empty(t, updated.OAuth2ClientID) |
| 400 | require.Empty(t, updated.OAuth2AuthURL) |
| 401 | require.Empty(t, updated.OAuth2TokenURL) |
| 402 | require.Empty(t, updated.OAuth2Scopes) |
| 403 | require.Empty(t, updated.APIKeyHeader) |
| 404 | } |
| 405 | |
| 406 | func TestMCPServerConfigsUserOIDCDirect(t *testing.T) { |
| 407 | t.Parallel() |
nothing calls this directly
no test coverage detected