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

Function TestAuthManager_authenticate_NoTicket

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

Source from the content-addressed store, hash-verified

319}
320
321func TestAuthManager_authenticate_NoTicket(t *testing.T) {
322 // Create a test server that returns response without ticket
323 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
324 if r.URL.Path == testEndpoint {
325 response := map[string]interface{}{
326 "data": map[string]interface{}{
327 "username": "testuser",
328 // Missing ticket
329 },
330 }
331
332 w.Header().Set("Content-Type", "application/json")
333 _ = json.NewEncoder(w).Encode(response)
334
335 return
336 }
337
338 http.NotFound(w, r)
339 }))
340 defer server.Close()
341
342 httpClient := &HTTPClient{
343 baseURL: server.URL,
344 client: server.Client(),
345 }
346 logger := testutils.NewTestLogger()
347
348 authManager := NewAuthManagerWithPassword(httpClient, "testuser", "testpass", logger)
349
350 token, err := authManager.authenticate(context.Background())
351 assert.Error(t, err)
352 assert.Nil(t, token)
353 assert.Contains(t, err.Error(), "authentication failed: no ticket received")
354}
355
356func TestAuthManager_authenticate_NetworkError(t *testing.T) {
357 // Use an invalid URL to simulate network error

Callers

nothing calls this directly

Calls 8

NewTestLoggerFunction · 0.92
HeaderMethod · 0.80
ClientMethod · 0.80
authenticateMethod · 0.80
SetMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected