Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Clone

Read only, no credentials:

https://rodent.software/git/vole.git

Write over SSH with a registered key:

git clone ssh://git@0.0.0.0:2222/vole.git

A free and open-source forge that lives in your Git repo.

Blame · server/dev_login_test.go

Line attribution on main · 44 line(s)

f09ef39e
Keenan Nemetz
15d ago
1 package server_test
2
3 // Dev login is a loopback-only development shortcut: no passkey ceremony, no
4 // HTTPS, but the same session and CSRF machinery every write uses.
5
6 import (
7 "net/http"
8 "strings"
9 "testing"
10
d37d301f
Keenan Nemetz
15h ago
11 "rodent.software/vole/forge/config"
f09ef39e
Keenan Nemetz
15d ago
12 )
13
14 func TestDevLoginSignsInALoopbackBrowser(t *testing.T) {
15 t.Parallel()
ed181212
Keenan Nemetz
13d ago
16 f := newFixtureWith(t, func(c *config.Config) { c.DevOnly = true; c.DevLogin = "keenan" })
f09ef39e
Keenan Nemetz
15d ago
17 f.publish(f.repo)
ed181212
Keenan Nemetz
13d ago
18 // The development listener is the address the browser actually reached; in a
19 // real deployment that is what http_addr names.
20 f.cfg.HTTPAddr = f.http.Listener.Addr().String()
f09ef39e
Keenan Nemetz
15d ago
21
ed03b3d1
Keenan Nemetz
2h ago
22 resp, body := f.browserGet(t, "/"+f.repo+"/issues", "")
f09ef39e
Keenan Nemetz
15d ago
23 if resp.StatusCode != http.StatusOK {
24 t.Fatalf("issues page = %d\n%s", resp.StatusCode, body)
25 }
26 if !strings.Contains(body, "New issue") {
27 t.Fatalf("dev login did not grant the owner's write controls:\n%s", body)
28 }
ab326d3a
Keenan Nemetz
14d ago
29 if !strings.Contains(body, `title="Development sign-in"`) {
f09ef39e
Keenan Nemetz
15d ago
30 t.Fatalf("the page does not mark the development session:\n%s", body)
31 }
32 var dev *http.Cookie
33 for _, c := range resp.Cookies() {
34 if c.Name == "vole_dev_session" {
35 dev = c
36 }
37 }
38 if dev == nil {
39 t.Fatal("no development session cookie was set")
40 }
41 if dev.Secure {
42 t.Fatal("the loopback dev cookie is Secure; an HTTP preview cannot return it")
43 }
44 }