summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/browser/src')
-rw-r--r--packages/browser/src/helpers/toUint8Array.ts4
-rw-r--r--packages/browser/src/methods/startAssertion.test.ts34
2 files changed, 37 insertions, 1 deletions
diff --git a/packages/browser/src/helpers/toUint8Array.ts b/packages/browser/src/helpers/toUint8Array.ts
index ed4aa5d..1855dd7 100644
--- a/packages/browser/src/helpers/toUint8Array.ts
+++ b/packages/browser/src/helpers/toUint8Array.ts
@@ -1,7 +1,9 @@
+const utf8Encoder = new TextEncoder();
+
/**
* A helper method to convert an arbitrary string sent from the server to a Uint8Array the
* authenticator will expect.
*/
export default function toUint8Array(value: string): Uint8Array {
- return Uint8Array.from(value, c => c.charCodeAt(0));
+ return utf8Encoder.encode(value);
}
diff --git a/packages/browser/src/methods/startAssertion.test.ts b/packages/browser/src/methods/startAssertion.test.ts
index 669e8eb..e919d18 100644
--- a/packages/browser/src/methods/startAssertion.test.ts
+++ b/packages/browser/src/methods/startAssertion.test.ts
@@ -17,6 +17,7 @@ const mockClientDataJSON = 'mockClientDataJSON';
const mockSignature = 'mockSignature';
const mockUserHandle = 'mockUserHandle';
+// With ASCII challenge
const goodOpts1: PublicKeyCredentialRequestOptionsJSON = {
challenge: 'fizz',
allowCredentials: [
@@ -29,6 +30,13 @@ const goodOpts1: PublicKeyCredentialRequestOptionsJSON = {
timeout: 1,
};
+// With UTF-8 challenge
+const goodOpts2UTF8: PublicKeyCredentialRequestOptionsJSON = {
+ challenge: 'やれやれだぜ',
+ allowCredentials: [],
+ timeout: 1,
+};
+
beforeEach(() => {
mockNavigatorGet.mockReset();
mockSupportsWebauthn.mockReset();
@@ -120,3 +128,29 @@ test('should throw error if assertion is cancelled for some reason', async done
done();
});
+
+test('should handle UTF-8 challenges', async done => {
+ mockSupportsWebauthn.mockReturnValue(true);
+
+ // Stub out a response so the method won't throw
+ mockNavigatorGet.mockImplementation(
+ (): Promise<any> => {
+ return new Promise(resolve => {
+ resolve({
+ response: {},
+ getClientExtensionResults: () => ({}),
+ });
+ });
+ },
+ );
+
+ await startAssertion(goodOpts2UTF8);
+
+ const argsPublicKey = mockNavigatorGet.mock.calls[0][0].publicKey;
+
+ expect(JSON.stringify(argsPublicKey.challenge)).toEqual(
+ '{"0":227,"1":130,"2":132,"3":227,"4":130,"5":140,"6":227,"7":130,"8":132,"9":227,"10":130,"11":140,"12":227,"13":129,"14":160,"15":227,"16":129,"17":156}',
+ );
+
+ done();
+});