Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/angry-camels-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@guardian/pan-domain-node": minor
---

Fix app crash with no cookie value
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/panda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ export class PanDomainAuthentication {
});
}

verify(requestCookies: string): Promise<AuthenticationResult> {
verify(requestCookies: string | undefined): Promise<AuthenticationResult> {
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);
});
Expand Down
14 changes: 14 additions & 0 deletions test/panda.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

});