Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backport -> release/3.5.x] test(cmd): record ngx.time() before generating a cert #12312

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions spec/02-integration/02-cmd/12-hybrid_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,42 +62,45 @@ describe("kong hybrid", function()
local cert = helpers.test_conf.prefix .. "/test4.crt"
local key = helpers.test_conf.prefix .. "/test4.key"

local time = ngx.time()
local ok, _, stdout = helpers.kong_exec("hybrid gen_cert " .. cert .. " " .. key)
assert.truthy(ok)
assert.matches("Successfully generated certificate/key pairs, they have been written to: ", stdout, nil, true)

local crt = x509.new(pl_file.read(cert))

assert.equals(crt:get_not_after() - crt:get_not_before(), 3 * 365 * 86400)
assert(crt:get_not_before() >= ngx.time())
assert(crt:get_not_before() >= time)
end)

it("gen_cert cert days can be overwritten with -d", function()
local cert = helpers.test_conf.prefix .. "/test5.crt"
local key = helpers.test_conf.prefix .. "/test5.key"

local time = ngx.time()
local ok, _, stdout = helpers.kong_exec("hybrid gen_cert -d 1 " .. cert .. " " .. key)
assert.truthy(ok)
assert.matches("Successfully generated certificate/key pairs, they have been written to: ", stdout, nil, true)

local crt = x509.new(pl_file.read(cert))

assert.equals(crt:get_not_after() - crt:get_not_before(), 86400)
assert(crt:get_not_before() >= ngx.time())
assert(crt:get_not_before() >= time)
end)

it("gen_cert cert days can be overwritten with --days", function()
local cert = helpers.test_conf.prefix .. "/test6.crt"
local key = helpers.test_conf.prefix .. "/test6.key"

local time = ngx.time()
local ok, _, stdout = helpers.kong_exec("hybrid gen_cert --days 2 " .. cert .. " " .. key)
assert.truthy(ok)
assert.matches("Successfully generated certificate/key pairs, they have been written to: ", stdout, nil, true)

local crt = x509.new(pl_file.read(cert))

assert.equals(crt:get_not_after() - crt:get_not_before(), 2 * 86400)
assert(crt:get_not_before() >= ngx.time())
assert(crt:get_not_before() >= time)
end)
end)
end)
Expand Down
Loading