aboutsummaryrefslogtreecommitdiffstats
path: root/web/web_test.go
diff options
context:
space:
mode:
authorAdam Mathes <adam@adammathes.com>2026-02-12 21:50:56 -0800
committerAdam Mathes <adam@adammathes.com>2026-02-12 21:50:56 -0800
commit42f1b4de384bcbbdab3b80d8e5cc53b36fcffd50 (patch)
tree3a5aab90607131231ec68367f8cc00425d7dc516 /web/web_test.go
parent9db2500fb340ef304c0f15f4379bc33589df9a63 (diff)
downloadneko-42f1b4de384bcbbdab3b80d8e5cc53b36fcffd50.tar.gz
neko-42f1b4de384bcbbdab3b80d8e5cc53b36fcffd50.tar.bz2
neko-42f1b4de384bcbbdab3b80d8e5cc53b36fcffd50.zip
Implement frontend login logic with >90% coverage
Diffstat (limited to 'web/web_test.go')
-rw-r--r--web/web_test.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/web/web_test.go b/web/web_test.go
index e11a98c..a73a6c9 100644
--- a/web/web_test.go
+++ b/web/web_test.go
@@ -317,6 +317,61 @@ func TestAuthWrapHandlerUnauthenticated(t *testing.T) {
}
}
+func TestApiLoginHandlerSuccess(t *testing.T) {
+ config.Config.DigestPassword = "testpass"
+ req := httptest.NewRequest("POST", "/api/login", nil)
+ req.Form = map[string][]string{"password": {"testpass"}}
+ rr := httptest.NewRecorder()
+ apiLoginHandler(rr, req)
+ if rr.Code != http.StatusOK {
+ t.Errorf("Expected 200, got %d", rr.Code)
+ }
+ body := rr.Body.String()
+ if body != `{"status":"ok"}` {
+ t.Errorf("Expected ok status, got %q", body)
+ }
+}
+
+func TestApiLoginHandlerFail(t *testing.T) {
+ config.Config.DigestPassword = "testpass"
+ req := httptest.NewRequest("POST", "/api/login", nil)
+ req.Form = map[string][]string{"password": {"wrongpass"}}
+ rr := httptest.NewRecorder()
+ apiLoginHandler(rr, req)
+ if rr.Code != http.StatusUnauthorized {
+ t.Errorf("Expected 401, got %d", rr.Code)
+ }
+}
+
+func TestApiAuthStatusHandlerAuthenticated(t *testing.T) {
+ config.Config.DigestPassword = "secret"
+ req := httptest.NewRequest("GET", "/api/auth", nil)
+ req.AddCookie(authCookie())
+ rr := httptest.NewRecorder()
+ apiAuthStatusHandler(rr, req)
+ if rr.Code != http.StatusOK {
+ t.Errorf("Expected 200, got %d", rr.Code)
+ }
+ body := rr.Body.String()
+ if body != `{"status":"ok", "authenticated":true}` {
+ t.Errorf("Expected authenticated true, got %q", body)
+ }
+}
+
+func TestApiAuthStatusHandlerUnauthenticated(t *testing.T) {
+ config.Config.DigestPassword = "secret"
+ req := httptest.NewRequest("GET", "/api/auth", nil)
+ rr := httptest.NewRecorder()
+ apiAuthStatusHandler(rr, req)
+ if rr.Code != http.StatusUnauthorized {
+ t.Errorf("Expected 401, got %d", rr.Code)
+ }
+ body := rr.Body.String()
+ if body != `{"status":"error", "authenticated":false}` {
+ t.Errorf("Expected authenticated false, got %q", body)
+ }
+}
+
func TestLoginHandlerGet(t *testing.T) {
req := httptest.NewRequest("GET", "/login/", nil)
rr := httptest.NewRecorder()