From ecad1e2e9d8c479a0f1a525a9b6f99383d6413fe Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Fri, 22 May 2020 14:59:40 -0700 Subject: Stop stripping base64 padding in browser --- packages/browser/src/helpers/toBase64String.test.ts | 15 +++++++++++++++ packages/browser/src/helpers/toBase64String.ts | 3 +-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 packages/browser/src/helpers/toBase64String.test.ts (limited to 'packages/browser/src/helpers') diff --git a/packages/browser/src/helpers/toBase64String.test.ts b/packages/browser/src/helpers/toBase64String.test.ts new file mode 100644 index 0000000..c16ec72 --- /dev/null +++ b/packages/browser/src/helpers/toBase64String.test.ts @@ -0,0 +1,15 @@ +import toBase64String from './toBase64String'; + +import toUintArray from './toUint8Array'; + +test('should convert a Buffer to a string with a length that is a multiple of 4', () => { + const base64 = toBase64String(Buffer.from('123456', 'ascii')); + + expect(base64.length % 4).toEqual(0); +}); + +test('should convert a Uint8Array to a string with a length that is a multiple of 4', () => { + const base64 = toBase64String(toUintArray('123456')); + + expect(base64.length % 4).toEqual(0); +}); diff --git a/packages/browser/src/helpers/toBase64String.ts b/packages/browser/src/helpers/toBase64String.ts index 8234002..9c949be 100644 --- a/packages/browser/src/helpers/toBase64String.ts +++ b/packages/browser/src/helpers/toBase64String.ts @@ -4,6 +4,5 @@ export default function toBase64String(buffer: ArrayBuffer): string { // TODO: Make sure converting buffer to Uint8Array() is correct return base64js.fromByteArray(new Uint8Array(buffer)) .replace(/\+/g, "-") - .replace(/\//g, "_") - .replace(/=/g, ""); + .replace(/\//g, "_"); } -- cgit v1.2.3 From 8a464cdfdd9bb707aa0525b414c00342f58fd94d Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Fri, 22 May 2020 15:23:29 -0700 Subject: Fix misspelling in toBase64String test --- packages/browser/src/helpers/toBase64String.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/browser/src/helpers') diff --git a/packages/browser/src/helpers/toBase64String.test.ts b/packages/browser/src/helpers/toBase64String.test.ts index c16ec72..bbcb11b 100644 --- a/packages/browser/src/helpers/toBase64String.test.ts +++ b/packages/browser/src/helpers/toBase64String.test.ts @@ -1,6 +1,6 @@ import toBase64String from './toBase64String'; -import toUintArray from './toUint8Array'; +import toUint8Array from './toUint8Array'; test('should convert a Buffer to a string with a length that is a multiple of 4', () => { const base64 = toBase64String(Buffer.from('123456', 'ascii')); @@ -9,7 +9,7 @@ test('should convert a Buffer to a string with a length that is a multiple of 4' }); test('should convert a Uint8Array to a string with a length that is a multiple of 4', () => { - const base64 = toBase64String(toUintArray('123456')); + const base64 = toBase64String(toUint8Array('123456')); expect(base64.length % 4).toEqual(0); }); -- cgit v1.2.3 From fe68bbcf520250b624fbea5ff33ca99988e7f9db Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Fri, 22 May 2020 15:24:06 -0700 Subject: Clarify usage of toUint8Array --- packages/browser/src/helpers/toUint8Array.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/browser/src/helpers') diff --git a/packages/browser/src/helpers/toUint8Array.ts b/packages/browser/src/helpers/toUint8Array.ts index a807a88..ed4aa5d 100644 --- a/packages/browser/src/helpers/toUint8Array.ts +++ b/packages/browser/src/helpers/toUint8Array.ts @@ -1,6 +1,6 @@ /** - * A helper method to convert a string sent from the server to a Uint8Array the authenticator will - * expect. + * 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)); -- cgit v1.2.3