-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemoBaselineRecoveryTest.java
More file actions
47 lines (40 loc) · 1.91 KB
/
DemoBaselineRecoveryTest.java
File metadata and controls
47 lines (40 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package ai.aletheia.db.seeding;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import ai.aletheia.db.UserRepository;
import ai.aletheia.db.entity.User;
import ai.aletheia.support.TenantContextExtension;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;
@SpringBootTest
@ActiveProfiles("dev")
@ExtendWith(TenantContextExtension.class)
@Transactional
class DemoBaselineRecoveryTest {
@Autowired private DemoBaselineRecovery recovery;
@Autowired private UserRepository userRepo;
@Test
void restoresDemoAdminAfterRowsRemoved() {
// demo@aletheia.ai now has one ADMIN row per demo tenant so it can switch
// between them via the per-tenant membership path. Removing every row
// should not stop recovery from re-seeding all of them.
List<User> existing = userRepo.findAllByEmail("demo@aletheia.ai");
assertTrue(existing.size() >= 1, "demo seed should provide at least one row");
userRepo.deleteAll(existing);
assertTrue(userRepo.findAllByEmail("demo@aletheia.ai").isEmpty());
recovery.ensureDemoBaseline();
List<User> restored = userRepo.findAllByEmail("demo@aletheia.ai");
assertEquals(existing.size(), restored.size(),
"recovery must restore the same number of demo memberships");
// Must never be re-created as SUPER_ADMIN — see V208 / cross-tenant bypass fix.
for (User u : restored) {
assertEquals("ADMIN", u.getRole(),
"demo@aletheia.ai must always be tenant-scoped ADMIN, never SUPER_ADMIN");
}
}
}