@@ -5,10 +5,10 @@ import io.sentry.SentryOptions
55import io.sentry.SentryReplayOptions.SentryReplayQuality.LOW
66import io.sentry.protocol.SdkVersion
77import io.sentry.protocol.SerializationUtils
8+ import kotlin.test.assertContentEquals
89import kotlin.test.assertEquals
910import kotlin.test.assertFalse
1011import kotlin.test.assertTrue
11- import kotlin.test.assertContentEquals
1212import org.junit.Test
1313import org.mockito.kotlin.mock
1414
@@ -54,14 +54,15 @@ class RRWebOptionsEventSerializationTest {
5454
5555 @Test
5656 fun `network detail fields are not included when networkDetailAllowUrls is empty` () {
57- val options = SentryOptions ().apply {
58- sessionReplay.setNetworkDetailAllowUrls(emptyArray())
59-
60- // Any config is ignored when no allowUrls are specified.
61- sessionReplay.setNetworkDetailDenyUrls(arrayOf(" https://internal.example.com/*" ))
62- sessionReplay.setNetworkRequestHeaders(listOf (" Authorization" , " X-Custom" ))
63- sessionReplay.setNetworkResponseHeaders(listOf (" X-RateLimit" , " Content-Type" ))
64- }
57+ val options =
58+ SentryOptions ().apply {
59+ sessionReplay.setNetworkDetailAllowUrls(emptyArray())
60+
61+ // Any config is ignored when no allowUrls are specified.
62+ sessionReplay.setNetworkDetailDenyUrls(arrayOf(" https://internal.example.com/*" ))
63+ sessionReplay.setNetworkRequestHeaders(listOf (" Authorization" , " X-Custom" ))
64+ sessionReplay.setNetworkResponseHeaders(listOf (" X-RateLimit" , " Content-Type" ))
65+ }
6566 val event = RRWebOptionsEvent (options)
6667
6768 val payload = event.optionsPayload
@@ -75,44 +76,62 @@ class RRWebOptionsEventSerializationTest {
7576
7677 @Test
7778 fun `networkDetailAllowUrls and headers are included when networkDetailAllowUrls is configured` () {
78- val options = SentryOptions ().apply {
79- sessionReplay.setNetworkDetailAllowUrls(arrayOf(" https://api.example.com/*" ))
80- sessionReplay.setNetworkRequestHeaders(listOf (" Authorization" , " X-Custom" ))
81- sessionReplay.setNetworkResponseHeaders(listOf (" X-RateLimit" , " Content-Type" ))
82- }
79+ val options =
80+ SentryOptions ().apply {
81+ sessionReplay.setNetworkDetailAllowUrls(arrayOf(" https://api.example.com/*" ))
82+ sessionReplay.setNetworkRequestHeaders(listOf (" Authorization" , " X-Custom" ))
83+ sessionReplay.setNetworkResponseHeaders(listOf (" X-RateLimit" , " Content-Type" ))
84+ }
8385 val event = RRWebOptionsEvent (options)
8486
8587 val payload = event.optionsPayload
8688 assertTrue(payload.containsKey(" networkDetailAllowUrls" ))
8789 assertTrue(payload.containsKey(" networkRequestHeaders" ))
8890 assertTrue(payload.containsKey(" networkResponseHeaders" ))
8991 assertEquals(true , payload[" networkDetailHasUrls" ])
90- assertContentEquals(arrayOf(" https://api.example.com/*" ), payload[" networkDetailAllowUrls" ] as Array <String >)
91- assertContentEquals(arrayOf(" Content-Type" , " Content-Length" , " Accept" , " Authorization" , " X-Custom" ), payload[" networkRequestHeaders" ] as Array <String >)
92- assertContentEquals(arrayOf(" Content-Type" , " Content-Length" , " Accept" , " X-RateLimit" ), payload[" networkResponseHeaders" ] as Array <String >)
92+ assertContentEquals(
93+ arrayOf(" https://api.example.com/*" ),
94+ payload[" networkDetailAllowUrls" ] as Array <String >,
95+ )
96+ assertContentEquals(
97+ arrayOf(" Content-Type" , " Content-Length" , " Accept" , " Authorization" , " X-Custom" ),
98+ payload[" networkRequestHeaders" ] as Array <String >,
99+ )
100+ assertContentEquals(
101+ arrayOf(" Content-Type" , " Content-Length" , " Accept" , " X-RateLimit" ),
102+ payload[" networkResponseHeaders" ] as Array <String >,
103+ )
93104 }
94105
95106 @Test
96107 fun `networkDetailDenyUrls are included when networkDetailAllowUrls is configured` () {
97- val options = SentryOptions ().apply {
98- sessionReplay.setNetworkDetailAllowUrls(arrayOf(" https://api.example.com/*" ))
99- sessionReplay.setNetworkDetailDenyUrls(arrayOf(" https://internal.example.com/*" ))
100- }
108+ val options =
109+ SentryOptions ().apply {
110+ sessionReplay.setNetworkDetailAllowUrls(arrayOf(" https://api.example.com/*" ))
111+ sessionReplay.setNetworkDetailDenyUrls(arrayOf(" https://internal.example.com/*" ))
112+ }
101113 val event = RRWebOptionsEvent (options)
102114
103115 val payload = event.optionsPayload
104116 assertTrue(payload.containsKey(" networkDetailAllowUrls" ))
105117 assertTrue(payload.containsKey(" networkDetailDenyUrls" ))
106- assertContentEquals(arrayOf(" https://api.example.com/*" ), payload[" networkDetailAllowUrls" ] as Array <String >)
107- assertContentEquals(arrayOf(" https://internal.example.com/*" ), payload[" networkDetailDenyUrls" ] as Array <String >)
118+ assertContentEquals(
119+ arrayOf(" https://api.example.com/*" ),
120+ payload[" networkDetailAllowUrls" ] as Array <String >,
121+ )
122+ assertContentEquals(
123+ arrayOf(" https://internal.example.com/*" ),
124+ payload[" networkDetailDenyUrls" ] as Array <String >,
125+ )
108126 }
109127
110128 @Test
111129 fun `networkCaptureBodies is included when networkDetailAllowUrls is configured` () {
112- val options = SentryOptions ().apply {
113- sessionReplay.setNetworkDetailAllowUrls(arrayOf(" https://api.example.com/*" ))
114- sessionReplay.setNetworkCaptureBodies(false )
115- }
130+ val options =
131+ SentryOptions ().apply {
132+ sessionReplay.setNetworkDetailAllowUrls(arrayOf(" https://api.example.com/*" ))
133+ sessionReplay.setNetworkCaptureBodies(false )
134+ }
116135 val event = RRWebOptionsEvent (options)
117136
118137 val payload = event.optionsPayload
@@ -122,9 +141,10 @@ class RRWebOptionsEventSerializationTest {
122141
123142 @Test
124143 fun `default networkCaptureBodies is included when networkDetailAllowUrls is configured` () {
125- val options = SentryOptions ().apply {
126- sessionReplay.setNetworkDetailAllowUrls(arrayOf(" https://api.example.com/*" ))
127- }
144+ val options =
145+ SentryOptions ().apply {
146+ sessionReplay.setNetworkDetailAllowUrls(arrayOf(" https://api.example.com/*" ))
147+ }
128148 val event = RRWebOptionsEvent (options)
129149
130150 val payload = event.optionsPayload
@@ -134,16 +154,23 @@ class RRWebOptionsEventSerializationTest {
134154
135155 @Test
136156 fun `default network request and response headers are included when networkDetailAllowUrls is configured but no custom headers set` () {
137- val options = SentryOptions ().apply {
138- sessionReplay.setNetworkDetailAllowUrls(arrayOf(" https://api.example.com/*" ))
139- // No custom headers set, should use defaults only
140- }
157+ val options =
158+ SentryOptions ().apply {
159+ sessionReplay.setNetworkDetailAllowUrls(arrayOf(" https://api.example.com/*" ))
160+ // No custom headers set, should use defaults only
161+ }
141162 val event = RRWebOptionsEvent (options)
142163
143164 val payload = event.optionsPayload
144165 assertTrue(payload.containsKey(" networkRequestHeaders" ))
145166 assertTrue(payload.containsKey(" networkResponseHeaders" ))
146- assertContentEquals(arrayOf(" Content-Type" , " Content-Length" , " Accept" ), payload[" networkRequestHeaders" ] as Array <String >)
147- assertContentEquals(arrayOf(" Content-Type" , " Content-Length" , " Accept" ), payload[" networkResponseHeaders" ] as Array <String >)
167+ assertContentEquals(
168+ arrayOf(" Content-Type" , " Content-Length" , " Accept" ),
169+ payload[" networkRequestHeaders" ] as Array <String >,
170+ )
171+ assertContentEquals(
172+ arrayOf(" Content-Type" , " Content-Length" , " Accept" ),
173+ payload[" networkResponseHeaders" ] as Array <String >,
174+ )
148175 }
149176}
0 commit comments