|
1 | 1 | package io.sentry.react |
2 | 2 |
|
3 | 3 | import android.app.Activity |
| 4 | +import com.facebook.react.bridge.JavaOnlyArray |
4 | 5 | import com.facebook.react.bridge.JavaOnlyMap |
5 | 6 | import com.facebook.react.common.JavascriptException |
6 | 7 | import io.sentry.Breadcrumb |
@@ -312,4 +313,95 @@ class RNSentryStartTest { |
312 | 313 |
|
313 | 314 | assertFalse("Tombstone should be disabled by default", options.isTombstoneEnabled) |
314 | 315 | } |
| 316 | + |
| 317 | + @Test |
| 318 | + fun `network detail replay options are forwarded to the native replay options`() { |
| 319 | + val mobileReplayOptions = |
| 320 | + JavaOnlyMap.of( |
| 321 | + "networkDetailAllowUrls", |
| 322 | + JavaOnlyArray.of("https://api.example.com"), |
| 323 | + "networkDetailDenyUrls", |
| 324 | + JavaOnlyArray.of("https://api.example.com/auth"), |
| 325 | + "networkCaptureBodies", |
| 326 | + true, |
| 327 | + "networkRequestHeaders", |
| 328 | + JavaOnlyArray.of("X-My-Header"), |
| 329 | + "networkResponseHeaders", |
| 330 | + JavaOnlyArray.of("X-Response-Header"), |
| 331 | + ) |
| 332 | + val rnOptions = |
| 333 | + JavaOnlyMap.of( |
| 334 | + "dsn", |
| 335 | + "https://abc@def.ingest.sentry.io/1234567", |
| 336 | + "replaysOnErrorSampleRate", |
| 337 | + 0.75, |
| 338 | + "mobileReplayOptions", |
| 339 | + mobileReplayOptions, |
| 340 | + ) |
| 341 | + val options = SentryAndroidOptions() |
| 342 | + |
| 343 | + RNSentryStart.getSentryAndroidOptions(options, rnOptions, logger) |
| 344 | + |
| 345 | + val replay = options.sessionReplay |
| 346 | + assertEquals(listOf("https://api.example.com"), replay.networkDetailAllowUrls) |
| 347 | + assertEquals(listOf("https://api.example.com/auth"), replay.networkDetailDenyUrls) |
| 348 | + assertTrue(replay.isNetworkCaptureBodies) |
| 349 | + assertTrue(replay.networkRequestHeaders.contains("X-My-Header")) |
| 350 | + assertTrue(replay.networkResponseHeaders.contains("X-Response-Header")) |
| 351 | + } |
| 352 | + |
| 353 | + @Test |
| 354 | + fun `networkCaptureBodies can be disabled via mobileReplayOptions`() { |
| 355 | + val mobileReplayOptions = |
| 356 | + JavaOnlyMap.of( |
| 357 | + "networkDetailAllowUrls", |
| 358 | + JavaOnlyArray.of("https://api.example.com"), |
| 359 | + "networkCaptureBodies", |
| 360 | + false, |
| 361 | + ) |
| 362 | + val rnOptions = |
| 363 | + JavaOnlyMap.of( |
| 364 | + "dsn", |
| 365 | + "https://abc@def.ingest.sentry.io/1234567", |
| 366 | + "replaysOnErrorSampleRate", |
| 367 | + 0.75, |
| 368 | + "mobileReplayOptions", |
| 369 | + mobileReplayOptions, |
| 370 | + ) |
| 371 | + val options = SentryAndroidOptions() |
| 372 | + |
| 373 | + RNSentryStart.getSentryAndroidOptions(options, rnOptions, logger) |
| 374 | + |
| 375 | + val replay = options.sessionReplay |
| 376 | + assertEquals(listOf("https://api.example.com"), replay.networkDetailAllowUrls) |
| 377 | + assertFalse(replay.isNetworkCaptureBodies) |
| 378 | + } |
| 379 | + |
| 380 | + @Test |
| 381 | + fun `RegExp-sourced network detail urls forwarded as strings are kept`() { |
| 382 | + // The JS layer serializes RegExp patterns to their source string before |
| 383 | + // crossing the bridge; the native side stores them as plain strings. |
| 384 | + val mobileReplayOptions = |
| 385 | + JavaOnlyMap.of( |
| 386 | + "networkDetailAllowUrls", |
| 387 | + JavaOnlyArray.of("^https://api\\.example\\.com/.*"), |
| 388 | + ) |
| 389 | + val rnOptions = |
| 390 | + JavaOnlyMap.of( |
| 391 | + "dsn", |
| 392 | + "https://abc@def.ingest.sentry.io/1234567", |
| 393 | + "replaysOnErrorSampleRate", |
| 394 | + 0.75, |
| 395 | + "mobileReplayOptions", |
| 396 | + mobileReplayOptions, |
| 397 | + ) |
| 398 | + val options = SentryAndroidOptions() |
| 399 | + |
| 400 | + RNSentryStart.getSentryAndroidOptions(options, rnOptions, logger) |
| 401 | + |
| 402 | + assertEquals( |
| 403 | + listOf("^https://api\\.example\\.com/.*"), |
| 404 | + options.sessionReplay.networkDetailAllowUrls, |
| 405 | + ) |
| 406 | + } |
315 | 407 | } |
0 commit comments