(t *testing.T)
| 487 | } |
| 488 | |
| 489 | func TestAuthManager_EnsureAuthenticated_WithPassword(t *testing.T) { |
| 490 | // Create a test server for authentication |
| 491 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 492 | if r.URL.Path == testEndpoint { |
| 493 | response := map[string]interface{}{ |
| 494 | "data": map[string]interface{}{ |
| 495 | "ticket": "ensure-auth-ticket", |
| 496 | "CSRFPreventionToken": "ensure-auth-csrf", |
| 497 | "username": "testuser", |
| 498 | }, |
| 499 | } |
| 500 | |
| 501 | w.Header().Set("Content-Type", "application/json") |
| 502 | _ = json.NewEncoder(w).Encode(response) |
| 503 | |
| 504 | return |
| 505 | } |
| 506 | |
| 507 | http.NotFound(w, r) |
| 508 | })) |
| 509 | defer server.Close() |
| 510 | |
| 511 | httpClient := &HTTPClient{ |
| 512 | baseURL: server.URL, |
| 513 | client: server.Client(), |
| 514 | } |
| 515 | logger := testutils.NewTestLogger() |
| 516 | |
| 517 | authManager := NewAuthManagerWithPassword(httpClient, "testuser", "testpass", logger) |
| 518 | |
| 519 | err := authManager.EnsureAuthenticated() |
| 520 | assert.NoError(t, err) |
| 521 | |
| 522 | // Verify that authentication was performed |
| 523 | assert.NotNil(t, authManager.authToken) |
| 524 | assert.Equal(t, "ensure-auth-ticket", authManager.authToken.Ticket) |
| 525 | } |
| 526 | |
| 527 | // Benchmark tests. |
| 528 | func BenchmarkAuthToken_IsValid(b *testing.B) { |
nothing calls this directly
no test coverage detected