mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-12-03 18:43:38 +01:00
Spec 10 skipped on every run: it issued and revoked real licences through
the production licence server and needed an admin token no workflow had.
Its selectors had also rotted against the current plan page ("Existing
purchases", "Activate Key", "No Pro license is active"), so licence
activation, the path every paying customer takes, had no running browser
coverage.
The in-memory Ed25519 issuer behind the Organization provisioning job now
mints a second ephemeral key whose grants carry the Pro plan. The spec
pastes that key into the plan page's license recovery field, checks the
Pro state in the UI and the entitlements API, and clears it back to
Community through the UI. The offline CI job runs it with the same
wrapper, so no production credentials or signing material are involved.
Spec 11's plan-panel matcher drops the labels that no longer exist.
Contract-Neutral: Adds a CI step running an existing spec through the existing offline issuer wrapper; E2E image distribution and installability are unchanged.
78 lines
4.9 KiB
JavaScript
78 lines
4.9 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { createPublicKey, verify } from 'node:crypto';
|
|
import test from 'node:test';
|
|
import { startOfflineLicenseIssuer } from './offline-license-issuer.mjs';
|
|
|
|
const post = (issuer, route, data, token = '') => fetch(issuer.url + route, {
|
|
method: 'POST', headers: { Authorization: `Bearer ${token}` }, body: JSON.stringify(data),
|
|
});
|
|
|
|
test('offline issuer signs scoped grants and binds status/refresh to each installation', async t => {
|
|
const issuer = await startOfflineLicenseIssuer();
|
|
t.after(() => issuer.close());
|
|
const activate = fingerprint => post(issuer, '/v1/activate', {
|
|
activation_key: issuer.activationKey, instance_fingerprint: fingerprint, runtime: { build: 'community' },
|
|
});
|
|
const responses = await Promise.all(['default', 'org-a', 'org-b'].map(activate));
|
|
assert.ok(responses.every(r => r.status === 201));
|
|
const states = await Promise.all(responses.map(r => r.json()));
|
|
assert.equal(new Set(states.map(s => s.installation.installation_id)).size, 3);
|
|
assert.equal(new Set(states.map(s => s.installation.installation_token)).size, 3);
|
|
const pub = createPublicKey({ format: 'jwk', key: { kty: 'OKP', crv: 'Ed25519',
|
|
x: Buffer.from(issuer.publicKey, 'base64').toString('base64url') } });
|
|
for (const [i, state] of states.entries()) {
|
|
const [head, body, signature] = state.grant.jwt.split('.');
|
|
assert.ok(verify(null, Buffer.from(`${head}.${body}`), pub, Buffer.from(signature, 'base64url')));
|
|
const claims = JSON.parse(Buffer.from(body, 'base64url'));
|
|
assert.equal(claims.iid, state.installation.installation_id);
|
|
assert.equal(claims.lid, state.license.license_id);
|
|
assert.equal(claims.st, 'active'); assert.equal(claims.tier, 'msp');
|
|
assert.equal(claims.feat, undefined); // Runtime derives features; no capability injection.
|
|
const data = { installation_id: claims.iid, instance_fingerprint: ['default', 'org-a', 'org-b'][i] };
|
|
for (const route of ['/v1/grants/status', '/v1/grants/refresh']) {
|
|
assert.equal((await post(issuer, route, data, state.installation.installation_token)).status, 200);
|
|
assert.equal((await post(issuer, route, data, 'wrong')).status, 401);
|
|
assert.equal((await post(issuer, route, { ...data, instance_fingerprint: 'wrong' }, state.installation.installation_token)).status, 401);
|
|
assert.equal((await post(issuer, route, data, states[(i + 1) % 3].installation.installation_token)).status, 401);
|
|
}
|
|
}
|
|
const repeated = await (await activate('org-a')).json();
|
|
assert.deepEqual(repeated.installation, states[1].installation);
|
|
});
|
|
|
|
test('offline issuer grants the Pro plan only for its own activation key', async t => {
|
|
const issuer = await startOfflineLicenseIssuer(); t.after(() => issuer.close());
|
|
assert.notEqual(issuer.proActivationKey, issuer.activationKey);
|
|
const activate = key => post(issuer, '/v1/activate', {
|
|
activation_key: key, instance_fingerprint: 'default', runtime: { build: 'community' },
|
|
}).then(r => r.json());
|
|
const pro = await activate(issuer.proActivationKey);
|
|
const claims = JSON.parse(Buffer.from(pro.grant.jwt.split('.')[1], 'base64url'));
|
|
assert.equal(pro.license.tier, 'pro');
|
|
assert.equal(claims.tier, 'pro'); assert.equal(claims.plan, 'pro_monthly');
|
|
assert.equal(claims.feat, undefined);
|
|
const refreshed = await (await post(issuer, '/v1/grants/refresh',
|
|
{ installation_id: claims.iid, instance_fingerprint: 'default' }, pro.installation.installation_token)).json();
|
|
assert.equal(JSON.parse(Buffer.from(refreshed.grant.jwt.split('.')[1], 'base64url')).tier, 'pro');
|
|
// One fingerprint activating a different key is a different licence binding.
|
|
const msp = await activate(issuer.activationKey);
|
|
assert.notEqual(msp.installation.installation_id, pro.installation.installation_id);
|
|
assert.equal(msp.license.tier, 'msp');
|
|
});
|
|
|
|
test('offline issuer rejects unsupported routes, bad activation and malformed input', async t => {
|
|
const issuer = await startOfflineLicenseIssuer(); t.after(() => issuer.close());
|
|
const data = { activation_key: issuer.activationKey, instance_fingerprint: 'default', runtime: { build: 'community' } };
|
|
for (const mutation of [{ activation_key: 'wrong' }, { runtime: { build: 'enterprise' } }, { instance_fingerprint: '' }]) {
|
|
assert.ok((await post(issuer, '/v1/activate', { ...data, ...mutation })).status >= 400);
|
|
}
|
|
assert.equal((await post(issuer, '/v1/licenses/exchange', data)).status, 404);
|
|
assert.equal((await fetch(issuer.url + '/v1/activate')).status, 404);
|
|
assert.equal((await fetch(issuer.url + '/v1/activate', { method: 'POST', body: '{' })).status, 400);
|
|
assert.equal((await post(issuer, '/v1/activate', { ...data, extra: 'x'.repeat(17000) })).status, 413);
|
|
const other = await startOfflineLicenseIssuer(); t.after(() => other.close());
|
|
assert.notEqual(other.publicKey, issuer.publicKey);
|
|
assert.notEqual(other.activationKey, issuer.activationKey);
|
|
assert.notEqual(other.proActivationKey, issuer.proActivationKey);
|
|
});
|