Skip to content

Commit

Permalink
fix(android): respect http configs for trackHttpBody and trackHttpHea…
Browse files Browse the repository at this point in the history
…ders
  • Loading branch information
abhaysood committed Aug 9, 2024
1 parent 803b31a commit 5524b73
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ internal class ConfigProviderImpl(
get() = getMergedConfig { userDefinedAttributeKeyWithSpaces }

override fun shouldTrackHttpBody(url: String, contentType: String?): Boolean {
if (!trackHttpBody) {
return false
}

if (contentType.isNullOrEmpty()) {
return false
}
Expand All @@ -119,6 +123,9 @@ internal class ConfigProviderImpl(
}

override fun shouldTrackHttpHeader(key: String): Boolean {
if (!trackHttpHeaders) {
return false
}
return !combinedHttpHeadersBlocklist.any { key.contains(it, ignoreCase = true) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,23 @@ class ConfigProviderTest {
assertEquals(true, configProvider.trackScreenshotOnCrash)
}

@Test
fun `shouldTrackHttpBody returns false if trackHttpBody is set to false`() {
val configProvider = ConfigProviderImpl(
defaultConfig = Config(
trackHttpBody = false,
httpUrlAllowlist = listOf("example.com"),
),
configLoader = configLoader,
)
Assert.assertFalse(configProvider.shouldTrackHttpBody("example.com", "application/json"))
}

@Test
fun `shouldTrackHttpBody returns true for a URL not blocked and allowed content type`() {
val contentType = "application/json"
val configProvider = ConfigProviderImpl(
defaultConfig = Config(httpUrlBlocklist = listOf("allowed.com")),
defaultConfig = Config(trackHttpBody = true, httpUrlBlocklist = listOf("allowed.com")),
configLoader = configLoader,
)
Assert.assertTrue(configProvider.shouldTrackHttpBody("example.com", contentType))
Expand All @@ -85,7 +97,7 @@ class ConfigProviderTest {
fun `shouldTrackHttpBody returns true for a allowed URL and content type`() {
val contentType = "application/json"
val configProvider = ConfigProviderImpl(
defaultConfig = Config(httpUrlAllowlist = listOf("allowed.com")),
defaultConfig = Config(trackHttpBody = true, httpUrlAllowlist = listOf("allowed.com")),
configLoader = configLoader,
)
Assert.assertTrue(configProvider.shouldTrackHttpBody("allowed.com", contentType))
Expand Down Expand Up @@ -142,10 +154,19 @@ class ConfigProviderTest {
Assert.assertFalse(configProvider.shouldTrackHttpBody(url, contentType))
}

@Test
fun `shouldTrackHttpHeader returns false if trackHttpHeaders is set to false`() {
val configProvider = ConfigProviderImpl(
defaultConfig = Config(trackHttpHeaders = false),
configLoader = configLoader,
)
Assert.assertFalse(configProvider.shouldTrackHttpHeader("key1"))
}

@Test
fun `shouldTrackHttpHeader returns true for a allowed header`() {
val configProvider = ConfigProviderImpl(
defaultConfig = Config(httpHeadersBlocklist = listOf("key1")),
defaultConfig = Config(trackHttpHeaders = true, httpHeadersBlocklist = listOf("key1")),
configLoader = configLoader,
)
Assert.assertTrue(configProvider.shouldTrackHttpHeader("key2"))
Expand Down Expand Up @@ -182,7 +203,10 @@ class ConfigProviderTest {
@Test
fun `shouldTrackHttpUrl given urlAllowlist is empty, urlBlocklist is not empty, returns true if url is not part of blocklist`() {
val configProvider = ConfigProviderImpl(
defaultConfig = Config(httpUrlBlocklist = listOf("blocked.com"), httpUrlAllowlist = emptyList()),
defaultConfig = Config(
httpUrlBlocklist = listOf("blocked.com"),
httpUrlAllowlist = emptyList(),
),
configLoader = configLoader,
)
Assert.assertTrue(configProvider.shouldTrackHttpUrl("https://allowed.com/"))
Expand All @@ -192,7 +216,10 @@ class ConfigProviderTest {
@Test
fun `shouldTrackHttpUrl given both urlAllowlist and urlBlocklist are not empty, considers only the allowlist`() {
val configProvider = ConfigProviderImpl(
defaultConfig = Config(httpUrlAllowlist = listOf("allowed.com", "unblocked.com"), httpUrlBlocklist = listOf("unblocked.com")),
defaultConfig = Config(
httpUrlAllowlist = listOf("allowed.com", "unblocked.com"),
httpUrlBlocklist = listOf("unblocked.com"),
),
configLoader = configLoader,
)
Assert.assertTrue(configProvider.shouldTrackHttpUrl("https://allowed.com/"))
Expand Down

0 comments on commit 5524b73

Please sign in to comment.