@@ -140,15 +140,22 @@ function _M.start(options)
140
140
assert (dir .rmtree (_M .test_dir ))
141
141
end
142
142
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.
143
152
if path .exists (_M .dehydrated_persist_accounts_dir ) then
144
153
local persist_account_time = path .getmtime (_M .dehydrated_persist_accounts_dir )
145
154
if persist_account_time < ngx .now () - 60 * 60 * 4 then
146
155
assert (dir .rmtree (_M .dehydrated_persist_accounts_dir ))
147
156
end
148
157
end
149
158
150
- assert (dir .makepath (path .dirname (_M .dehydrated_persist_accounts_dir )))
151
-
152
159
_M .started_once = true
153
160
end
154
161
@@ -169,7 +176,12 @@ function _M.start(options)
169
176
assert (dir .makepath (_M .current_test_dir .. " /auto-ssl/letsencrypt" ))
170
177
assert (unistd .chown (_M .current_test_dir .. " /auto-ssl" , _M .nobody_user ))
171
178
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.
172
182
if path .exists (_M .dehydrated_persist_accounts_dir ) then
183
+ _M .dehydrated_cached_accounts = true
184
+
173
185
local _ , cp_err = shell_blocking .capture_combined ({ " cp" , " -pr" , _M .dehydrated_persist_accounts_dir , _M .current_test_accounts_dir })
174
186
assert (not cp_err , cp_err )
175
187
218
230
219
231
function _M .stop ()
220
232
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.
221
235
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 )))
222
237
local _ , cp_err = shell_blocking .capture_combined ({ " cp" , " -pr" , _M .current_test_accounts_dir , _M .dehydrated_persist_accounts_dir })
223
238
assert (not cp_err , cp_err )
224
239
end
0 commit comments