git.iko.soy/opencode-android
on a0ce9ce help sign in
46 lines 2.0 kB history raw
1package soy.iko.opencode.data.repo
3import org.junit.Assert.assertEquals
4import org.junit.Assert.assertFalse
5import org.junit.Assert.assertTrue
6import org.junit.Test
8class CrashLoggerScrubTest {
10 @Test
11 fun scrubUrls_replacesBareUrl() {
12 assertEquals("see [url] for details", CrashLogger.scrubUrls("see http://host:4096/path for details"))
13 }
15 @Test
16 fun scrubUrls_replacesUrlWithCredentials() {
17 // Ktor/OkHttp exception messages embed the full request URL, which may carry
18 // auth or internal paths — none of it may survive into a stored crash report.
19 val scrubbed = CrashLogger.scrubUrls("Bad response: GET https://u:se%20cret@10.0.0.2:4096/session/s%201/message")
20 assertFalse("password leaked: $scrubbed", scrubbed.contains("se%20cret"))
21 assertFalse("host leaked: $scrubbed", scrubbed.contains("10.0.0.2"))
22 assertTrue("redaction marker missing: $scrubbed", scrubbed.contains("[url]"))
23 }
25 @Test
26 fun scrubUrls_replacesEveryOccurrenceIncludingCausedBy() {
27 // printStackTrace re-emits the message on the top line and on each "Caused by:"
28 // line; the scrub must catch all of them, not just the first.
29 val report = """
30 io.ktor.client.plugins.ClientRequestException: GET https://srv/event
31 at Foo.bar(Foo.kt:1)
32 Caused by: java.net.SocketTimeoutException: Request timeout https://srv/session
33 """.trimIndent()
34 val scrubbed = CrashLogger.scrubUrls(report)
35 assertFalse(scrubbed.contains("https://"))
36 // Non-URL content (class names, stack frames) is preserved.
37 assertTrue(scrubbed.contains("ClientRequestException"))
38 assertTrue(scrubbed.contains("Foo.kt:1"))
39 }
41 @Test
42 fun scrubUrls_leavesPlainTextUntouched() {
43 val text = "opencode-android crash report\nAndroid: 14 (API 34)\nno urls here"
44 assertEquals(text, CrashLogger.scrubUrls(text))
45 }