forked from 3scale/APIcast
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapicast-policy-nginx_filters.t
149 lines (141 loc) · 3.18 KB
/
apicast-policy-nginx_filters.t
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
use lib 't';
use Test::APIcast::Blackbox 'no_plan';
check_accum_error_log();
run_tests();
repeat_each(1);
__DATA__
=== TEST 1: Check If-Match is returning 412
--- configuration
{
"services": [
{
"id": 42,
"proxy": {
"policy_chain": [
{
"name": "apicast.policy.upstream",
"configuration":
{
"rules": [ { "regex": "/", "url": "http://echo" } ]
}
}
]
}
}
]
}
--- request
GET /
--- more_headers
If-Match: anything
--- error_code: 412
--- no_error_log
[error]
=== TEST 2: Check If-Match header is deleted and processed
--- backend
location /transactions/authrep.xml {
content_by_lua_block {
ngx.say("OK")
}
}
--- configuration
{
"services": [
{
"id": 42,
"backend_version": 1,
"backend_authentication_type": "service_token",
"backend_authentication_value": "token-value",
"proxy": {
"api_backend": "http://test:$TEST_NGINX_SERVER_PORT/",
"proxy_rules": [
{ "pattern": "/", "http_method": "GET", "metric_system_name": "hits", "delta": 2 }
],
"policy_chain": [
{ "name": "apicast.policy.apicast" },
{ "name": "apicast.policy.nginx_filters",
"configuration": {
"headers": [
{"name": "If-Match", "append": false}
]
}
}
]
}
}
]
}
--- upstream
location / {
content_by_lua_block {
local assert = require('luassert')
assert.same(ngx.req.get_headers()["If-Match"], nil)
assert.same(ngx.req.get_headers()["Test"], "one")
ngx.say('yay, api backend');
}
}
--- request
GET /?user_key=foo
--- more_headers
If-Match: anything
Test: one
--- error_code: 200
--- response_body
yay, api backend
--- no_error_log
[error]
=== TEST 3: Check If-Match header is sent to the upstream API
--- backend
location /transactions/authrep.xml {
content_by_lua_block {
ngx.say("OK")
}
}
--- configuration
{
"services": [
{
"id": 42,
"backend_version": 1,
"backend_authentication_type": "service_token",
"backend_authentication_value": "token-value",
"proxy": {
"api_backend": "http://test:$TEST_NGINX_SERVER_PORT/",
"proxy_rules": [
{ "pattern": "/", "http_method": "GET", "metric_system_name": "hits", "delta": 2 }
],
"policy_chain": [
{ "name": "apicast.policy.apicast" },
{ "name": "apicast.policy.nginx_filters",
"configuration": {
"headers": [
{"name": "If-Match", "append": true}
]
}
}
]
}
}
]
}
--- upstream
location / {
rewrite_by_lua_block {
local assert = require('luassert')
assert.same(ngx.req.get_headers()["If-Match"], "anything")
assert.same(ngx.req.get_headers()["Test"], "one")
ngx.req.clear_header("If-Match")
ngx.say("yay, api backend")
ngx.exit(200)
}
}
--- request
GET /?user_key=foo
--- more_headers
If-Match: anything
Test: one
--- error_code: 200
--- response_body
yay, api backend
--- no_error_log
[error]