fix:"隔离验证码投递并统一密码重置受理"
Repository verification / backend (push) Canceled after 0s
Repository verification / frontend (push) Canceled after 0s

This commit is contained in:
xpp committed 2026-10-22 08:49:04 +08:00
1 parent 02c21e5c19
commit ba5dbc195e
16 files changed
+639 -57

No files matched your search

@@ -54,6 +54,7 @@ class PlatformAdminPostgresTest {
private CatalogService catalog;
private WalletService wallet;
private VerificationService verification;
private VerificationDispatchService dispatch;
private TestSender sender;
@BeforeEach void setup() throws Exception {
@@ -87,12 +88,14 @@ class PlatformAdminPostgresTest {
context.registerBean(WalletService.class, () -> new WalletService(jdbc, context.getBean(AuthService.class)));
context.registerBean(UsageAuditService.class, () -> new UsageAuditService(jdbc,json));
context.registerBean(ChatBillingService.class, () -> new ChatBillingService(jdbc,json,context.getBean(UsageAuditService.class)));
context.registerBean(VerificationService.class, () -> new VerificationService(jdbc, sender, "test-pepper"));
context.registerBean(VerificationDispatchService.class, () -> new VerificationDispatchService(jdbc,sender,new SecretCipher("test-delivery-encryption"),json,context.getBean(DataSourceTransactionManager.class)));
context.registerBean(VerificationService.class, () -> new VerificationService(jdbc, context.getBean(VerificationDispatchService.class), "test-pepper"));
context.refresh();
auth = context.getBean(AuthService.class);
catalog = context.getBean(CatalogService.class);
wallet = context.getBean(WalletService.class);
verification = context.getBean(VerificationService.class);
dispatch = context.getBean(VerificationDispatchService.class);
auth.ensureAdmin("test_owner", "local-password", "Test Owner");
ownerToken = auth.login("test_owner", "local-password", meta).token();
memberId = auth.createUser(ownerToken, "test_member", "local-password", "Test Member", meta).id();
@@ -335,6 +338,7 @@ class PlatformAdminPostgresTest {
http.perform(post("/api/auth/register").contentType("application/json").content(json.writeValueAsBytes(input))).andExpect(status().isBadRequest());
http.perform(post("/api/auth/verification").contentType("application/json").content(json.writeValueAsBytes(input)))
.andExpect(status().isOk()).andExpect(jsonPath("$.code").doesNotExist()).andExpect(jsonPath("$.sent").value(true));
assertTrue(VerificationDeliveryFixture.deliverOne(dispatch));
String code = sender.codes.get(account);
assertNotEquals(code,jdbc.queryForObject("SELECT code_hash FROM registration_codes WHERE account=?",String.class,account));
input.put("verificationCode",code);
@@ -350,16 +354,19 @@ class PlatformAdminPostgresTest {
assertThrows(ApiException.class, () -> verification.send(account,"bad-invite","127.0.0.1"));
verification.send(account,invite,"127.0.0.1");
assertThrows(ApiException.class, () -> verification.send(account,invite,"127.0.0.1"));
assertTrue(VerificationDeliveryFixture.deliverOne(dispatch));
String correct=sender.codes.get(account);
String wrong=correct.equals("000000")?"111111":"000000";
for(int i=0;i<5;i++) assertThrows(ApiException.class, () -> verification.consume(account,wrong));
assertEquals(5,jdbc.queryForObject("SELECT attempts FROM registration_codes WHERE account=?",Integer.class,account));
assertThrows(ApiException.class, () -> verification.consume(account,correct));
verification.send("expired@example.test",invite,"127.0.0.1");
assertTrue(VerificationDeliveryFixture.deliverOne(dispatch));
jdbc.update("UPDATE registration_codes SET expires_at=now()-interval '1 second' WHERE account='expired@example.test'");
assertThrows(ApiException.class, () -> verification.consume("expired@example.test",sender.codes.get("expired@example.test")));
sender.fail=true;
assertThrows(ApiException.class, () -> verification.send("failed@example.test",invite,"127.0.0.1"));
assertEquals(true,verification.send("failed@example.test",invite,"127.0.0.1").get("sent"));
assertTrue(VerificationDeliveryFixture.deliverOne(dispatch));
assertTrue(jdbc.queryForObject("SELECT consumed FROM registration_codes WHERE account='failed@example.test'",Boolean.class));
assertEquals(1,jdbc.queryForObject("SELECT count(*) FROM verification_send_events WHERE account='failed@example.test'",Integer.class));
sender.enabled=false;