test(config): verify audit action in staged/live config IT
Replace the misleading putConfig_staged_auditActionIsStagedAppConfig test (which only checked pushResult.total == 0, a duplicate of _savesButDoesNotPush) with two real audit-log assertions: one verifying "stage_app_config" is written for apply=staged and a new companion test verifying "update_app_config" for the live path. Uses jdbcTemplate to query audit_log directly (Option B). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6,8 +6,6 @@ import com.cameleer.server.app.TestSecurityHelper;
|
|||||||
import com.cameleer.server.app.storage.PostgresApplicationConfigRepository;
|
import com.cameleer.server.app.storage.PostgresApplicationConfigRepository;
|
||||||
import com.cameleer.server.core.agent.AgentRegistryService;
|
import com.cameleer.server.core.agent.AgentRegistryService;
|
||||||
import com.cameleer.server.core.agent.CommandType;
|
import com.cameleer.server.core.agent.CommandType;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -37,7 +35,6 @@ class ApplicationConfigControllerIT extends AbstractPostgresIT {
|
|||||||
AgentRegistryService registryService;
|
AgentRegistryService registryService;
|
||||||
|
|
||||||
@Autowired private TestRestTemplate restTemplate;
|
@Autowired private TestRestTemplate restTemplate;
|
||||||
@Autowired private ObjectMapper objectMapper;
|
|
||||||
@Autowired private TestSecurityHelper securityHelper;
|
@Autowired private TestSecurityHelper securityHelper;
|
||||||
@Autowired private PostgresApplicationConfigRepository configRepository;
|
@Autowired private PostgresApplicationConfigRepository configRepository;
|
||||||
|
|
||||||
@@ -164,14 +161,30 @@ class ApplicationConfigControllerIT extends AbstractPostgresIT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void putConfig_staged_auditActionIsStagedAppConfig() throws Exception {
|
void putConfig_staged_auditActionIsStagedAppConfig() {
|
||||||
registerLiveAgent("audit-agent-" + UUID.randomUUID().toString().substring(0, 8));
|
registerLiveAgent("audit-agent-" + UUID.randomUUID().toString().substring(0, 8));
|
||||||
|
|
||||||
ResponseEntity<String> response = putConfig("staged");
|
ResponseEntity<String> response = putConfig("staged");
|
||||||
|
|
||||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
JsonNode body = objectMapper.readTree(response.getBody());
|
|
||||||
// The response carries the saved config; no pushed agents
|
String action = jdbcTemplate.queryForObject(
|
||||||
assertThat(body.path("pushResult").path("total").asInt()).isEqualTo(0);
|
"SELECT action FROM audit_log WHERE target = ? ORDER BY timestamp DESC LIMIT 1",
|
||||||
|
String.class, appSlug);
|
||||||
|
assertThat(action).isEqualTo("stage_app_config");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void putConfig_live_auditActionIsUpdateAppConfig() {
|
||||||
|
registerLiveAgent("audit-agent-live-" + UUID.randomUUID().toString().substring(0, 8));
|
||||||
|
|
||||||
|
ResponseEntity<String> response = putConfig(null);
|
||||||
|
|
||||||
|
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
|
|
||||||
|
String action = jdbcTemplate.queryForObject(
|
||||||
|
"SELECT action FROM audit_log WHERE target = ? ORDER BY timestamp DESC LIMIT 1",
|
||||||
|
String.class, appSlug);
|
||||||
|
assertThat(action).isEqualTo("update_app_config");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user