Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/certbot/certbot.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'certbot-nginx/tests')
-rw-r--r--certbot-nginx/tests/configurator_test.py46
-rw-r--r--certbot-nginx/tests/display_ops_test.py9
-rw-r--r--certbot-nginx/tests/nginxparser_test.py10
-rw-r--r--certbot-nginx/tests/obj_test.py37
-rw-r--r--certbot-nginx/tests/parser_obj_test.py11
-rw-r--r--certbot-nginx/tests/parser_test.py8
6 files changed, 65 insertions, 56 deletions
diff --git a/certbot-nginx/tests/configurator_test.py b/certbot-nginx/tests/configurator_test.py
index e667d5375..a182f789a 100644
--- a/certbot-nginx/tests/configurator_test.py
+++ b/certbot-nginx/tests/configurator_test.py
@@ -24,7 +24,6 @@ import test_util as util
class NginxConfiguratorTest(util.NginxTest):
"""Test a semi complex vhost configuration."""
-
def setUp(self):
super().setUp()
@@ -79,8 +78,8 @@ class NginxConfiguratorTest(util.NginxTest):
self.config.prepare()
except errors.PluginError as err:
err_msg = str(err)
- self.assertTrue("lock" in err_msg)
- self.assertTrue(self.config.conf("server-root") in err_msg)
+ self.assertIn("lock", err_msg)
+ self.assertIn(self.config.conf("server-root"), err_msg)
else: # pragma: no cover
self.fail("Exception wasn't raised!")
@@ -192,8 +191,9 @@ class NginxConfiguratorTest(util.NginxTest):
'69.255.225.155']
for name in bad_results:
- self.assertRaises(errors.MisconfigurationError,
- self.config.choose_vhosts, name)
+ with self.subTest(name=name):
+ self.assertRaises(errors.MisconfigurationError,
+ self.config.choose_vhosts, name)
def test_ipv6only(self):
# ipv6_info: (ipv6_active, ipv6only_present)
@@ -215,7 +215,7 @@ class NginxConfiguratorTest(util.NginxTest):
self.assertFalse(addr.ipv6only)
def test_more_info(self):
- self.assertTrue('nginx.conf' in self.config.more_info())
+ self.assertIn('nginx.conf', self.config.more_info())
def test_deploy_cert_requires_fullchain_path(self):
self.config.version = (1, 3, 1)
@@ -547,7 +547,7 @@ class NginxConfiguratorTest(util.NginxTest):
self.config.enhance("www.example.com", "redirect")
generated_conf = self.config.parser.parsed[example_conf]
- self.assertTrue(util.contains_at_depth(generated_conf, expected, 2))
+ self.assertIs(util.contains_at_depth(generated_conf, expected, 2), True)
# Test that we successfully add a redirect when there is
# no listen directive
@@ -557,7 +557,7 @@ class NginxConfiguratorTest(util.NginxTest):
expected = UnspacedList(_redirect_block_for_domain("migration.com"))[0]
generated_conf = self.config.parser.parsed[migration_conf]
- self.assertTrue(util.contains_at_depth(generated_conf, expected, 2))
+ self.assertIs(util.contains_at_depth(generated_conf, expected, 2), True)
def test_split_for_redirect(self):
example_conf = self.config.parser.abs_path('sites-enabled/example.com')
@@ -627,7 +627,7 @@ class NginxConfiguratorTest(util.NginxTest):
"Strict-Transport-Security")
expected = ['add_header', 'Strict-Transport-Security', '"max-age=31536000"', 'always']
generated_conf = self.config.parser.parsed[example_conf]
- self.assertTrue(util.contains_at_depth(generated_conf, expected, 2))
+ self.assertIs(util.contains_at_depth(generated_conf, expected, 2), True)
def test_multiple_headers_hsts(self):
headers_conf = self.config.parser.abs_path('sites-enabled/headers.com')
@@ -635,7 +635,7 @@ class NginxConfiguratorTest(util.NginxTest):
"Strict-Transport-Security")
expected = ['add_header', 'Strict-Transport-Security', '"max-age=31536000"', 'always']
generated_conf = self.config.parser.parsed[headers_conf]
- self.assertTrue(util.contains_at_depth(generated_conf, expected, 2))
+ self.assertIs(util.contains_at_depth(generated_conf, expected, 2), True)
def test_http_header_hsts_twice(self):
self.config.enhance("www.example.com", "ensure-http-header",
@@ -645,7 +645,6 @@ class NginxConfiguratorTest(util.NginxTest):
self.config.enhance, "www.example.com",
"ensure-http-header", "Strict-Transport-Security")
-
@mock.patch('certbot_nginx._internal.obj.VirtualHost.contains_list')
def test_certbot_redirect_exists(self, mock_contains_list):
# Test that we add no redirect statement if there is already a
@@ -867,7 +866,7 @@ class NginxConfiguratorTest(util.NginxTest):
vhs = self.config._choose_vhosts_wildcard("*.com",
prefer_ssl=True)
# Check that the dialog was called with migration.com
- self.assertTrue(vhost in mock_select_vhs.call_args[0][0])
+ self.assertIn(vhost, mock_select_vhs.call_args[0][0])
# And the actual returned values
self.assertEqual(len(vhs), 1)
@@ -883,7 +882,7 @@ class NginxConfiguratorTest(util.NginxTest):
vhs = self.config._choose_vhosts_wildcard("*.com",
prefer_ssl=False)
# Check that the dialog was called with migration.com
- self.assertTrue(vhost in mock_select_vhs.call_args[0][0])
+ self.assertIn(vhost, mock_select_vhs.call_args[0][0])
# And the actual returned values
self.assertEqual(len(vhs), 1)
@@ -928,7 +927,7 @@ class NginxConfiguratorTest(util.NginxTest):
if 'summer.com' in x.names][0]
mock_dialog.return_value = [vhost]
self.config.enhance("*.com", "staple-ocsp", "example/chain.pem")
- self.assertTrue(mock_dialog.called)
+ self.assertIs(mock_dialog.called, True)
@mock.patch("certbot_nginx._internal.display_ops.select_vhost_multiple")
def test_enhance_wildcard_double_redirect(self, mock_dialog):
@@ -1042,7 +1041,8 @@ class InstallSslOptionsConfTest(util.NginxTest):
f.write("hashofanoldversion")
with mock.patch("certbot.plugins.common.logger") as mock_logger:
self._call()
- self.assertEqual(mock_logger.warning.call_args[0][0],
+ self.assertEqual(
+ mock_logger.warning.call_args[0][0],
"%s has been manually modified; updated file "
"saved to %s. We recommend updating %s for security purposes.")
self.assertEqual(crypto_util.sha256sum(self.config.mod_ssl_conf_src),
@@ -1054,9 +1054,11 @@ class InstallSslOptionsConfTest(util.NginxTest):
def test_current_file_hash_in_all_hashes(self):
from certbot_nginx._internal.constants import ALL_SSL_OPTIONS_HASHES
- self.assertTrue(self._current_ssl_options_hash() in ALL_SSL_OPTIONS_HASHES,
+ self.assertIn(
+ self._current_ssl_options_hash(), ALL_SSL_OPTIONS_HASHES,
"Constants.ALL_SSL_OPTIONS_HASHES must be appended"
- " with the sha256 hash of self.config.mod_ssl_conf when it is updated.")
+ " with the sha256 hash of self.config.mod_ssl_conf when it is updated."
+ )
def test_ssl_config_files_hash_in_all_hashes(self):
"""
@@ -1077,9 +1079,11 @@ class InstallSslOptionsConfTest(util.NginxTest):
self.assertTrue(all_files)
for one_file in all_files:
file_hash = crypto_util.sha256sum(one_file)
- self.assertTrue(file_hash in ALL_SSL_OPTIONS_HASHES,
- "Constants.ALL_SSL_OPTIONS_HASHES must be appended with the sha256 "
- "hash of {0} when it is updated.".format(one_file))
+ self.assertIn(
+ file_hash, ALL_SSL_OPTIONS_HASHES,
+ f"Constants.ALL_SSL_OPTIONS_HASHES must be appended with the sha256 "
+ f"hash of {one_file} when it is updated."
+ )
def test_nginx_version_uses_correct_config(self):
self.config.version = (1, 5, 8)
@@ -1127,7 +1131,7 @@ class DetermineDefaultServerRootTest(certbot_test_util.ConfigTestCase):
self.assertIn("/usr/local/etc/nginx", server_root)
self.assertIn("/etc/nginx", server_root)
else:
- self.assertTrue(server_root in ("/etc/nginx", "/usr/local/etc/nginx"))
+ self.assertIn(server_root, ("/etc/nginx", "/usr/local/etc/nginx"))
if __name__ == "__main__":
diff --git a/certbot-nginx/tests/display_ops_test.py b/certbot-nginx/tests/display_ops_test.py
index 7480a1109..19f51e7e8 100644
--- a/certbot-nginx/tests/display_ops_test.py
+++ b/certbot-nginx/tests/display_ops_test.py
@@ -27,15 +27,16 @@ class SelectVhostMultiTest(util.NginxTest):
vhs = select_vhost_multiple([self.vhosts[3],
self.vhosts[2],
self.vhosts[1]])
- self.assertTrue(self.vhosts[2] in vhs)
- self.assertTrue(self.vhosts[3] in vhs)
- self.assertFalse(self.vhosts[1] in vhs)
+ self.assertIn(self.vhosts[2], vhs)
+ self.assertIn(self.vhosts[3], vhs)
+ self.assertNotIn(self.vhosts[1], vhs)
@certbot_util.patch_display_util()
def test_select_cancel(self, mock_util):
mock_util().checklist.return_value = (display_util.CANCEL, "whatever")
vhs = select_vhost_multiple([self.vhosts[2], self.vhosts[3]])
- self.assertFalse(vhs)
+ self.assertEqual(len(vhs), 0)
+ self.assertEqual(vhs, [])
if __name__ == "__main__":
diff --git a/certbot-nginx/tests/nginxparser_test.py b/certbot-nginx/tests/nginxparser_test.py
index 8f7d5accf..d8f0a5909 100644
--- a/certbot-nginx/tests/nginxparser_test.py
+++ b/certbot-nginx/tests/nginxparser_test.py
@@ -432,15 +432,15 @@ class TestUnspacedList(unittest.TestCase):
self.assertEqual(ul3, ["some", "things", "why", "did", "whether"])
def test_is_dirty(self):
- self.assertEqual(False, self.ul2.is_dirty())
+ self.assertIs(self.ul2.is_dirty(), False)
ul3 = UnspacedList([])
ul3.append(self.ul)
- self.assertEqual(False, self.ul.is_dirty())
- self.assertEqual(True, ul3.is_dirty())
+ self.assertIs(self.ul.is_dirty(), False)
+ self.assertIs(ul3.is_dirty(), True)
ul4 = UnspacedList([[1], [2, 3, 4]])
- self.assertEqual(False, ul4.is_dirty())
+ self.assertIs(ul4.is_dirty(), False)
ul4[1][2] = 5
- self.assertEqual(True, ul4.is_dirty())
+ self.assertIs(ul4.is_dirty(), True)
if __name__ == '__main__':
diff --git a/certbot-nginx/tests/obj_test.py b/certbot-nginx/tests/obj_test.py
index f385649ed..de82e5682 100644
--- a/certbot-nginx/tests/obj_test.py
+++ b/certbot-nginx/tests/obj_test.py
@@ -19,37 +19,37 @@ class AddrTest(unittest.TestCase):
def test_fromstring(self):
self.assertEqual(self.addr1.get_addr(), "192.168.1.1")
self.assertEqual(self.addr1.get_port(), "")
- self.assertFalse(self.addr1.ssl)
- self.assertFalse(self.addr1.default)
+ self.assertIs(self.addr1.ssl, False)
+ self.assertIs(self.addr1.default, False)
self.assertEqual(self.addr2.get_addr(), "192.168.1.1")
self.assertEqual(self.addr2.get_port(), "*")
- self.assertTrue(self.addr2.ssl)
- self.assertFalse(self.addr2.default)
+ self.assertIs(self.addr2.ssl, True)
+ self.assertIs(self.addr2.default, False)
self.assertEqual(self.addr3.get_addr(), "192.168.1.1")
self.assertEqual(self.addr3.get_port(), "80")
- self.assertFalse(self.addr3.ssl)
- self.assertFalse(self.addr3.default)
+ self.assertIs(self.addr3.ssl, False)
+ self.assertIs(self.addr3.default, False)
self.assertEqual(self.addr4.get_addr(), "*")
self.assertEqual(self.addr4.get_port(), "80")
- self.assertTrue(self.addr4.ssl)
- self.assertTrue(self.addr4.default)
+ self.assertIs(self.addr4.ssl, True)
+ self.assertIs(self.addr4.default, True)
self.assertEqual(self.addr5.get_addr(), "myhost")
self.assertEqual(self.addr5.get_port(), "")
- self.assertFalse(self.addr5.ssl)
- self.assertFalse(self.addr5.default)
+ self.assertIs(self.addr5.ssl, False)
+ self.assertIs(self.addr5.default, False)
self.assertEqual(self.addr6.get_addr(), "")
self.assertEqual(self.addr6.get_port(), "80")
- self.assertFalse(self.addr6.ssl)
- self.assertTrue(self.addr6.default)
+ self.assertIs(self.addr6.ssl, False)
+ self.assertIs(self.addr6.default, True)
- self.assertTrue(self.addr8.default)
+ self.assertIs(self.addr8.default, True)
- self.assertEqual(None, self.addr7)
+ self.assertIsNone(self.addr7)
def test_str(self):
self.assertEqual(str(self.addr1), "192.168.1.1")
@@ -177,10 +177,10 @@ class VirtualHostTest(unittest.TestCase):
self.assertEqual(stringified, str(self.vhost1))
def test_has_header(self):
- self.assertTrue(self.vhost_has_hsts.has_header('Strict-Transport-Security'))
- self.assertFalse(self.vhost_has_hsts.has_header('Bogus-Header'))
- self.assertFalse(self.vhost1.has_header('Strict-Transport-Security'))
- self.assertFalse(self.vhost1.has_header('Bogus-Header'))
+ self.assertIs(self.vhost_has_hsts.has_header('Strict-Transport-Security'), True)
+ self.assertIs(self.vhost_has_hsts.has_header('Bogus-Header'), False)
+ self.assertIs(self.vhost1.has_header('Strict-Transport-Security'), False)
+ self.assertIs(self.vhost1.has_header('Bogus-Header'), False)
def test_contains_list(self):
from certbot_nginx._internal.obj import VirtualHost
@@ -224,5 +224,6 @@ class VirtualHostTest(unittest.TestCase):
self.assertTrue(vhost_haystack.contains_list(test_needle))
self.assertFalse(vhost_bad_haystack.contains_list(test_needle))
+
if __name__ == "__main__":
unittest.main() # pragma: no cover
diff --git a/certbot-nginx/tests/parser_obj_test.py b/certbot-nginx/tests/parser_obj_test.py
index 8262c5f52..4d1f25277 100644
--- a/certbot-nginx/tests/parser_obj_test.py
+++ b/certbot-nginx/tests/parser_obj_test.py
@@ -35,8 +35,8 @@ class CommentHelpersTest(unittest.TestCase):
self.assertTrue(_is_certbot_comment(comment))
self.assertEqual(comment.dump(), COMMENT_BLOCK)
self.assertEqual(comment.dump(True), [' '] + COMMENT_BLOCK)
- self.assertEqual(_certbot_comment(None, 2).dump(True),
- [' '] + COMMENT_BLOCK)
+ self.assertEqual(_certbot_comment(None, 2).dump(True), [' '] + COMMENT_BLOCK)
+
class ParsingHooksTest(unittest.TestCase):
def test_is_sentence(self):
@@ -94,6 +94,7 @@ class ParsingHooksTest(unittest.TestCase):
parse_raw([], add_spaces=True)
fake_parser1.parse.called_with([None, True])
+
class SentenceTest(unittest.TestCase):
def setUp(self):
from certbot_nginx._internal.parser_obj import Sentence
@@ -140,6 +141,7 @@ class SentenceTest(unittest.TestCase):
self.sentence.parse(['\n\t \n', 'tabs'])
self.assertEqual(self.sentence.get_tabs(), '')
+
class BlockTest(unittest.TestCase):
def setUp(self):
from certbot_nginx._internal.parser_obj import Block
@@ -244,8 +246,8 @@ class StatementsTest(unittest.TestCase):
def test_parse_hides_trailing_whitespace(self):
self.statements.parse(self.raw + ['\n\n '])
- self.assertTrue(isinstance(self.statements.dump()[-1], list))
- self.assertTrue(self.statements.dump(True)[-1].isspace())
+ self.assertIsInstance(self.statements.dump()[-1], list)
+ self.assertIs(self.statements.dump(True)[-1].isspace(), True)
self.assertEqual(self.statements.dump(True)[-1], '\n\n ')
def test_iterate(self):
@@ -254,5 +256,6 @@ class StatementsTest(unittest.TestCase):
for i, elem in enumerate(self.statements.iterate(match=lambda x: 'sentence' in x)):
self.assertEqual(expected[i], elem.dump())
+
if __name__ == "__main__":
unittest.main() # pragma: no cover
diff --git a/certbot-nginx/tests/parser_test.py b/certbot-nginx/tests/parser_test.py
index 9047cb446..7d5b5e669 100644
--- a/certbot-nginx/tests/parser_test.py
+++ b/certbot-nginx/tests/parser_test.py
@@ -203,8 +203,7 @@ class NginxParserTest(util.NginxTest):
mock_vhost.raw = [['listen', '80'],
['ssl', 'on'],
['server_name', '*.www.foo.com', '*.www.example.com']]
- self.assertTrue(nparser.has_ssl_on_directive(mock_vhost))
-
+ self.assertIs(nparser.has_ssl_on_directive(mock_vhost), True)
def test_remove_server_directives(self):
nparser = parser.NginxParser(self.config_path)
@@ -452,7 +451,7 @@ class NginxParserTest(util.NginxTest):
nparser.filedump(ext='')
# check properties of new vhost
- self.assertFalse(next(iter(new_vhost.addrs)).default)
+ self.assertIs(next(iter(new_vhost.addrs)).default, False)
self.assertNotEqual(new_vhost.path, default.path)
# check that things are written to file correctly
@@ -461,7 +460,7 @@ class NginxParserTest(util.NginxTest):
new_defaults = [x for x in new_vhosts if 'default' in x.filep]
self.assertEqual(len(new_defaults), 2)
new_vhost_parsed = new_defaults[1]
- self.assertFalse(next(iter(new_vhost_parsed.addrs)).default)
+ self.assertIs(next(iter(new_vhost_parsed.addrs)).default, False)
self.assertEqual(next(iter(default.names)), next(iter(new_vhost_parsed.names)))
self.assertEqual(len(default.raw), len(new_vhost_parsed.raw))
self.assertTrue(next(iter(default.addrs)).super_eq(next(iter(new_vhost_parsed.addrs))))
@@ -533,5 +532,6 @@ class NginxParserTest(util.NginxTest):
for output in log.output
))
+
if __name__ == "__main__":
unittest.main() # pragma: no cover