diff --git a/.changeset/angry-camels-tie.md b/.changeset/angry-camels-tie.md new file mode 100644 index 0000000..49f4581 --- /dev/null +++ b/.changeset/angry-camels-tie.md @@ -0,0 +1,5 @@ +--- +"@guardian/pan-domain-node": minor +--- + +Fix app crash with no cookie value diff --git a/package-lock.json b/package-lock.json index e8e0d3d..453908e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@guardian/pan-domain-node", - "version": "1.0.0", + "version": "1.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@guardian/pan-domain-node", - "version": "1.0.0", + "version": "1.1.0", "license": "Apache-2.0", "dependencies": { "@aws-sdk/client-s3": "^3.299.0", diff --git a/src/panda.ts b/src/panda.ts index 0c5015e..61348a1 100644 --- a/src/panda.ts +++ b/src/panda.ts @@ -146,9 +146,9 @@ export class PanDomainAuthentication { }); } - verify(requestCookies: string): Promise { + verify(requestCookies: string | undefined): Promise { return this.getPublicKey().then(publicKey => { - const cookies = cookie.parse(requestCookies); + const cookies = cookie.parse(requestCookies ?? ''); const pandaCookie = cookies[this.cookieName]; return verifyUser(pandaCookie, publicKey, new Date(), this.validateUser); }); diff --git a/test/panda.test.ts b/test/panda.test.ts index 19c92f8..a27897a 100644 --- a/test/panda.test.ts +++ b/test/panda.test.ts @@ -349,6 +349,20 @@ describe('panda class', function () { }; expect(authenticationResult).toStrictEqual(expected); }); + + it('should fail to authenticate with no-cookie reason if no cookie is present at all', async () => { + jest.setSystemTime(100); + + const panda = new PanDomainAuthentication('rightcookiename', 'region', 'bucket', 'keyfile', guardianValidation); + const noCookie = undefined; + const authenticationResult = await panda.verify(noCookie); + + const expected: CookieFailure = { + success: false, + reason: "no-cookie" + }; + expect(authenticationResult).toStrictEqual(expected); + }); }); });