Files
SHiNE-server/SHiNE-server/shine-server-archive/src/test/java/server/archive/FreeRegistrationWorkflowLocalCheck.java
T

42 lines
2.6 KiB
Java

package server.archive;
import server.archive.registration.*;
import javax.sql.DataSource;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HexFormat;
/** Только проверки без БД/сети; полное E2E требует PostgreSQL и Turbo. */
public final class FreeRegistrationWorkflowLocalCheck {
public static void main(String[] args) throws Exception {
var signer = new RegistrarSigner() {
public byte[] publicKey32() { return new byte[32]; }
public byte[] sign(byte[] message) { return new byte[64]; }
};
DataSource noDb = new DataSource() {
public java.sql.Connection getConnection() throws java.sql.SQLException { throw new java.sql.SQLException("No database in local test"); }
public java.sql.Connection getConnection(String u, String p) throws java.sql.SQLException { return getConnection(); }
public java.io.PrintWriter getLogWriter() {return null;}
public void setLogWriter(java.io.PrintWriter x) {}
public void setLoginTimeout(int x) {}
public int getLoginTimeout() {return 0;}
public java.util.logging.Logger getParentLogger() {return java.util.logging.Logger.getAnonymousLogger();}
public <T> T unwrap(Class<T> iface) throws java.sql.SQLException {throw new java.sql.SQLException("unsupported");}
public boolean isWrapperFor(Class<?> iface) {return false;}
};
var issuer = new FreeRegistrationIssuer(noDb, signer);
var importer = new VerifiedFreeRegistrationImporter();
var workflow = new FreeRegistrationWorkflow(issuer,
new FreeRegistrationPublisher(issuer, new TurboDataItemUploader(ArweaveBlocksConfig.load()), importer),
(email, code) -> { throw new AssertionError("No real email in an offline check"); },
false, false, AllowedEmailDomains.load(Files.isRegularFile(Path.of("allowed-email-domains.txt"))
? Path.of("allowed-email-domains.txt") : Path.of("../allowed-email-domains.txt")));
try { workflow.confirm("unknown", "123456"); throw new AssertionError("Missing challenge accepted"); }
catch (IllegalArgumentException expected) { }
try { importer.importSigned(new byte[]{1,2,3}, VerifiedFreeRegistrationImporter.Provenance.TURBO_ACCEPTED);
throw new AssertionError("Invalid bytes accepted"); }
catch (IllegalArgumentException expected) { }
System.out.println("PASS: workflow missing challenge + reject invalid signed bytes");
}
}