@guardian/pan-domain-node 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @guardian/pan-domain-node
2
2
 
3
+ ## 1.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5c14027: Fix app crash with no cookie value
8
+
3
9
  ## 1.1.0
4
10
 
5
11
  ### Minor Changes
@@ -17,5 +17,5 @@ export declare class PanDomainAuthentication {
17
17
  constructor(cookieName: string, region: string, bucket: string, keyFile: string, validateUser: ValidateUserFn, credentialsProvider?: AwsCredentialIdentityProvider);
18
18
  stop(): void;
19
19
  getPublicKey(): Promise<string>;
20
- verify(requestCookies: string): Promise<AuthenticationResult>;
20
+ verify(requestCookies: string | undefined): Promise<AuthenticationResult>;
21
21
  }
package/dist/src/panda.js CHANGED
@@ -157,7 +157,7 @@ class PanDomainAuthentication {
157
157
  }
158
158
  verify(requestCookies) {
159
159
  return this.getPublicKey().then(publicKey => {
160
- const cookies = cookie.parse(requestCookies);
160
+ const cookies = cookie.parse(requestCookies !== null && requestCookies !== void 0 ? requestCookies : '');
161
161
  const pandaCookie = cookies[this.cookieName];
162
162
  return verifyUser(pandaCookie, publicKey, new Date(), this.validateUser);
163
163
  });
@@ -283,5 +283,16 @@ describe('panda class', function () {
283
283
  };
284
284
  expect(authenticationResult).toStrictEqual(expected);
285
285
  }));
286
+ it('should fail to authenticate with no-cookie reason if no cookie is present at all', () => __awaiter(this, void 0, void 0, function* () {
287
+ jest.setSystemTime(100);
288
+ const panda = new panda_1.PanDomainAuthentication('rightcookiename', 'region', 'bucket', 'keyfile', api_1.guardianValidation);
289
+ const noCookie = undefined;
290
+ const authenticationResult = yield panda.verify(noCookie);
291
+ const expected = {
292
+ success: false,
293
+ reason: "no-cookie"
294
+ };
295
+ expect(authenticationResult).toStrictEqual(expected);
296
+ }));
286
297
  });
287
298
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guardian/pan-domain-node",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "NodeJs implementation of Guardian pan-domain auth verification",
5
5
  "main": "dist/src/api.js",
6
6
  "types": "dist/src/api.d.ts",
package/src/panda.ts CHANGED
@@ -146,9 +146,9 @@ export class PanDomainAuthentication {
146
146
  });
147
147
  }
148
148
 
149
- verify(requestCookies: string): Promise<AuthenticationResult> {
149
+ verify(requestCookies: string | undefined): Promise<AuthenticationResult> {
150
150
  return this.getPublicKey().then(publicKey => {
151
- const cookies = cookie.parse(requestCookies);
151
+ const cookies = cookie.parse(requestCookies ?? '');
152
152
  const pandaCookie = cookies[this.cookieName];
153
153
  return verifyUser(pandaCookie, publicKey, new Date(), this.validateUser);
154
154
  });
@@ -349,6 +349,20 @@ describe('panda class', function () {
349
349
  };
350
350
  expect(authenticationResult).toStrictEqual(expected);
351
351
  });
352
+
353
+ it('should fail to authenticate with no-cookie reason if no cookie is present at all', async () => {
354
+ jest.setSystemTime(100);
355
+
356
+ const panda = new PanDomainAuthentication('rightcookiename', 'region', 'bucket', 'keyfile', guardianValidation);
357
+ const noCookie = undefined;
358
+ const authenticationResult = await panda.verify(noCookie);
359
+
360
+ const expected: CookieFailure = {
361
+ success: false,
362
+ reason: "no-cookie"
363
+ };
364
+ expect(authenticationResult).toStrictEqual(expected);
365
+ });
352
366
  });
353
367
 
354
368
  });