@@ -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
218230
219231function _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