подготовка к билду

This commit is contained in:
Ivan Fontosh
2026-04-19 23:22:05 +08:00
parent 2fa20da94d
commit 726c89e104
13 changed files with 180 additions and 13 deletions
@@ -54,3 +54,29 @@ void test('verifyLicenseToken: неверное устройство', () => {
if (bad.ok) assert.fail('expected failure');
assert.equal(bad.reason, 'wrong_device');
});
void test('verifyLicenseToken: токен с переносами строк после копирования', () => {
const { publicKey, privateKey } = generateKeyPairSync('ed25519');
const pubB64 = publicKey.export({ type: 'spki', format: 'der' }).toString('base64');
const licensePayload = {
v: 1 as const,
sub: 'lic_wrap',
pid: 'dnd_player',
iat: 100,
exp: 2_000_000_000,
did: null as string | null,
};
const body = canonicalJson(licensePayload);
const sig = sign(null, Buffer.from(body, 'utf8'), privateKey);
const token = joinSignedLicenseToken(body, new Uint8Array(sig.buffer, sig.byteOffset, sig.byteLength));
const mid = Math.max(1, Math.floor(token.length / 2));
const messy = `${token.slice(0, mid)}\n${token.slice(mid, mid + 3)} \r\n ${token.slice(mid + 3)}`;
const ok = verifyLicenseToken(messy, {
nowSec: 1_700_000_000,
deviceId: 'any',
publicKeyOverrideSpkiDerB64: pubB64,
});
if (!ok.ok) assert.fail(`expected ok, got ${ok.reason}`);
assert.equal(ok.payload.sub, 'lic_wrap');
});