Skip to content

Commit

Permalink
Fix following first CI errors & complete tests
Browse files Browse the repository at this point in the history
Signed-off-by: Romain Caire <[email protected]>
  • Loading branch information
supercairos committed Mar 8, 2024
1 parent 85e78fb commit 3c5a336
Show file tree
Hide file tree
Showing 4 changed files with 299 additions and 108 deletions.
19 changes: 11 additions & 8 deletions server/introspectionhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strconv"

"github.com/coreos/go-oidc/v3/oidc"

"github.com/dexidp/dex/server/internal"
)

Expand All @@ -18,8 +19,8 @@ type introspectionError struct {
desc string
}

func (r *introspectionError) Error() string {
return fmt.Sprintf("introspection error: status %d, %q %s", r.code, r.typ, r.desc)
func (e *introspectionError) Error() string {
return fmt.Sprintf("introspection error: status %d, %q %s", e.code, e.typ, e.desc)
}

func (e *introspectionError) Is(tgt error) bool {
Expand All @@ -33,15 +34,15 @@ func (e *introspectionError) Is(tgt error) bool {
e.desc == target.desc
}

func newIntrospectInactiveTokenError() error {
func newIntrospectInactiveTokenError() *introspectionError {
return &introspectionError{typ: errInactiveToken, desc: "", code: http.StatusUnauthorized}
}

func newIntrospectInternalServerError() error {
return &introspectionError{typ: errInvalidRequest, desc: "", code: http.StatusInternalServerError}
func newIntrospectInternalServerError() *introspectionError {
return &introspectionError{typ: errServerError, desc: "", code: http.StatusInternalServerError}
}

func newIntrospectBadRequestError(desc string) error {
func newIntrospectBadRequestError(desc string) *introspectionError {
return &introspectionError{typ: errInvalidRequest, desc: desc, code: http.StatusBadRequest}
}

Expand Down Expand Up @@ -176,15 +177,17 @@ func (s *Server) handleIntrospect(w http.ResponseWriter, r *http.Request) {
s.logger.Errorf("An unknown error occurred: %s", err.Error())
s.introspectErrHelper(w, errServerError, "An unknown error occurred", http.StatusInternalServerError)
}

return
}

rawJson, jsonErr := json.Marshal(introspect)
rawJSON, jsonErr := json.Marshal(introspect)
if jsonErr != nil {
s.introspectErrHelper(w, errServerError, jsonErr.Error(), 500)
}

w.Header().Set("Content-Type", "application/json")
w.Write(rawJson)
w.Write(rawJSON)
}

func (s *Server) introspectErrHelper(w http.ResponseWriter, typ string, description string, statusCode int) {
Expand Down
Loading

0 comments on commit 3c5a336

Please sign in to comment.