-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ade3611
commit 3276174
Showing
2 changed files
with
200 additions
and
37 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
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 |
---|---|---|
|
@@ -103,7 +103,7 @@ describe(`recipeImplementationFunctions: ${printPath("[test/webauthn/recipeImple | |
assert.equal(generatedOptions.user.displayName, email); | ||
}); | ||
|
||
it("should throw an error if the recover account token is invalid", async function () { | ||
it("should return the correct error if the recover account token is invalid", async function () { | ||
await initST(); | ||
|
||
const generatedOptions = await getWebAuthnRecipe().recipeInterfaceImpl.registerOptions({ | ||
|
@@ -118,7 +118,7 @@ describe(`recipeImplementationFunctions: ${printPath("[test/webauthn/recipeImple | |
assert.equal(generatedOptions.status, "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR"); | ||
}); | ||
|
||
it("should throw an error if the email is invalid", async function () { | ||
it("should return the correct error if the email is invalid", async function () { | ||
await initST(); | ||
|
||
const generatedOptions = await getWebAuthnRecipe().recipeInterfaceImpl.registerOptions({ | ||
|
@@ -133,7 +133,7 @@ describe(`recipeImplementationFunctions: ${printPath("[test/webauthn/recipeImple | |
assert.equal(generatedOptions.status, "INVALID_EMAIL_ERROR"); | ||
}); | ||
|
||
it("should return the correct error if the passed options are invalid", async function () { | ||
it("when attestation is invalid, should return the correct error", async function () { | ||
await initST(); | ||
|
||
const email = "[email protected]"; | ||
|
@@ -150,6 +150,108 @@ describe(`recipeImplementationFunctions: ${printPath("[test/webauthn/recipeImple | |
assert.equal(generatedOptions.status, "INVALID_OPTIONS_ERROR"); | ||
}); | ||
|
||
it("when residentKey is invalid, should return the correct error", async function () { | ||
await initST(); | ||
|
||
const email = "[email protected]"; | ||
const generatedOptions = await getWebAuthnRecipe().recipeInterfaceImpl.registerOptions({ | ||
relyingPartyId: rpId, | ||
relyingPartyName: rpName, | ||
residentKey: "invalid", | ||
origin, | ||
email, | ||
tenantId: "public", | ||
userContext, | ||
}); | ||
|
||
assert.equal(generatedOptions.status, "INVALID_OPTIONS_ERROR"); | ||
}); | ||
|
||
it("when supportedAlgorithmIds is invalid, should return the correct error", async function () { | ||
await initST(); | ||
|
||
const email = "[email protected]"; | ||
const generatedOptions = await getWebAuthnRecipe().recipeInterfaceImpl.registerOptions({ | ||
relyingPartyId: rpId, | ||
relyingPartyName: rpName, | ||
supportedAlgorithmIds: "invalid", | ||
origin, | ||
email, | ||
tenantId: "public", | ||
userContext, | ||
}); | ||
|
||
assert.equal(generatedOptions.status, "INVALID_OPTIONS_ERROR"); | ||
}); | ||
|
||
it("when timeout is negative, should return the correct error", async function () { | ||
await initST(); | ||
|
||
const email = "[email protected]"; | ||
const generatedOptions = await getWebAuthnRecipe().recipeInterfaceImpl.registerOptions({ | ||
relyingPartyId: rpId, | ||
relyingPartyName: rpName, | ||
timeout: -1000, | ||
origin, | ||
email, | ||
tenantId: "public", | ||
userContext, | ||
}); | ||
|
||
assert.equal(generatedOptions.status, "INVALID_OPTIONS_ERROR"); | ||
}); | ||
|
||
it("when timeout is invalid, should return the correct error", async function () { | ||
await initST(); | ||
|
||
const email = "[email protected]"; | ||
const generatedOptions = await getWebAuthnRecipe().recipeInterfaceImpl.registerOptions({ | ||
relyingPartyId: rpId, | ||
relyingPartyName: rpName, | ||
timeout: "invalid", | ||
origin, | ||
email, | ||
tenantId: "public", | ||
userContext, | ||
}); | ||
|
||
assert.equal(generatedOptions.status, "INVALID_OPTIONS_ERROR"); | ||
}); | ||
|
||
it("when userPresence is invalid, should return the correct error", async function () { | ||
await initST(); | ||
|
||
const email = "[email protected]"; | ||
const generatedOptions = await getWebAuthnRecipe().recipeInterfaceImpl.registerOptions({ | ||
relyingPartyId: rpId, | ||
relyingPartyName: rpName, | ||
userPresence: "invalid", | ||
origin, | ||
email, | ||
tenantId: "public", | ||
userContext, | ||
}); | ||
|
||
assert.equal(generatedOptions.status, "INVALID_OPTIONS_ERROR"); | ||
}); | ||
|
||
it("when userVerification is invalid, should return the correct error", async function () { | ||
await initST(); | ||
|
||
const email = "[email protected]"; | ||
const generatedOptions = await getWebAuthnRecipe().recipeInterfaceImpl.registerOptions({ | ||
relyingPartyId: rpId, | ||
relyingPartyName: rpName, | ||
userVerification: "invalid", | ||
origin, | ||
email, | ||
tenantId: "public", | ||
userContext, | ||
}); | ||
|
||
assert.equal(generatedOptions.status, "INVALID_OPTIONS_ERROR"); | ||
}); | ||
|
||
it("should return the correct error if the options origin does not match the relying party id", async function () { | ||
await initST(); | ||
|
||
|
@@ -189,7 +291,7 @@ describe(`recipeImplementationFunctions: ${printPath("[test/webauthn/recipeImple | |
assert.equal(generatedOptions.createdAt + generatedOptions.timeout, generatedOptions.expiresAt); | ||
}); | ||
|
||
it("should return the correct error if the passed options are invalid", async function () { | ||
it("when userVerification is invalid, should return the correct error", async function () { | ||
await initST(); | ||
|
||
const generatedOptions = await getWebAuthnRecipe().recipeInterfaceImpl.signInOptions({ | ||
|
@@ -204,6 +306,51 @@ describe(`recipeImplementationFunctions: ${printPath("[test/webauthn/recipeImple | |
assert.equal(generatedOptions.status, "INVALID_OPTIONS_ERROR"); | ||
}); | ||
|
||
it("when userPresence is invalid, should return the correct error", async function () { | ||
await initST(); | ||
|
||
const generatedOptions = await getWebAuthnRecipe().recipeInterfaceImpl.signInOptions({ | ||
relyingPartyId: rpId, | ||
relyingPartyName: rpName, | ||
userPresence: "invalid", | ||
origin, | ||
tenantId: "public", | ||
userContext, | ||
}); | ||
|
||
assert.equal(generatedOptions.status, "INVALID_OPTIONS_ERROR"); | ||
}); | ||
|
||
it("when timeout is invalid, should return the correct error", async function () { | ||
await initST(); | ||
|
||
const generatedOptions = await getWebAuthnRecipe().recipeInterfaceImpl.signInOptions({ | ||
relyingPartyId: rpId, | ||
relyingPartyName: rpName, | ||
timeout: "invalid", | ||
origin, | ||
tenantId: "public", | ||
userContext, | ||
}); | ||
|
||
assert.equal(generatedOptions.status, "INVALID_OPTIONS_ERROR"); | ||
}); | ||
|
||
it("when timeout is negative, should return the correct error", async function () { | ||
await initST(); | ||
|
||
const generatedOptions = await getWebAuthnRecipe().recipeInterfaceImpl.signInOptions({ | ||
relyingPartyId: rpId, | ||
relyingPartyName: rpName, | ||
timeout: -1000, | ||
origin, | ||
tenantId: "public", | ||
userContext, | ||
}); | ||
|
||
assert.equal(generatedOptions.status, "INVALID_OPTIONS_ERROR"); | ||
}); | ||
|
||
it("should return the correct error if the options origin does not match the relying party id", async function () { | ||
await initST(); | ||
|
||
|
@@ -325,8 +472,8 @@ describe(`recipeImplementationFunctions: ${printPath("[test/webauthn/recipeImple | |
const signUpResponse2 = await getWebAuthnRecipe().recipeInterfaceImpl.signUp({ | ||
webauthnGeneratedOptionsId: registerOptionsResponse.webauthnGeneratedOptionsId, | ||
credential: { | ||
type: 1, | ||
...credential, | ||
type: 1, | ||
}, | ||
tenantId: "public", | ||
userContext, | ||
|
@@ -335,7 +482,7 @@ describe(`recipeImplementationFunctions: ${printPath("[test/webauthn/recipeImple | |
assert.equal(signUpResponse2.status, "INVALID_CREDENTIALS_ERROR"); | ||
}); | ||
|
||
it("should return the correct error if the options do not exist", async function () { | ||
it("when credential id is null or undefined, should return the correct error if the credential is invalid", async function () { | ||
await initST(); | ||
|
||
const email = "[email protected]"; | ||
|
@@ -344,24 +491,27 @@ describe(`recipeImplementationFunctions: ${printPath("[test/webauthn/recipeImple | |
|
||
const { createCredential } = await getWebauthnLib(); | ||
const credential = createCredential(registerOptionsResponse, { | ||
rpId, | ||
rpName, | ||
origin, | ||
rpId: rpId, | ||
rpName: rpName, | ||
origin: origin, | ||
userNotPresent: false, | ||
userNotVerified: false, | ||
}); | ||
|
||
const signUpResponse = await getWebAuthnRecipe().recipeInterfaceImpl.signUp({ | ||
webauthnGeneratedOptionsId: "invalid", | ||
credential, | ||
const signUpResponse2 = await getWebAuthnRecipe().recipeInterfaceImpl.signUp({ | ||
webauthnGeneratedOptionsId: registerOptionsResponse.webauthnGeneratedOptionsId, | ||
credential: { | ||
...credential, | ||
id: null, | ||
}, | ||
tenantId: "public", | ||
userContext, | ||
}); | ||
|
||
assert.equal(signUpResponse.status, "OPTIONS_NOT_FOUND_ERROR"); | ||
assert.equal(signUpResponse2.status, "INVALID_CREDENTIALS_ERROR"); | ||
}); | ||
|
||
it("should return the correct error if the origin of the credential does not match the origin of the options", async function () { | ||
it("should return the correct error if the options do not exist", async function () { | ||
await initST(); | ||
|
||
const email = "[email protected]"; | ||
|
@@ -372,33 +522,27 @@ describe(`recipeImplementationFunctions: ${printPath("[test/webauthn/recipeImple | |
const credential = createCredential(registerOptionsResponse, { | ||
rpId, | ||
rpName, | ||
origin: "https://test.com", | ||
origin, | ||
userNotPresent: false, | ||
userNotVerified: false, | ||
}); | ||
|
||
const signUpResponse = await getWebAuthnRecipe().recipeInterfaceImpl.signUp({ | ||
webauthnGeneratedOptionsId: registerOptionsResponse.webauthnGeneratedOptionsId, | ||
webauthnGeneratedOptionsId: "invalid", | ||
credential, | ||
tenantId: "public", | ||
userContext, | ||
}); | ||
|
||
assert.equal(signUpResponse.status, "INVALID_OPTIONS_ERROR"); | ||
assert.equal(signUpResponse.status, "OPTIONS_NOT_FOUND_ERROR"); | ||
}); | ||
|
||
it("should return the correct error if the origin of the credential is not part of the relying party id", async function () { | ||
it("should return the correct error if the origin of the credential does not match the origin of the options", async function () { | ||
await initST(); | ||
|
||
const email = "[email protected]"; | ||
const registerOptionsResponse = await getWebAuthnRecipe().recipeInterfaceImpl.registerOptions({ | ||
relyingPartyId: rpId, | ||
relyingPartyName: rpName, | ||
origin: "https://test.com", | ||
email, | ||
tenantId: "public", | ||
userContext, | ||
}); | ||
const registerOptionsResponse = await createRegisterOptions(email); | ||
assert(registerOptionsResponse.status === "OK"); | ||
|
||
const { createCredential } = await getWebauthnLib(); | ||
const credential = createCredential(registerOptionsResponse, { | ||
|
@@ -486,6 +630,8 @@ describe(`recipeImplementationFunctions: ${printPath("[test/webauthn/recipeImple | |
userContext, | ||
}); | ||
|
||
console.log(signInResponse); | ||
|
||
assert.equal(signInResponse.status, "CREDENTIAL_NOT_FOUND_ERROR"); | ||
}); | ||
|
||
|
@@ -546,8 +692,25 @@ describe(`recipeImplementationFunctions: ${printPath("[test/webauthn/recipeImple | |
const signInResponse2 = await getWebAuthnRecipe().recipeInterfaceImpl.signIn({ | ||
webauthnGeneratedOptionsId: signInOptionsResponse.webauthnGeneratedOptionsId, | ||
credential: { | ||
...credential.assertion, | ||
type: 1, | ||
}, | ||
tenantId: "public", | ||
userContext, | ||
}); | ||
assert.equal(signInResponse2.status, "INVALID_CREDENTIALS_ERROR"); | ||
}); | ||
|
||
it("when credential id is null or undefined, should return the correct error if the credential is invalid", async function () { | ||
await initST(); | ||
|
||
const { signUpResponse, signInOptionsResponse, credential } = await createUser(rpId, rpName, origin); | ||
|
||
const signInResponse2 = await getWebAuthnRecipe().recipeInterfaceImpl.signIn({ | ||
webauthnGeneratedOptionsId: signInOptionsResponse.webauthnGeneratedOptionsId, | ||
credential: { | ||
...credential.assertion, | ||
id: null, | ||
}, | ||
tenantId: "public", | ||
userContext, | ||
|