MCPcopy
hub / github.com/vouch/vouch-proxy / TestLoginHandler

Function TestLoginHandler

handlers/login_test.go:183–221  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

181 }
182}
183func TestLoginHandler(t *testing.T) {
184 handler := http.HandlerFunc(LoginHandler)
185
186 tests := []struct {
187 name string
188 configFile string
189 wantcode int
190 }{
191 {"general test", "/config/testing/handler_login_url.yml", http.StatusFound},
192 {"general test", "/config/testing/handler_login_redirecturls.yml", http.StatusFound},
193 }
194
195 for _, tt := range tests {
196 t.Run(tt.name, func(t *testing.T) {
197 setUp(tt.configFile)
198
199 req, err := http.NewRequest("GET", "/logout?url=http://myapp.example.com/login", nil)
200 if err != nil {
201 t.Fatal(err)
202 }
203 rr := httptest.NewRecorder()
204 handler.ServeHTTP(rr, req)
205
206 if rr.Code != tt.wantcode {
207 t.Errorf("LogoutHandler() status = %v, want %v", rr.Code, tt.wantcode)
208 }
209
210 // confirm the OAuthClient has a properly configured
211 redirectURL, err := url.Parse(rr.Header()["Location"][0])
212 if err != nil {
213 t.Fatal(err)
214 }
215 redirectParam := redirectURL.Query().Get("redirect_uri")
216 assert.NotEmpty(t, cfg.OAuthClient.RedirectURL, "cfg.OAuthClient.RedirectURL is empty")
217 assert.NotEmpty(t, redirectParam, "redirect_uri should not be empty when redirected to google oauth")
218
219 })
220 }
221}
222func TestLoginErrTooManyRedirects(t *testing.T) {
223
224 handler := http.HandlerFunc(LoginHandler)

Callers

nothing calls this directly

Calls 2

HeaderMethod · 0.80
setUpFunction · 0.70

Tested by

no test coverage detected