Skip to content

Commit 247f375

Browse files
committed
Merge branch 'Cargo-renew-allow_domain-delete-expired'
2 parents 3f1c47d + 15afeb5 commit 247f375

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

spec/expiry_spec.lua

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,84 @@ describe("expiry", function()
182182
assert.Not.matches("[alert]", error_log, nil, true)
183183
assert.Not.matches("[emerg]", error_log, nil, true)
184184
end)
185+
186+
it("removes cert on renewal if expiration has expired and allow_domain is false", function()
187+
server.start({
188+
auto_ssl_pre_new = [[
189+
options["renew_check_interval"] = 1
190+
options["allow_domain"] = function(domain)
191+
if string.find(domain, "disallowed.example") then
192+
return false
193+
else
194+
return true
195+
end
196+
end
197+
]],
198+
})
199+
200+
-- Issue a new certificate for a valid domain so we can use that for
201+
-- copying and manipulation.
202+
do
203+
local httpc = http.new()
204+
local _, connect_err = httpc:connect("127.0.0.1", 9443)
205+
assert.equal(nil, connect_err)
206+
207+
local _, ssl_err = httpc:ssl_handshake(nil, server.ngrok_hostname, true)
208+
assert.equal(nil, ssl_err)
209+
210+
local res, request_err = httpc:request({ path = "/foo" })
211+
assert.equal(nil, request_err)
212+
assert.equal(200, res.status)
213+
214+
local body, body_err = res:read_body()
215+
assert.equal(nil, body_err)
216+
assert.equal("foo", body)
217+
218+
local error_log = server.nginx_error_log_tail:read()
219+
assert.matches("issuing new certificate for", error_log, nil, true)
220+
end
221+
222+
-- Copy the cert to a disallowed domain to verify first that non-expired
223+
-- disallowed certs remain.
224+
local cert_path = server.current_test_dir .. "/auto-ssl/storage/file/" .. ngx.escape_uri(server.ngrok_hostname .. ":latest")
225+
local disallowed_cert_path = server.current_test_dir .. "/auto-ssl/storage/file/" .. ngx.escape_uri("disallowed.example:latest")
226+
local _, cp_err = shell_blocking.capture_combined({ "cp", "-p", cert_path, disallowed_cert_path })
227+
assert.equal(nil, cp_err)
228+
229+
-- Wait for scheduled renewals to happen.
230+
ngx.sleep(3)
231+
232+
local error_log = server.nginx_error_log_tail:read()
233+
assert.matches("auto-ssl: checking certificate renewals for disallowed.example", error_log, nil, true)
234+
assert.matches("auto-ssl: expiry date is more than 30 days out, skipping renewal: disallowed.example", error_log, nil, true)
235+
236+
local content = assert(file.read(disallowed_cert_path))
237+
assert.string(content)
238+
local data = assert(cjson.decode(content))
239+
assert.number(data["expiry"])
240+
241+
-- Set the expiration time to some time in the past.
242+
data["expiry"] = 1000
243+
244+
assert(file.write(disallowed_cert_path, assert(cjson.encode(data))))
245+
246+
-- Wait for scheduled renewals to happen.
247+
ngx.sleep(5)
248+
249+
-- Verify that the disallowed domain got removed now that the cert was set
250+
-- to expire in the past.
251+
error_log = server.nginx_error_log_tail:read()
252+
assert.matches("auto-ssl: checking certificate renewals for disallowed.example", error_log, nil, true)
253+
assert.matches("auto-ssl: domain not allowed, not renewing: disallowed.example", error_log, nil, true)
254+
assert.matches(" auto-ssl: existing certificate is expired, deleting: disallowed.example", error_log, nil, true)
255+
256+
local file_content, file_err = file.read(disallowed_cert_path)
257+
assert.equal(nil, file_content)
258+
assert.matches("No such file or directory", file_err, nil, true)
259+
260+
error_log = server.read_error_log()
261+
assert.Not.matches("[error]", error_log, nil, true)
262+
assert.Not.matches("[alert]", error_log, nil, true)
263+
assert.Not.matches("[emerg]", error_log, nil, true)
264+
end)
185265
end)

0 commit comments

Comments
 (0)