Регистрация: бесплатная регистрация работает

This commit is contained in:
AidarKC
2026-10-24 16:17:34 +03:00
parent cab26bbf41
commit a520c5c5e1
14 changed files with 111 additions and 34 deletions
@@ -78,8 +78,14 @@ public final class HeaderBody implements BodyRecord {
public HeaderBody check() {
if ((subType & 0xFFFF) != 0) throw new IllegalArgumentException("HeaderBody subType must be 0");
if (login == null || login.isBlank()) throw new IllegalArgumentException("Login is blank");
if (!login.matches("^[A-Za-z0-9_]+$")) throw new IllegalArgumentException("Login must match ^[A-Za-z0-9_]+$");
byte[] loginUtf8 = login.getBytes(StandardCharsets.UTF_8);
// Legacy login remains valid; new registration uses a canonical full login@namespace.
// This changes only validation, not the serialized HEADER body or signature format.
boolean legacyLogin = login.matches("^[A-Za-z0-9_]+$");
boolean namespacedLogin = loginUtf8.length <= 30 && login.matches("^[a-z0-9_]+@[a-z0-9_]+$");
if (!legacyLogin && !namespacedLogin) {
throw new IllegalArgumentException("Login must be legacy [A-Za-z0-9_]+ or canonical login@namespace (max 30 bytes)");
}
if (loginUtf8.length == 0 || loginUtf8.length > 255) throw new IllegalArgumentException("Login utf8 len must be 1..255");
requireNonZeroKey(initialBlockchainKey32);
return this;
@@ -98,6 +98,23 @@ final class TargetLoginFormatTest {
assertArrayEquals(INITIAL_KEY, parsed.initialBlockchainKey32);
}
@Test
void namespacedHeaderRoundTripAcceptsPaidAndFreeUsers() {
for (String login : new String[]{"alice@free", "alice@shine", "a_b@free", "abcdefghijklmnopqrstuvwxy@free"}) {
HeaderBody source = new HeaderBody(login, INITIAL_KEY);
HeaderBody parsed = new HeaderBody(HeaderBody.SUBTYPE_COMPAT, HeaderBody.VER, source.toBytes()).check();
assertEquals(login, parsed.login);
assertArrayEquals(INITIAL_KEY, parsed.initialBlockchainKey32);
}
}
@Test
void namespacedHeaderRejectsMalformedOrOversizedLogin() {
for (String login : new String[]{"alice@", "@shine", "alice@@free", "Alice@free", "alice@FREE", "alice.free@shine", "abcdefghijklmnopqrstuvwxyz@free"}) {
assertThrows(IllegalArgumentException.class, () -> new HeaderBody(login, INITIAL_KEY), login);
}
}
private static byte[] hash(int seed) {
byte[] out = new byte[32];
Arrays.fill(out, (byte) seed);
@@ -13,10 +13,10 @@ import server.logic.ws_protocol.JSON.utils.NetExceptionResponseFactory;
import server.logic.ws_protocol.WireCodes;
import shine.db.dao.BlockchainStateDAO;
import shine.db.dao.CanonicalChainResolver;
import shine.db.dao.SolanaUserPdaCurrentDAO;
import shine.db.dao.CurrentUsersDAO;
import shine.db.entities.BlockEntry;
import shine.db.entities.BlockchainStateEntry;
import shine.db.entities.SolanaUserPdaCurrentEntry;
import shine.db.entities.CurrentUserEntry;
import java.util.ArrayList;
import java.util.Collections;
@@ -26,7 +26,7 @@ import java.util.List;
public final class Net_GetMyBlockchain_Handler implements JsonMessageHandler {
private final CanonicalChainResolver canonical = CanonicalChainResolver.getInstance();
private final BlockchainStateDAO states = BlockchainStateDAO.getInstance();
private final SolanaUserPdaCurrentDAO users = SolanaUserPdaCurrentDAO.getInstance();
private final CurrentUsersDAO users = CurrentUsersDAO.getInstance();
@Override
public Net_Response handle(Net_Request baseReq, ConnectionContext ctx) {
@@ -36,7 +36,7 @@ public final class Net_GetMyBlockchain_Handler implements JsonMessageHandler {
}
try {
String login = ctx.getLogin().trim();
SolanaUserPdaCurrentEntry user = users.getByLogin(login);
CurrentUserEntry user = users.getByLogin(login);
if (user == null || user.getBlockchainName() == null || user.getBlockchainName().isBlank()) {
return NetExceptionResponseFactory.error(req, 404, "BLOCKCHAIN_NOT_FOUND", "Текущий блокчейн пользователя не найден");
}