Skip to content

Commit

Permalink
fix(reactnative): deserialize the apiKey from react native events if …
Browse files Browse the repository at this point in the history
…they are present
  • Loading branch information
lemnik committed Jan 31, 2022
1 parent a1e96f8 commit d88a237
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
* Fixed an issue where feature-flags were not always sent if an OnSendCallback was configured
[#1589](https://github.com/bugsnag/bugsnag-android/pull/1589)

* Fix a bug where api keys set in React Native callbacks were ignored
[#1592](https://github.com/bugsnag/bugsnag-android/pull/1592)

## 5.19.1 (2022-01-21)

### Bug fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ internal class EventDeserializer(
event.context = map["context"] as String?
event.groupingHash = map["groupingHash"] as String?

// apiKey if it exists in the map and is not empty
val apiKey = (map["apiKey"] as? String)?.takeIf { it.isNotEmpty() }
apiKey?.let { event.apiKey = apiKey }

// app/device
event.app = appDeserializer.deserialize(map["app"] as MutableMap<String, Any>)
event.device = deviceDeserializer.deserialize(map["device"] as MutableMap<String, Any>)
Expand All @@ -62,7 +66,8 @@ internal class EventDeserializer(
if (map.containsKey("nativeStack") && event.errors.isNotEmpty()) {
runCatching {
val jsError = event.errors.first()
val nativeStackDeserializer = NativeStackDeserializer(projectPackages, client.config)
val nativeStackDeserializer =
NativeStackDeserializer(projectPackages, client.config)
val nativeStack = nativeStackDeserializer.deserialize(map)
jsError.stacktrace.addAll(0, nativeStack)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class EventDeserializerTest {
assertEquals("app-id", event.app.id)
assertEquals("device-id", event.device.id)
assertEquals("123", event.getMetadata("custom", "id"))
assertEquals(TestData.generateConfig().apiKey, event.apiKey)
}

@Test
Expand All @@ -115,4 +116,30 @@ class EventDeserializerTest {
assertFalse(event.isUnhandled)
assertTrue(TestHooks.getUnhandledOverridden(event))
}

@Test
fun deserializeApiKeyOverridden() {
val map: MutableMap<String, Any?> = hashMapOf(
"apiKey" to "abc123",
"severity" to "info",
"user" to mapOf("id" to "123"),
"unhandled" to false,
"severityReason" to hashMapOf(
"type" to "unhandledException",
"unhandledOverridden" to true
),
"breadcrumbs" to listOf(breadcrumbMap()),
"threads" to listOf(threadMap()),
"errors" to listOf(errorMap()),
"metadata" to metadataMap(),
"app" to mapOf("id" to "app-id"),
"device" to mapOf(
"id" to "device-id",
"runtimeVersions" to hashMapOf<String, Any>()
)
)

val event = EventDeserializer(client, emptyList()).deserialize(map)
assertEquals("abc123", event.apiKey)
}
}

0 comments on commit d88a237

Please sign in to comment.