Allow run lifecycle reports through auth gate

This commit is contained in:
npc0-hue
2026-08-06 22:26:15 +08:00
parent d28e998411
commit 4b0233cf6f
2 changed files with 33 additions and 0 deletions
+32
View File
@@ -166,6 +166,38 @@ func TestRunHTTPEnvelopeRequiresValidSignatureAndRejectsReplay(t *testing.T) {
}
}
func TestAuthorizedRouterAllowsRunLifecycleReportWithoutBearer(t *testing.T) {
store := repo.NewMemoryStore()
core := service.NewCoreService(store)
if _, err := core.CreateGamePlugin(validGamePluginRequest().ToDomain()); err != nil {
t.Fatalf("create plugin: %v", err)
}
if _, err := core.CreateRunEndpoint(validRunEndpointRequest().ToDomain()); err != nil {
t.Fatalf("create endpoint: %v", err)
}
if _, err := core.CreateServerInstance(domain.ServerInstance{ID: "server-authorized-lifecycle", PluginID: "server.scum", RunEndpointID: "run-local", Name: "Authorized Lifecycle", State: domain.ServerInstanceStateFailed, ConfigVersion: 1}); err != nil {
t.Fatalf("create server: %v", err)
}
router := NewAuthorizedRouterWithCore(core)
hello := decodeBody[dto.RunControlHelloResponse](t, performRunControlHello(t, router, validRunControlHelloRequest()))
if hello.SessionToken == "" {
t.Fatalf("expected run session token")
}
body, err := json.Marshal(dto.RunLifecycleReportRequest{RunEndpointID: "run-local", SessionToken: hello.SessionToken, ServerInstanceID: "server-authorized-lifecycle", Capability: domain.LifecycleCapabilityStart, State: domain.JobStateSucceeded, Progress: dto.JobProgressBody{Percent: 100}, ExecutionResult: dto.RunJobExecutionResultBody{Kind: "process", ProcessState: "running"}})
if err != nil {
t.Fatalf("marshal lifecycle report: %v", err)
}
signed := signedRunRequest(t, router, "/api/v1/run/lifecycle/report", body, hello.SessionToken, "nonce-api-lifecycle-authorized", time.Now().UTC())
assertStatus(t, signed, http.StatusOK)
updated, err := core.GetServerInstance("server-authorized-lifecycle")
if err != nil {
t.Fatalf("get server: %v", err)
}
if updated.State != domain.ServerInstanceStateRunning {
t.Fatalf("expected run lifecycle report to project running, got %s", updated.State)
}
}
func signedRunRequest(t *testing.T, router http.Handler, path string, body []byte, token string, nonce string, stamp time.Time) *httptest.ResponseRecorder {
t.Helper()
timestamp := strconv.FormatInt(stamp.Unix(), 10)