mirror of
https://github.com/certbot/certbot.git
synced 2026-07-28 00:35:50 +02:00
Return domains for _find_domains_or_certname (#3937)
* Return domains for _find_domains_or_certname * Revamp find_domains_or_certname
This commit is contained in:
+12
-3
@@ -284,17 +284,26 @@ def _find_domains_or_certname(config, installer):
|
||||
"""Retrieve domains and certname from config or user input.
|
||||
"""
|
||||
domains = None
|
||||
certname = config.certname
|
||||
# first, try to get domains from the config
|
||||
if config.domains:
|
||||
domains = config.domains
|
||||
elif not config.certname:
|
||||
# if we can't do that but we have a certname, get the domains
|
||||
# with that certname
|
||||
elif certname:
|
||||
domains = cert_manager.domains_for_certname(config, certname)
|
||||
|
||||
# that certname might not have existed, or there was a problem.
|
||||
# try to get domains from the user.
|
||||
if not domains:
|
||||
domains = display_ops.choose_names(installer)
|
||||
|
||||
if not domains and not config.certname:
|
||||
if not domains and not certname:
|
||||
raise errors.Error("Please specify --domains, or --installer that "
|
||||
"will help in domain names autodiscovery, or "
|
||||
"--cert-name for an existing certificate name.")
|
||||
|
||||
return domains, config.certname
|
||||
return domains, certname
|
||||
|
||||
|
||||
def _report_new_cert(config, cert_path, fullchain_path):
|
||||
|
||||
@@ -159,10 +159,12 @@ class ObtainCertTest(unittest.TestCase):
|
||||
self.assertRaises(errors.ConfigurationError, self._call,
|
||||
('certonly --webroot -d example.com -d test.com --cert-name example.com').split())
|
||||
|
||||
@mock.patch('certbot.cert_manager.domains_for_certname')
|
||||
@mock.patch('certbot.display.ops.choose_names')
|
||||
@mock.patch('certbot.cert_manager.lineage_for_certname')
|
||||
@mock.patch('certbot.main._report_new_cert')
|
||||
def test_find_lineage_for_domains_new_certname(self, mock_report_cert,
|
||||
mock_lineage):
|
||||
mock_lineage, mock_choose_names, mock_domains_for_certname):
|
||||
mock_lineage.return_value = None
|
||||
|
||||
# no lineage with this name but we specified domains so create a new cert
|
||||
@@ -172,8 +174,10 @@ class ObtainCertTest(unittest.TestCase):
|
||||
self.assertTrue(mock_report_cert.call_count == 1)
|
||||
|
||||
# no lineage with this name and we didn't give domains
|
||||
self.assertRaises(errors.ConfigurationError, self._call,
|
||||
('certonly --webroot --cert-name example.com').split())
|
||||
mock_choose_names.return_value = ["somename"]
|
||||
mock_domains_for_certname.return_value = None
|
||||
self._call(('certonly --webroot --cert-name example.com').split())
|
||||
self.assertTrue(mock_choose_names.called)
|
||||
|
||||
class FindDomainsOrCertnameTest(unittest.TestCase):
|
||||
"""Tests for certbot.main._find_domains_or_certname."""
|
||||
@@ -193,6 +197,14 @@ class FindDomainsOrCertnameTest(unittest.TestCase):
|
||||
# pylint: disable=protected-access
|
||||
self.assertRaises(errors.Error, main._find_domains_or_certname, mock_config, None)
|
||||
|
||||
@mock.patch('certbot.cert_manager.domains_for_certname')
|
||||
def test_grab_domains(self, mock_domains):
|
||||
mock_config = mock.Mock(domains=None, certname="one.com")
|
||||
mock_domains.return_value = ["one.com", "two.com"]
|
||||
# pylint: disable=protected-access
|
||||
self.assertEqual(main._find_domains_or_certname(mock_config, None),
|
||||
(["one.com", "two.com"], "one.com"))
|
||||
|
||||
|
||||
class RevokeTest(unittest.TestCase):
|
||||
"""Tests for certbot.main.revoke."""
|
||||
|
||||
Reference in New Issue
Block a user