/
openresty.t
125 lines (94 loc) · 3.27 KB
/
openresty.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
# vi:filetype=perl
use lib 'lib';
use Test::Nginx::Socket;
repeat_each(100);
worker_connections(2048);
workers(2);
#master_on;
log_level('warn');
plan tests => repeat_each() * 3 * blocks();
our $http_config = <<'_EOC_';
upstream backend {
drizzle_server 127.0.0.1:3306 dbname=test
password=some_pass user=monty protocol=mysql;
drizzle_keepalive max=200 overflow=reject;
}
_EOC_
our $config = <<'_EOC_';
xss_get on;
xss_callback_arg _callback;
location = '/=/view/PostsByMonth/~/~' {
if ($arg_year !~ '^\d{4}$') {
rds_json_ret 400 'Bad "year" argument';
}
if ($arg_month !~ '^\d{1,2}$') {
rds_json_ret 400 'Bad "month" argument';
}
drizzle_query
"select id, title, day(created) as day
from posts
where year(created) = $arg_year and month(created) = $arg_month
order by created asc";
drizzle_pass backend;
error_page 500 = @err500;
error_page 502 = @err502;
error_page 503 = @err503;
error_page 404 = @err404;
error_page 400 = @err400;
rds_json on;
}
location @err500 { rds_json_ret 500 "Internal Server Error"; }
location @err502 { rds_json_ret 502 "Bad Gateway"; }
location @err503 { rds_json_ret 503 "Service Unavailable"; }
location @err404 { rds_json_ret 404 "Not Found"; }
location @err400 { rds_json_ret 400 "Bad Request"; }
_EOC_
no_long_string();
run_tests();
#no_diff();
__DATA__
=== TEST 1: PostsByMonth view (no month arg)
--- http_config eval: $::http_config
--- config eval: $::config
--- request
GET /=/view/PostsByMonth/~/~?_callback=foo
--- response_headers
Content-Type: application/x-javascript
--- response_body chop
foo({"errcode":400,"errstr":"Bad \"month\" argument"});
=== TEST 2: PostsByMonth view (bad month)
--- http_config eval: $::http_config
--- config eval: $::config
--- request
GET /=/view/PostsByMonth/~/~?month=1234&_callback=foo
--- response_headers
Content-Type: application/x-javascript
--- response_body chop
foo({"errcode":400,"errstr":"Bad \"month\" argument"});
=== TEST 3: PostsByMonth view (emtpy result)
--- http_config eval: $::http_config
--- config eval: $::config
--- request
GET /=/view/PostsByMonth/~/~?year=1984&month=2&_callback=bar
--- response_headers
Content-Type: application/x-javascript
--- response_body chop
bar([]);
=== TEST 4: PostsByMonth view (non-emtpy result)
--- http_config eval: $::http_config
--- config eval: $::config
--- request
GET /=/view/PostsByMonth/~/~?year=2009&month=10&_callback=foo
--- response_headers
Content-Type: application/x-javascript
--- response_body chop
foo([{"id":114,"title":"Hacking on the Nginx echo module","day":15}]);
=== TEST 5: PostsByMonth view (non-emtpy result)
--- http_config eval: $::http_config
--- config eval: $::config
--- request
GET /=/view/PostsByMonth/~/~?year=2009&month=12&_callback=foo
--- response_headers
Content-Type: application/x-javascript
--- response_body chop
foo([{"id":117,"title":"Major updates to ngx_chunkin: lots of bug fixes and beginning of keep-alive support","day":4},{"id":118,"title":"ngx_memc: an extended version of ngx_memcached that supports set, add, delete, and many more commands","day":6},{"id":119,"title":"Test::Nginx::LWP and Test::Nginx::Socket are now on CPAN","day":8}]);