(t *testing.T)
| 321 | } |
| 322 | |
| 323 | func TestHTTPClient_UnauthorizedWithTicketAuth(t *testing.T) { |
| 324 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 325 | w.WriteHeader(http.StatusUnauthorized) |
| 326 | _, _ = w.Write([]byte("Unauthorized")) |
| 327 | })) |
| 328 | defer server.Close() |
| 329 | |
| 330 | client := NewHTTPClient(server.Client(), server.URL, testutils.NewTestLogger()) |
| 331 | |
| 332 | // Create mock auth manager |
| 333 | authManager := NewAuthManagerWithPassword(client, "user", "pass", testutils.NewTestLogger()) |
| 334 | authManager.authToken = &AuthToken{ |
| 335 | Ticket: "expired-ticket", |
| 336 | CSRFToken: "expired-csrf", |
| 337 | ExpiresAt: time.Now().Add(1 * time.Hour), |
| 338 | } |
| 339 | client.SetAuthManager(authManager) |
| 340 | |
| 341 | var result map[string]interface{} |
| 342 | err := client.Get(context.Background(), "/test", &result) |
| 343 | |
| 344 | require.Error(t, err) |
| 345 | assert.Contains(t, err.Error(), "authentication failed") |
| 346 | |
| 347 | // Verify that the token was cleared |
| 348 | assert.Nil(t, authManager.authToken) |
| 349 | } |
| 350 | |
| 351 | func TestHTTPClient_InvalidJSON(t *testing.T) { |
| 352 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
nothing calls this directly
no test coverage detected