Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Fix /deactivate (#2474)
Browse files Browse the repository at this point in the history
* Fix /deactivate

* Update test to correctly check the expected response
  • Loading branch information
S7evinK authored May 20, 2022
1 parent 21dd5a7 commit a53c930
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
7 changes: 2 additions & 5 deletions clientapi/auth/user_interactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ type userInteractiveFlow struct {
// the user already has a valid access token, but we want to double-check
// that it isn't stolen by re-authenticating them.
type UserInteractive struct {
Completed []string
Flows []userInteractiveFlow
Flows []userInteractiveFlow
// Map of login type to implementation
Types map[string]Type
// Map of session ID to completed login types, will need to be extended in future
Expand All @@ -116,7 +115,6 @@ func NewUserInteractive(userAccountAPI api.UserLoginAPI, cfg *config.ClientAPI)
Config: cfg,
}
return &UserInteractive{
Completed: []string{},
Flows: []userInteractiveFlow{
{
Stages: []string{typePassword.Name()},
Expand All @@ -140,7 +138,6 @@ func (u *UserInteractive) IsSingleStageFlow(authType string) bool {

func (u *UserInteractive) AddCompletedStage(sessionID, authType string) {
// TODO: Handle multi-stage flows
u.Completed = append(u.Completed, authType)
delete(u.Sessions, sessionID)
}

Expand All @@ -157,7 +154,7 @@ func (u *UserInteractive) Challenge(sessionID string) *util.JSONResponse {
return &util.JSONResponse{
Code: 401,
JSON: Challenge{
Completed: u.Completed,
Completed: u.Sessions[sessionID],
Flows: u.Flows,
Session: sessionID,
Params: make(map[string]interface{}),
Expand Down
35 changes: 35 additions & 0 deletions clientapi/auth/user_interactive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,38 @@ func TestUserInteractivePasswordBadLogin(t *testing.T) {
}
}
}

func TestUserInteractive_AddCompletedStage(t *testing.T) {
tests := []struct {
name string
sessionID string
}{
{
name: "first user",
sessionID: util.RandomString(8),
},
{
name: "second user",
sessionID: util.RandomString(8),
},
{
name: "third user",
sessionID: util.RandomString(8),
},
}
u := setup()
ctx := context.Background()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, resp := u.Verify(ctx, []byte("{}"), nil)
challenge, ok := resp.JSON.(Challenge)
if !ok {
t.Fatalf("expected a Challenge, got %T", resp.JSON)
}
if len(challenge.Completed) > 0 {
t.Fatalf("expected 0 completed stages, got %d", len(challenge.Completed))
}
u.AddCompletedStage(tt.sessionID, "")
})
}
}

0 comments on commit a53c930

Please sign in to comment.