|
| 1 | +import * as assert from 'assert'; |
| 2 | +import { deriveEnterpriseSalt } from '../../src'; |
| 3 | + |
| 4 | +// Real fixture values captured from a live environment (DB + browser devtools) |
| 5 | +const REAL_FIXTURE = { |
| 6 | + basePrfSalt: 'ZqJ64M2dL65zn2-Jxd58SMN2ILc9QjbCFxUTGHd_LC8', |
| 7 | + enterpriseId: '69c2aea1a3d7bc07f7f775c0ca86b0ec', |
| 8 | + expectedDerivedSalt: 'oiasOqzkuyuEz/8043+3IXYghSu3LV4N/a1MLIRzmU8=', |
| 9 | +}; |
| 10 | + |
| 11 | +describe('deriveEnterpriseSalt', function () { |
| 12 | + it('produces the correct derived salt for real fixture values', function () { |
| 13 | + // Verifies SDK output matches what the retail UI produces for the same inputs, |
| 14 | + // ensuring clients can move between SDK and retail app seamlessly. |
| 15 | + assert.strictEqual( |
| 16 | + deriveEnterpriseSalt(REAL_FIXTURE.basePrfSalt, REAL_FIXTURE.enterpriseId), |
| 17 | + REAL_FIXTURE.expectedDerivedSalt |
| 18 | + ); |
| 19 | + }); |
| 20 | + |
| 21 | + it('is deterministic — same inputs always produce the same salt', function () { |
| 22 | + const first = deriveEnterpriseSalt(REAL_FIXTURE.basePrfSalt, REAL_FIXTURE.enterpriseId); |
| 23 | + const second = deriveEnterpriseSalt(REAL_FIXTURE.basePrfSalt, REAL_FIXTURE.enterpriseId); |
| 24 | + assert.ok(first); |
| 25 | + assert.strictEqual(first, second); |
| 26 | + }); |
| 27 | + |
| 28 | + it('produces different salts for different enterpriseIds with the same prfSalt', function () { |
| 29 | + const saltA = deriveEnterpriseSalt(REAL_FIXTURE.basePrfSalt, REAL_FIXTURE.enterpriseId); |
| 30 | + const saltB = deriveEnterpriseSalt(REAL_FIXTURE.basePrfSalt, 'different-enterprise-id'); |
| 31 | + assert.notStrictEqual(saltA, saltB); |
| 32 | + }); |
| 33 | + |
| 34 | + it('produces different salts for different prfSalts with the same enterpriseId', function () { |
| 35 | + const saltA = deriveEnterpriseSalt(REAL_FIXTURE.basePrfSalt, REAL_FIXTURE.enterpriseId); |
| 36 | + const saltB = deriveEnterpriseSalt('deadbeefcafebabe0102030405060708', REAL_FIXTURE.enterpriseId); |
| 37 | + assert.notStrictEqual(saltA, saltB); |
| 38 | + }); |
| 39 | + |
| 40 | + it('returns a non-empty base64 string', function () { |
| 41 | + const result = deriveEnterpriseSalt(REAL_FIXTURE.basePrfSalt, REAL_FIXTURE.enterpriseId); |
| 42 | + assert.strictEqual(typeof result, 'string'); |
| 43 | + assert.ok(result.length > 0); |
| 44 | + assert.match(result, /^[A-Za-z0-9+/]+=*$/); |
| 45 | + }); |
| 46 | +}); |
0 commit comments