From d18c6771e3d617d253cc7132a5caa9355ec50640 Mon Sep 17 00:00:00 2001 From: Artiom Tofan Date: Wed, 7 Jan 2026 15:30:07 +0100 Subject: [PATCH 1/3] =?UTF-8?q?feat(payload):=20=E2=9C=A8=20add=20`=5Forig?= =?UTF-8?q?in`=20to=20`EnqueueTokenPayload`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Include `_origin` property in the payload generation process. - Update `DeserializePayload` to correctly assign `Origin` from JSON data. --- src/Payload.ts | 1 + src/model/PayloadDto.ts | 4 +++- src/model/TokenOrigin.ts | 5 +++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Payload.ts b/src/Payload.ts index 8472649..173ff8c 100644 --- a/src/Payload.ts +++ b/src/Payload.ts @@ -97,6 +97,7 @@ export class EnqueueTokenPayload implements IEnqueueTokenPayload { if (payload) { newPayload.RelativeQuality = payload.RelativeQuality; newPayload._customData = payload._customData; + newPayload._origin = payload._origin; if (!key || key.length == 0) { newPayload.Key = payload.Key; } diff --git a/src/model/PayloadDto.ts b/src/model/PayloadDto.ts index 38b7256..ffbe966 100644 --- a/src/model/PayloadDto.ts +++ b/src/model/PayloadDto.ts @@ -41,7 +41,9 @@ export class PayloadDto { payload.CustomData = jsonData['cd']; } - jsonData['o'] = payload.Origin ?? jsonData['o']; + if (jsonData['o']) { + payload.Origin = jsonData['o']; + } return payload; } diff --git a/src/model/TokenOrigin.ts b/src/model/TokenOrigin.ts index 18f2857..3240aec 100644 --- a/src/model/TokenOrigin.ts +++ b/src/model/TokenOrigin.ts @@ -1,4 +1,5 @@ export enum TokenOrigin { - Connector, - InviteOnly + Connector = "Connector", + InviteOnly = "InviteOnly", + AkamaiBotManagerHeaderValidator = "AkamaiBotManagerHeaderValidator" } \ No newline at end of file From 3fe2e55dac6fab9c4080b99617760f75bf3e89d0 Mon Sep 17 00:00:00 2001 From: Artiom Tofan Date: Wed, 7 Jan 2026 15:30:14 +0100 Subject: [PATCH 2/3] =?UTF-8?q?feat(tests):=20=E2=9C=A8=20add=20tests=20fo?= =?UTF-8?q?r=20`TokenOrigin`=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Implement tests for creating tokens with specific origins. - Ensure serialization includes `TokenOrigin` in payloads. --- tests/EnqueueToken.ts | 48 ++++++++++++++++++++++++++++++------ tests/EnqueueTokenPayload.ts | 47 ++++++++++++++++++++++++++--------- 2 files changed, 75 insertions(+), 20 deletions(-) diff --git a/tests/EnqueueToken.ts b/tests/EnqueueToken.ts index b53bb73..0f212b4 100644 --- a/tests/EnqueueToken.ts +++ b/tests/EnqueueToken.ts @@ -1,12 +1,13 @@ /* eslint-disable sonarjs/no-duplicate-string */ -import {expect} from "chai"; -import {Payload} from "../src"; -import {Utils} from "../src/QueueITHelpers"; -import {EnqueueToken, Token} from "../src/Token"; -import {TokenVersion} from "../src/model/TokenVersion"; -import {EncryptionType} from "../src/model/EncryptionType"; -import {HeaderDto} from "../src/model/HeaderDto"; +import { expect } from "chai"; +import { Payload } from "../src"; +import { Utils } from "../src/QueueITHelpers"; +import { EnqueueToken, Token } from "../src/Token"; +import { TokenVersion } from "../src/model/TokenVersion"; +import { EncryptionType } from "../src/model/EncryptionType"; +import { HeaderDto } from "../src/model/HeaderDto"; +import { TokenOrigin } from "../src/model/TokenOrigin"; describe('Enqueue Token', () => { it('should create a simple token', () => { @@ -122,7 +123,7 @@ describe('Enqueue Token', () => { it('should sign a token with payload and custom data', () => { const expectedSignedToken = - "eyJ0eXAiOiJRVDEiLCJlbmMiOiJBRVMyNTYiLCJpc3MiOjE1MzQ3MjMyMDAwMDAsImV4cCI6MTUzOTEyOTYwMDAwMCwidGkiOiJhMjFkNDIzYS00M2ZkLTQ4MjEtODRmYS00MzkwZjZhMmZkM2UiLCJjIjoidGlja2V0YW5pYSIsImUiOiJteWV2ZW50In0.0rDlI69F1Dx4Twps5qD4cQrbXbCRiezBd6fH1PVm6CnVY456FALkAhN3rgVrh_PGCJHcEXN5zoqFg65MH8WZc_CQdD63hJre3Sedu0-9zIs.aZgzkJm57etFaXjjME_-9LjOgPNTTqkp1aJ057HuEiU"; + "eyJ0eXAiOiJRVDEiLCJlbmMiOiJBRVMyNTYiLCJpc3MiOjE1MzQ3MjMyMDAwMDAsImV4cCI6MTUzOTEyOTYwMDAwMCwidGkiOiJhMjFkNDIzYS00M2ZkLTQ4MjEtODRmYS00MzkwZjZhMmZkM2UiLCJjIjoidGlja2V0YW5pYSIsImUiOiJteWV2ZW50In0.0rDlI69F1Dx4Twps5qD4cQrbXbCRiezBd6fH1PVm6CnVY456FALkAhN3rgVrh_PGCJHcEXN5zoqFg65MH8WZcxl-G7_FAsZgEyBPRqsoJoylWJjVe-e1HI-voBaV7x6Q.bRyvSKj3Dn0w_HPer62N0mVQP4dNPl5OIcXw7DrTH5g"; const payload = Payload .Enqueue() @@ -282,4 +283,35 @@ describe('Enqueue Token', () => { expect(enqueueToken.TokenVersion).to.be.equal(TokenVersion.QT1); expect(enqueueToken.Payload).to.be.undefined; }); + + it('should create token with AkamaiBotManagerHeaderValidator origin and parse it back correctly', () => { + const expectedCustomerId = "testId"; + const expectedKey = "testkey"; + const expectedOrigin = TokenOrigin.AkamaiBotManagerHeaderValidator; + const secretKey = "testKey"; + + const payload = Payload + .Enqueue() + .WithKey(expectedKey) + .WithOrigin(expectedOrigin) + .Generate(); + + const token = Token + .Enqueue(expectedCustomerId) + .WithPayload(payload) + .Generate(secretKey); + + // Verify the payload before parsing + expect(token.Payload.TokenOrigin).to.be.equal(expectedOrigin); + expect(token.Payload.Key).to.be.equal(expectedKey); + + // Parse the token back + const parsedToken = Token.Parse(token.Token, secretKey); + + // Verify all properties are preserved + expect(parsedToken.CustomerId).to.be.equal(expectedCustomerId); + expect(parsedToken.Payload).to.not.be.undefined; + expect(parsedToken.Payload.Key).to.be.equal(expectedKey); + expect(parsedToken.Payload.TokenOrigin).to.be.equal(expectedOrigin); + }); }); diff --git a/tests/EnqueueTokenPayload.ts b/tests/EnqueueTokenPayload.ts index 6ba6009..c265066 100644 --- a/tests/EnqueueTokenPayload.ts +++ b/tests/EnqueueTokenPayload.ts @@ -1,6 +1,7 @@ -import {expect} from "chai"; -import {IEnqueueTokenPayload, Payload} from "../src/Payload"; -import {Utils} from "../src/QueueITHelpers"; +import { expect } from "chai"; +import { IEnqueueTokenPayload, Payload } from "../src/Payload"; +import { Utils } from "../src/QueueITHelpers"; +import { TokenOrigin } from "../src/model/TokenOrigin"; describe('Enqueue token payload', function () { it('should be able to generate a simple payload', () => { @@ -111,8 +112,30 @@ describe('Enqueue token payload', function () { expect(actualCustomData).to.be.equal(expectedCustomDataValue); }); + it('Should be able to generate a payload only with Token Origin', () => { + const instance = Payload.Enqueue() + .WithOrigin(TokenOrigin.Connector) + .Generate(); + + const actualOrigin = instance.TokenOrigin; + expect(actualOrigin).to.be.equal(TokenOrigin.Connector); + }); + + it('should serialize payload with InviteOnly origin', () => { + const expectedJson = "{\"k\":\"myKey\",\"o\":\"InviteOnly\"}"; + + const instance = Payload + .Enqueue() + .WithKey("myKey") + .WithOrigin(TokenOrigin.InviteOnly) + .Generate(); + const actualJson = Utils.uint8ArrayToString(instance.Serialize()); + + expect(actualJson).to.be.equal(expectedJson); + }); + it('should serialize key with relative quality and multiple custom data', () => { - const expectedJson = "{\"r\":0.456,\"k\":\"myKey\",\"cd\":{\"key1\":\"Value1\",\"key2\":\"Value2\",\"key3\":\"Value3\"}}"; + const expectedJson = "{\"r\":0.456,\"k\":\"myKey\",\"cd\":{\"key1\":\"Value1\",\"key2\":\"Value2\",\"key3\":\"Value3\"},\"o\":\"Connector\"}"; const instance = Payload .Enqueue() @@ -128,7 +151,7 @@ describe('Enqueue token payload', function () { }); it('should serialize key relative quality and one custom data', () => { - const expectedJson = "{\"r\":0.456,\"k\":\"myKey\",\"cd\":{\"key1\":\"Value1\"}}"; + const expectedJson = "{\"r\":0.456,\"k\":\"myKey\",\"cd\":{\"key1\":\"Value1\"},\"o\":\"Connector\"}"; const instance = Payload .Enqueue() @@ -142,7 +165,7 @@ describe('Enqueue token payload', function () { }); it('should serialize key and relative quality', () => { - const expectedJson = "{\"r\":0.456,\"k\":\"myKey\"}"; + const expectedJson = "{\"r\":0.456,\"k\":\"myKey\",\"o\":\"Connector\"}"; const instance = Payload .Enqueue() @@ -155,7 +178,7 @@ describe('Enqueue token payload', function () { }); it('should serialize key only', () => { - const expectedJson = "{\"k\":\"myKey\"}"; + const expectedJson = "{\"k\":\"myKey\",\"o\":\"Connector\"}"; const instance = Payload .Enqueue() @@ -167,7 +190,7 @@ describe('Enqueue token payload', function () { }); it('should serialize key only escaped', () => { - const expectedJson = "{\"k\":\"my\\\"Key\"}"; + const expectedJson = "{\"k\":\"my\\\"Key\",\"o\":\"Connector\"}"; const instance = Payload .Enqueue() @@ -179,7 +202,7 @@ describe('Enqueue token payload', function () { }); it('should serialize relative quality only', () => { - const expectedJson = "{\"r\":0.456}"; + const expectedJson = "{\"r\":0.456,\"o\":\"Connector\"}"; const instance = Payload .Enqueue() @@ -191,7 +214,7 @@ describe('Enqueue token payload', function () { }); it('should serialize custom data only', () => { - const expectedJson = "{\"cd\":{\"key1\":\"Value1\"}}"; + const expectedJson = "{\"cd\":{\"key1\":\"Value1\"},\"o\":\"Connector\"}"; const instance = Payload .Enqueue() @@ -203,7 +226,7 @@ describe('Enqueue token payload', function () { }); it('should serialize custom data escaped', () => { - const expectedJson = "{\"cd\":{\"ke\\\"y1\":\"Va\\\"lue1\"}}"; + const expectedJson = "{\"cd\":{\"ke\\\"y1\":\"Va\\\"lue1\"},\"o\":\"Connector\"}"; const instance = Payload .Enqueue() @@ -215,7 +238,7 @@ describe('Enqueue token payload', function () { }); it('should be encrypted correctly', () => { - const expectedEncryptedPayload = "0rDlI69F1Dx4Twps5qD4cQrbXbCRiezBd6fH1PVm6CnVY456FALkAhN3rgVrh_PGCJHcEXN5zoqFg65MH8WZc_CQdD63hJre3Sedu0-9zIs"; + const expectedEncryptedPayload = "0rDlI69F1Dx4Twps5qD4cQrbXbCRiezBd6fH1PVm6CnVY456FALkAhN3rgVrh_PGCJHcEXN5zoqFg65MH8WZcxl-G7_FAsZgEyBPRqsoJoylWJjVe-e1HI-voBaV7x6Q"; const payload = Payload .Enqueue() .WithKey("somekey") From 1abaaede760e3118c15a32faa1bab3737d6fc70d Mon Sep 17 00:00:00 2001 From: Artiom Tofan Date: Wed, 7 Jan 2026 15:30:30 +0100 Subject: [PATCH 3/3] =?UTF-8?q?fix(package):=20=F0=9F=90=9B=20bump=20versi?= =?UTF-8?q?on=20to=20`1.0.5`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f345fb4..01a252b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@queue-it/queue-token", - "version": "1.0.4", + "version": "1.0.5", "description": "Ensures that end users cannot enter the queue without a valid token and to be a container which can carry sensitive user information from integrating system into the queue", "repository": "https://github.com/queueit/QueueToken.V1.JavaScript", "main": "dist/index.js",