1
1
package io.sentry.transport
2
2
3
+ import io.sentry.ILogger
3
4
import io.sentry.ISerializer
4
5
import io.sentry.RequestDetails
5
6
import io.sentry.SentryEnvelope
6
7
import io.sentry.SentryEvent
8
+ import io.sentry.SentryLevel
7
9
import io.sentry.SentryOptions
8
10
import io.sentry.SentryOptions.Proxy
9
11
import io.sentry.Session
@@ -19,6 +21,7 @@ import java.io.IOException
19
21
import java.net.InetSocketAddress
20
22
import java.net.Proxy.Type
21
23
import java.net.URL
24
+ import java.nio.charset.Charset
22
25
import javax.net.ssl.HostnameVerifier
23
26
import javax.net.ssl.HttpsURLConnection
24
27
import javax.net.ssl.SSLSocketFactory
@@ -40,6 +43,7 @@ class HttpConnectionTest {
40
43
var sslSocketFactory: SSLSocketFactory ? = null
41
44
var hostnameVerifier: HostnameVerifier ? = null
42
45
val requestDetails = mock<RequestDetails >()
46
+ val options = SentryOptions ()
43
47
44
48
init {
45
49
whenever(connection.outputStream).thenReturn(mock())
@@ -54,7 +58,6 @@ class HttpConnectionTest {
54
58
}
55
59
56
60
fun getSUT (): HttpConnection {
57
- val options = SentryOptions ()
58
61
options.setSerializer(serializer)
59
62
options.proxy = proxy
60
63
options.sslSocketFactory = sslSocketFactory
@@ -187,6 +190,34 @@ class HttpConnectionTest {
187
190
verify(fixture.connection, never()).hostnameVerifier = any()
188
191
}
189
192
193
+ @Test
194
+ fun `When connection error message contains formatting symbols, does not crash the logger` () {
195
+ fixture.options.isDebug = true
196
+ fixture.options.setLogger(object : ILogger {
197
+ override fun log (level : SentryLevel , message : String , vararg args : Any? ) =
198
+ println (String .format(message, args))
199
+
200
+ override fun log (level : SentryLevel , message : String , throwable : Throwable ? ) =
201
+ println (message)
202
+
203
+ override fun log (
204
+ level : SentryLevel ,
205
+ throwable : Throwable ? ,
206
+ message : String ,
207
+ vararg args : Any?
208
+ ) = println (String .format(message))
209
+
210
+ override fun isEnabled (level : SentryLevel ? ): Boolean = true
211
+ })
212
+
213
+ // when error message contains funky formatting symbols
214
+ whenever(fixture.connection.errorStream).thenReturn(" Something is off %d, %s, %s\n " .byteInputStream(Charset .forName(" UTF-8" )))
215
+ val transport = fixture.getSUT()
216
+
217
+ // it should not crash
218
+ transport.send(createEnvelope())
219
+ }
220
+
190
221
@Test
191
222
fun `When Proxy host and port are given, set to connection` () {
192
223
fixture.proxy = Proxy (" proxy.example.com" , " 8090" )
0 commit comments