Skip to content

Commit

Permalink
allow 36 and 32 character session ids
Browse files Browse the repository at this point in the history
  • Loading branch information
lbloder committed Nov 8, 2024
1 parent 613cc60 commit 1e8c6a7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion sentry/src/main/java/io/sentry/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ public static final class Deserializer implements JsonDeserializer<Session> {
switch (nextName) {
case JsonKeys.SID:
String sid = reader.nextStringOrNull();
if (sid != null && sid.length() == 32) {
if (sid != null && (sid.length() == 36 || sid.length() == 32)) {
sessionId = sid;
} else {
logger.log(SentryLevel.ERROR, "%s sid is not valid.", sid);
Expand Down
19 changes: 15 additions & 4 deletions sentry/src/test/java/io/sentry/JsonSerializerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,17 @@ class JsonSerializerTest {
assertSessionData(expectedSession)
}

@Test
fun `session deserializes 32 character id`() {
val sessionId = "c81d4e2ebcf211e6869b7df92533d2db"
val session = createSessionMockData("c81d4e2ebcf211e6869b7df92533d2db")
val jsonSession = serializeToString(session)
// reversing, so we can assert values and not a json string
val expectedSession = fixture.serializer.deserialize(StringReader(jsonSession), Session::class.java)

assertSessionData(expectedSession, "c81d4e2ebcf211e6869b7df92533d2db")
}

@Test
fun `When deserializing an Envelope, all the values should be set to the SentryEnvelope object`() {
val jsonEnvelope = FileFromResources.invoke("envelope_session.txt")
Expand Down Expand Up @@ -1248,9 +1259,9 @@ class JsonSerializerTest {
assertEquals(replayRecording, deserializedRecording)
}

private fun assertSessionData(expectedSession: Session?) {
private fun assertSessionData(expectedSession: Session?, expectedSessionId: String = "c81d4e2e-bcf2-11e6-869b-7df92533d2db") {
assertNotNull(expectedSession)
assertEquals("c81d4e2e-bcf2-11e6-869b-7df92533d2db", expectedSession.sessionId)
assertEquals(expectedSessionId, expectedSession.sessionId)
assertEquals("123", expectedSession.distinctId)
assertTrue(expectedSession.init!!)
assertEquals("2020-02-07T14:16:00.000Z", DateUtils.getTimestamp(expectedSession.started!!))
Expand Down Expand Up @@ -1280,14 +1291,14 @@ class JsonSerializerTest {
private fun generateEmptySentryEvent(date: Date = Date()): SentryEvent =
SentryEvent(date)

private fun createSessionMockData(): Session =
private fun createSessionMockData(sessionId: String = "c81d4e2e-bcf2-11e6-869b-7df92533d2db"): Session =
Session(
Session.State.Ok,
DateUtils.getDateTime("2020-02-07T14:16:00.000Z"),
DateUtils.getDateTime("2020-02-07T14:16:00.000Z"),
2,
"123",
"c81d4e2e-bcf2-11e6-869b-7df92533d2db",
sessionId,
true,
123456.toLong(),
6000.toDouble(),
Expand Down
2 changes: 1 addition & 1 deletion sentry/src/test/java/io/sentry/cache/CacheStrategyTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class CacheStrategyTest {
DateUtils.getDateTime("2020-02-07T14:16:00.000Z"),
2,
"123",
"c81d4e2e-bcf2-11e6-869b-7df92533d2db",
"c81d4e2ebcf211e6869b7df92533d2db",
init,
123456.toLong(),
6000.toDouble(),
Expand Down

0 comments on commit 1e8c6a7

Please sign in to comment.