管理员角色也允许登录前台用户端
This commit is contained in:
@@ -118,20 +118,17 @@ class WorkflowTest {
|
||||
}
|
||||
|
||||
private JsonNode loginData(String email) throws Exception {
|
||||
return loginResponse(email, 200).path("data");
|
||||
}
|
||||
|
||||
private JsonNode loginResponse(String email, int status) throws Exception {
|
||||
String captcha =
|
||||
perform(get("/api/auth/captcha"), 200).path("data").path("captchaCode").asText();
|
||||
return perform(
|
||||
body(
|
||||
post("/api/auth/login"),
|
||||
Map.of(
|
||||
"email",
|
||||
email,
|
||||
"captchaCode",
|
||||
captcha,
|
||||
"captchaAnswer",
|
||||
"abcde")),
|
||||
200)
|
||||
.path("data");
|
||||
Map<String, Object> input = new HashMap<>();
|
||||
input.put("email", email);
|
||||
input.put("captchaCode", captcha);
|
||||
input.put("captchaAnswer", "abcde");
|
||||
return perform(body(post("/api/auth/login"), input), status);
|
||||
}
|
||||
|
||||
private String login(String email) throws Exception {
|
||||
@@ -1591,12 +1588,57 @@ class WorkflowTest {
|
||||
+ " user_code=?",
|
||||
code);
|
||||
perform(auth(get("/api/users/me"), fresh), 401);
|
||||
String captcha =
|
||||
perform(get("/api/auth/captcha"), 200).path("data").path("captchaCode").asText();
|
||||
perform(
|
||||
body(
|
||||
post("/api/auth/login"),
|
||||
Map.of("email", email, "captchaCode", captcha, "captchaAnswer", "ABCDE")),
|
||||
403);
|
||||
String promoted = login(email);
|
||||
perform(auth(get("/api/users/me"), promoted), 200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void adminCanUseItsOwnCommunityWorkspaceAfterCaptchaLogin() throws Exception {
|
||||
String email = "community-admin@example.invalid";
|
||||
JsonNode previousLogin = loginData(email);
|
||||
String userCode = previousLogin.path("user").path("userCode").asText();
|
||||
jdbc.update(
|
||||
"UPDATE sys_user SET role='ADMIN',"
|
||||
+ " session_version=session_version+1 WHERE user_code=?",
|
||||
userCode);
|
||||
perform(auth(get("/api/users/me"), previousLogin.path("token").asText()), 401);
|
||||
|
||||
JsonNode login = loginData(email);
|
||||
String token = login.path("token").asText();
|
||||
assertThat(login.path("user").path("userCode").asText()).isEqualTo(userCode);
|
||||
assertThat(login.path("user").has("id")).isFalse();
|
||||
assertThat(login.path("user").has("passwordHash")).isFalse();
|
||||
JsonNode me = perform(auth(get("/api/users/me"), token), 200).path("data");
|
||||
assertThat(me.path("userCode").asText()).isEqualTo(userCode);
|
||||
assertThat(me.has("id")).isFalse();
|
||||
String projectCode = create(token, "管理员的社区项目");
|
||||
head(token, projectCode);
|
||||
|
||||
String other = login("another-owner@example.invalid");
|
||||
String otherProject = create(other, "其他用户的项目");
|
||||
perform(auth(get("/api/workspace/projects/" + otherProject + "/tree"), token), 404);
|
||||
|
||||
jdbc.update(
|
||||
"UPDATE sys_user SET status='DISABLED', session_version=session_version+1"
|
||||
+ " WHERE user_code=?",
|
||||
userCode);
|
||||
perform(auth(get("/api/users/me"), token), 401);
|
||||
assertThat(loginResponse(email, 403).path("code").asText()).isEqualTo("ACCOUNT_DISABLED");
|
||||
jdbc.update(
|
||||
"UPDATE sys_user SET status='ACTIVE', session_version=session_version+1"
|
||||
+ " WHERE user_code=?",
|
||||
userCode);
|
||||
perform(auth(get("/api/users/me"), token), 401);
|
||||
String fresh = login(email);
|
||||
perform(auth(get("/api/users/me"), fresh), 200);
|
||||
|
||||
jdbc.update(
|
||||
"UPDATE sys_user SET session_version=session_version+1 WHERE user_code=?",
|
||||
userCode);
|
||||
perform(auth(get("/api/users/me"), fresh), 401);
|
||||
String renewed = login(email);
|
||||
perform(auth(get("/api/users/me"), renewed), 200);
|
||||
perform(auth(post("/api/auth/logout"), renewed), 200);
|
||||
perform(auth(get("/api/users/me"), renewed), 401);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user