mirror of
https://github.com/certbot/certbot.git
synced 2026-01-27 19:42:53 +03:00
Merge pull request #3415 from certbot/issue_3282
clarify invalid email error in non-interactive
This commit is contained in:
@@ -150,8 +150,14 @@ def perform_registration(acme, config):
|
||||
return acme.register(messages.NewRegistration.from_data(email=config.email))
|
||||
except messages.Error as e:
|
||||
if e.typ == "urn:acme:error:invalidEmail":
|
||||
config.namespace.email = display_ops.get_email(invalid=True)
|
||||
return perform_registration(acme, config)
|
||||
if config.noninteractive_mode:
|
||||
msg = ("The ACME server believes %s is an invalid email address. "
|
||||
"Please ensure it is a valid email and attempt "
|
||||
"registration again." % config.email)
|
||||
raise errors.Error(msg)
|
||||
else:
|
||||
config.namespace.email = display_ops.get_email(invalid=True)
|
||||
return perform_registration(acme, config)
|
||||
else:
|
||||
raise
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ def get_email(invalid=False, optional=True):
|
||||
invalid_prefix + msg if invalid else msg)
|
||||
except errors.MissingCommandlineFlag:
|
||||
msg = ("You should register before running non-interactively, "
|
||||
"or provide --agree-tos and --email <email_address> flags")
|
||||
"or provide --agree-tos and --email <email_address> flags.")
|
||||
raise errors.MissingCommandlineFlag(msg)
|
||||
|
||||
if code != display_util.OK:
|
||||
|
||||
@@ -63,6 +63,7 @@ class RegisterTest(unittest.TestCase):
|
||||
@mock.patch("certbot.client.display_ops.get_email")
|
||||
def test_email_retry(self, _rep, mock_get_email):
|
||||
from acme import messages
|
||||
self.config.noninteractive_mode = False
|
||||
msg = "DNS problem: NXDOMAIN looking up MX for example.com"
|
||||
mx_err = messages.Error(detail=msg, typ="urn:acme:error:invalidEmail")
|
||||
with mock.patch("certbot.client.acme_client.Client") as mock_client:
|
||||
@@ -70,6 +71,15 @@ class RegisterTest(unittest.TestCase):
|
||||
self._call()
|
||||
self.assertEqual(mock_get_email.call_count, 1)
|
||||
|
||||
@mock.patch("certbot.account.report_new_account")
|
||||
def test_email_invalid_noninteractive(self, _rep):
|
||||
from acme import messages
|
||||
msg = "DNS problem: NXDOMAIN looking up MX for example.com"
|
||||
mx_err = messages.Error(detail=msg, typ="urn:acme:error:invalidEmail")
|
||||
with mock.patch("certbot.client.acme_client.Client") as mock_client:
|
||||
mock_client().register.side_effect = [mx_err, mock.MagicMock()]
|
||||
self.assertRaises(errors.Error, self._call)
|
||||
|
||||
def test_needs_email(self):
|
||||
self.config.email = None
|
||||
self.assertRaises(errors.Error, self._call)
|
||||
|
||||
Reference in New Issue
Block a user