Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 109 lines (74 sloc) 1.775 kb
5441a7e @agentzh various coding style fixes in Jeremy Wohl's patch for cryptographically ...
agentzh authored
1 # vi:filetype=
c11f17f @jeremywohl Add cryptographically strong random string functions.
jeremywohl authored
2
3 use Test::Nginx::Socket;
4
5441a7e @agentzh various coding style fixes in Jeremy Wohl's patch for cryptographically ...
agentzh authored
5 repeat_each(2);
c11f17f @jeremywohl Add cryptographically strong random string functions.
jeremywohl authored
6
7 plan tests => repeat_each() * 2 * blocks();
8
9 no_long_string();
10
11 run_tests();
12
13 #no_diff();
14
15 __DATA__
16
17 === TEST 1: a 32-character alphanum
18 --- config
19 location /alphanum {
20 set_secure_random_alphanum $res 32;
21
22 echo $res;
23 }
24 --- request
25 GET /alphanum
26 --- response_body_like: ^[a-zA-Z0-9]{32}$
27
5441a7e @agentzh various coding style fixes in Jeremy Wohl's patch for cryptographically ...
agentzh authored
28
29
c11f17f @jeremywohl Add cryptographically strong random string functions.
jeremywohl authored
30 === TEST 2: a 16-character alphanum
31 --- config
32 location /alphanum {
33 set_secure_random_alphanum $res 16;
34
35 echo $res;
36 }
37 --- request
38 GET /alphanum
39 --- response_body_like: ^[a-zA-Z0-9]{16}$
40
5441a7e @agentzh various coding style fixes in Jeremy Wohl's patch for cryptographically ...
agentzh authored
41
42
c11f17f @jeremywohl Add cryptographically strong random string functions.
jeremywohl authored
43 === TEST 3: a 1-character alphanum
44 --- config
45 location /alphanum {
46 set_secure_random_alphanum $res 1;
47
48 echo $res;
49 }
50 --- request
51 GET /alphanum
52 --- response_body_like: ^[a-zA-Z0-9]{1}$
53
5441a7e @agentzh various coding style fixes in Jeremy Wohl's patch for cryptographically ...
agentzh authored
54
55
c11f17f @jeremywohl Add cryptographically strong random string functions.
jeremywohl authored
56 === TEST 4: length less than <= 0 should fail
57 --- config
58 location /alphanum {
59 set_secure_random_alphanum $res 0;
60
61 echo $res;
62 }
63 --- request
64 GET /alphanum
65 --- response_body_like: 500 Internal Server Error
66 --- error_code: 500
67
5441a7e @agentzh various coding style fixes in Jeremy Wohl's patch for cryptographically ...
agentzh authored
68
69
c11f17f @jeremywohl Add cryptographically strong random string functions.
jeremywohl authored
70 === TEST 5: length less than <= 0 should fail
71 --- config
72 location /alphanum {
73 set_secure_random_alphanum $res -4;
74
75 echo $res;
76 }
77 --- request
78 GET /alphanum
79 --- response_body_like: 500 Internal Server Error
80 --- error_code: 500
81
5441a7e @agentzh various coding style fixes in Jeremy Wohl's patch for cryptographically ...
agentzh authored
82
83
c11f17f @jeremywohl Add cryptographically strong random string functions.
jeremywohl authored
84 === TEST 6: non-numeric length should fail
85 --- config
86 location /alphanum {
87 set_secure_random_alphanum $res bob;
88
89 echo $res;
90 }
91 --- request
92 GET /alphanum
93 --- response_body_like: 500 Internal Server Error
94 --- error_code: 500
95
5441a7e @agentzh various coding style fixes in Jeremy Wohl's patch for cryptographically ...
agentzh authored
96
97
c11f17f @jeremywohl Add cryptographically strong random string functions.
jeremywohl authored
98 === TEST 7: a 16-character lcalpha
99 --- config
100 location /lcalpha {
101 set_secure_random_lcalpha $res 16;
102
103 echo $res;
104 }
105 --- request
106 GET /lcalpha
107 --- response_body_like: ^[a-z]{16}$
5441a7e @agentzh various coding style fixes in Jeremy Wohl's patch for cryptographically ...
agentzh authored
108
Something went wrong with that request. Please try again.