forked from xhgit/webup-cloud
Merge pull request '禁止归档项目绕过托管运行限制' (#21) from codex/block-archived-runtime into main
Reviewed-on: http://git.xhmcl.com/xhgit/webup-cloud/pulls/21
This commit is contained in:
commit
77db572895
4 files changed
+49
-2
No files matched your search
@@ -43,6 +43,8 @@ public class DeploymentWorker {
|
||||
UUID id = UUID.fromString(op.get("id").toString());
|
||||
String lease = op.get("lease_token").toString();
|
||||
try {
|
||||
if ("RESUME".equals(op.get("action")))
|
||||
operations.checkAllowed(UUID.fromString(op.get("project_id").toString()));
|
||||
gateway.request(
|
||||
"/runtime/projects/" + op.get("project_id") + "/state",
|
||||
Map.of("action", op.get("action"), "operationId", id.toString()));
|
||||
|
||||
@@ -282,8 +282,7 @@ public class HostingService {
|
||||
}
|
||||
|
||||
Map<String, Object> beforeSourceSnapshot(UUID user, UUID project, String key) {
|
||||
if ("ARCHIVED".equals(own(user, project).get("status")))
|
||||
throw new ApiError.Failure(409, "归档项目不能发布");
|
||||
own(user, project);
|
||||
operations.checkAllowed(project);
|
||||
var replay = deploymentReplay(project, key);
|
||||
if (replay != null) return replay;
|
||||
|
||||
@@ -28,6 +28,7 @@ public class RuntimeOperationService {
|
||||
return UUID.fromString(p.get("id").toString());
|
||||
}
|
||||
if (action.equals("RESUME")) {
|
||||
checkNotArchived(project);
|
||||
var allowed =
|
||||
db.queryForList("SELECT status FROM project_moderation WHERE project_id=?", project);
|
||||
if (allowed.isEmpty() || !"APPROVED".equals(allowed.getFirst().get("status")))
|
||||
@@ -98,6 +99,7 @@ public class RuntimeOperationService {
|
||||
}
|
||||
|
||||
public void checkAllowed(UUID project) {
|
||||
checkNotArchived(project);
|
||||
String message =
|
||||
switch (reviewStatus(project)) {
|
||||
case "APPROVED" -> null;
|
||||
@@ -107,4 +109,12 @@ public class RuntimeOperationService {
|
||||
};
|
||||
if (message != null) throw new ApiError.Failure(403, message);
|
||||
}
|
||||
|
||||
private void checkNotArchived(UUID project) {
|
||||
if (db.queryForObject(
|
||||
"SELECT COUNT(*) FROM projects WHERE id=? AND status='ARCHIVED'",
|
||||
Integer.class,
|
||||
project)
|
||||
!= 0) throw new ApiError.Failure(409, "归档项目不能执行运行操作");
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ class HostingIntegrationTest {
|
||||
@Autowired WalletService wallets;
|
||||
@Autowired HostingService hosting;
|
||||
@Autowired DeploymentCoordinator deployments;
|
||||
@Autowired RuntimeOperationService operations;
|
||||
@Autowired ObjectMapper json;
|
||||
@MockitoBean EphemeralStore store;
|
||||
UUID user, project, plan;
|
||||
@@ -136,6 +137,41 @@ class HostingIntegrationTest {
|
||||
rollback.path("services").get(0).path("environment").path("ADMIN_PASSWORD").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void archivedProjectCannotQueueOrApplyReleasesOrResumeRuntime() {
|
||||
hosting.subscribe(user, project, plan, "archived-plan");
|
||||
hosting.service(user, project, null, spec(200));
|
||||
hosting.deploy(user, project, "before-archive", null);
|
||||
users.db().update("UPDATE projects SET status='ARCHIVED' WHERE id=?", project);
|
||||
assertEquals(
|
||||
409,
|
||||
assertThrows(
|
||||
ApiError.Failure.class, () -> hosting.deploy(user, project, "after-archive", null))
|
||||
.status);
|
||||
assertEquals(
|
||||
409,
|
||||
assertThrows(
|
||||
ApiError.Failure.class,
|
||||
() -> hosting.deploy(user, project, "rollback", UUID.randomUUID()))
|
||||
.status);
|
||||
assertEquals(
|
||||
409,
|
||||
assertThrows(
|
||||
ApiError.Failure.class, () -> hosting.beforeSourceSnapshot(user, project, "source"))
|
||||
.status);
|
||||
assertEquals(
|
||||
409,
|
||||
assertThrows(
|
||||
ApiError.Failure.class,
|
||||
() -> operations.enqueue(project, user, "RESUME", "test", "archived-resume"))
|
||||
.status);
|
||||
var queued = deployments.claim();
|
||||
assertNotNull(queued);
|
||||
assertEquals(
|
||||
409, assertThrows(ApiError.Failure.class, () -> deployments.payload(queued)).status);
|
||||
assertNotNull(operations.enqueue(project, user, "SUSPEND", "test", "archived-suspend"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void purchaseIsIdempotentAndSnapshotsPlan() {
|
||||
hosting.subscribe(user, project, plan, "first");
|
||||
|
||||
Reference in new issue
Block a user