| 19 | ) |
| 20 | |
| 21 | func TestLogoutHandler(t *testing.T) { |
| 22 | setUp("/config/testing/handler_logout_url.yml") |
| 23 | handler := http.HandlerFunc(LogoutHandler) |
| 24 | |
| 25 | tests := []struct { |
| 26 | name string |
| 27 | url string |
| 28 | wantcode int |
| 29 | }{ |
| 30 | {"allowed", "http://myapp.example.com/login", http.StatusFound}, |
| 31 | {"allowed", "https://oauth2.googleapis.com/revoke", http.StatusFound}, |
| 32 | {"not allowed", "http://myapp.example.com/loginagain", http.StatusBadRequest}, |
| 33 | {"not allowed", "http://google.com/", http.StatusBadRequest}, |
| 34 | } |
| 35 | |
| 36 | for _, tt := range tests { |
| 37 | t.Run(tt.name, func(t *testing.T) { |
| 38 | req, err := http.NewRequest("GET", "/logout?url="+tt.url, nil) |
| 39 | req.Host = "myapp.example.com" |
| 40 | if err != nil { |
| 41 | t.Fatal(err) |
| 42 | } |
| 43 | rr := httptest.NewRecorder() |
| 44 | handler.ServeHTTP(rr, req) |
| 45 | if rr.Code != tt.wantcode { |
| 46 | t.Errorf("LogoutHandler() status = %v, want %v", rr.Code, tt.wantcode) |
| 47 | } |
| 48 | if rr.Code == http.StatusFound && rr.Header().Get("Location") != tt.url { |
| 49 | t.Errorf("LogoutHandler() redirect = %s, want %s", rr.Header().Get("Location"), tt.url) |
| 50 | } |
| 51 | }) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | func TestProviderLogoutHandler(t *testing.T) { |
| 56 | setUp("/config/testing/handler_logout_provider.yml") |