-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve debugging/DX when enabling MFA (#822)
* fix: improve debugging/DX when enabling MFA * feat: add list of unsatisfied factors to error message * test: add test that checks that the mfa info endpoint errors if user is stuck
- Loading branch information
Showing
12 changed files
with
113 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -226,6 +226,64 @@ describe(`mfa-api: ${printPath("[test/mfa/mfa.api.test.js]")}`, function () { | |
assert.deepEqual(["emailpassword", "otp-email", "totp"], res.body.factors.allowedToSetup); | ||
}); | ||
|
||
it("mfa info errors if the user is stuck", async function () { | ||
const connectionURI = await startSTWithMultitenancy(); | ||
let requireFactor = false; | ||
|
||
SuperTokens.init({ | ||
supertokens: { | ||
connectionURI, | ||
}, | ||
appInfo: { | ||
apiDomain: "api.supertokens.io", | ||
appName: "SuperTokens", | ||
websiteDomain: "supertokens.io", | ||
}, | ||
recipeList: [ | ||
EmailPassword.init(), | ||
ThirdParty.init(), | ||
AccountLinking.init({ | ||
shouldDoAutomaticAccountLinking: async () => ({ | ||
shouldAutomaticallyLink: true, | ||
shouldRequireVerification: true, | ||
}), | ||
}), | ||
MultiFactorAuth.init({ | ||
override: { | ||
functions: (oI) => ({ | ||
...oI, | ||
getMFARequirementsForAuth: () => (requireFactor ? ["otp-phone"] : []), | ||
}), | ||
}, | ||
}), | ||
Session.init(), | ||
], | ||
}); | ||
|
||
const app = getTestExpressApp(); | ||
|
||
await EmailPassword.signUp("public", "[email protected]", "password"); | ||
|
||
let res = await epSignIn(app, "[email protected]", "password"); | ||
assert.equal("OK", res.body.status); | ||
|
||
let cookies = extractInfoFromResponse(res); | ||
const accessToken = cookies.accessTokenFromAny; | ||
|
||
res = await getMfaInfo(app, accessToken); | ||
assert.equal("OK", res.body.status); | ||
assert.deepEqual([], res.body.factors.next); | ||
|
||
requireFactor = true; | ||
|
||
res = await getMfaInfo(app, accessToken, 500); | ||
assert( | ||
res.text.includes( | ||
"The user is required to complete secondary factors they are not allowed to (otp-phone), likely because of configuration issues." | ||
) | ||
); | ||
}); | ||
|
||
it("test that only a valid first factor is allowed to login", async function () { | ||
const connectionURI = await startSTWithMultitenancy(); | ||
SuperTokens.init({ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters