Промежуточно: синхронизировать регистр логинов

This commit is contained in:
AidarKC
2026-10-29 13:10:12 +03:00
parent d2b2876a79
commit 395aa62bda
23 changed files with 312 additions and 42 deletions
@@ -0,0 +1,92 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { AuthService } from '../js/services/auth-service.js';
const target = {
login: 'alexsmith@shine', // case из имени цепочки, а не из регистрации
blockchainName: 'alexsmith@shine-001',
blockNumber: 4,
blockHash: 'ab'.repeat(32),
forkNumber: 1,
};
const original = 'AlexSmith@shine';
const input = { login: 'tester@shine', storagePwd: 'test', message: target, text: 'ответ' };
function mockService({ registered = original, exists = true } = {}) {
const service = new AuthService('wss://local.example/ws');
const sent = [];
const requested = [];
service.getUser = async (login) => {
requested.push(login);
return { exists, login: registered, blockchainName: 'alexsmith@shine-001' };
};
service.addBlockSigned = async (args) => {
sent.push(args);
return { serverLastGlobalNumber: 1, serverLastGlobalHash: 'ac'.repeat(32) };
};
return { service, sent, requested };
}
const hasLogin = (bodyBytes, login) => Buffer.from(bodyBytes).includes(Buffer.from(login, 'utf8'));
test('ссылки reply, rating, status, like и unlike подписываются с регистром регистрации', async () => {
for (const method of ['addBlockReply', 'addBlockRating', 'addBlockStatusAction', 'addBlockLike', 'addBlockUnlike']) {
const { service, sent, requested } = mockService();
await service[method]({ ...input, statusSubType: 110 });
assert.equal(sent.length, 1, method);
assert.deepEqual(requested, [target.login], method);
assert.ok(hasLogin(sent[0].bodyBytes, original), `${method}: оригинальный логин отсутствует`);
assert.ok(!hasLogin(sent[0].bodyBytes, target.login), `${method}: записан lowercase`);
}
});
test('если регистрационный логин не подтверждён, клиент не подписывает блок', async () => {
for (const data of [{ exists: false }, { registered: 'Other@shine' }]) {
const { service, sent } = mockService(data);
await assert.rejects(() => service.addBlockReply(input), /Не удалось подтвердить/);
assert.equal(sent.length, 0);
}
});
test('связи между пользователями фиксируют исходный регистр цели', async () => {
const { service, sent } = mockService();
service.ensureChainInitializedForLineOps = async () => ({ blockchainName: 'tester@shine-001' });
service.resolveFixedLineTail = async () => ({ prevLineNumber: 0, prevLineHashHex: 'ac'.repeat(32), thisLineNumber: 1 });
service.rememberLineTail = () => {};
await service.addBlockConnectionTarget({
login: 'tester@shine', storagePwd: 'test', subType: 30,
toLogin: target.login, toForkNumber: 1, toBlockNumber: 0, toBlockHashHex: 'ab'.repeat(32),
});
assert.equal(sent.length, 1);
assert.ok(hasLogin(sent[0].bodyBytes, original));
assert.ok(!hasLogin(sent[0].bodyBytes, target.login));
});
test('HEADER и PostgreSQL требуют неизменяемого регистра, Solana sync отклоняет переименование', () => {
const client = readFileSync(new URL('../js/services/auth-service.js', import.meta.url), 'utf8');
const handler = readFileSync(new URL('../../SHiNE-server/shine-server-net-protocol/src/main/java/server/logic/ws_protocol/JSON/handlers/blockchain/Net_AddBlock_Handler.java', import.meta.url), 'utf8');
const header = readFileSync(new URL('../../SHiNE-server/shine-server-blockchain/src/main/java/blockchain/body/HeaderBody.java', import.meta.url), 'utf8');
const migration = readFileSync(new URL('../../SHiNE-server/shine-server-db/src/main/resources/postgres/migration_v37.sql', import.meta.url), 'utf8');
assert.match(client, /bodyBytes: makeHeaderBodyBytes\(\{ login: registeredLogin, initialBlockchainKey32 \}\)/);
assert.doesNotMatch(client, /makeHeaderBodyBytes\(\{ login: cleanLogin\.toLowerCase\(\)/);
assert.match(handler, /headerBody\.login\.equals\(registeredOwner\.getLogin\(\)\)/);
assert.match(header, /\[A-Za-z0-9_\]\+@\[a-z0-9_\]\+/);
assert.match(migration, /old_user\.login <> NEW\.login/);
assert.match(migration, /NEW\.login IS DISTINCT FROM OLD\.login/);
});
test('лента, список подписок и дерево обсуждения возвращают оригинальный регистр автора', () => {
const base = new URL('../../SHiNE-server/shine-server-net-protocol/src/main/java/server/logic/ws_protocol/JSON/handlers/channels/', import.meta.url);
const read = (file) => readFileSync(new URL(file, base), 'utf8');
const channel = read('Net_GetChannelMessages_Handler.java');
const thread = read('Net_GetMessageThread_Handler.java');
const feed = read('Net_ListSubscriptionsFeed_Handler.java');
const helper = read('ChannelsReadSupport.java');
assert.match(channel, /setAuthorLogin\(ChannelsReadSupport\.officialLogin\(/);
assert.match(channel, /setOwnerLogin\(ChannelsReadSupport\.officialLogin\(/);
assert.match(thread, /node\.setAuthorLogin\(ChannelsReadSupport\.officialLogin\(/);
assert.match(feed, /lm\.setAuthorLogin\(ChannelsReadSupport\.officialLogin\(/);
assert.match(feed, /channelRef\.setOwnerLogin\(ChannelsReadSupport\.officialLogin\(/);
assert.match(helper, /value = canonicalLogin\(c, raw\)/);
});