blob: 926ebbc4e608428e1916edd9b0be739129094d62 (
plain)
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:ft=
use Test::Nginx::Socket::Lua;
repeat_each(2);
plan tests => repeat_each() * (3 * blocks());
our $HttpConfig = <<'_EOC_';
lua_package_path 'lib/?.lua;;';
lua_package_cpath 'lib/?.so;;';
_EOC_
no_long_string();
run_tests();
__DATA__
=== TEST 1: hello MD5
--- http_config eval: $::HttpConfig
--- config
location /t {
content_by_lua '
local resty_md5 = require "resty.md5"
local str = require "resty.string"
local md5 = resty_md5:new()
ngx.say(md5:update("hello"))
local digest = md5:final()
ngx.say(digest == ngx.md5_bin("hello"))
ngx.say("md5: ", str.to_hex(digest))
';
}
--- request
GET /t
--- response_body
true
true
md5: 5d41402abc4b2a76b9719d911017c592
--- no_error_log
[error]
=== TEST 2: MD5 incremental
--- http_config eval: $::HttpConfig
--- config
location /t {
content_by_lua '
local resty_md5 = require "resty.md5"
local str = require "resty.string"
local md5 = resty_md5:new()
ngx.say(md5:update("hel"))
ngx.say(md5:update("lo"))
local digest = md5:final()
ngx.say("md5: ", str.to_hex(digest))
';
}
--- request
GET /t
--- response_body
true
true
md5: 5d41402abc4b2a76b9719d911017c592
--- no_error_log
[error]
=== TEST 3: MD5 empty string
--- http_config eval: $::HttpConfig
--- config
location /t {
content_by_lua '
local resty_md5 = require "resty.md5"
local str = require "resty.string"
local md5 = resty_md5:new()
ngx.say(md5:update(""))
local digest = md5:final()
ngx.say(digest == ngx.md5_bin(""))
ngx.say("md5: ", str.to_hex(digest))
';
}
--- request
GET /t
--- response_body
true
true
md5: d41d8cd98f00b204e9800998ecf8427e
--- no_error_log
[error]
=== TEST 4: MD5 update with len parameter
--- http_config eval: $::HttpConfig
--- config
location /t {
content_by_lua '
local resty_md5 = require "resty.md5"
local str = require "resty.string"
local md5 = resty_md5:new()
ngx.say(md5:update("hello", 3))
local digest = md5:final()
ngx.say(digest == ngx.md5_bin("hel"))
md5 = resty_md5:new()
ngx.say(md5:update("hello", 3))
ngx.say(md5:update("loxxx", 2))
digest = md5:final()
ngx.say(digest == ngx.md5_bin("hello"))
ngx.say("md5: ", str.to_hex(digest))
';
}
--- request
GET /t
--- response_body
true
true
true
true
true
md5: 5d41402abc4b2a76b9719d911017c592
--- no_error_log
[error]
|