用户编码生成缩短为12字符

This commit is contained in:
lxp
2026-10-19 13:53:53 +08:00
parent 97f816fffc
commit 8a3ecabdc0
6 changed files with 171 additions and 18 deletions
@@ -282,7 +282,7 @@ class WorkflowTest {
perform(auth(put("/api/community/projects/" + legacy + "/like"), owner), 200);
JsonNode comment = perform(body(auth(post("/api/community/projects/" + legacy + "/comments"), owner), Map.of("content", "兼容测试")), 200).path("data");
assertThat(comment.path("commentCode").asText()).hasSize(32);
assertThat(copy.path("owner").path("userCode").asText()).hasSize(32);
assertThat(copy.path("owner").path("userCode").asText()).hasSize(12);
}
@Test
@@ -589,7 +589,8 @@ class WorkflowTest {
JsonNode first = loginData("OWNER@example.com");
JsonNode second = loginData("owner@example.com");
assertThat(first.path("user").path("userCode").asText())
.isEqualTo(second.path("user").path("userCode").asText());
.isEqualTo(second.path("user").path("userCode").asText())
.matches("[0-9abcdefghjkmnpqrstvwxyz]{12}");
assertThat(jdbc.queryForObject("SELECT COUNT(*) FROM sys_user", Long.class)).isEqualTo(1L);
JsonNode challenge = perform(get("/api/auth/captcha"), 200).path("data");
assertThat(challenge.path("image").asText()).startsWith("data:image/png;base64,");
@@ -621,6 +622,22 @@ class WorkflowTest {
perform(get("/api/workspace/projects"), 401);
}
@Test
void loginPreservesLegacyUserCodes() throws Exception {
String legacyCode = "1234567890abcdef1234567890abcdef";
jdbc.update(
"INSERT INTO sys_user (user_code, email, nickname, status, created_at, updated_at)"
+ " VALUES (?, ?, ?, 'ACTIVE', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)",
legacyCode, "legacy@example.com", "历史用户");
JsonNode data = loginData("LEGACY@example.com");
assertThat(data.path("user").path("userCode").asText()).isEqualTo(legacyCode);
JsonNode me = perform(auth(get("/api/users/me"), data.path("token").asText()), 200)
.path("data");
assertThat(me.path("userCode").asText()).isEqualTo(legacyCode);
assertThat(me.has("id")).isFalse();
assertThat(jdbc.queryForObject("SELECT COUNT(*) FROM sys_user", Long.class)).isEqualTo(1L);
}
@Test
void openApiMatchesRoutesAndPublicAuthenticationAndOnlyFourTablesExist() throws Exception {
JsonNode spec = perform(get("/v3/api-docs"), 200);