Skip to content

Commit

Permalink
fix: Change response status to 200 (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsklikas authored and shipperizer committed Jul 11, 2023
1 parent 36d761a commit 89af73b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/kratos/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (a *API) handleCreateFlow(w http.ResponseWriter, r *http.Request) {
// The frontend will call this endpoint with an XHR request, so the status code is
// not that important (the redirect happens based on the response body). But we still send
// a redirect code response to be consistent with the hydra response.
http.Redirect(w, r, redirectTo.RedirectTo, http.StatusSeeOther)
w.WriteHeader(http.StatusOK)
w.Write(resp)
return
}
Expand Down
14 changes: 11 additions & 3 deletions pkg/kratos/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,18 @@ func TestHandleCreateFlowWithSession(t *testing.T) {

res := w.Result()

if res.StatusCode != http.StatusSeeOther {
t.Fatal("Expected HTTP status code 303, got: ", res.Status)
data, err := ioutil.ReadAll(res.Body)
if err != nil {
t.Fatalf("Expected error to be nil got %v", err)
}
redirectResp := hClient.NewOAuth2RedirectToWithDefaults()
if err := json.Unmarshal(data, redirectResp); err != nil {
t.Fatalf("Expected error to be nil got %v", err)
}
if res.StatusCode != http.StatusOK {
t.Fatal("Expected HTTP status code 200, got: ", res.Status)
}
if res.Header["Location"][0] != redirect {
if redirectResp.RedirectTo != redirect {
t.Fatalf("Expected redirect to %s, got: %s", redirect, res.Header["Location"][0])
}
}
Expand Down

0 comments on commit 89af73b

Please sign in to comment.