TestParseAuthDefinition verifies that parseAuthDefinition correctly maps YAML map keys to AuthDefinition fields.
(t *testing.T)
| 410 | // TestParseAuthDefinition verifies that parseAuthDefinition correctly maps YAML map keys |
| 411 | // to AuthDefinition fields. |
| 412 | func TestParseAuthDefinition(t *testing.T) { |
| 413 | tests := []struct { |
| 414 | name string |
| 415 | input map[string]any |
| 416 | expected AuthDefinition |
| 417 | }{ |
| 418 | { |
| 419 | name: "empty map produces zero-value AuthDefinition", |
| 420 | input: map[string]any{}, |
| 421 | expected: AuthDefinition{}, |
| 422 | }, |
| 423 | { |
| 424 | name: "simple secret only (backwards compat)", |
| 425 | input: map[string]any{ |
| 426 | "secret": "MY_API_KEY", |
| 427 | }, |
| 428 | expected: AuthDefinition{Secret: "MY_API_KEY"}, |
| 429 | }, |
| 430 | { |
| 431 | name: "full oauth-client-credentials config", |
| 432 | input: map[string]any{ |
| 433 | "strategy": "oauth-client-credentials", |
| 434 | "token-url": "https://auth.example.com/oauth/token", |
| 435 | "client-id": "MY_CLIENT_ID", |
| 436 | "client-secret": "MY_CLIENT_SECRET", |
| 437 | "token-field": "access_token", |
| 438 | "header-name": "api-key", |
| 439 | }, |
| 440 | expected: AuthDefinition{ |
| 441 | Strategy: AuthStrategyOAuthClientCreds, |
| 442 | TokenURL: "https://auth.example.com/oauth/token", |
| 443 | ClientIDRef: "MY_CLIENT_ID", |
| 444 | ClientSecretRef: "MY_CLIENT_SECRET", |
| 445 | TokenField: "access_token", |
| 446 | HeaderName: "api-key", |
| 447 | }, |
| 448 | }, |
| 449 | { |
| 450 | name: "api-key strategy with header-name", |
| 451 | input: map[string]any{ |
| 452 | "strategy": "api-key", |
| 453 | "secret": "CUSTOM_API_KEY", |
| 454 | "header-name": "x-api-key", |
| 455 | }, |
| 456 | expected: AuthDefinition{ |
| 457 | Strategy: AuthStrategyAPIKey, |
| 458 | Secret: "CUSTOM_API_KEY", |
| 459 | HeaderName: "x-api-key", |
| 460 | }, |
| 461 | }, |
| 462 | } |
| 463 | |
| 464 | for _, tt := range tests { |
| 465 | t.Run(tt.name, func(t *testing.T) { |
| 466 | result := parseAuthDefinition(tt.input) |
| 467 | require.NotNil(t, result, "parseAuthDefinition should never return nil") |
| 468 | assert.Equal(t, tt.expected, *result, "parsed AuthDefinition should match expected") |
| 469 | }) |
nothing calls this directly
no test coverage detected