@@ -6,6 +6,7 @@ import kotlin.test.Test
6
6
import kotlin.test.assertEquals
7
7
import kotlin.test.assertFailsWith
8
8
import kotlin.test.assertNull
9
+ import kotlin.text.substring
9
10
10
11
class SentryTraceHeaderTest {
11
12
@Test
@@ -15,6 +16,92 @@ class SentryTraceHeaderTest {
15
16
assertEquals(" sentry-trace header does not conform to expected format: $sentryId " , ex.message)
16
17
}
17
18
19
+ @Test
20
+ fun `when there is a trailing dash without sampling decision throws exception` () {
21
+ val sentryId = SentryId ()
22
+ val spanId = SpanId ()
23
+ val ex =
24
+ assertFailsWith<InvalidSentryTraceHeaderException > { SentryTraceHeader (" $sentryId -$spanId -" ) }
25
+ assertEquals(
26
+ " sentry-trace header does not conform to expected format: $sentryId -$spanId -" ,
27
+ ex.message,
28
+ )
29
+ }
30
+
31
+ @Test
32
+ fun `when trace-id has less than 32 characters throws exception` () {
33
+ val sentryId = SentryId ().toString().substring(0 , 8 )
34
+ val spanId = SpanId ()
35
+ val ex =
36
+ assertFailsWith<InvalidSentryTraceHeaderException > { SentryTraceHeader (" $sentryId -$spanId " ) }
37
+ assertEquals(
38
+ " sentry-trace header does not conform to expected format: $sentryId -$spanId " ,
39
+ ex.message,
40
+ )
41
+ }
42
+
43
+ @Test
44
+ fun `when trace-id has more than 32 characters throws exception` () {
45
+ val sentryId = SentryId ().toString() + " abc"
46
+ val spanId = SpanId ()
47
+ val ex =
48
+ assertFailsWith<InvalidSentryTraceHeaderException > { SentryTraceHeader (" $sentryId -$spanId " ) }
49
+ assertEquals(
50
+ " sentry-trace header does not conform to expected format: $sentryId -$spanId " ,
51
+ ex.message,
52
+ )
53
+ }
54
+
55
+ @Test
56
+ fun `when trace-id contains invalid characters throws exception` () {
57
+ var sentryId = SentryId ().toString()
58
+ sentryId = sentryId.substring(0 , 8 ) + " g" + sentryId.substring(8 )
59
+ val spanId = SpanId ()
60
+ val ex =
61
+ assertFailsWith<InvalidSentryTraceHeaderException > { SentryTraceHeader (" $sentryId -$spanId " ) }
62
+ assertEquals(
63
+ " sentry-trace header does not conform to expected format: $sentryId -$spanId " ,
64
+ ex.message,
65
+ )
66
+ }
67
+
68
+ @Test
69
+ fun `when span-id has less than 16 characters throws exception` () {
70
+ val sentryId = SentryId ()
71
+ val spanId = SpanId ().toString().substring(0 , 8 )
72
+ val ex =
73
+ assertFailsWith<InvalidSentryTraceHeaderException > { SentryTraceHeader (" $sentryId -$spanId " ) }
74
+ assertEquals(
75
+ " sentry-trace header does not conform to expected format: $sentryId -$spanId " ,
76
+ ex.message,
77
+ )
78
+ }
79
+
80
+ @Test
81
+ fun `when span-id has more than 32 characters throws exception` () {
82
+ val sentryId = SentryId ()
83
+ val spanId = SpanId ().toString() + " abc"
84
+ val ex =
85
+ assertFailsWith<InvalidSentryTraceHeaderException > { SentryTraceHeader (" $sentryId -$spanId " ) }
86
+ assertEquals(
87
+ " sentry-trace header does not conform to expected format: $sentryId -$spanId " ,
88
+ ex.message,
89
+ )
90
+ }
91
+
92
+ @Test
93
+ fun `when span-id contains invalid characters throws exception` () {
94
+ val sentryId = SentryId ()
95
+ var spanId = SpanId ().toString()
96
+ spanId = spanId.substring(0 , 8 ) + " g" + spanId.substring(8 )
97
+ val ex =
98
+ assertFailsWith<InvalidSentryTraceHeaderException > { SentryTraceHeader (" $sentryId -$spanId " ) }
99
+ assertEquals(
100
+ " sentry-trace header does not conform to expected format: $sentryId -$spanId " ,
101
+ ex.message,
102
+ )
103
+ }
104
+
18
105
@Test
19
106
fun `handles header with positive sampling decision` () {
20
107
val sentryId = SentryId ()
0 commit comments