-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Added support for identify with JWT
- Loading branch information
github-actions
committed
Jan 22, 2024
1 parent
1399bad
commit b44d038
Showing
6 changed files
with
193 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import org.apache.commons.lang3.RandomStringUtils | |
import org.assertj.core.api.Assertions.assertThat | ||
import org.awaitility.Awaitility.await | ||
import org.awaitility.Duration | ||
import org.json.JSONObject | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
@@ -258,4 +259,159 @@ class ExtoleSdkTests { | |
assertThat(initialTime).isBefore(timeAfterIdentify) | ||
} | ||
|
||
@Test | ||
fun testIdentifyJwtWillFlushCache() { | ||
val jwt = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImtpZCI6IjUzNmQwNWE2LTMzZWUtNDI2NC04ODI2LW" + | ||
"JhZDRjOTAyMWZhZiJ9.eyJpc3MiOiJtb2JpbGUtc2RrLmV4dG9sZS5jb20iLCJhdWQiOlsiZXh0b2xlLmNvbSJ" + | ||
"dLCJlbWFpbCI6InNka3BlcnNvbi1lbWFpbEBtYWlsb3NhdXIuY29tIiwiaWF0IjoxNzA1NTg0Mjg0LCJleHAiO" + | ||
"jI0ODMxODQyODR9.XdB5-j58GcEeKqKkCLd5f_G78CLLJIHCmsfcOpH-n3o" | ||
val extole = | ||
runBlocking { | ||
return@runBlocking Extole.init( | ||
"mobile-monitor.extole.io", | ||
context = context, appName = "mobile-monitor", labels = setOf("business"), | ||
data = mapOf("version" to "1.0"), | ||
) | ||
} | ||
|
||
|
||
val initialTimeStampValue = runBlocking { | ||
val (ctaZone, _) = extole.fetchZone("mobile_cta_timestamp") | ||
val initialTimestampValue = ctaZone?.get("timestamp") | ||
initialTimestampValue as Long | ||
} | ||
|
||
val emailBeforeIdentify = runBlocking { | ||
val (ctaZone, _) = extole.fetchZone("mobile_cta_timestamp") | ||
ctaZone?.get("email").toString() | ||
} | ||
|
||
assertThat(emailBeforeIdentify).isEqualTo("null") | ||
|
||
runBlocking { | ||
extole.identifyJwt(jwt) | ||
} | ||
|
||
val timeStampValueAfterIdentify = runBlocking { | ||
val (ctaZone, _) = extole.fetchZone("mobile_cta_timestamp") | ||
val initialTimestampValue = ctaZone?.get("timestamp") | ||
initialTimestampValue as Long | ||
} | ||
|
||
val initialTime = Instant.ofEpochSecond(initialTimeStampValue) | ||
val timeAfterIdentify = Instant.ofEpochSecond(timeStampValueAfterIdentify) | ||
assertThat(initialTime).isBefore(timeAfterIdentify) | ||
|
||
|
||
val emailAfterIdentify = runBlocking { | ||
val (ctaZone, _) = extole.fetchZone("mobile_cta_timestamp") | ||
ctaZone?.get("email") as String | ||
} | ||
|
||
assertThat(emailAfterIdentify).isEqualTo("[email protected]") | ||
} | ||
|
||
@Test | ||
fun testIdentifyJwtWithoutEmail() { | ||
val jwt = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImtpZCI6IjUzNmQwNWE2LTMzZWUtNDI2NC04ODI2" + | ||
"LWJhZDRjOTAyMWZhZiJ9.eyJpc3MiOiJtb2JpbGUtc2RrLmV4dG9sZS5jb20iLCJhdWQiOlsiZXh0b2xlLmN" + | ||
"vbSJdLCJpYXQiOjE3MDU5MjQwMDksImV4cCI6MjQ4MzUyNDAwOX0.X2GnR6OV9amojSLSzoXeecoujrnMzyY" + | ||
"As5VWzR86U4M"; | ||
|
||
val extole = | ||
runBlocking { | ||
return@runBlocking Extole.init( | ||
"mobile-monitor.extole.io", | ||
context = context, appName = "mobile-monitor", labels = setOf("business"), | ||
data = mapOf("version" to "1.0"), | ||
) | ||
} | ||
|
||
|
||
val initialTimeStampValue = runBlocking { | ||
val (ctaZone, _) = extole.fetchZone("mobile_cta_timestamp") | ||
val initialTimestampValue = ctaZone?.get("timestamp") | ||
initialTimestampValue as Long | ||
} | ||
|
||
val emailBeforeIdentify = runBlocking { | ||
val (ctaZone, _) = extole.fetchZone("mobile_cta_timestamp") | ||
ctaZone?.get("email").toString() | ||
} | ||
|
||
assertThat(emailBeforeIdentify).isEqualTo("null") | ||
|
||
runBlocking { | ||
extole.identifyJwt(jwt) | ||
} | ||
|
||
val timeStampValueAfterIdentify = runBlocking { | ||
val (ctaZone, _) = extole.fetchZone("mobile_cta_timestamp") | ||
val initialTimestampValue = ctaZone?.get("timestamp") | ||
initialTimestampValue as Long | ||
} | ||
|
||
val initialTime = Instant.ofEpochSecond(initialTimeStampValue) | ||
val timeAfterIdentify = Instant.ofEpochSecond(timeStampValueAfterIdentify) | ||
assertThat(initialTime).isEqualTo(timeAfterIdentify) | ||
|
||
|
||
val emailAfterIdentify = runBlocking { | ||
val (ctaZone, _) = extole.fetchZone("mobile_cta_timestamp") | ||
ctaZone?.get("email").toString() | ||
} | ||
|
||
assertThat(emailAfterIdentify).isEqualTo("null") | ||
} | ||
|
||
@Test | ||
fun testIdentifyWithInvalidJwt() { | ||
val jwt = "invalid_jwt"; | ||
|
||
val extole = | ||
runBlocking { | ||
return@runBlocking Extole.init( | ||
"mobile-monitor.extole.io", | ||
context = context, appName = "mobile-monitor", labels = setOf("business"), | ||
data = mapOf("version" to "1.0"), | ||
) | ||
} | ||
|
||
|
||
val initialTimeStampValue = runBlocking { | ||
val (ctaZone, _) = extole.fetchZone("mobile_cta_timestamp") | ||
val initialTimestampValue = ctaZone?.get("timestamp") | ||
initialTimestampValue as Long | ||
} | ||
|
||
val emailBeforeIdentify = runBlocking { | ||
val (ctaZone, _) = extole.fetchZone("mobile_cta_timestamp") | ||
ctaZone?.get("email").toString() | ||
} | ||
|
||
assertThat(emailBeforeIdentify).isEqualTo("null") | ||
|
||
runBlocking { | ||
extole.identifyJwt(jwt) | ||
} | ||
|
||
val timeStampValueAfterIdentify = runBlocking { | ||
val (ctaZone, _) = extole.fetchZone("mobile_cta_timestamp") | ||
val initialTimestampValue = ctaZone?.get("timestamp") | ||
initialTimestampValue as Long | ||
} | ||
|
||
val initialTime = Instant.ofEpochSecond(initialTimeStampValue) | ||
val timeAfterIdentify = Instant.ofEpochSecond(timeStampValueAfterIdentify) | ||
assertThat(initialTime).isEqualTo(timeAfterIdentify) | ||
|
||
|
||
val emailAfterIdentify = runBlocking { | ||
val (ctaZone, _) = extole.fetchZone("mobile_cta_timestamp") | ||
ctaZone?.get("email").toString() | ||
} | ||
|
||
assertThat(emailAfterIdentify).isEqualTo("null") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters