Skip to content

Commit

Permalink
fix: rotate session id when reset is called (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored Aug 29, 2024
1 parent 939a349 commit 9c6bacf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Next

- fix: rotate session id when reset is called ([#174](https://github.com/PostHog/posthog-ios/pull/174))
- chore: expose session id ([#165](https://github.com/PostHog/posthog-ios/pull/165)), ([#170](https://github.com/PostHog/posthog-ios/pull/170)) and ([#171](https://github.com/PostHog/posthog-ios/pull/171))

## 3.7.2 - 2024-08-16
Expand Down
1 change: 1 addition & 0 deletions PostHog/PostHogSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ let maxRetryDelay = 30.0
replayQueue?.clear()
flagCallReported.removeAll()
PostHogSessionManager.shared.endSession()
PostHogSessionManager.shared.startSession()
}

private func getGroups() -> [String: String] {
Expand Down
10 changes: 7 additions & 3 deletions PostHogTests/PostHogSDKTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ class PostHogSDKTest: QuickSpec {
sut.close()
}

it("clears sessionId after reset") {
it("reset sessionId after reset") {
let sut = self.getSut(captureApplicationLifecycleEvents: true, flushAt: 1)
let mockNow = MockDate()
now = { mockNow.date }
Expand All @@ -676,7 +676,8 @@ class PostHogSDKTest: QuickSpec {
var events = getBatchedEvents(server)
expect(events.count) == 1

expect(events[0].properties["$session_id"] as? String).toNot(beNil())
let currentSessionId = events[0].properties["$session_id"] as? String
expect(currentSessionId).toNot(beNil())

sut.reset()

Expand All @@ -690,7 +691,10 @@ class PostHogSDKTest: QuickSpec {
events = getBatchedEvents(server)
expect(events.count) == 1

expect(events[0].properties["$session_id"] as? String).to(beNil())
let newSessionId = events[0].properties["$session_id"] as? String
expect(newSessionId).toNot(beNil())

expect(currentSessionId).toNot(equal(newSessionId))

sut.reset()
sut.close()
Expand Down

0 comments on commit 9c6bacf

Please sign in to comment.