Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Ser/Deser of the UserFeedback from cached envelope #1611

Merged
merged 3 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

* Fix: set min sdk version of sentry-android-fragment to API 14 (#1608)
* Fix: Ser/Deser of the UserFeedback from cached envelope (#1611)
* Feat: Add request body extraction for Spring MVC integration (#1595)

## 5.1.0-beta.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,21 @@ public void write(JsonWriter writer, SentryEnvelopeItemHeader value) throws IOEx
break;
case "type":
try {
final String nextString = StringUtils.capitalize(reader.nextString());
String nextString = reader.nextString();

if (nextString != null) {
type = SentryItemType.valueOf(nextString);
// special case the String 'user_report since the enum is called UserFeedback
// instead of UserReport, this is gonna be fixed when we move away from reflection.
Comment on lines +76 to +77
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (nextString.equalsIgnoreCase("user_report")) {
type = SentryItemType.UserFeedback;
} else {
final String capitalizedString = StringUtils.capitalize(nextString);

// NPE check because of uber:nullaway
if (capitalizedString != null) {
type = SentryItemType.valueOf(capitalizedString);
}
}
}
} catch (IllegalArgumentException ignored) {
// invalid type
Expand Down
27 changes: 23 additions & 4 deletions sentry/src/test/java/io/sentry/SentryEnvelopeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ class SentryEnvelopeTest {

@Test
fun `deserialize sample envelope with event and two attachments`() {
val envelopeReader = EnvelopeReader()
val testFile = this::class.java.classLoader.getResource("envelope-event-attachment.txt")
val stream = testFile!!.openStream()
val envelope = envelopeReader.read(stream)
val envelope = readEnvelope("envelope-event-attachment.txt")

assertNotNull(envelope)
assertEquals("9ec79c33ec9942ab8353589fcb2e04dc", envelope.header.eventId.toString())
assertEquals(3, envelope.items.count())
Expand Down Expand Up @@ -137,4 +135,25 @@ abcdefghij""".toInputStream()
assertEquals(10, secondItem.header.length)
assertEquals(10, secondItem.data.size)
}

@Test
fun `deserializes an user feedback`() {
marandaneto marked this conversation as resolved.
Show resolved Hide resolved
val envelope = readEnvelope("envelope-feedback.txt")
marandaneto marked this conversation as resolved.
Show resolved Hide resolved

assertNotNull(envelope)
assertEquals("bdd63725a2b84c1eabd761106e17d390", envelope.header.eventId.toString())
assertEquals(1, envelope.items.count())
val firstItem = envelope.items.elementAt(0)
assertEquals(SentryItemType.UserFeedback, firstItem.header.type)
assertEquals("application/json", firstItem.header.contentType)
assertEquals(103, firstItem.header.length)
assertEquals(103, firstItem.data.size)
}

private fun readEnvelope(fileName: String): SentryEnvelope? {
marandaneto marked this conversation as resolved.
Show resolved Hide resolved
val envelopeReader = EnvelopeReader()
val testFile = this::class.java.classLoader.getResource(fileName)
val stream = testFile!!.openStream()
return envelopeReader.read(stream)
}
}
3 changes: 3 additions & 0 deletions sentry/src/test/resources/envelope-feedback.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"event_id":"bdd63725a2b84c1eabd761106e17d390","sdk":{"name":"sentry.dart.flutter","version":"6.0.0-beta.3","packages":[{"name":"pub:sentry","version":"6.0.0-beta.3"},{"name":"pub:sentry_flutter","version":"6.0.0-beta.3"}],"integrations":["isolateErrorIntegration","runZonedGuardedIntegration","widgetsFlutterBindingIntegration","flutterErrorIntegration","widgetsBindingIntegration","nativeSdkIntegration","loadAndroidImageListIntegration","loadReleaseIntegration"]}}
{"content_type":"application/json","type":"user_report","length":103}
{"event_id":"bdd63725a2b84c1eabd761106e17d390","name":"jonas","email":"a@b.com","comments":"bad stuff"}