SHA256
Разделить среды и закрепить лицензии в HEADER 1.0
This commit is contained in:
@@ -5,18 +5,12 @@ import vm from 'node:vm';
|
||||
|
||||
const read = file => fs.readFileSync(new URL(file, import.meta.url), 'utf8');
|
||||
const auth = read('../js/services/auth-service.js');
|
||||
const register = read('../js/pages/register-view.js');
|
||||
const termsPath = new URL('../js/pages/registration-terms-view.js', import.meta.url);
|
||||
const hasRegistrationTerms = fs.existsSync(termsPath);
|
||||
const terms = hasRegistrationTerms ? read('../js/pages/registration-terms-view.js') : '';
|
||||
const router = read('../js/router.js');
|
||||
const email = read('../js/pages/registration-email-view.js');
|
||||
const paid = read('../js/pages/registration-payment-view.js');
|
||||
|
||||
// Исполняем именно production-сериализатор, а не дублируем алгоритм тестовым кодом.
|
||||
const makeBytesFunction = auth.split('function makeHeaderBodyBytes(')[1]?.split('\nfunction makeUserParamBodyBytes(')[0];
|
||||
assert.ok(makeBytesFunction);
|
||||
const context = {
|
||||
HEADER_DEFAULT_LICENSE: auth.match(/export const HEADER_DEFAULT_LICENSE = '([^']+)'/)[1],
|
||||
utf8Bytes: value => new TextEncoder().encode(value),
|
||||
int8Byte: value => Uint8Array.of(value),
|
||||
concatBytes: (...parts) => Uint8Array.from(parts.flatMap(part => Array.from(part))),
|
||||
@@ -24,7 +18,7 @@ const context = {
|
||||
};
|
||||
const makeHeaderBodyBytes = vm.runInNewContext(`function makeHeaderBodyBytes(${makeBytesFunction}\nmakeHeaderBodyBytes`, context);
|
||||
|
||||
test('CORE/CONTENT HEADER 2 contains identity, arbitrary license and initial key', () => {
|
||||
test('CORE/CONTENT HEADER 1 contains identity, arbitrary license and initial key', () => {
|
||||
const key = Uint8Array.from({ length: 32 }, (_, n) => n + 1);
|
||||
const result = makeHeaderBodyBytes({ login: 'Alice@shine', initialBlockchainKey32: key });
|
||||
const login = new TextEncoder().encode('Alice@shine');
|
||||
@@ -34,21 +28,12 @@ test('CORE/CONTENT HEADER 2 contains identity, arbitrary license and initial key
|
||||
const identityOffset = 6 + login.length;
|
||||
assert.equal(result[identityOffset], 1);
|
||||
assert.deepEqual(Array.from(result.slice(identityOffset + 1, identityOffset + 3)), [0, 0]);
|
||||
assert.deepEqual(Array.from(result.slice(identityOffset + 3, identityOffset + 5)), [0, 7]);
|
||||
assert.equal(new TextDecoder().decode(result.slice(identityOffset + 5, identityOffset + 12)), 'CC0-1.0');
|
||||
assert.deepEqual(Array.from(result.slice(identityOffset + 12)), Array.from(key));
|
||||
assert.equal(result.length, 5 + 1 + login.length + 1 + 2 + 2 + 7 + 32);
|
||||
const license = context.HEADER_DEFAULT_LICENSE;
|
||||
const licenseBytes = new TextEncoder().encode(license);
|
||||
assert.deepEqual(Array.from(result.slice(identityOffset + 3, identityOffset + 5)), [licenseBytes.length >> 8, licenseBytes.length & 255]);
|
||||
assert.equal(new TextDecoder().decode(result.slice(identityOffset + 5, identityOffset + 5 + licenseBytes.length)), license);
|
||||
assert.deepEqual(Array.from(result.slice(identityOffset + 5 + licenseBytes.length)), Array.from(key));
|
||||
assert.equal(result.length, 5 + 1 + login.length + 1 + 2 + 2 + licenseBytes.length + 32);
|
||||
assert.match(auth, /msgSubType: MSG_SUBTYPE_TECH_HEADER,\s*msgVersion: HEADER_VERSION/);
|
||||
assert.match(auth, /export const HEADER_VERSION = 2/);
|
||||
});
|
||||
|
||||
test('free and paid registration both require accepted documents before any registration operation', { skip: !hasRegistrationTerms }, () => {
|
||||
assert.match(register, /navigate\('registration-terms-view'\)/);
|
||||
assert.match(terms, /draft\.termsAccepted = true/);
|
||||
assert.match(terms, /draft\.flowType === 'free' \? 'registration-email-view' : 'registration-payment-view'/);
|
||||
assert.match(email, /if \(!state\.registrationDraft\.termsAccepted\)/);
|
||||
assert.match(paid, /if \(!state\.registrationDraft\.termsAccepted\)/);
|
||||
assert.match(router, /\['registration-terms-view', 'register\/terms'\]/);
|
||||
assert.match(terms, /CC0_LEGAL_CODE_URL/);
|
||||
assert.match(terms, /DOCUMENT_COUNT = 4/);
|
||||
assert.match(auth, /export const HEADER_VERSION = 1/);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user