forked from 3scale/APIcast
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapicast-policy-standalone.t
218 lines (192 loc) · 3.87 KB
/
apicast-policy-standalone.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
use lib 't';
use Test::APIcast::Blackbox 'no_plan';
sub Test::Base::Filter::eval_self {
my ($self, $input) = @_;
my $block = $self->current_block;
{
my @ARGV = ($block);
my @return = CORE::eval($input);
return $@ if $@;
return @return;
}
}
run_tests();
__DATA__
=== TEST 1: standalone accepts configuration
--- environment_file: standalone
--- configuration_format: yaml
--- configuration
server:
listen:
- port: $TEST_NGINX_SERVER_PORT
name: test
routes:
- match:
uri_path: /t
server_port: test
destination:
service: echo
internal:
- name: echo
policy_chain:
- policy: apicast.policy.echo
--- request
GET /t
--- response_body
GET /t HTTP/1.1
--- error_code: 200
--- no_error_log
[error]
[warn]
=== TEST 2: standalone can point to external destination
--- environment_file: standalone
--- configuration_format: yaml
--- configuration
server:
listen:
- port: $TEST_NGINX_SERVER_PORT
name: test
routes:
- match:
uri_path: /t
server_port: test
destination:
upstream: test-mock
external:
- name: test-mock
server: http://mock:$TEST_NGINX_SERVER_PORT
--- upstream_name: mock
--- upstream
location = /t {
echo "test";
}
--- request
GET /t
--- response_body
test
--- error_code: 200
--- no_error_log
[error]
[warn]
=== TEST 3: data-uri encoded yaml configuration
--- environment_file: standalone
--- env eval_self
use URI;
my ($self) = @_;
my $block = $self->current_block;
my $format = $block->configuration_format;
my $configuration = Test::Nginx::Util::expand_env_in_config($block->configuration);
my $u = URI->new("data:");
$u->media_type("application/$format");
$u->data(scalar($configuration));
$block->set_value('configuration', '');
(
'APICAST_CONFIGURATION' => $u->as_string,
)
--- configuration_file:
--- configuration_format: yaml
--- configuration env
server:
listen:
- port: $TEST_NGINX_SERVER_PORT
name: test
routes:
- match:
uri_path: /t
server_port: test
destination:
service: echo
internal:
- name: echo
policy_chain:
- policy: apicast.policy.echo
--- request
GET /t
--- response_body
GET /t HTTP/1.1
--- error_code: 200
--- no_error_log
[error]
[warn]
=== TEST 4: service with policy chain and upstream
--- environment_file: standalone
--- configuration_format: yaml
--- configuration
server:
listen:
- port: $TEST_NGINX_SERVER_PORT
name: test
routes:
- match:
uri_path: /t
server_port: test
destination:
service: cors
internal:
- name: cors
upstream: http://test_upstream:$TEST_NGINX_SERVER_PORT
policy_chain:
- policy: apicast.policy.cors
--- upstream_name: test_upstream
--- upstream
location = /t {
echo "test";
}
--- request
GET /t
--- more_headers
Origin: http://example.com
Access-Control-Request-Method: GET
Access-Control-Request-Headers: Content-Type
--- response_body
test
--- response_headers
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: GET
Access-Control-Allow-Origin: http://example.com
Access-Control-Allow-Credentials: true
--- error_code: 200
--- no_error_log
[error]
[warn]
=== TEST 5: service with policy chain and null configuration
--- environment_file: standalone
--- configuration_format: yaml
--- configuration
server:
listen:
- port: $TEST_NGINX_SERVER_PORT
name: test
routes:
- match:
uri_path: /t
server_port: test
destination:
service: echo
internal:
- name: echo
policy_chain:
- policy: apicast.policy.echo
configuration:
--- request
GET /t
--- response_body
GET /t HTTP/1.1
--- error_code: 200
--- no_error_log
[error]
[warn]
=== TEST 6: invalid configuration
--- environment_file: standalone
--- SKIP: works on OpenResty 1.15.x
--- must_die
--- configuration_format: yaml
--- configuration
server:
- wrong
invalid: true
--- request
GET
--- error_log
[error]
did not find expected '-' indicator