Skip to content

Commit

Permalink
Merge pull request #30 from TelemetryDeck/fix-custom-salt
Browse files Browse the repository at this point in the history
Fix use of custom user salt when hashing the client id
  • Loading branch information
winsmith authored Jun 25, 2024
2 parents 02b1bab + 7b89dbe commit 06e27d5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/src/main/java/com/telemetrydeck/sdk/TelemetryManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ class TelemetryManager(
enrichedPayload = provider.enrich(signalType, clientUser, enrichedPayload)
}
val userValue = clientUser ?: configuration.defaultUser ?: ""

val userValueWithSalt = userValue + (configuration.salt ?: "")
val hashedUser = hashString(userValue, "SHA-256")

val payload = SignalPayload(additionalPayload = enrichedPayload)
val signal = Signal(
appID = configuration.telemetryAppID,
Expand Down
11 changes: 11 additions & 0 deletions lib/src/test/java/com/telemetrydeck/sdk/TelemetryManagerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ class TelemetryManagerTest {
Assert.assertEquals("false", queuedSignal.isTestMode)
}

@Test
fun telemetryManager_applies_custom_salt() {
val appID = "32CB6574-6732-4238-879F-582FEBEB6536"
val config = TelemetryManagerConfiguration(appID)
config.salt = "my salt"
val manager = TelemetryManager.Builder().configuration(config).build(null)
manager.queue("type", "clientUser", emptyMap())
val queuedSignal = manager.cache?.empty()?.first()
Assert.assertEquals("9a68a3790deb1db66f80855b8e7c5a97df8002ef90d3039f9e16c94cfbd11d99", queuedSignal?.clientUser)
}

@Test
fun telemetryManager_builder_set_configuration() {
val appID = "32CB6574-6732-4238-879F-582FEBEB6536"
Expand Down

0 comments on commit 06e27d5

Please sign in to comment.