forked from 3scale/APIcast
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapicast-policy-on_failed.t
111 lines (101 loc) · 2.19 KB
/
apicast-policy-on_failed.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
use lib 't';
use Test::APIcast::Blackbox 'no_plan';
use Cwd qw(abs_path);
BEGIN {
$ENV{TEST_NGINX_APICAST_POLICY_LOAD_PATH} = 't/fixtures/policies';
}
env_to_apicast(
'APICAST_POLICY_LOAD_PATH' => abs_path($ENV{TEST_NGINX_APICAST_POLICY_LOAD_PATH}),
);
repeat_each();
run_tests();
__DATA__
=== TEST 1: policy with invalid configuration return 503
--- configuration
{
"services": [
{
"id": 42,
"proxy": {
"policy_chain": [
{ "name": "example_policy", "version": "1.0.0", "configuration": { } },
{ "name": "apicast.policy.on_failed", "configuration": {} },
{ "name": "apicast.policy.echo" }
]
}
}
]
}
--- request
GET /test
--- error_code: 503
--- error_log
Stop request because policy: 'example_policy' failed, error=
=== TEST 2: policy with access phase issues return 503
--- configuration
{
"services": [
{
"id": 42,
"proxy": {
"policy_chain": [
{
"name": "example_policy",
"version": "1.0.0",
"configuration": {
"message": "foo",
"fail_access": true
}
},
{
"name": "apicast.policy.on_failed",
"configuration": {}
},
{
"name": "apicast.policy.echo"
}
]
}
}
]
}
--- request
GET /test
--- error_code: 503
--- error_log
Stop request because policy: 'example_policy' failed, error=
=== TEST 3: policy with access phase issues return provided status code
--- configuration
{
"services": [
{
"id": 42,
"proxy": {
"policy_chain": [
{
"name": "example_policy",
"version": "1.0.0",
"configuration": {
"message": "foo",
"fail_access": true
}
},
{
"name": "apicast.policy.on_failed",
"configuration": {
"error_status_code": 401
}
},
{
"name": "apicast.policy.echo"
}
]
}
}
]
}
--- request
GET /test
--- error_code: 401
--- error_log
Stop request because policy: 'example_policy' failed, error='