MCPcopy
hub / github.com/syncthing/syncthing / TestHTTPGetIndexAuth

Function TestHTTPGetIndexAuth

test/http_test.go:77–125  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

75}
76
77func TestHTTPGetIndexAuth(t *testing.T) {
78 p := startInstance(t, 1)
79 defer checkedStop(t, p)
80
81 // Without auth should give 401
82
83 res, err := http.Get("http://127.0.0.1:8081/")
84 if err != nil {
85 t.Fatal(err)
86 }
87 res.Body.Close()
88 if res.StatusCode != 401 {
89 t.Errorf("Status %d != 401", res.StatusCode)
90 }
91
92 // With wrong username/password should give 401
93
94 req, err := http.NewRequest("GET", "http://127.0.0.1:8081/", nil)
95 if err != nil {
96 t.Fatal(err)
97 }
98 req.SetBasicAuth("testuser", "wrongpass")
99
100 res, err = http.DefaultClient.Do(req)
101 if err != nil {
102 t.Fatal(err)
103 }
104 res.Body.Close()
105 if res.StatusCode != 401 {
106 t.Fatalf("Status %d != 401", res.StatusCode)
107 }
108
109 // With correct username/password should succeed
110
111 req, err = http.NewRequest("GET", "http://127.0.0.1:8081/", nil)
112 if err != nil {
113 t.Fatal(err)
114 }
115 req.SetBasicAuth("testuser", "testpass")
116
117 res, err = http.DefaultClient.Do(req)
118 if err != nil {
119 t.Fatal(err)
120 }
121 res.Body.Close()
122 if res.StatusCode != 200 {
123 t.Fatalf("Status %d != 200", res.StatusCode)
124 }
125}
126
127func TestHTTPOptions(t *testing.T) {
128 p := startInstance(t, 2)

Callers

nothing calls this directly

Calls 6

startInstanceFunction · 0.85
checkedStopFunction · 0.85
FatalMethod · 0.80
DoMethod · 0.80
GetMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected