mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
Remove unused test files for lua-resty-string
This commit is contained in:
parent
e918e26c8a
commit
c71a7d9321
11 changed files with 0 additions and 1450 deletions
589
src/deps/src/lua-resty-string/t/aes.t
vendored
589
src/deps/src/lua-resty-string/t/aes.t
vendored
|
|
@ -1,589 +0,0 @@
|
|||
# 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_
|
||||
|
||||
#log_level 'warn';
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: AES default hello
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local aes = require "resty.aes"
|
||||
local str = require "resty.string"
|
||||
local aes_default = aes:new("secret")
|
||||
local encrypted = aes_default:encrypt("hello")
|
||||
ngx.say("AES-128 CBC MD5: ", str.to_hex(encrypted))
|
||||
local decrypted = aes_default:decrypt(encrypted)
|
||||
ngx.say(decrypted == "hello")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
AES-128 CBC MD5: 7b47a4dbb11e2cddb2f3740c9e3a552b
|
||||
true
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 2: AES empty key hello
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local aes = require "resty.aes"
|
||||
local str = require "resty.string"
|
||||
local aes_default = aes:new("")
|
||||
local encrypted = aes_default:encrypt("hello")
|
||||
ngx.say("AES-128 (empty key) CBC MD5: ", str.to_hex(encrypted))
|
||||
local decrypted = aes_default:decrypt(encrypted)
|
||||
ngx.say(decrypted == "hello")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
AES-128 (empty key) CBC MD5: 6cb1a35bf9d66e92c9dec684fc329746
|
||||
true
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 3: AES 8-byte salt
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local aes = require "resty.aes"
|
||||
local str = require "resty.string"
|
||||
local aes_default = aes:new("secret","WhatSalt")
|
||||
local encrypted = aes_default:encrypt("hello")
|
||||
ngx.say("AES-128 (salted) CBC MD5: ", str.to_hex(encrypted))
|
||||
local decrypted = aes_default:decrypt(encrypted)
|
||||
ngx.say(decrypted == "hello")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
AES-128 (salted) CBC MD5: f72db89f8e19326d8da4928be106705c
|
||||
true
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 4: AES oversized or too short salt
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local aes = require "resty.aes"
|
||||
local str = require "resty.string"
|
||||
local res, err = aes:new("secret","Oversized!")
|
||||
ngx.say(res, ", ", err)
|
||||
res, err = aes:new("secret","abc")
|
||||
ngx.say(res, ", ", err)
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
nil, salt must be 8 characters or nil
|
||||
nil, salt must be 8 characters or nil
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 5: AES-256 ECB SHA1 no salt
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local aes = require "resty.aes"
|
||||
local str = require "resty.string"
|
||||
local aes_default = aes:new("secret",nil,
|
||||
aes.cipher(256,"ecb"),aes.hash.sha1)
|
||||
local encrypted = aes_default:encrypt("hello")
|
||||
ngx.say("AES-256 ECB SHA1: ", str.to_hex(encrypted))
|
||||
local decrypted = aes_default:decrypt(encrypted)
|
||||
ngx.say(decrypted == "hello")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
AES-256 ECB SHA1: 927148b31f0e89696a222489403f540d
|
||||
true
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 6: AES-256 ECB SHA1x5 no salt
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local aes = require "resty.aes"
|
||||
local str = require "resty.string"
|
||||
local aes_default = aes:new("secret",nil,
|
||||
aes.cipher(256,"ecb"),aes.hash.sha1,5)
|
||||
local encrypted = aes_default:encrypt("hello")
|
||||
ngx.say("AES-256 ECB SHA1: ", str.to_hex(encrypted))
|
||||
local decrypted = aes_default:decrypt(encrypted)
|
||||
ngx.say(decrypted == "hello")
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
AES-256 ECB SHA1: d1a9b6e59b8980e783df223889563bee
|
||||
true
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 7: AES-128 CBC custom keygen
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local aes = require "resty.aes"
|
||||
local str = require "resty.string"
|
||||
local aes_default = aes:new("Xr4ilOzQ4PCOq3aQ0qbuaQ==",nil,
|
||||
aes.cipher(128,"cbc"),
|
||||
{iv = ngx.decode_base64("Jq5cyFTja2vfyjZoSN6muw=="),
|
||||
method = ngx.decode_base64})
|
||||
local encrypted = aes_default:encrypt("hello")
|
||||
ngx.say("AES-128 CBC (custom keygen) MD5: ", str.to_hex(encrypted))
|
||||
local decrypted = aes_default:decrypt(encrypted)
|
||||
ngx.say(decrypted == "hello")
|
||||
local aes_check = aes:new("secret")
|
||||
local encrypted_check = aes_check:encrypt("hello")
|
||||
ngx.say(encrypted_check == encrypted)
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
AES-128 CBC (custom keygen) MD5: 7b47a4dbb11e2cddb2f3740c9e3a552b
|
||||
true
|
||||
true
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 8: AES-128 CBC custom keygen (without method)
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local aes = require "resty.aes"
|
||||
local str = require "resty.string"
|
||||
local aes_default = aes:new(ngx.decode_base64("Xr4ilOzQ4PCOq3aQ0qbuaQ=="),nil,
|
||||
aes.cipher(128,"cbc"),
|
||||
{iv = ngx.decode_base64("Jq5cyFTja2vfyjZoSN6muw==")})
|
||||
local encrypted = aes_default:encrypt("hello")
|
||||
ngx.say("AES-128 CBC (custom keygen) MD5: ", str.to_hex(encrypted))
|
||||
local decrypted = aes_default:decrypt(encrypted)
|
||||
ngx.say(decrypted == "hello")
|
||||
local aes_check = aes:new("secret")
|
||||
local encrypted_check = aes_check:encrypt("hello")
|
||||
ngx.say(encrypted_check == encrypted)
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
AES-128 CBC (custom keygen) MD5: 7b47a4dbb11e2cddb2f3740c9e3a552b
|
||||
true
|
||||
true
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 9: AES-128 CBC custom keygen (without method, bad key len)
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local aes = require "resty.aes"
|
||||
local str = require "resty.string"
|
||||
|
||||
local aes_default, err = aes:new("hel", nil, aes.cipher(128,"cbc"),
|
||||
{iv = ngx.decode_base64("Jq5cyFTja2vfyjZoSN6muw==")})
|
||||
|
||||
if not aes_default then
|
||||
ngx.say("failed to new: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
local encrypted = aes_default:encrypt("hello")
|
||||
ngx.say("AES-128 CBC (custom keygen) MD5: ", str.to_hex(encrypted))
|
||||
local decrypted = aes_default:decrypt(encrypted)
|
||||
ngx.say(decrypted == "hello")
|
||||
local aes_check = aes:new("secret")
|
||||
local encrypted_check = aes_check:encrypt("hello")
|
||||
ngx.say(encrypted_check == encrypted)
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
failed to new: bad key length
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 10: AES-128 CBC custom keygen (without method, bad iv)
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local aes = require "resty.aes"
|
||||
local str = require "resty.string"
|
||||
|
||||
local aes_default, err = aes:new(
|
||||
ngx.decode_base64("Xr4ilOzQ4PCOq3aQ0qbuaQ=="),
|
||||
nil,
|
||||
aes.cipher(128,"cbc"),
|
||||
{iv = "helloworld&helloworld"}
|
||||
)
|
||||
|
||||
if not aes_default then
|
||||
ngx.say("failed to new: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
local encrypted = aes_default:encrypt("hello")
|
||||
ngx.say("AES-128 CBC (custom keygen) MD5: ", str.to_hex(encrypted))
|
||||
local decrypted = aes_default:decrypt(encrypted)
|
||||
ngx.say(decrypted == "hello")
|
||||
local aes_check = aes:new("secret")
|
||||
local encrypted_check = aes_check:encrypt("hello")
|
||||
ngx.say(encrypted_check == encrypted)
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
failed to new: bad iv length
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 11: AES-256 GCM sha256 no salt
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local aes = require "resty.aes"
|
||||
local str = require "resty.string"
|
||||
local aes_default = aes:new("secret",nil,
|
||||
aes.cipher(256,"gcm"), aes.hash.sha256, 1, 12)
|
||||
local encrypted = aes_default:encrypt("hello")
|
||||
ngx.say("AES-256 GCM: ", str.to_hex(encrypted[1]),
|
||||
" tag: ", str.to_hex(encrypted[2]))
|
||||
local decrypted, err = aes_default:decrypt(encrypted[1], encrypted[2])
|
||||
ngx.say(decrypted == "hello")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
AES-256 GCM: 4acef84443 tag: bcecc29fb0d8b5c895e21f6ea89681a2
|
||||
true
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 12: AES-256 GCM with iv
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local function from_hex(s)
|
||||
return (s:gsub('..', function (cc)
|
||||
return string.char(tonumber(cc, 16))
|
||||
end))
|
||||
end
|
||||
local aes = require "resty.aes"
|
||||
local str = require "resty.string"
|
||||
local aes_default = aes:new(
|
||||
from_hex("40A4510F290AD8182AF4B0260C655F8511E5B46BCA20EA191D8BC7B4D99CE95F"),
|
||||
nil,
|
||||
aes.cipher(256,"gcm"),
|
||||
{iv = from_hex("f31a8c01e125e4720481be05")})
|
||||
local encrypted = aes_default:encrypt("13770713710")
|
||||
ngx.say("AES-256 GCM: ", str.to_hex(encrypted[1]),
|
||||
" tag: ", str.to_hex(encrypted[2]))
|
||||
local decrypted, err = aes_default:decrypt(encrypted[1], encrypted[2])
|
||||
ngx.say(decrypted == "13770713710")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
AES-256 GCM: 755eccf6aa0cd51d55ad0c tag: 9a61f5a3cc3089bbe7de00a3dd484a1d
|
||||
true
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 13: AES-256 GCM sha256 no salt
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local aes = require "resty.aes"
|
||||
local str = require "resty.string"
|
||||
local aes_default = aes:new("secret",nil,
|
||||
aes.cipher(256,"gcm"), aes.hash.sha256, 1, 12)
|
||||
local encrypted = aes_default.encrypt("hello")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- error_code: 500
|
||||
--- response_body eval
|
||||
qr/500 Internal Server Error/
|
||||
--- error_log eval
|
||||
qr/\[error\] .*? lua entry thread aborted: runtime error: content_by_lua\(nginx.conf:\d+\):6: bad argument #1 self: table expected, got string/ms
|
||||
|
||||
|
||||
|
||||
=== TEST 14: AES-256 GCM sha256 no salt
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local aes = require "resty.aes"
|
||||
local str = require "resty.string"
|
||||
local aes_default = aes:new("secret",nil,
|
||||
aes.cipher(256,"gcm"), aes.hash.sha256, 1, 12)
|
||||
local encrypted = aes_default.encrypt("hello")
|
||||
local decrypted, err = aes_default.decrypt(encrypted[1], encrypted[2])
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- error_code: 500
|
||||
--- response_body eval
|
||||
qr/500 Internal Server Error/
|
||||
--- error_log eval
|
||||
qr/\[error\] .*? lua entry thread aborted: runtime error: content_by_lua\(nginx.conf:\d+\):6: bad argument #1 self: table expected, got string/ms
|
||||
|
||||
|
||||
|
||||
=== TEST 15: AES-256 CBC, user padding string + disable padding for aes object
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local aes = require "resty.aes"
|
||||
local str = require "resty.string"
|
||||
local key = ngx.decode_base64("abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG=")
|
||||
|
||||
local text = "hello"
|
||||
local block_size = 32
|
||||
local pad = block_size - #text % block_size
|
||||
ngx.say("pad: ", pad)
|
||||
local text_padded = text .. string.rep(string.char(pad), pad)
|
||||
|
||||
local aes_256_cbc_without_padding, err = aes:new(
|
||||
key, nil, aes.cipher(256,"cbc"), {iv = string.sub(key, 1, 16)},
|
||||
nil, nil, false
|
||||
)
|
||||
if not aes_256_cbc_without_padding then
|
||||
ngx.log(ngx.WARN, err)
|
||||
return
|
||||
end
|
||||
|
||||
local encrypted_without_aes_padding, err = aes_256_cbc_without_padding:encrypt(text_padded)
|
||||
if not encrypted_without_aes_padding then
|
||||
ngx.log(ngx.ERR, err)
|
||||
end
|
||||
ngx.say("AES-256 CBC (custom keygen, user padding with block_size=32, disable padding) HEX: ",
|
||||
str.to_hex(encrypted_without_aes_padding),
|
||||
", len: ", string.len(encrypted_without_aes_padding))
|
||||
|
||||
local decrypted = aes_256_cbc_without_padding:decrypt(encrypted_without_aes_padding)
|
||||
local pad = string.byte(string.sub(decrypted, #decrypted))
|
||||
ngx.say("pad: ", pad)
|
||||
|
||||
local decrypted_text = string.sub(decrypted, 1, #decrypted - pad)
|
||||
ngx.say(decrypted_text == "hello")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
pad: 27
|
||||
AES-256 CBC (custom keygen, user padding with block_size=32, disable padding) HEX: eebf8ca13072beede75c595a11b7fb0beffb7ccfb03f72d08456b555610172d1, len: 32
|
||||
pad: 27
|
||||
true
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 16: AES-256 CBC, user padding string + enable padding (default) for aes object, encrypted string will be longer due to auto padding
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local aes = require "resty.aes"
|
||||
local str = require "resty.string"
|
||||
local key = ngx.decode_base64("abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG=")
|
||||
|
||||
local text = "hello"
|
||||
local block_size = 32
|
||||
local pad = block_size - #text % block_size
|
||||
ngx.say("pad: ", pad)
|
||||
local text_padded = text .. string.rep(string.char(pad), pad)
|
||||
|
||||
local aes_256_cbc_with_padding, err = aes:new(
|
||||
key, nil, aes.cipher(256,"cbc"), {iv = string.sub(key, 1, 16)},
|
||||
nil, nil, true
|
||||
)
|
||||
if not aes_256_cbc_with_padding then
|
||||
ngx.log(ngx.ERR, err)
|
||||
return
|
||||
end
|
||||
|
||||
local encrypted_with_aes_padding, err = aes_256_cbc_with_padding:encrypt(text_padded)
|
||||
if not encrypted_with_aes_padding then
|
||||
ngx.log(ngx.ERR, err)
|
||||
end
|
||||
|
||||
-- padding will always be added, so `len = text_padded + padding_block_size`
|
||||
ngx.say("AES-256 CBC (custom keygen, user padding with block_size=32, enable padding) HEX: ",
|
||||
str.to_hex(encrypted_with_aes_padding),
|
||||
", len: ", string.len(encrypted_with_aes_padding))
|
||||
|
||||
local decrypted = aes_256_cbc_with_padding:decrypt(encrypted_with_aes_padding)
|
||||
local pad = string.byte(string.sub(decrypted, #decrypted))
|
||||
ngx.say("pad: ", pad)
|
||||
|
||||
local decrypted_text = string.sub(decrypted, 1, #decrypted - pad)
|
||||
ngx.say(decrypted_text == "hello")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
pad: 27
|
||||
AES-256 CBC (custom keygen, user padding with block_size=32, enable padding) HEX: eebf8ca13072beede75c595a11b7fb0beffb7ccfb03f72d08456b555610172d15c54a6a02e960ce527a28c8551adfdff, len: 48
|
||||
pad: 27
|
||||
true
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 17: AES-256 CBC, string without user padding + disable padding for aes object
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local aes = require "resty.aes"
|
||||
local str = require "resty.string"
|
||||
local key = ngx.decode_base64("abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG=")
|
||||
|
||||
local text = "hello"
|
||||
local aes_256_cbc_without_padding, err = aes:new(
|
||||
key, nil, aes.cipher(256,"cbc"), {iv = string.sub(key, 1, 16)},
|
||||
nil, nil, false
|
||||
)
|
||||
if not aes_256_cbc_without_padding then
|
||||
ngx.log(ngx.WARN, err)
|
||||
return
|
||||
end
|
||||
|
||||
local encrypted_unpadded_text, err = aes_256_cbc_without_padding:encrypt(text)
|
||||
if not encrypted_unpadded_text then
|
||||
ngx.say("ERROR: unpadded text: ", err)
|
||||
end
|
||||
|
||||
local aes_256_cbc_with_padding, err = aes:new(
|
||||
key, nil, aes.cipher(256,"cbc"), {iv = string.sub(key, 1, 16)},
|
||||
nil, nil, true
|
||||
)
|
||||
if not aes_256_cbc_with_padding then
|
||||
ngx.log(ngx.ERR, err)
|
||||
return
|
||||
end
|
||||
|
||||
local encrypted_text, err = aes_256_cbc_with_padding:encrypt(text)
|
||||
if not encrypted_text then
|
||||
ngx.log(ngx.ERR, err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("AES-256 CBC (custom keygen, without user padding, enable padding) HEX: ",
|
||||
str.to_hex(encrypted_text),
|
||||
", len: ", string.len(encrypted_text))
|
||||
|
||||
local decrypted = aes_256_cbc_with_padding:decrypt(encrypted_text)
|
||||
ngx.say(decrypted == "hello")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
ERROR: unpadded text: EVP_EncryptFinal_ex failed
|
||||
AES-256 CBC (custom keygen, without user padding, enable padding) HEX: 794617717c15d28cc729b983cb9d2257, len: 16
|
||||
true
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 18: AES-256 GCM sha256 no salt with AAD
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local aes = require "resty.aes"
|
||||
local str = require "resty.string"
|
||||
local aes_default = aes:new("secret",nil,
|
||||
aes.cipher(256,"gcm"), aes.hash.sha256, 1, 12)
|
||||
local encrypted = aes_default:encrypt("hello", "aad")
|
||||
ngx.say("AES-256 GCM: ", str.to_hex(encrypted[1]),
|
||||
" tag: ", str.to_hex(encrypted[2]))
|
||||
local decrypted, err = aes_default:decrypt(encrypted[1], encrypted[2], "aad")
|
||||
ngx.say(decrypted == "hello")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
AES-256 GCM: 4acef84443 tag: 46f4f3ca65395568407e15768b7526d9
|
||||
true
|
||||
--- no_error_log
|
||||
[error]
|
||||
40
src/deps/src/lua-resty-string/t/aes_allocation.t
vendored
40
src/deps/src/lua-resty-string/t/aes_allocation.t
vendored
|
|
@ -1,40 +0,0 @@
|
|||
# vi:ft=
|
||||
|
||||
use Test::Nginx::Socket::Lua;
|
||||
|
||||
repeat_each(200);
|
||||
|
||||
plan tests => repeat_each() * (3 * blocks());
|
||||
|
||||
our $HttpConfig = <<'_EOC_';
|
||||
lua_package_path 'lib/?.lua;;';
|
||||
lua_package_cpath 'lib/?.so;;';
|
||||
_EOC_
|
||||
|
||||
#log_level 'warn';
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: AES buffer allocation test
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local aes = require "resty.aes"
|
||||
local str = require "resty.string"
|
||||
local rnd = require "resty.random"
|
||||
local aes_default = aes:new("secretsecretsecr", nil, aes.cipher(128, "ecb"))
|
||||
local data = rnd.bytes(math.random(4096, 16384))
|
||||
local encrypted = aes_default:encrypt(data)
|
||||
local decrypted = aes_default:decrypt(encrypted)
|
||||
ngx.say(decrypted == data)
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
true
|
||||
--- no_error_log
|
||||
[error]
|
||||
34
src/deps/src/lua-resty-string/t/atoi.t
vendored
34
src/deps/src/lua-resty-string/t/atoi.t
vendored
|
|
@ -1,34 +0,0 @@
|
|||
# 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: atoi
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local str = require "resty.string"
|
||||
ngx.say(1 + str.atoi("32"))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
33
|
||||
--- no_error_log
|
||||
[error]
|
||||
124
src/deps/src/lua-resty-string/t/md5.t
vendored
124
src/deps/src/lua-resty-string/t/md5.t
vendored
|
|
@ -1,124 +0,0 @@
|
|||
# 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]
|
||||
56
src/deps/src/lua-resty-string/t/random.t
vendored
56
src/deps/src/lua-resty-string/t/random.t
vendored
|
|
@ -1,56 +0,0 @@
|
|||
# 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: pseudo random bytes
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local rand = require "resty.random"
|
||||
local str = require "resty.string"
|
||||
local s = rand.bytes(5)
|
||||
ngx.say("res: ", str.to_hex(s))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body_like
|
||||
^res: [a-f0-9]{10}$
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 2: strong random bytes
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local rand = require "resty.random"
|
||||
local str = require "resty.string"
|
||||
local s = rand.bytes(5, true)
|
||||
ngx.say("res: ", str.to_hex(s))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body_like
|
||||
^res: [a-f0-9]{10}$
|
||||
--- no_error_log
|
||||
[error]
|
||||
92
src/deps/src/lua-resty-string/t/sha1.t
vendored
92
src/deps/src/lua-resty-string/t/sha1.t
vendored
|
|
@ -1,92 +0,0 @@
|
|||
# vi:ft=
|
||||
|
||||
use Test::Nginx::Socket::Lua;
|
||||
|
||||
repeat_each(2);
|
||||
|
||||
plan tests => repeat_each() * (3 * blocks());
|
||||
|
||||
our $HttpConfig = <<'_EOC_';
|
||||
#lua_code_cache off;
|
||||
lua_package_path 'lib/?.lua;;';
|
||||
lua_package_cpath 'lib/?.so;;';
|
||||
_EOC_
|
||||
|
||||
no_long_string();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: hello SHA-1
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local resty_sha1 = require "resty.sha1"
|
||||
local str = require "resty.string"
|
||||
local sha1 = resty_sha1:new()
|
||||
ngx.say(sha1:update("hello"))
|
||||
local digest = sha1:final()
|
||||
ngx.say(digest == ngx.sha1_bin("hello"))
|
||||
ngx.say("sha1: ", str.to_hex(digest))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
true
|
||||
true
|
||||
sha1: aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 2: SHA-1 incremental
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local resty_sha1 = require "resty.sha1"
|
||||
local str = require "resty.string"
|
||||
local sha1 = resty_sha1:new()
|
||||
ngx.say(sha1:update("hel"))
|
||||
ngx.say(sha1:update("lo"))
|
||||
local digest = sha1:final()
|
||||
ngx.say("sha1: ", str.to_hex(digest))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
true
|
||||
true
|
||||
sha1: aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 3: SHA-1 empty string
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local resty_sha1 = require "resty.sha1"
|
||||
local str = require "resty.string"
|
||||
local sha1 = resty_sha1:new()
|
||||
ngx.say(sha1:update(""))
|
||||
local digest = sha1:final()
|
||||
ngx.say(digest == ngx.sha1_bin(""))
|
||||
ngx.say("sha1: ", str.to_hex(digest))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
true
|
||||
true
|
||||
sha1: da39a3ee5e6b4b0d3255bfef95601890afd80709
|
||||
--- no_error_log
|
||||
[error]
|
||||
140
src/deps/src/lua-resty-string/t/sha224.t
vendored
140
src/deps/src/lua-resty-string/t/sha224.t
vendored
|
|
@ -1,140 +0,0 @@
|
|||
# vi:ft=
|
||||
|
||||
use Test::Nginx::Socket::Lua;
|
||||
|
||||
repeat_each(2);
|
||||
|
||||
plan tests => repeat_each() * (3 * blocks());
|
||||
|
||||
our $HttpConfig = <<'_EOC_';
|
||||
#lua_code_cache off;
|
||||
lua_package_path 'lib/?.lua;;';
|
||||
lua_package_cpath 'lib/?.so;;';
|
||||
_EOC_
|
||||
|
||||
no_long_string();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: hello SHA-224
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local resty_sha224 = require "resty.sha224"
|
||||
local str = require "resty.string"
|
||||
local sha224 = resty_sha224:new()
|
||||
ngx.say(sha224:update("hello"))
|
||||
local digest = sha224:final()
|
||||
ngx.say("sha224: ", str.to_hex(digest))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
true
|
||||
sha224: ea09ae9cc6768c50fcee903ed054556e5bfc8347907f12598aa24193
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 2: SHA-224 incremental
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local resty_sha224 = require "resty.sha224"
|
||||
local str = require "resty.string"
|
||||
local sha224 = resty_sha224:new()
|
||||
ngx.say(sha224:update("hel"))
|
||||
ngx.say(sha224:update("lo"))
|
||||
local digest = sha224:final()
|
||||
ngx.say("sha224: ", str.to_hex(digest))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
true
|
||||
true
|
||||
sha224: ea09ae9cc6768c50fcee903ed054556e5bfc8347907f12598aa24193
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 3: SHA-224 empty string
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local resty_sha224 = require "resty.sha224"
|
||||
local str = require "resty.string"
|
||||
local sha224 = resty_sha224:new()
|
||||
ngx.say(sha224:update(""))
|
||||
local digest = sha224:final()
|
||||
ngx.say("sha224: ", str.to_hex(digest))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
true
|
||||
sha224: d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 4: hello (SHA-1 + SHA-224 + SHA-256 + SHA-512 at the same time)
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local resty_sha224 = require "resty.sha224"
|
||||
local resty_sha256 = require "resty.sha256"
|
||||
local resty_sha1 = require "resty.sha1"
|
||||
local resty_sha512 = require "resty.sha512"
|
||||
|
||||
local str = require "resty.string"
|
||||
|
||||
local sha224 = resty_sha224:new()
|
||||
local sha256 = resty_sha256:new()
|
||||
local sha1 = resty_sha1:new()
|
||||
local sha512 = resty_sha512:new()
|
||||
|
||||
ngx.say(sha224:update("hello"))
|
||||
ngx.say(sha256:update("hello"))
|
||||
ngx.say(sha1:update("hello"))
|
||||
ngx.say(sha512:update("hello"))
|
||||
|
||||
|
||||
local digest = sha224:final()
|
||||
ngx.say("sha224: ", str.to_hex(digest))
|
||||
|
||||
digest = sha256:final()
|
||||
ngx.say("sha256: ", str.to_hex(digest))
|
||||
|
||||
digest = sha1:final()
|
||||
ngx.say("sha1: ", str.to_hex(digest))
|
||||
|
||||
digest = sha512:final()
|
||||
ngx.say("sha512: ", str.to_hex(digest))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
sha224: ea09ae9cc6768c50fcee903ed054556e5bfc8347907f12598aa24193
|
||||
sha256: 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
|
||||
sha1: aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d
|
||||
sha512: 9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043
|
||||
--- no_error_log
|
||||
[error]
|
||||
88
src/deps/src/lua-resty-string/t/sha256.t
vendored
88
src/deps/src/lua-resty-string/t/sha256.t
vendored
|
|
@ -1,88 +0,0 @@
|
|||
# vi:ft=
|
||||
|
||||
use Test::Nginx::Socket::Lua;
|
||||
|
||||
repeat_each(2);
|
||||
|
||||
plan tests => repeat_each() * (3 * blocks());
|
||||
|
||||
our $HttpConfig = <<'_EOC_';
|
||||
#lua_code_cache off;
|
||||
lua_package_path 'lib/?.lua;;';
|
||||
lua_package_cpath 'lib/?.so;;';
|
||||
_EOC_
|
||||
|
||||
no_long_string();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: hello SHA-256
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local resty_sha256 = require "resty.sha256"
|
||||
local str = require "resty.string"
|
||||
local sha256 = resty_sha256:new()
|
||||
ngx.say(sha256:update("hello"))
|
||||
local digest = sha256:final()
|
||||
ngx.say("sha256: ", str.to_hex(digest))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
true
|
||||
sha256: 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 2: SHA-256 incremental
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local resty_sha256 = require "resty.sha256"
|
||||
local str = require "resty.string"
|
||||
local sha256 = resty_sha256:new()
|
||||
ngx.say(sha256:update("hel"))
|
||||
ngx.say(sha256:update("lo"))
|
||||
local digest = sha256:final()
|
||||
ngx.say("sha256: ", str.to_hex(digest))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
true
|
||||
true
|
||||
sha256: 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 3: SHA-256 empty string
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local resty_sha256 = require "resty.sha256"
|
||||
local str = require "resty.string"
|
||||
local sha256 = resty_sha256:new()
|
||||
ngx.say(sha256:update(""))
|
||||
local digest = sha256:final()
|
||||
ngx.say("sha256: ", str.to_hex(digest))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
true
|
||||
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||
--- no_error_log
|
||||
[error]
|
||||
88
src/deps/src/lua-resty-string/t/sha384.t
vendored
88
src/deps/src/lua-resty-string/t/sha384.t
vendored
|
|
@ -1,88 +0,0 @@
|
|||
# vi:ft=
|
||||
|
||||
use Test::Nginx::Socket;
|
||||
|
||||
repeat_each(2);
|
||||
|
||||
plan tests => repeat_each() * (3 * blocks());
|
||||
|
||||
our $HttpConfig = <<'_EOC_';
|
||||
#lua_code_cache off;
|
||||
lua_package_path 'lib/?.lua;;';
|
||||
lua_package_cpath 'lib/?.so;;';
|
||||
_EOC_
|
||||
|
||||
no_long_string();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: hello SHA-384
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local resty_sha384 = require "resty.sha384"
|
||||
local str = require "resty.string"
|
||||
local sha384 = resty_sha384:new()
|
||||
ngx.say(sha384:update("hello"))
|
||||
local digest = sha384:final()
|
||||
ngx.say("sha384: ", str.to_hex(digest))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
true
|
||||
sha384: 59e1748777448c69de6b800d7a33bbfb9ff1b463e44354c3553bcdb9c666fa90125a3c79f90397bdf5f6a13de828684f
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 2: SHA-384 incremental
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local resty_sha384 = require "resty.sha384"
|
||||
local str = require "resty.string"
|
||||
local sha384 = resty_sha384:new()
|
||||
ngx.say(sha384:update("hel"))
|
||||
ngx.say(sha384:update("lo"))
|
||||
local digest = sha384:final()
|
||||
ngx.say("sha384: ", str.to_hex(digest))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
true
|
||||
true
|
||||
sha384: 59e1748777448c69de6b800d7a33bbfb9ff1b463e44354c3553bcdb9c666fa90125a3c79f90397bdf5f6a13de828684f
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 3: SHA-384 empty string
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local resty_sha384 = require "resty.sha384"
|
||||
local str = require "resty.string"
|
||||
local sha384 = resty_sha384:new()
|
||||
ngx.say(sha384:update(""))
|
||||
local digest = sha384:final()
|
||||
ngx.say("sha384: ", str.to_hex(digest))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
true
|
||||
sha384: 38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b
|
||||
--- no_error_log
|
||||
[error]
|
||||
88
src/deps/src/lua-resty-string/t/sha512.t
vendored
88
src/deps/src/lua-resty-string/t/sha512.t
vendored
|
|
@ -1,88 +0,0 @@
|
|||
# vi:ft=
|
||||
|
||||
use Test::Nginx::Socket::Lua;
|
||||
|
||||
repeat_each(2);
|
||||
|
||||
plan tests => repeat_each() * (3 * blocks());
|
||||
|
||||
our $HttpConfig = <<'_EOC_';
|
||||
#lua_code_cache off;
|
||||
lua_package_path 'lib/?.lua;;';
|
||||
lua_package_cpath 'lib/?.so;;';
|
||||
_EOC_
|
||||
|
||||
no_long_string();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: hello SHA-512
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local resty_sha512 = require "resty.sha512"
|
||||
local str = require "resty.string"
|
||||
local sha512 = resty_sha512:new()
|
||||
ngx.say(sha512:update("hello"))
|
||||
local digest = sha512:final()
|
||||
ngx.say("sha512: ", str.to_hex(digest))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
true
|
||||
sha512: 9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 2: SHA-512 incremental
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local resty_sha512 = require "resty.sha512"
|
||||
local str = require "resty.string"
|
||||
local sha512 = resty_sha512:new()
|
||||
ngx.say(sha512:update("hel"))
|
||||
ngx.say(sha512:update("lo"))
|
||||
local digest = sha512:final()
|
||||
ngx.say("sha512: ", str.to_hex(digest))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
true
|
||||
true
|
||||
sha512: 9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 3: SHA-512 empty string
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local resty_sha512 = require "resty.sha512"
|
||||
local str = require "resty.string"
|
||||
local sha512 = resty_sha512:new()
|
||||
ngx.say(sha512:update(""))
|
||||
local digest = sha512:final()
|
||||
ngx.say("sha512: ", str.to_hex(digest))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
true
|
||||
sha512: cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
|
||||
--- no_error_log
|
||||
[error]
|
||||
111
src/deps/src/lua-resty-string/t/version.t
vendored
111
src/deps/src/lua-resty-string/t/version.t
vendored
|
|
@ -1,111 +0,0 @@
|
|||
# vim:set ft= ts=4 sw=4 et:
|
||||
|
||||
use Test::Nginx::Socket::Lua;
|
||||
use Cwd qw(cwd);
|
||||
|
||||
repeat_each(2);
|
||||
|
||||
plan tests => repeat_each() * (3 * blocks());
|
||||
|
||||
my $pwd = cwd();
|
||||
|
||||
our $HttpConfig = qq{
|
||||
lua_package_path "$pwd/lib/?.lua;;";
|
||||
};
|
||||
|
||||
$ENV{TEST_NGINX_RESOLVER} = '8.8.8.8';
|
||||
|
||||
no_long_string();
|
||||
#no_diff();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: sha1 version
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local sha1 = require "resty.sha1"
|
||||
ngx.say(sha1._VERSION)
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body_like chop
|
||||
^\d+\.\d+$
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 2: md5 version
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local md5 = require "resty.md5"
|
||||
ngx.say(md5._VERSION)
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body_like chop
|
||||
^\d+\.\d+$
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 3: resty.string version
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local str = require "resty.string"
|
||||
ngx.say(str._VERSION)
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body_like chop
|
||||
^\d+\.\d+$
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 4: resty.random version
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local rand = require "resty.random"
|
||||
ngx.say(rand._VERSION)
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body_like chop
|
||||
^\d+\.\d+$
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 5: resty.aes version
|
||||
--- http_config eval: $::HttpConfig
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua '
|
||||
local aes = require "resty.aes"
|
||||
ngx.say(aes._VERSION)
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body_like chop
|
||||
^\d+\.\d+$
|
||||
--- no_error_log
|
||||
[error]
|
||||
Loading…
Reference in a new issue