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

Commit a53c930

Browse files
authored
Fix /deactivate (#2474)
* Fix /deactivate * Update test to correctly check the expected response
1 parent 21dd5a7 commit a53c930

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

clientapi/auth/user_interactive.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ type userInteractiveFlow struct {
102102
// the user already has a valid access token, but we want to double-check
103103
// that it isn't stolen by re-authenticating them.
104104
type UserInteractive struct {
105-
Completed []string
106-
Flows []userInteractiveFlow
105+
Flows []userInteractiveFlow
107106
// Map of login type to implementation
108107
Types map[string]Type
109108
// Map of session ID to completed login types, will need to be extended in future
@@ -116,7 +115,6 @@ func NewUserInteractive(userAccountAPI api.UserLoginAPI, cfg *config.ClientAPI)
116115
Config: cfg,
117116
}
118117
return &UserInteractive{
119-
Completed: []string{},
120118
Flows: []userInteractiveFlow{
121119
{
122120
Stages: []string{typePassword.Name()},
@@ -140,7 +138,6 @@ func (u *UserInteractive) IsSingleStageFlow(authType string) bool {
140138

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

@@ -157,7 +154,7 @@ func (u *UserInteractive) Challenge(sessionID string) *util.JSONResponse {
157154
return &util.JSONResponse{
158155
Code: 401,
159156
JSON: Challenge{
160-
Completed: u.Completed,
157+
Completed: u.Sessions[sessionID],
161158
Flows: u.Flows,
162159
Session: sessionID,
163160
Params: make(map[string]interface{}),

clientapi/auth/user_interactive_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,38 @@ func TestUserInteractivePasswordBadLogin(t *testing.T) {
187187
}
188188
}
189189
}
190+
191+
func TestUserInteractive_AddCompletedStage(t *testing.T) {
192+
tests := []struct {
193+
name string
194+
sessionID string
195+
}{
196+
{
197+
name: "first user",
198+
sessionID: util.RandomString(8),
199+
},
200+
{
201+
name: "second user",
202+
sessionID: util.RandomString(8),
203+
},
204+
{
205+
name: "third user",
206+
sessionID: util.RandomString(8),
207+
},
208+
}
209+
u := setup()
210+
ctx := context.Background()
211+
for _, tt := range tests {
212+
t.Run(tt.name, func(t *testing.T) {
213+
_, resp := u.Verify(ctx, []byte("{}"), nil)
214+
challenge, ok := resp.JSON.(Challenge)
215+
if !ok {
216+
t.Fatalf("expected a Challenge, got %T", resp.JSON)
217+
}
218+
if len(challenge.Completed) > 0 {
219+
t.Fatalf("expected 0 completed stages, got %d", len(challenge.Completed))
220+
}
221+
u.AddCompletedStage(tt.sessionID, "")
222+
})
223+
}
224+
}

0 commit comments

Comments
 (0)