Add tests

This commit is contained in:
2024-10-03 14:00:39 +01:00
parent 4b99a4c5fa
commit 8767756431
4 changed files with 675 additions and 71 deletions
+6 -2
View File
@@ -78,6 +78,9 @@ func (t *TraefikOidc) handleLogout(rw http.ResponseWriter, req *http.Request) {
handleError(rw, "Failed to save session", http.StatusInternalServerError, t.logger)
return
}
rw.WriteHeader(http.StatusForbidden)
rw.Write([]byte("Logged out"))
}
func (t *TraefikOidc) handleCallback(rw http.ResponseWriter, req *http.Request) (bool, string) {
@@ -97,15 +100,16 @@ func (t *TraefikOidc) handleCallback(rw http.ResponseWriter, req *http.Request)
code := req.URL.Query().Get("code")
redirectURL := buildFullURL(t.scheme, req.Host, t.redirURLPath)
oauth2Token, err := t.exchangeCodeForToken(ctx, code, redirectURL)
if err != nil {
handleError(rw, "Failed to exchange token", http.StatusInternalServerError, t.logger)
handleError(rw, "Failed to exchange token", http.StatusUnauthorized, t.logger)
return false, ""
}
rawIDToken, ok := oauth2Token["id_token"].(string)
if !ok {
handleError(rw, "No id_token field in oauth2 token", http.StatusInternalServerError, t.logger)
handleError(rw, "No id_token field in oauth2 token", http.StatusUnauthorized, t.logger)
return false, ""
}