Skip to content

Commit 39fd352

Browse files
committed
Merge remote-tracking branch 'origin/master' into no-gnu-date
2 parents c48b003 + 81dae33 commit 39fd352

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

spec/sanity_spec.lua

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,14 +325,18 @@ describe("sanity", function()
325325
it("deletes dehydrated temporary files after successful cert deployment", function()
326326
server.start()
327327

328-
local result, err = shell_blocking.capture_combined({ "ls", "-1", server.current_test_dir .. "/auto-ssl/letsencrypt" })
329-
assert.equal(nil, err)
330-
assert.same({
331-
"accounts",
328+
local ls_before_result, ls_before_err = shell_blocking.capture_combined({ "ls", "-1", server.current_test_dir .. "/auto-ssl/letsencrypt" })
329+
assert.equal(nil, ls_before_err)
330+
local expected_ls_before = {
332331
"conf.d",
333332
"config",
334333
"locks",
335-
}, pl_utils.split(result["output"]))
334+
}
335+
if server.dehydrated_cached_accounts then
336+
table.insert(expected_ls_before, "accounts")
337+
end
338+
table.sort(expected_ls_before)
339+
assert.same(expected_ls_before, pl_utils.split(ls_before_result["output"]))
336340

337341
local httpc = http.new()
338342
local _, connect_err = httpc:connect("127.0.0.1", 9443)
@@ -383,12 +387,16 @@ describe("sanity", function()
383387

384388
local ls_before_result, ls_before_err = shell_blocking.capture_combined({ "ls", "-1", server.current_test_dir .. "/auto-ssl/letsencrypt" })
385389
assert.equal(nil, ls_before_err)
386-
assert.same({
387-
"accounts",
390+
local expected_ls_before = {
388391
"conf.d",
389392
"config",
390393
"locks",
391-
}, pl_utils.split(ls_before_result["output"]))
394+
}
395+
if server.dehydrated_cached_accounts then
396+
table.insert(expected_ls_before, "accounts")
397+
end
398+
table.sort(expected_ls_before)
399+
assert.same(expected_ls_before, pl_utils.split(ls_before_result["output"]))
392400

393401
local httpc = http.new()
394402

spec/support/server.lua

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,22 @@ function _M.start(options)
140140
assert(dir.rmtree(_M.test_dir))
141141
end
142142

143+
-- We persist the Let's Encrypt account configuration across individual
144+
-- test runs so that each test doesn't register it's own account and we
145+
-- don't hit the Let's Encrypt rate limits of 10 accounts per IP per 3
146+
-- hours (https://letsencrypt.org/docs/rate-limits/).
147+
--
148+
-- But we still want to ensure the normal account creation process works
149+
-- and creates files with the right permissions, so if the persisted
150+
-- account config is older than 4 hours, delete it, so the next test run
151+
-- perform a normal, fresh account registration.
143152
if path.exists(_M.dehydrated_persist_accounts_dir) then
144153
local persist_account_time = path.getmtime(_M.dehydrated_persist_accounts_dir)
145154
if persist_account_time < ngx.now() - 60 * 60 * 4 then
146155
assert(dir.rmtree(_M.dehydrated_persist_accounts_dir))
147156
end
148157
end
149158

150-
assert(dir.makepath(path.dirname(_M.dehydrated_persist_accounts_dir)))
151-
152159
_M.started_once = true
153160
end
154161

@@ -169,7 +176,12 @@ function _M.start(options)
169176
assert(dir.makepath(_M.current_test_dir .. "/auto-ssl/letsencrypt"))
170177
assert(unistd.chown(_M.current_test_dir .. "/auto-ssl", _M.nobody_user))
171178

179+
-- If there is persisted account configuration, copy it into place for this
180+
-- test run. This prevents us hitting account registration rate limits if we
181+
-- were to register a new account on every test.
172182
if path.exists(_M.dehydrated_persist_accounts_dir) then
183+
_M.dehydrated_cached_accounts = true
184+
173185
local _, cp_err = shell_blocking.capture_combined({ "cp", "-pr", _M.dehydrated_persist_accounts_dir, _M.current_test_accounts_dir })
174186
assert(not cp_err, cp_err)
175187

@@ -218,7 +230,10 @@ end
218230

219231
function _M.stop()
220232
if _M.nginx_process then
233+
-- On shutdown, if we don't already have persisted account config, then
234+
-- copy the generated config into the persisted directory.
221235
if _M.current_test_accounts_dir and not path.exists(_M.dehydrated_persist_accounts_dir) and path.exists(_M.current_test_accounts_dir) then
236+
assert(dir.makepath(path.dirname(_M.dehydrated_persist_accounts_dir)))
222237
local _, cp_err = shell_blocking.capture_combined({ "cp", "-pr", _M.current_test_accounts_dir, _M.dehydrated_persist_accounts_dir })
223238
assert(not cp_err, cp_err)
224239
end

0 commit comments

Comments
 (0)