forked from xhgit/webup-cloud
Authorize service ownership before checking restart eligibility
This commit is contained in:
1 parent
da93d4fa1c
commit
b5a2be3f9f
2 files changed
+38
-2
No files matched your search
@@ -57,7 +57,8 @@ public class RuntimeController {
|
||||
@AuthenticationPrincipal SecurityConfig.Identity who,
|
||||
@PathVariable UUID project,
|
||||
@PathVariable UUID service) {
|
||||
String servicePath = path(who, project, service);
|
||||
operations.checkAllowed(project);
|
||||
return gateway.request(path(who, project, service) + "/restart", Map.of());
|
||||
return gateway.request(servicePath + "/restart", Map.of());
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ import org.springframework.test.context.DynamicPropertySource;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import org.springframework.test.web.servlet.*;
|
||||
|
||||
@SpringBootTest
|
||||
@SpringBootTest(properties = "app.encryption-key=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=")
|
||||
@AutoConfigureMockMvc
|
||||
@ActiveProfiles("test")
|
||||
class IdentityIntegrationTest {
|
||||
@@ -35,6 +35,7 @@ class IdentityIntegrationTest {
|
||||
|
||||
@Autowired MockMvc mvc;
|
||||
@Autowired IdentityService users;
|
||||
@Autowired HostingService hosting;
|
||||
@Autowired ObjectMapper json;
|
||||
@MockitoBean EphemeralStore store;
|
||||
final Map<String, String> ephemeral = new ConcurrentHashMap<>();
|
||||
@@ -92,6 +93,40 @@ class IdentityIntegrationTest {
|
||||
return json.readTree(result).get("token").asText();
|
||||
}
|
||||
|
||||
@Test
|
||||
void restartDoesNotRevealAnotherProjectsModerationState() throws Exception {
|
||||
UUID owner = user("owner@restart.test");
|
||||
user("other@restart.test");
|
||||
UUID project = UUID.randomUUID();
|
||||
users
|
||||
.db()
|
||||
.update(
|
||||
"INSERT INTO projects(id,owner_id,name,description,stack,requirements) VALUES"
|
||||
+ " (?,?,?,'','HTML','')",
|
||||
project,
|
||||
owner,
|
||||
"Private project");
|
||||
users
|
||||
.db()
|
||||
.update("INSERT INTO project_moderation(project_id,status) VALUES (?,'BANNED')", project);
|
||||
Object service =
|
||||
hosting
|
||||
.service(
|
||||
owner,
|
||||
project,
|
||||
null,
|
||||
new HostingController.ServiceSpec(
|
||||
"web", "nginx:example", List.of(), null, 3000, 250, 256, 1, "/", true))
|
||||
.get("id");
|
||||
String url = "/api/projects/" + project + "/runtime/services/" + service + "/restart";
|
||||
mvc.perform(post(url).header("Authorization", "Bearer " + token("other@restart.test")))
|
||||
.andExpect(status().isNotFound())
|
||||
.andExpect(jsonPath("$.message").value("项目不存在"));
|
||||
mvc.perform(post(url).header("Authorization", "Bearer " + token("owner@restart.test")))
|
||||
.andExpect(status().isForbidden())
|
||||
.andExpect(jsonPath("$.message").value("网站已被封禁,请联系管理员"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void captchaIsServerGeneratedAndOneUse() throws Exception {
|
||||
String result =
|
||||
|
||||
Reference in new issue
Block a user