MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / TestAuthManager_EnsureAuthenticated_WithPassword

Function TestAuthManager_EnsureAuthenticated_WithPassword

pkg/api/auth_test.go:489–525  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

487}
488
489func 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.
528func BenchmarkAuthToken_IsValid(b *testing.B) {

Callers

nothing calls this directly

Calls 7

NewTestLoggerFunction · 0.92
HeaderMethod · 0.80
ClientMethod · 0.80
EnsureAuthenticatedMethod · 0.80
SetMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected