Регистрация V2: не проверено end-to-end

This commit is contained in:
AidarKC
2026-10-23 19:21:52 +03:00
parent 6c8159c5f7
commit cab26bbf41
95 changed files with 4469 additions and 1088 deletions
@@ -0,0 +1,42 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'../..');
const read = path => fs.readFileSync(`${root}/${path}`,'utf8');
const registry=read('SHiNE-server/shine-server-net-protocol/src/main/java/server/logic/ws_protocol/JSON/JsonHandlerRegistry.java');
const api=read('shine-UI/js/services/registration-v2-api.js');
const ops=['GetNamespaces','CheckRegistrationLogin','CheckRegistrationEmail',
'StartFreeRegistration','ConfirmFreeRegistration','GetRegistrationStatus'];
test('в серверном реестре ровно согласованные шесть операций, каждый op имеет request type',()=>{
for(const op of ops) {
assert.ok(registry.includes(`Map.entry("${op}", new Net_Registration_Handler`));
assert.ok(registry.includes(`Map.entry("${op}", Net_Registration_Request.class`));
}
assert.doesNotMatch(registry,/Map\.entry\("CheckRegistrationAvailability"/);
});
test('проверки login и email независимы и не отправляют лишних данных',()=>{
assert.match(api,/checkRegistrationLogin = .*call\('CheckRegistrationLogin', \{ fullLogin:/);
assert.match(api,/checkRegistrationEmail = .*call\('CheckRegistrationEmail', \{ email \}/);
});
test('free-регистрация передаёт ровно три публичных ключа, не пароли и не секреты',()=>{
const request=api.match(/export const startFreeRegistration = \([\s\S]*?\n\}\);/);
assert.ok(request);
assert.match(request[0],/rootPublicKeyB64/);
assert.match(request[0],/blockchainPublicKeyB64/);
assert.match(request[0],/clientPublicKeyB64/);
assert.doesNotMatch(request[0],/password|masterSecret|privatePkcs8|seed32/);
});
test('free экран показывает учебный код и ждёт Turbo, платный upgrade требует сравнить ключи',()=>{
const email=read('shine-UI/js/pages/registration-email-view.js');
assert.match(email,/код 1111/);assert.match(email,/confirmFreeRegistration/);
assert.match(email,/completeRegistrationLogin/);
const upgrade=read('shine-UI/js/pages/registration-upgrade-view.js');
assert.match(upgrade,/keys\.rootPair/);assert.match(upgrade,/bytesToBase58/);
assert.match(upgrade,/upgradeFreeUserOnSolana/);
});
test('никто не выкладывает регистрационный email в debug log',()=>{
const processor=read('SHiNE-server/shine-server-net-protocol/src/main/java/server/logic/ws_protocol/JSON/JsonInboundProcessor.java');
assert.match(processor,/registration payload redacted/);
});
@@ -0,0 +1,52 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import { fileURLToPath } from 'node:url';
import { resolve, dirname } from 'node:path';
import { encodeNamespacePda, decodeNamespacePda, normalizeFullLogin, userPdaSeed32,
namespacePdaSeed32, buildFreeCertificateInnerMessage } from '../js/services/shine-namespace-service.js';
import { serializeCreateUserPdaArgs } from '../js/services/shine-user-pda-service.js';
const dirnameHere = dirname(fileURLToPath(import.meta.url));
const props = Object.fromEntries(fs.readFileSync(resolve(dirnameHere, '../../shine-solana/shine/tests/fixtures/registration-v2.properties'), 'utf8')
.split(/\r?\n/).filter(x => x.includes('=')).map(line => [line.slice(0,line.indexOf('=')), line.slice(line.indexOf('=')+1)]));
const hex = x => Buffer.from(x).toString('hex');
const bh = x => Uint8Array.from(Buffer.from(x, 'hex'));
test('строгая нормализация полных логинов', () => {
assert.equal(normalizeFullLogin('alice@shine'), 'alice@shine');
for (const bad of ['alice','ALICE@shine','alice@Shine',' alice@shine','alice@@shine','alice.s@shine','a'.repeat(30)+'@a'])
assert.throws(() => normalizeFullLogin(bad));
assert.notEqual(normalizeFullLogin('a_b@shine'), normalizeFullLogin('ab@shine'));
});
test('namespace v1 бинарно соответствует Rust/Java вектору', () => {
const raw = bh(props.namespace_free_bytes_hex);
const ns = decodeNamespacePda(raw);
assert.equal(ns.namespace, 'free'); assert.equal(ns.type, 2);
assert.equal(ns.serverLogin, 'registrar@shine');
assert.deepEqual(encodeNamespacePda(ns), raw);
assert.throws(() => decodeNamespacePda(new Uint8Array([...raw, 0])));
assert.throws(() => decodeNamespacePda(raw.slice(0,-1)));
});
test('SHA256 PDA seeds stable and domain separated', async () => {
assert.equal(hex(await userPdaSeed32('bob@free')), props.user_bob_free_seed);
assert.equal(hex(await namespacePdaSeed32('free')), props.namespace_free_seed);
assert.notEqual(hex(await userPdaSeed32('bob@free')), hex(await namespacePdaSeed32('free')));
});
test('inner message is byte-for-byte fixture', () => {
const b = buildFreeCertificateInnerMessage('bob@free',
bh('03a107bff3ce10be1d70dd18e74bc09967e4d6309ba50d5f1ddc8664125531b8'),
bh('29acbae141bccaf0b22e1a94d34d0bc7361e526d0bfe12c89794bc9322966dd7'),
bh('2543b92ff1095511476adc8369db6ddc933665a11978dda1404ee1066ca9559d'));
assert.equal(hex(b), props.inner_message_hex);
});
test('create instruction suffix encodes registrar signature, never promo', () => {
const common = {login:'bob@free', rootKey32: new Uint8Array(32), createdAtMs:1n,
clientKey32:new Uint8Array(32), blockchainKey32:new Uint8Array(32),
recordSignature64:new Uint8Array(64), accessServers:[], serverAddresses:[]};
const paid = serializeCreateUserPdaArgs(common);
const free = serializeCreateUserPdaArgs({...common, registrarSignature64: new Uint8Array(64).fill(7)});
assert.equal(paid[paid.length-1], 0);
assert.equal(free[paid.length-1], 1);
assert.deepEqual(free.slice(paid.length), new Uint8Array(64).fill(7));
assert.equal(free[0],3);
});
+21
View File
@@ -0,0 +1,21 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { validateLoginOrThrow } from '../server-ui/js/server-ui-shared.js';
const read = p => readFileSync(new URL(p, import.meta.url), 'utf8');
test('server UI принимает полные логины и legacy при обновлении', () => {
assert.equal(validateLoginOrThrow('server@shine'), 'server@shine');
assert.equal(validateLoginOrThrow('old_server'), 'old_server');
assert.throws(() => validateLoginOrThrow('x'.repeat(26)+'@shine'));
assert.throws(() => validateLoginOrThrow('server@@shine'));
assert.throws(() => validateLoginOrThrow('server.name@shine'));
});
test('форма создания требует namespace type1 и правильный fee payer', () => {
const page = read('../server-ui/js/create-server-pda-page.js');
const service = read('../js/services/shine-user-pda-service.js');
const html = read('../server-ui/create-server-pda.html');
assert.match(page, /namespace\.type !== 1/);
assert.match(page, /getNamespace\(/);
assert.match(html, /maxlength="30"/);
assert.match(service, /feePayerPrivatePkcs8B64: keyBundle\.clientPair\.privatePkcs8B64/);
});