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:
hsiegeln
2026-04-22 22:13:53 +02:00
parent 76129d407e
commit e716dbf8ca

View File

@@ -6,8 +6,6 @@ import com.cameleer.server.app.TestSecurityHelper;
import com.cameleer.server.app.storage.PostgresApplicationConfigRepository;
import com.cameleer.server.core.agent.AgentRegistryService;
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.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -37,7 +35,6 @@ class ApplicationConfigControllerIT extends AbstractPostgresIT {
AgentRegistryService registryService;
@Autowired private TestRestTemplate restTemplate;
@Autowired private ObjectMapper objectMapper;
@Autowired private TestSecurityHelper securityHelper;
@Autowired private PostgresApplicationConfigRepository configRepository;
@@ -164,14 +161,30 @@ class ApplicationConfigControllerIT extends AbstractPostgresIT {
}
@Test
void putConfig_staged_auditActionIsStagedAppConfig() throws Exception {
void putConfig_staged_auditActionIsStagedAppConfig() {
registerLiveAgent("audit-agent-" + UUID.randomUUID().toString().substring(0, 8));
ResponseEntity<String> response = putConfig("staged");
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
JsonNode body = objectMapper.readTree(response.getBody());
// The response carries the saved config; no pushed agents
assertThat(body.path("pushResult").path("total").asInt()).isEqualTo(0);
String action = jdbcTemplate.queryForObject(
"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");
}
}