chore: license server updates and tests
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
|
||||
import { canonicalJson } from '../lib/canonicalJson.mjs';
|
||||
|
||||
void test('canonicalJson: stable key order', () => {
|
||||
const a = canonicalJson({ b: 2, a: 1 });
|
||||
const b = canonicalJson({ a: 1, b: 2 });
|
||||
assert.equal(a, b);
|
||||
assert.equal(a, '{"a":1,"b":2}');
|
||||
});
|
||||
|
||||
void test('canonicalJson: rejects non-finite number', () => {
|
||||
assert.throws(() => canonicalJson({ x: NaN }), TypeError);
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { generateKeyPairSync, verify } from 'node:crypto';
|
||||
import test from 'node:test';
|
||||
|
||||
import { signPayload } from '../lib/signPayload.mjs';
|
||||
|
||||
void test('signPayload produces verifiable Ed25519 token', () => {
|
||||
const { privateKey, publicKey } = generateKeyPairSync('ed25519');
|
||||
const pem = privateKey.export({ type: 'pkcs8', format: 'pem' });
|
||||
const payload = { v: 1, sub: 's1', pid: 'p', iat: 1, exp: 2, did: 'd1' };
|
||||
const token = signPayload(payload, pem);
|
||||
const [bodyB64, sigB64] = token.split('.');
|
||||
assert.ok(bodyB64 && sigB64);
|
||||
const body = Buffer.from(bodyB64, 'base64url');
|
||||
const sig = Buffer.from(sigB64, 'base64url');
|
||||
const ok = verify(null, body, publicKey, sig);
|
||||
assert.equal(ok, true);
|
||||
});
|
||||
Reference in New Issue
Block a user