Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,13 @@ public Single<Event> appendEvent(Session session, Event event) {
String userId = session.userId();
String sessionId = session.id();

ConcurrentMap<String, ConcurrentMap<String, Session>> appSessions = sessions.get(appName);
ConcurrentMap<String, Session> userSessions =
appSessions == null ? null : appSessions.get(userId);
if (userSessions == null || !userSessions.containsKey(sessionId)) {
return Single.error(new SessionNotFoundException("Session not found: " + sessionId));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave the session id out of this message, e.g. just "Session not found". Session ids can come from the caller, and we keep caller-supplied values out of exception messages.

}

// --- Update User/App State (Same as before) ---
EventActions actions = event.actions();
if (actions != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,20 @@ public void lifecycle_deleteSession() {
.isNull();
}

@Test
public void appendEvent_rejectsDeletedSession() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also cover a user who still has another session. Deleting the only session removes the whole app entry, so this test never reaches the containsKey check.

InMemorySessionService sessionService = new InMemorySessionService();
Session session =
sessionService.createSession("app", "user", new HashMap<>(), "session1").blockingGet();
sessionService.deleteSession("app", "user", "session1").blockingAwait();

sessionService
.appendEvent(session, Event.builder().build())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider giving this event an app-scoped state delta (State.APP_PREFIX + "key") and checking another session doesn't see it. That covers the "check before mutating state" part of the fix.

.test()
.assertError(SessionNotFoundException.class);
assertThat(sessionService.listSessions("app", "user").blockingGet().sessions()).isEmpty();
}

@Test
public void appendEvent_updatesSessionState() {
InMemorySessionService sessionService = new InMemorySessionService();
Expand Down
Loading