Skip to content

Commit

Permalink
bug: fix renable totpAllowed = true after disable
Browse files Browse the repository at this point in the history
Signed-off-by: Sarah Funkhouser <[email protected]>
  • Loading branch information
golanglemonade committed Jan 28, 2025
1 parent d0b1069 commit 0507f1a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/ent/hooks/tfasettings.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ func HookVerifyTFA() ent.Hook {
if ok && !totpAllowed {
// if TOTP is not allowed, clear the TFA settings
m.SetVerified(false)
m.SetRecoveryCodes(nil)
m.SetTfaSecret("")
m.ClearRecoveryCodes()
m.ClearTfaSecret()

// disable TFA on the user settings
if err := setUserTFASetting(ctx, m, false); err != nil {
Expand Down
5 changes: 4 additions & 1 deletion internal/graphapi/tfasetting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (suite *GraphTestSuite) TestMutationUpdateTFASetting() {
TotpAllowed: lo.ToPtr(true),
},
client: suite.client.api,
ctx: testUser2.UserCtx,
ctx: testUser1.UserCtx,
},
}

Expand Down Expand Up @@ -272,6 +272,9 @@ func (suite *GraphTestSuite) TestMutationUpdateTFASetting() {
} else if !*tc.input.TotpAllowed { // settings were cleared
assert.Empty(t, resp.UpdateTFASetting.QRCode)
assert.Empty(t, resp.UpdateTFASetting.TfaSecret)
assert.Empty(t, resp.UpdateTFASetting.RecoveryCodes)
assert.False(t, resp.UpdateTFASetting.TfaSetting.Verified)
assert.False(t, *resp.UpdateTFASetting.TfaSetting.TotpAllowed)
}

// make sure user setting is updated correctly
Expand Down

0 comments on commit 0507f1a

Please sign in to comment.