-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(*) test cdata type before passing in ffi
- Loading branch information
Showing
9 changed files
with
199 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# vim:set ft= ts=4 sw=4 et fdm=marker: | ||
|
||
use Test::Nginx::Socket::Lua 'no_plan'; | ||
use Cwd qw(cwd); | ||
|
||
|
||
my $pwd = cwd(); | ||
|
||
our $HttpConfig = qq{ | ||
lua_package_path "$pwd/t/openssl/x509/?.lua;$pwd/lib/?.lua;$pwd/lib/?/init.lua;$pwd/../lib/?.lua;$pwd/../lib/?/init.lua;;"; | ||
}; | ||
|
||
|
||
run_tests(); | ||
|
||
__DATA__ | ||
=== TEST 1: Generates CSR with RSA pkey correctly | ||
--- http_config eval: $::HttpConfig | ||
--- config | ||
location =/t { | ||
content_by_lua_block { | ||
local util = require("util") | ||
local pkey = require("resty.openssl.pkey").new() | ||
local der, err = util.create_csr(pkey, "dns1.com", "dns2.com", "dns3.com") | ||
if err then | ||
ngx.log(ngx.ERR, err) | ||
return | ||
end | ||
ngx.update_time() | ||
local fname = "ci_" .. math.floor(ngx.now() * 1000) | ||
local f = io.open(fname, "wb") | ||
f:write(der) | ||
f:close() | ||
ngx.say(io.popen("openssl req -inform der -in " .. fname .. " -noout -text", 'r'):read("*a")) | ||
os.remove(fname) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body_like eval | ||
".+CN\\s*=\\s*dns1.com.+rsaEncryption.+2048 bit.+DNS:dns1.com.+DNS:dns2.com.+DNS:dns3.com" | ||
--- no_error_log | ||
[error] | ||
|
||
=== TEST 2: Rejects invalid arguments | ||
--- http_config eval: $::HttpConfig | ||
--- config | ||
location =/t { | ||
content_by_lua_block { | ||
local csr = require("resty.openssl.x509.csr").new() | ||
err = csr:setSubject("not a subject") | ||
ngx.say(err) | ||
err = csr:setSubjectAlt("not a alt") | ||
ngx.say(err) | ||
err = csr:setPublicKey("not a pkey") | ||
ngx.say(err) | ||
err = csr:sign("not a pkey") | ||
ngx.say(err) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body eval | ||
"expect a x509.name instance at #1 | ||
expect a x509.altname instance at #1 | ||
expect a pkey instance at #1 | ||
expect a pkey instance at #1 | ||
" | ||
--- no_error_log | ||
[error] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
local function create_csr(domain_pkey, ...) | ||
local domains = {...} | ||
|
||
local err | ||
|
||
local subject = require("resty.openssl.x509.name").new() | ||
err = subject:add("CN", domains[1]) | ||
if err then | ||
return nil, err | ||
end | ||
|
||
local alt, err | ||
if #{...} > 1 then | ||
alt, err = require("resty.openssl.x509.altname").new() | ||
if err then | ||
return nil, err | ||
end | ||
|
||
for _, domain in pairs(domains) do | ||
err = alt:add("DNS", domain) | ||
if err then | ||
return nil, err | ||
end | ||
end | ||
end | ||
|
||
local csr = require("resty.openssl.x509.csr").new() | ||
err = csr:setSubject(subject) | ||
if err then | ||
return nil, err | ||
end | ||
if alt then | ||
err = csr:setSubjectAlt(alt) | ||
if err then | ||
return nil, err | ||
end | ||
end | ||
|
||
err = csr:setPublicKey(domain_pkey) | ||
if err then | ||
return nil, err | ||
end | ||
|
||
err = csr:sign(domain_pkey) | ||
if err then | ||
return nil, err | ||
end | ||
|
||
return csr:tostring("DER"), nil | ||
end | ||
|
||
return { | ||
create_csr = create_csr, | ||
} |