fix(audit): exclude authenticated principal from snapshots

This commit is contained in:
2026-08-08 13:15:01 +08:00
parent dca8c05d33
commit b6b5e2dc55
2 changed files with 14 additions and 6 deletions
@@ -29,12 +29,14 @@ class BusinessAuditAspectTest {
@Test
void platformOperationUsesTargetCustomerAndKeepsOperatorScope() throws Throwable {
AuditEvent event = invoke(new AuthenticatedUser(7L, 0L, 0L, 1L,
"platform.admin", "PLATFORM", "WEB", Set.of()), 10001L);
"platform.admin", "PLATFORM", "WEB", Set.of("platform:customer:edit")), 10001L);
assertThat(event.tenantId()).isEqualTo(10001L);
assertThat(event.operatorTenantId()).isZero();
assertThat(event.userId()).isEqualTo(7L);
assertThat(event.appCode()).isEqualTo("PLATFORM");
assertThat(event.beforeData()).isEqualTo("[10001]");
assertThat(event.beforeData()).doesNotContain("platform.admin", "platform:customer:edit", "permissions");
}
@Test
@@ -57,7 +59,7 @@ class BusinessAuditAspectTest {
new UsernamePasswordAuthenticationToken(user, null, List.of()));
TestOperations target = new TestOperations();
Method method = TestOperations.class.getDeclaredMethod("update", long.class);
Method method = TestOperations.class.getDeclaredMethod("update", AuthenticatedUser.class, long.class);
MethodSignature signature = mock(MethodSignature.class);
when(signature.getMethod()).thenReturn(method);
when(signature.getParameterNames()).thenReturn(null);
@@ -65,7 +67,7 @@ class BusinessAuditAspectTest {
ProceedingJoinPoint joinPoint = mock(ProceedingJoinPoint.class);
when(joinPoint.getSignature()).thenReturn(signature);
when(joinPoint.getTarget()).thenReturn(target);
when(joinPoint.getArgs()).thenReturn(new Object[]{requestedTenantId});
when(joinPoint.getArgs()).thenReturn(new Object[]{user, requestedTenantId});
when(joinPoint.proceed()).thenReturn("ok");
aspect.around(joinPoint, method.getAnnotation(BusinessAudit.class));
@@ -76,8 +78,8 @@ class BusinessAuditAspectTest {
}
private static final class TestOperations {
@BusinessAudit(event = "TEST_UPDATE", resourceType = "TEST", captureBefore = false, captureAfter = false)
public String update(long tenantId) {
@BusinessAudit(event = "TEST_UPDATE", resourceType = "TEST", captureAfter = false)
public String update(AuthenticatedUser user, long tenantId) {
return "ok";
}
}