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

Function TestProviderLogoutHandler

handlers/logout_test.go:55–96  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

53}
54
55func TestProviderLogoutHandler(t *testing.T) {
56 setUp("/config/testing/handler_logout_provider.yml")
57 handler := http.HandlerFunc(LogoutHandler)
58
59 tests := []struct {
60 name string
61 url string
62 wantcode int
63 }{
64 {"allowed", "http://myapp.example.com/login", http.StatusFound},
65 {"allowed", "https://oauth2.googleapis.com/revoke", http.StatusFound},
66 {"not allowed", "http://myapp.example.com/loginagain", http.StatusBadRequest},
67 {"not allowed", "http://google.com/", http.StatusBadRequest},
68 }
69
70 for _, tt := range tests {
71 t.Run(tt.name, func(t *testing.T) {
72 req, err := http.NewRequest("GET", "/logout?url="+tt.url, nil)
73 if err != nil {
74 t.Fatal(err)
75 }
76 rr := httptest.NewRecorder()
77 handler.ServeHTTP(rr, req)
78 if rr.Code != tt.wantcode {
79 t.Errorf("LogoutHandler() status = %v, want %v", rr.Code, tt.wantcode)
80 }
81 if rr.Code == http.StatusFound {
82 wanted := tt.url
83 req, _ := http.NewRequest("GET", cfg.GenOAuth.LogoutURL, nil)
84
85 q := req.URL.Query()
86 q.Add("post_logout_redirect_uri", wanted)
87 req.URL.RawQuery = q.Encode()
88 wanted = req.URL.String()
89
90 if rr.Header().Get("Location") != wanted {
91 t.Errorf("LogoutHandler() redirect = %s, want %s", rr.Header().Get("Location"), wanted)
92 }
93 }
94 })
95 }
96}

Callers

nothing calls this directly

Calls 2

HeaderMethod · 0.80
setUpFunction · 0.70

Tested by

no test coverage detected