summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/methods
diff options
context:
space:
mode:
authorMatthew Miller <matthew@millerti.me>2023-10-02 23:01:42 -0700
committerMatthew Miller <matthew@millerti.me>2023-10-02 23:01:42 -0700
commit5e0079f2304428a58cc2fc7118f329b40c403b52 (patch)
treef536857b09c8cd86473d278d063b980cf7e05cfa /packages/browser/src/methods
parent798a8fa184d9787aaa3eb8d15a10f31277479e3e (diff)
Update tests
Diffstat (limited to 'packages/browser/src/methods')
-rw-r--r--packages/browser/src/methods/startAuthentication.test.ts35
1 files changed, 35 insertions, 0 deletions
diff --git a/packages/browser/src/methods/startAuthentication.test.ts b/packages/browser/src/methods/startAuthentication.test.ts
index fb31dcc..3aaf33d 100644
--- a/packages/browser/src/methods/startAuthentication.test.ts
+++ b/packages/browser/src/methods/startAuthentication.test.ts
@@ -297,6 +297,22 @@ test('should set up autofill a.k.a. Conditional UI', async () => {
.toEqual(0);
});
+test('should set up conditional UI if "webauthn" is the only autocomplete token', async () => {
+ /**
+ * According to WHATWG "webauthn" can be the only token in the autocomplete attribute:
+ * https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-detail-tokens
+ */
+ document.body.innerHTML = `
+ <form>
+ <label for="username">Username</label>
+ <input type="text" name="username" autocomplete="webauthn" />
+ <button type="submit">Submit</button>
+ </form>
+ `;
+
+ await expect(startAuthentication(goodOpts1, true)).resolves;
+});
+
test('should throw error if autofill not supported', async () => {
mockSupportsAutofill.mockResolvedValue(false);
@@ -320,6 +336,25 @@ test('should throw error if no acceptable <input> is found', async () => {
rejected.toThrow(/no <input>/i);
});
+test('should throw error if "webauthn" is not final autocomplete token', async () => {
+ /**
+ * According to WHATWG "webauthn" must be the final token in the autocomplete attribute when
+ * multiple tokens are present:
+ * https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-detail-tokens
+ */
+ document.body.innerHTML = `
+ <form>
+ <label for="username">Username</label>
+ <input type="text" name="username" autocomplete="webauthn username" />
+ <button type="submit">Submit</button>
+ </form>
+ `;
+
+ const rejected = await expect(startAuthentication(goodOpts1, true)).rejects;
+ rejected.toThrow(Error);
+ rejected.toThrow(/no <input>/i);
+});
+
test('should return authenticatorAttachment if present', async () => {
// Mock extension return values from authenticator
mockNavigatorGet.mockImplementation((): Promise<unknown> => {