fix(auth): reject placeholder mobile numbers
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package com.baiyue.auth.repository;
|
||||
|
||||
import com.baiyue.auth.dto.AccountManagementDtos.ChangeLoginIdentifiersRequest;
|
||||
import com.baiyue.auth.dto.MerchantRegisterRequest;
|
||||
import jakarta.validation.Validation;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class LoginIdentifierContractTest {
|
||||
|
||||
@Test
|
||||
void mainlandMobileRuleRejectsPlaceholderNumbersAcrossJavaAndSql() throws Exception {
|
||||
try (var factory = Validation.buildDefaultValidatorFactory()) {
|
||||
var validator = factory.getValidator();
|
||||
var invalidRegistration = new MerchantRegisterRequest(
|
||||
"merchant.user", "Password1", "测试用户", "测试企业", "张三",
|
||||
"11111111111", null, "CN", null);
|
||||
var validChange = new ChangeLoginIdentifiersRequest(
|
||||
"merchant.user", "13800138000", "Password1");
|
||||
var invalidChange = new ChangeLoginIdentifiersRequest(
|
||||
"merchant.user", "11111111111", "Password1");
|
||||
|
||||
assertThat(validator.validate(invalidRegistration)).isNotEmpty();
|
||||
assertThat(validator.validate(validChange)).isEmpty();
|
||||
assertThat(validator.validate(invalidChange)).isNotEmpty();
|
||||
}
|
||||
|
||||
String sql = new ClassPathResource("db/auth-login-identifiers.sql")
|
||||
.getContentAsString(StandardCharsets.UTF_8);
|
||||
assertThat(sql)
|
||||
.contains("REGEXP '^1[3-9][0-9]{9}$'")
|
||||
.doesNotContain("REGEXP '^1[0-9]{10}$'");
|
||||
}
|
||||
}
|
||||
@@ -128,6 +128,18 @@ class AuthServiceSmallJwtTest {
|
||||
verify(repository, never()).findByUsername("13800138000");
|
||||
}
|
||||
|
||||
@Test
|
||||
void placeholderNumberIsNeverResolvedAsAMobileLoginIdentifier() {
|
||||
when(repository.findByUsername("11111111111")).thenReturn(null);
|
||||
|
||||
assertThatThrownBy(() -> service.login(new LoginRequest("11111111111", "secret")))
|
||||
.isInstanceOf(com.baiyue.common.core.exception.BizException.class)
|
||||
.hasMessageContaining("登录标识或密码错误");
|
||||
|
||||
verify(repository).findByUsername("11111111111");
|
||||
verify(repository, never()).findByPhone("11111111111");
|
||||
}
|
||||
|
||||
@Test
|
||||
void refreshRotatesDomesticAndOverseasTokensFromOneAuthorizationSnapshot() {
|
||||
AuthAccount account = new AuthAccount();
|
||||
|
||||
Reference in New Issue
Block a user