1
1
package com.coder.gateway.util
2
2
3
+ import java.net.URL
3
4
import kotlin.test.Test
5
+ import kotlin.test.assertContains
4
6
import kotlin.test.assertEquals
5
7
import kotlin.test.assertFailsWith
6
8
7
- import java.net.URL
8
-
9
9
internal class HeadersTest {
10
10
@Test
11
11
fun testGetHeadersOK () {
@@ -19,6 +19,11 @@ internal class HeadersTest {
19
19
" printf 'foo=bar='" to mapOf (" foo" to " bar=" ),
20
20
" printf 'foo=bar=baz'" to mapOf (" foo" to " bar=baz" ),
21
21
" printf 'foo='" to mapOf (" foo" to " " ),
22
+ " printf 'foo=bar '" to mapOf (" foo" to " bar " ),
23
+ " exit 0" to mapOf (),
24
+ " printf ''" to mapOf (),
25
+ " printf 'ignore me' >&2" to mapOf (),
26
+ " printf 'foo=bar' && printf 'ignore me' >&2" to mapOf (" foo" to " bar" ),
22
27
)
23
28
tests.forEach{
24
29
assertEquals(
@@ -30,22 +35,25 @@ internal class HeadersTest {
30
35
31
36
@Test
32
37
fun testGetHeadersFail () {
33
- val tests = listOf (
34
- " printf 'foo=bar\\ r\\ n\\ r\\ n'" ,
35
- " printf '\\ r\\ nfoo=bar'" ,
36
- " printf '=foo'" ,
37
- " printf 'foo'" ,
38
- " printf ' =foo'" ,
39
- " printf 'foo =bar'" ,
40
- " printf 'foo foo=bar'" ,
41
- " printf ''" ,
42
- " exit 0" ,
43
- " exit 1" ,
38
+ val tests = mapOf (
39
+ " printf '=foo'" to " Header name is missing in \" =foo\" " ,
40
+ " printf 'foo'" to " Header \" foo\" does not have two parts" ,
41
+ " printf ' =foo'" to " Header name is missing in \" =foo\" " ,
42
+ " printf 'foo =bar'" to " Header name cannot contain spaces, got \" foo \" " ,
43
+ " printf 'foo foo=bar'" to " Header name cannot contain spaces, got \" foo foo\" " ,
44
+ " printf ' foo=bar '" to " Header name cannot contain spaces, got \" foo\" " ,
45
+ " exit 1" to " Unexpected exit value: 1" ,
46
+ " printf 'foobar' >&2 && exit 1" to " foobar" ,
47
+ " printf 'foo=bar\\ r\\ n\\ r\\ n'" to " Blank lines are not allowed" ,
48
+ " printf '\\ r\\ nfoo=bar'" to " Blank lines are not allowed" ,
49
+ " printf '\\ r\\ n'" to " Blank lines are not allowed" ,
50
+ " printf 'f=b\\ r\\ n\\ r\\ nb=q'" to " Blank lines are not allowed"
44
51
)
45
52
tests.forEach{
46
- assertFailsWith(
53
+ val ex = assertFailsWith(
47
54
exceptionClass = Exception ::class ,
48
- block = { getHeaders(URL (" http://localhost" ), it) })
55
+ block = { getHeaders(URL (" http://localhost" ), it.key) })
56
+ assertContains(ex.message.toString(), it.value)
49
57
}
50
58
}
51
59
0 commit comments