From 7f2c4816062ef955893fc0b8c6213893831c7415 Mon Sep 17 00:00:00 2001 From: "Jason R. Stevens, CFA" Date: Sun, 13 Aug 2023 11:44:16 -0500 Subject: [PATCH 1/3] :sparkles: add sub token property to generateAccessToken #3 --- src/promo-node-utils.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/promo-node-utils.ts b/src/promo-node-utils.ts index b810c60..d58387a 100644 --- a/src/promo-node-utils.ts +++ b/src/promo-node-utils.ts @@ -49,12 +49,13 @@ function generateAccessToken( clientId: string, appId: string, clientSecret: string, - expiration?: number + expiration?: number, + sub?: string ) { const timestamp = Date.now(); const exp = expiration ? timestamp + expiration : timestamp + 1800; let accessToken: PromoAccessTokenJwt = { - sub: '', + sub: sub || '', iss: issuer, cid: clientId, aid: appId, From 7be42f844027d95e8a6164aa5ae32a7c9d648b21 Mon Sep 17 00:00:00 2001 From: "Jason R. Stevens, CFA" Date: Sun, 13 Aug 2023 11:52:04 -0500 Subject: [PATCH 2/3] :recycle: add test for actual generateAccessToken function from source --- __tests__/getToken.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/__tests__/getToken.test.ts b/__tests__/getToken.test.ts index 5ea7023..e49054d 100644 --- a/__tests__/getToken.test.ts +++ b/__tests__/getToken.test.ts @@ -1,17 +1,17 @@ import { getToken } from '../src/.'; -import { generateAccessToken } from './test-utils'; +import { generateAccessToken } from '../src/promo-node-utils'; jest.setTimeout(40000); describe('getToken', () => { const clientSecret = '57hMbxBuIsWAMiT4k0XZ0JmQV5M0BrpR6E4nN9vbEoWvNy5S'; // never do this in your client side js but this is safe due to it being a testing application alone - const appId = 'ygzRl6CiiUivwsNn3UjntatUDP4k' - const clientId = 'm4MohkXSo2xMVWYXj6NecyS5uEeJ' - const hostName = 'http://localhost:3000' + const appId = 'ygzRl6CiiUivwsNn3UjntatUDP4k'; + const clientId = 'm4MohkXSo2xMVWYXj6NecyS5uEeJ'; + const hostName = 'http://localhost:3000'; let accessTokenSigned: string = generateAccessToken( hostName, clientId, appId, - clientSecret, + clientSecret ); it('returns a string', async () => { From 2bbb71ffc65d27a7e35c3ec571d36536e99a7dd7 Mon Sep 17 00:00:00 2001 From: "Jason R. Stevens, CFA" Date: Sun, 13 Aug 2023 11:52:04 -0500 Subject: [PATCH 3/3] :sparkles: :white_check_mark: add test for new sub usage per #3 --- __tests__/generateAccessToken.test.ts | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 __tests__/generateAccessToken.test.ts diff --git a/__tests__/generateAccessToken.test.ts b/__tests__/generateAccessToken.test.ts new file mode 100644 index 0000000..44b1bd4 --- /dev/null +++ b/__tests__/generateAccessToken.test.ts @@ -0,0 +1,40 @@ +import { generateAccessToken } from '../src/promo-node-utils'; +jest.setTimeout(40000); + +describe('generateAccessToken no sub', () => { + const clientSecret = 'test client secret'; // never do this in your client side js but this is safe due to it being a testing application alone + const appId = 'test app id'; + const clientId = 'test client id'; + const hostName = 'http://localhost:3000'; + let accessTokenSigned: string = generateAccessToken( + hostName, + clientId, + appId, + clientSecret + ); + + it('returns a string', async () => { + expect(typeof accessTokenSigned).toBe('string'); + }); +}); + +describe('generateAccessToken with sub and expiration', () => { + const clientSecret = 'test client secret'; // never do this in your client side js but this is safe due to it being a testing application alone + const appId = 'test app id'; + const clientId = 'test client id'; + const hostName = 'http://localhost:3000'; + const sub = 'test@tincre.com'; + const expiration = 123456 + let accessTokenSigned: string = generateAccessToken( + hostName, + clientId, + appId, + clientSecret, + expiration, + sub + ); + + it('returns a string', async () => { + expect(typeof accessTokenSigned).toBe('string'); + }); +});