MCPcopy Index your code
hub / github.com/ZenNotes/zennotes / loginAndJar

Function loginAndJar

apps/server/internal/httpserver/security_test.go:44–61  ·  view source on GitHub ↗

loginAndJar logs in with the given token and returns a cookiejar that subsequent calls can reuse.

(t *testing.T, server *httptest.Server, token string)

Source from the content-addressed store, hash-verified

42// loginAndJar logs in with the given token and returns a cookiejar
43// that subsequent calls can reuse.
44func loginAndJar(t *testing.T, server *httptest.Server, token string) http.CookieJar {
45 t.Helper()
46 jar, err := cookiejar.New(nil)
47 if err != nil {
48 t.Fatalf("cookiejar.New: %v", err)
49 }
50 client := &http.Client{Jar: jar}
51 body, _ := json.Marshal(map[string]string{"token": token})
52 resp, err := client.Post(server.URL+"/api/session/login", "application/json", bytes.NewReader(body))
53 if err != nil {
54 t.Fatalf("login: %v", err)
55 }
56 defer resp.Body.Close()
57 if resp.StatusCode != http.StatusOK {
58 t.Fatalf("login status: %d", resp.StatusCode)
59 }
60 return jar
61}
62
63func TestSessionLoginProtectsVaultRoutes(t *testing.T) {
64 root := t.TempDir()

Calls 1

CloseMethod · 0.80

Tested by

no test coverage detected