diff options
Diffstat (limited to 'internal/handlers/handlers_test.go')
| -rw-r--r-- | internal/handlers/handlers_test.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/internal/handlers/handlers_test.go b/internal/handlers/handlers_test.go index 0ad36b2..b338aa2 100644 --- a/internal/handlers/handlers_test.go +++ b/internal/handlers/handlers_test.go @@ -1971,6 +1971,41 @@ func TestSettingsTemplate_HasCSRFToken(t *testing.T) { "settings.html must expose .CSRFToken (e.g. via meta tag) for JavaScript passkey registration") } +// TestSettingsTemplate_HidesPasskeysWhenDisabled verifies that the settings +// template conditionally shows the passkeys section based on WebAuthnEnabled. +func TestSettingsTemplate_HidesPasskeysWhenDisabled(t *testing.T) { + assertTemplateContains(t, "../../web/templates/settings.html", + ".WebAuthnEnabled", + "settings.html must check .WebAuthnEnabled to conditionally show passkeys section") +} + +// TestHandleSettingsPage_PassesWebAuthnEnabled verifies the settings handler +// includes WebAuthnEnabled in template data. +func TestHandleSettingsPage_PassesWebAuthnEnabled(t *testing.T) { + h, cleanup := setupTestHandler(t) + defer cleanup() + + req := httptest.NewRequest("GET", "/settings", nil) + w := httptest.NewRecorder() + + h.HandleSettingsPage(w, req) + + if w.Code != http.StatusOK { + t.Fatalf("Expected status 200, got %d", w.Code) + } + + mock := h.renderer.(*MockRenderer) + if len(mock.Calls) == 0 { + t.Fatal("Expected renderer to be called") + } + + lastCall := mock.Calls[len(mock.Calls)-1] + dataStr := fmt.Sprintf("%+v", lastCall.Data) + if !strings.Contains(dataStr, "WebAuthnEnabled") { + t.Error("Settings page template data must include WebAuthnEnabled field") + } +} + // TestHandleSettingsPage_PassesCSRFToken verifies the settings handler includes // a CSRFToken in its template data so the passkey registration JS can use it. func TestHandleSettingsPage_PassesCSRFToken(t *testing.T) { |
