summaryrefslogtreecommitdiffstats
path: root/reg-tests/converter/bytes.vtc
blob: 8abe401e55be49cef2a47ff59e37aed5ee91b498 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
varnishtest "bytes converter Test"

feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(2.9-dev4)'"

feature ignore_unknown_macro

# TEST - 1
server s1 {
	rxreq
	txresp -hdr "Connection: close"
} -repeat 1 -start

haproxy h1 -conf {
	defaults
		mode http
		timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
		timeout client  "${HAPROXY_TEST_TIMEOUT-5s}"
		timeout server  "${HAPROXY_TEST_TIMEOUT-5s}"

	frontend fe
		bind "fd@${fe}"

		#### requests
		http-request  set-var(txn.input) req.hdr(input)

		http-response set-header bytes_0      "%[var(txn.input),bytes(0)]"
		http-response set-header bytes_1      "%[var(txn.input),bytes(1)]"
		http-response set-header bytes_0_3    "%[var(txn.input),bytes(0,3)]"
		http-response set-header bytes_1_3    "%[var(txn.input),bytes(1,3)]"
		http-response set-header bytes_99     "%[var(txn.input),bytes(99)]"
		http-response set-header bytes_5      "%[var(txn.input),bytes(5)]"
		http-response set-header bytes_6      "%[var(txn.input),bytes(6)]"
		http-response set-header bytes_0_6    "%[var(txn.input),bytes(0,6)]"
		http-response set-header bytes_0_7    "%[var(txn.input),bytes(0,7)]"

		http-response set-var(txn.var_start) int(0)
		http-response set-header bytes_var0    "%[var(txn.input),bytes(txn.var_start)]"

		http-response set-var(txn.var_start) int(1)
		http-response set-var(txn.var_length) int(3)
		http-response set-header bytes_var1_var3    "%[var(txn.input),bytes(txn.var_start,txn.var_length)]"

		http-response set-var(txn.var_start) int(99)
		http-response set-header bytes_var99  "%[var(txn.input),bytes(txn.var_start)]"

		http-response set-var(txn.var_start) int(0)
		http-response set-var(txn.var_length) int(7)
		http-response set-header bytes_var0_var7    "%[var(txn.input),bytes(txn.var_start,txn.var_length)]"

		http-response set-var(txn.var_start) int(1)
		http-response set-var(txn.var_length) int(3)
		http-response set-header bytes_var1_3   "%[var(txn.input),bytes(txn.var_start,3)]"
		http-response set-header bytes_1_var3   "%[var(txn.input),bytes(1,txn.var_length)]"

		http-response set-var(txn.var_start) int(-1)
		http-response set-var(txn.var_length) int(-1)
		http-response set-header bytes_varminus1        "%[var(txn.input),bytes(txn.var_start)]"
		http-response set-header bytes_0_varminus1      "%[var(txn.input),bytes(0,txn.var_length)]"

		http-response set-header bytes_varNA    "%[var(txn.input),bytes(txn.NA)]"
		http-response set-header bytes_1_varNA  "%[var(txn.input),bytes(1,txn.NA)]"

		default_backend be

	backend be
		server s1 ${s1_addr}:${s1_port}
} -start

client c1 -connect ${h1_fe_sock} {
	txreq -url "/" \
		-hdr "input: 012345"
	rxresp
	expect resp.status == 200
	expect resp.http.bytes_0 == "012345"
	expect resp.http.bytes_1 == "12345"
	expect resp.http.bytes_0_3 == "012"
	expect resp.http.bytes_1_3 == "123"
	expect resp.http.bytes_99 == ""
	expect resp.http.bytes_5 == "5"
	expect resp.http.bytes_6 == ""
	expect resp.http.bytes_0_6 == "012345"

	# since specified length is > input length, response contains the input till the end
	expect resp.http.bytes_0_7 == "012345"

	expect resp.http.bytes_var0 == "012345"
	expect resp.http.bytes_var1_var3 == "123"
	expect resp.http.bytes_var99 == ""
	expect resp.http.bytes_var0_var7 == "012345"
	expect resp.http.bytes_var1_3 == "123"
	expect resp.http.bytes_1_var3 == "123"
	expect resp.http.bytes_varminus1 == ""
	expect resp.http.bytes_0_varminus1 == ""
	expect resp.http.bytes_varNA == ""
	expect resp.http.bytes_1_varNA == ""
} -run

# TEST - 2
# negative starting index causes startup failure
haproxy h2 -conf {
	defaults
		mode http
		timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
		timeout client  "${HAPROXY_TEST_TIMEOUT-5s}"
		timeout server  "${HAPROXY_TEST_TIMEOUT-5s}"

	frontend fe
		bind "fd@${fe}"

		http-response set-header bytes_output     "%[var(txn.input),bytes(-1)]"

		default_backend be

	backend be
		server s1 ${s1_addr}:${s1_port}
} -start -expectexit 1

# TEST - 3
# negative length causes startup failure
haproxy h3 -conf {
	defaults
		mode http
		timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
		timeout client  "${HAPROXY_TEST_TIMEOUT-5s}"
		timeout server  "${HAPROXY_TEST_TIMEOUT-5s}"

	frontend fe
		bind "fd@${fe}"

		http-response set-header bytes_output     "%[var(txn.input),bytes(0,-1)]"

		default_backend be

	backend be
		server s1 ${s1_addr}:${s1_port}
} -start -expectexit 1

# TEST - 4
# 0 length causes startup failure
haproxy h4 -conf {
	defaults
		mode http
		timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
		timeout client  "${HAPROXY_TEST_TIMEOUT-5s}"
		timeout server  "${HAPROXY_TEST_TIMEOUT-5s}"

	frontend fe
		bind "fd@${fe}"

		http-response set-header bytes_output     "%[var(txn.input),bytes(0,0)]"

		default_backend be

	backend be
		server s1 ${s1_addr}:${s1_port}
} -start -expectexit 1