@@ -6,6 +6,7 @@ import kotlin.test.Test
66import kotlin.test.assertEquals
77import kotlin.test.assertFailsWith
88import kotlin.test.assertNull
9+ import kotlin.text.substring
910
1011class SentryTraceHeaderTest {
1112 @Test
@@ -15,6 +16,80 @@ class SentryTraceHeaderTest {
1516 assertEquals(" sentry-trace header does not conform to expected format: $sentryId " , ex.message)
1617 }
1718
19+ @Test
20+ fun `when trace-id has less than 32 characters throws exception` () {
21+ val sentryId = SentryId ().toString().substring(0 , 8 )
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 more than 32 characters throws exception` () {
33+ val sentryId = SentryId ().toString() + " abc"
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 contains invalid characters throws exception` () {
45+ var sentryId = SentryId ().toString()
46+ sentryId = sentryId.substring(0 , 8 ) + " g" + sentryId.substring(8 )
47+ val spanId = SpanId ()
48+ val ex =
49+ assertFailsWith<InvalidSentryTraceHeaderException > { SentryTraceHeader (" $sentryId -$spanId " ) }
50+ assertEquals(
51+ " sentry-trace header does not conform to expected format: $sentryId -$spanId " ,
52+ ex.message,
53+ )
54+ }
55+
56+ @Test
57+ fun `when span-id has less than 16 characters throws exception` () {
58+ val sentryId = SentryId ()
59+ val spanId = SpanId ().toString().substring(0 , 8 )
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 more than 32 characters throws exception` () {
70+ val sentryId = SentryId ()
71+ val spanId = SpanId ().toString() + " abc"
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 contains invalid characters throws exception` () {
82+ val sentryId = SentryId ()
83+ var spanId = SpanId ().toString()
84+ spanId = spanId.substring(0 , 8 ) + " g" + spanId.substring(8 )
85+ val ex =
86+ assertFailsWith<InvalidSentryTraceHeaderException > { SentryTraceHeader (" $sentryId -$spanId " ) }
87+ assertEquals(
88+ " sentry-trace header does not conform to expected format: $sentryId -$spanId " ,
89+ ex.message,
90+ )
91+ }
92+
1893 @Test
1994 fun `handles header with positive sampling decision` () {
2095 val sentryId = SentryId ()
0 commit comments