Skip to content

Commit 9a4d87e

Browse files
supertokens-agent-runnerclaude
andcommitted
fix: make activity-log audit-event tests storage-agnostic
AccountLinkingAuditEventTest and LifecycleMutationEventTest cast the configured storage to the concrete io.supertokens.inmemorydb.Start, which throws ClassCastException on the postgres Tests job (Start there is io.supertokens.storage.postgresql.Start). The readEvents helper only uses startTransaction + TransactionConnection.getConnection(), both declared on the storage-agnostic SQLStorage interface, so cast to SQLStorage instead. This lets both tests run against whichever store is configured rather than forcing in-memory, restoring postgres coverage of the audit emit path. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 54176e4 commit 9a4d87e

2 files changed

Lines changed: 19 additions & 19 deletions

File tree

src/test/java/io/supertokens/test/accountlinking/AccountLinkingAuditEventTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import io.supertokens.emailpassword.EmailPassword;
2424
import io.supertokens.featureflag.EE_FEATURES;
2525
import io.supertokens.featureflag.FeatureFlagTestContent;
26-
import io.supertokens.inmemorydb.Start;
2726
import io.supertokens.pluginInterface.STORAGE_TYPE;
2827
import io.supertokens.pluginInterface.auditlog.AuditLogEvent;
2928
import io.supertokens.pluginInterface.auditlog.AuditedResult;
@@ -32,6 +31,7 @@
3231
import io.supertokens.pluginInterface.authRecipe.sqlStorage.AuthRecipeSQLStorage;
3332
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
3433
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
34+
import io.supertokens.pluginInterface.sqlStorage.SQLStorage;
3535
import io.supertokens.storageLayer.StorageLayer;
3636
import io.supertokens.test.TestingProcessManager;
3737
import io.supertokens.test.Utils;
@@ -91,7 +91,7 @@ public void linkEmitsExactlyOneEventCommittedWithTheMapping() throws Exception {
9191
if (process == null) {
9292
return;
9393
}
94-
Start storage = (Start) StorageLayer.getStorage(process.getProcess());
94+
SQLStorage storage = (SQLStorage) StorageLayer.getStorage(process.getProcess());
9595

9696
AuthRecipeUserInfo recipe = EmailPassword.signUp(process.getProcess(), "r@example.com", "password");
9797
AuthRecipeUserInfo primary = EmailPassword.signUp(process.getProcess(), "p@example.com", "password");
@@ -136,7 +136,7 @@ public void alreadyLinkedCallEmitsNoEvent() throws Exception {
136136
if (process == null) {
137137
return;
138138
}
139-
Start storage = (Start) StorageLayer.getStorage(process.getProcess());
139+
SQLStorage storage = (SQLStorage) StorageLayer.getStorage(process.getProcess());
140140

141141
AuthRecipeUserInfo recipe = EmailPassword.signUp(process.getProcess(), "r@example.com", "password");
142142
AuthRecipeUserInfo primary = EmailPassword.signUp(process.getProcess(), "p@example.com", "password");
@@ -164,7 +164,7 @@ public void plainUnlinkEmitsEventAndFreesTheUser() throws Exception {
164164
if (process == null) {
165165
return;
166166
}
167-
Start storage = (Start) StorageLayer.getStorage(process.getProcess());
167+
SQLStorage storage = (SQLStorage) StorageLayer.getStorage(process.getProcess());
168168

169169
AuthRecipeUserInfo recipe = EmailPassword.signUp(process.getProcess(), "r@example.com", "password");
170170
AuthRecipeUserInfo primary = EmailPassword.signUp(process.getProcess(), "p@example.com", "password");
@@ -204,7 +204,7 @@ public void deleteBranchUnlinkEmitsEvent() throws Exception {
204204
if (process == null) {
205205
return;
206206
}
207-
Start storage = (Start) StorageLayer.getStorage(process.getProcess());
207+
SQLStorage storage = (SQLStorage) StorageLayer.getStorage(process.getProcess());
208208

209209
AuthRecipeUserInfo primary = EmailPassword.signUp(process.getProcess(), "p@example.com", "password");
210210
AuthRecipeUserInfo other = EmailPassword.signUp(process.getProcess(), "o@example.com", "password");
@@ -249,7 +249,7 @@ public void unlinkingALonePrimaryEmitsNoEvent() throws Exception {
249249
if (process == null) {
250250
return;
251251
}
252-
Start storage = (Start) StorageLayer.getStorage(process.getProcess());
252+
SQLStorage storage = (SQLStorage) StorageLayer.getStorage(process.getProcess());
253253

254254
AuthRecipeUserInfo primary = EmailPassword.signUp(process.getProcess(), "p@example.com", "password");
255255
AuthRecipe.createPrimaryUser(process.getProcess(), primary.getSupertokensUserId());
@@ -281,7 +281,7 @@ public void injectedFailureAfterMappingWriteRollsBackBoth() throws Exception {
281281
if (process == null) {
282282
return;
283283
}
284-
Start storage = (Start) StorageLayer.getStorage(process.getProcess());
284+
SQLStorage storage = (SQLStorage) StorageLayer.getStorage(process.getProcess());
285285
AuthRecipeSQLStorage authRecipeStorage =
286286
(AuthRecipeSQLStorage) StorageLayer.getStorage(process.getProcess());
287287
ActivityLogSQLStorage auditStorage = (ActivityLogSQLStorage) storage;
@@ -344,7 +344,7 @@ private void stopProcess(TestingProcessManager.TestingProcess process) throws Ex
344344
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED));
345345
}
346346

347-
private List<Row> readEvents(Start storage, String eventType) throws Exception {
347+
private List<Row> readEvents(SQLStorage storage, String eventType) throws Exception {
348348
String query = "SELECT recipe_user_id, primary_or_recipe_user_id, event_type, payload FROM "
349349
+ ACTIVITY_LOG + " WHERE event_type = ? ORDER BY created_at";
350350
return storage.startTransaction(con -> {

src/test/java/io/supertokens/test/accountlinking/LifecycleMutationEventTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
import io.supertokens.emailpassword.EmailPassword;
2525
import io.supertokens.featureflag.EE_FEATURES;
2626
import io.supertokens.featureflag.FeatureFlagTestContent;
27-
import io.supertokens.inmemorydb.Start;
2827
import io.supertokens.multitenancy.Multitenancy;
2928
import io.supertokens.pluginInterface.STORAGE_TYPE;
3029
import io.supertokens.pluginInterface.Storage;
3130
import io.supertokens.pluginInterface.authRecipe.AuthRecipeUserInfo;
31+
import io.supertokens.pluginInterface.sqlStorage.SQLStorage;
3232
import io.supertokens.storageLayer.StorageLayer;
3333
import io.supertokens.test.TestingProcessManager;
3434
import io.supertokens.useridmapping.UserIdMapping;
@@ -78,7 +78,7 @@ public void deletingStandaloneUserEmitsGroupDeletion() throws Exception {
7878
if (process == null) {
7979
return;
8080
}
81-
Start storage = (Start) StorageLayer.getStorage(process.getProcess());
81+
SQLStorage storage = (SQLStorage) StorageLayer.getStorage(process.getProcess());
8282

8383
AuthRecipeUserInfo user = EmailPassword.signUp(process.getProcess(), "u@example.com", "password");
8484
AuthRecipe.deleteUser(process.getProcess(), user.getSupertokensUserId(), false);
@@ -106,7 +106,7 @@ public void deletingLinkedGroupWithRemoveAllEmitsSingleGroupDeletion() throws Ex
106106
if (process == null) {
107107
return;
108108
}
109-
Start storage = (Start) StorageLayer.getStorage(process.getProcess());
109+
SQLStorage storage = (SQLStorage) StorageLayer.getStorage(process.getProcess());
110110

111111
AuthRecipeUserInfo primary = EmailPassword.signUp(process.getProcess(), "p@example.com", "password");
112112
AuthRecipeUserInfo member = EmailPassword.signUp(process.getProcess(), "m@example.com", "password");
@@ -139,7 +139,7 @@ public void deletingOneMemberEmitsUserDeletion() throws Exception {
139139
if (process == null) {
140140
return;
141141
}
142-
Start storage = (Start) StorageLayer.getStorage(process.getProcess());
142+
SQLStorage storage = (SQLStorage) StorageLayer.getStorage(process.getProcess());
143143

144144
AuthRecipeUserInfo primary = EmailPassword.signUp(process.getProcess(), "p@example.com", "password");
145145
AuthRecipeUserInfo member = EmailPassword.signUp(process.getProcess(), "m@example.com", "password");
@@ -205,7 +205,7 @@ public void memberDeletionRecordsShrunkAfterPresence() throws Exception {
205205

206206
AuthRecipe.deleteUser(t1.toAppIdentifier(), a1Storage, member.getSupertokensUserId(), false, null);
207207

208-
List<Row> events = readEvents((Start) a1Storage, LifecycleEventType.USER_DELETION.getValue());
208+
List<Row> events = readEvents((SQLStorage) a1Storage, LifecycleEventType.USER_DELETION.getValue());
209209
assertEquals(1, events.size());
210210
LifecycleEventPayload payload = LifecycleEventPayload.fromJson(events.get(0).payload);
211211
assertEquals(LifecycleEventType.USER_DELETION, payload.type);
@@ -230,7 +230,7 @@ public void deletingNonexistentUserEmitsNoEvent() throws Exception {
230230
if (process == null) {
231231
return;
232232
}
233-
Start storage = (Start) StorageLayer.getStorage(process.getProcess());
233+
SQLStorage storage = (SQLStorage) StorageLayer.getStorage(process.getProcess());
234234

235235
AuthRecipe.deleteUser(process.getProcess(), "00000000-0000-0000-0000-000000000000", true);
236236

@@ -254,7 +254,7 @@ public void deletingMappedStandaloneUserEmitsGroupDeletionWithSuperTokensId() th
254254
if (process == null) {
255255
return;
256256
}
257-
Start storage = (Start) StorageLayer.getStorage(process.getProcess());
257+
SQLStorage storage = (SQLStorage) StorageLayer.getStorage(process.getProcess());
258258

259259
AuthRecipeUserInfo user = EmailPassword.signUp(process.getProcess(), "u@example.com", "password");
260260
String externalId = "ext-standalone";
@@ -288,7 +288,7 @@ public void deletingMappedMemberEmitsUserDeletionWithSuperTokensRecipeId() throw
288288
if (process == null) {
289289
return;
290290
}
291-
Start storage = (Start) StorageLayer.getStorage(process.getProcess());
291+
SQLStorage storage = (SQLStorage) StorageLayer.getStorage(process.getProcess());
292292

293293
AuthRecipeUserInfo primary = EmailPassword.signUp(process.getProcess(), "p@example.com", "password");
294294
AuthRecipeUserInfo member = EmailPassword.signUp(process.getProcess(), "m@example.com", "password");
@@ -344,7 +344,7 @@ public void associatingUserWithTenantEmitsEvent() throws Exception {
344344
boolean added = Multitenancy.addUserIdToTenant(main, t2, t2Storage, user.getSupertokensUserId());
345345
assertTrue(added);
346346

347-
List<Row> events = readEvents((Start) a1Storage, LifecycleEventType.TENANT_ASSOCIATION.getValue());
347+
List<Row> events = readEvents((SQLStorage) a1Storage, LifecycleEventType.TENANT_ASSOCIATION.getValue());
348348
assertEquals(1, events.size());
349349
Row event = events.get(0);
350350
assertEquals(user.getSupertokensUserId(), event.recipeUserId);
@@ -360,7 +360,7 @@ public void associatingUserWithTenantEmitsEvent() throws Exception {
360360
// Associating again is a no-op — still exactly one event.
361361
boolean addedAgain = Multitenancy.addUserIdToTenant(main, t2, t2Storage, user.getSupertokensUserId());
362362
assertFalse(addedAgain);
363-
assertEquals(1, readEvents((Start) a1Storage, LifecycleEventType.TENANT_ASSOCIATION.getValue()).size());
363+
assertEquals(1, readEvents((SQLStorage) a1Storage, LifecycleEventType.TENANT_ASSOCIATION.getValue()).size());
364364

365365
stopProcess(process);
366366
}
@@ -386,7 +386,7 @@ private void stopProcess(TestingProcessManager.TestingProcess process) throws Ex
386386
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED));
387387
}
388388

389-
private List<Row> readEvents(Start storage, String eventType) throws Exception {
389+
private List<Row> readEvents(SQLStorage storage, String eventType) throws Exception {
390390
String query = "SELECT recipe_user_id, primary_or_recipe_user_id, event_type, payload FROM "
391391
+ ACTIVITY_LOG + " WHERE event_type = ? ORDER BY created_at";
392392
return storage.startTransaction(con -> {

0 commit comments

Comments
 (0)