2019-11-25 17:30:24 -05:00
|
|
|
"""Tests for certbot_nginx._internal.http_01"""
|
2018-01-11 20:06:23 -05:00
|
|
|
import unittest
|
|
|
|
|
|
Refactor certbot/ and certbot/tests/ to use the same structure as the other packages (#7544)
Summary of changes in this PR:
- Refactor files involved in the `certbot` module to be of a similar structure to every other package; that is, inside a directory inside the main repo root (see below).
- Make repo root README symlink to `certbot` README.
- Pull tests outside of the distributed module.
- Make `certbot/tests` not be a module so that `certbot` isn't added to Python's path for module discovery.
- Remove `--pyargs` from test calls, and make sure to call tests from repo root since without `--pyargs`, `pytest` takes directory names rather than package names as arguments.
- Replace mentions of `.` with `certbot` when referring to packages to install, usually editably.
- Clean up some unused code around executing tests in a different directory.
- Create public shim around main and make that the entry point.
New directory structure summary:
```
repo root ("certbot", probably, but for clarity all files I mention are relative to here)
├── certbot
│ ├── setup.py
│ ├── certbot
│ │ ├── __init__.py
│ │ ├── achallenges.py
│ │ ├── _internal
│ │ │ ├── __init__.py
│ │ │ ├── account.py
│ │ │ ├── ...
│ │ ├── ...
│ ├── tests
│ │ ├── account_test.py
│ │ ├── display
│ │ │ ├── __init__.py
│ │ │ ├── ...
│ │ ├── ... # note no __init__.py at this level
│ ├── ...
├── acme
│ ├── ...
├── certbot-apache
│ ├── ...
├── ...
```
* refactor certbot/ and certbot/tests/ to use the same structure as the other packages
* git grep -lE "\-e(\s+)\." | xargs sed -i -E "s/\-e(\s+)\./-e certbot/g"
* git grep -lE "\.\[dev\]" | xargs sed -i -E "s/\.\[dev\]/certbot[dev]/g"
* git grep -lE "\.\[dev3\]" | xargs sed -i -E "s/\.\[dev3\]/certbot[dev3]/g"
* Remove replacement of certbot into . in install_and_test.py
* copy license back out to main folder
* remove linter_plugin.py and CONTRIBUTING.md from certbot/MANIFEST.in because these files are not under certbot/
* Move README back into main folder, and make the version inside certbot/ a symlink
* symlink certbot READMEs the other way around
* move testdata into the public api certbot zone
* update source_paths in tox.ini to certbot/certbot to find the right subfolder for tests
* certbot version has been bumped down a directory level
* make certbot tests directory not a package and import sibling as module
* Remove unused script cruft
* change . to certbot in test_sdists
* remove outdated comment referencing a command that doesn't work
* Install instructions should reference an existing file
* update file paths in Dockerfile
* some package named in tox.ini were manually specified, change those to certbot
* new directory format doesn't work easily with pyargs according to http://doc.pytest.org/en/latest/goodpractices.html#tests-as-part-of-application-code
* remove other instance of pyargs
* fix up some references in _release.sh by searching for ' . ' and manual check
* another stray . in tox.ini
* fix paths in tools/_release.sh
* Remove final --pyargs call, and now-unnecessary call to modules instead of local files, since that's fixed by certbot's code being one layer deeper
* Create public shim around main and make that the entry point
* without pyargs, tests cannot be run from an empty directory
* Remove cruft for running certbot directly from main
* Have main shim take real arg
* add docs/api file for main, and fix up main comment
* Update certbot/docs/install.rst
Co-Authored-By: Brad Warren <bmw@users.noreply.github.com>
* Fix comments in readthedocs requirements files to refer to current package
* Update .[docs] reference in contributing.rst
* Move plugins tests to certbot tests directory
* add certbot tests to MANIFEST.in so packagers can run python setup.py test
* move examples directory inside certbot/
* Move CHANGELOG into certbot, and create a top-level symlink
* Remove unused sys and logging from main shim
* nginx http01 test no longer relies on certbot plugins common test
2019-11-25 17:28:06 -05:00
|
|
|
import josepy as jose
|
2020-04-15 14:39:44 -04:00
|
|
|
try:
|
|
|
|
|
import mock
|
|
|
|
|
except ImportError: # pragma: no cover
|
|
|
|
|
from unittest import mock # type: ignore
|
2018-01-11 20:06:23 -05:00
|
|
|
|
|
|
|
|
from acme import challenges
|
|
|
|
|
from certbot import achallenges
|
|
|
|
|
from certbot.tests import acme_util
|
Refactor certbot/ and certbot/tests/ to use the same structure as the other packages (#7544)
Summary of changes in this PR:
- Refactor files involved in the `certbot` module to be of a similar structure to every other package; that is, inside a directory inside the main repo root (see below).
- Make repo root README symlink to `certbot` README.
- Pull tests outside of the distributed module.
- Make `certbot/tests` not be a module so that `certbot` isn't added to Python's path for module discovery.
- Remove `--pyargs` from test calls, and make sure to call tests from repo root since without `--pyargs`, `pytest` takes directory names rather than package names as arguments.
- Replace mentions of `.` with `certbot` when referring to packages to install, usually editably.
- Clean up some unused code around executing tests in a different directory.
- Create public shim around main and make that the entry point.
New directory structure summary:
```
repo root ("certbot", probably, but for clarity all files I mention are relative to here)
├── certbot
│ ├── setup.py
│ ├── certbot
│ │ ├── __init__.py
│ │ ├── achallenges.py
│ │ ├── _internal
│ │ │ ├── __init__.py
│ │ │ ├── account.py
│ │ │ ├── ...
│ │ ├── ...
│ ├── tests
│ │ ├── account_test.py
│ │ ├── display
│ │ │ ├── __init__.py
│ │ │ ├── ...
│ │ ├── ... # note no __init__.py at this level
│ ├── ...
├── acme
│ ├── ...
├── certbot-apache
│ ├── ...
├── ...
```
* refactor certbot/ and certbot/tests/ to use the same structure as the other packages
* git grep -lE "\-e(\s+)\." | xargs sed -i -E "s/\-e(\s+)\./-e certbot/g"
* git grep -lE "\.\[dev\]" | xargs sed -i -E "s/\.\[dev\]/certbot[dev]/g"
* git grep -lE "\.\[dev3\]" | xargs sed -i -E "s/\.\[dev3\]/certbot[dev3]/g"
* Remove replacement of certbot into . in install_and_test.py
* copy license back out to main folder
* remove linter_plugin.py and CONTRIBUTING.md from certbot/MANIFEST.in because these files are not under certbot/
* Move README back into main folder, and make the version inside certbot/ a symlink
* symlink certbot READMEs the other way around
* move testdata into the public api certbot zone
* update source_paths in tox.ini to certbot/certbot to find the right subfolder for tests
* certbot version has been bumped down a directory level
* make certbot tests directory not a package and import sibling as module
* Remove unused script cruft
* change . to certbot in test_sdists
* remove outdated comment referencing a command that doesn't work
* Install instructions should reference an existing file
* update file paths in Dockerfile
* some package named in tox.ini were manually specified, change those to certbot
* new directory format doesn't work easily with pyargs according to http://doc.pytest.org/en/latest/goodpractices.html#tests-as-part-of-application-code
* remove other instance of pyargs
* fix up some references in _release.sh by searching for ' . ' and manual check
* another stray . in tox.ini
* fix paths in tools/_release.sh
* Remove final --pyargs call, and now-unnecessary call to modules instead of local files, since that's fixed by certbot's code being one layer deeper
* Create public shim around main and make that the entry point
* without pyargs, tests cannot be run from an empty directory
* Remove cruft for running certbot directly from main
* Have main shim take real arg
* add docs/api file for main, and fix up main comment
* Update certbot/docs/install.rst
Co-Authored-By: Brad Warren <bmw@users.noreply.github.com>
* Fix comments in readthedocs requirements files to refer to current package
* Update .[docs] reference in contributing.rst
* Move plugins tests to certbot tests directory
* add certbot tests to MANIFEST.in so packagers can run python setup.py test
* move examples directory inside certbot/
* Move CHANGELOG into certbot, and create a top-level symlink
* Remove unused sys and logging from main shim
* nginx http01 test no longer relies on certbot plugins common test
2019-11-25 17:28:06 -05:00
|
|
|
from certbot.tests import util as test_util
|
2019-11-25 17:30:24 -05:00
|
|
|
from certbot_nginx._internal.obj import Addr
|
2019-11-26 20:45:18 -05:00
|
|
|
import test_util as util
|
2018-01-11 20:06:23 -05:00
|
|
|
|
Refactor certbot/ and certbot/tests/ to use the same structure as the other packages (#7544)
Summary of changes in this PR:
- Refactor files involved in the `certbot` module to be of a similar structure to every other package; that is, inside a directory inside the main repo root (see below).
- Make repo root README symlink to `certbot` README.
- Pull tests outside of the distributed module.
- Make `certbot/tests` not be a module so that `certbot` isn't added to Python's path for module discovery.
- Remove `--pyargs` from test calls, and make sure to call tests from repo root since without `--pyargs`, `pytest` takes directory names rather than package names as arguments.
- Replace mentions of `.` with `certbot` when referring to packages to install, usually editably.
- Clean up some unused code around executing tests in a different directory.
- Create public shim around main and make that the entry point.
New directory structure summary:
```
repo root ("certbot", probably, but for clarity all files I mention are relative to here)
├── certbot
│ ├── setup.py
│ ├── certbot
│ │ ├── __init__.py
│ │ ├── achallenges.py
│ │ ├── _internal
│ │ │ ├── __init__.py
│ │ │ ├── account.py
│ │ │ ├── ...
│ │ ├── ...
│ ├── tests
│ │ ├── account_test.py
│ │ ├── display
│ │ │ ├── __init__.py
│ │ │ ├── ...
│ │ ├── ... # note no __init__.py at this level
│ ├── ...
├── acme
│ ├── ...
├── certbot-apache
│ ├── ...
├── ...
```
* refactor certbot/ and certbot/tests/ to use the same structure as the other packages
* git grep -lE "\-e(\s+)\." | xargs sed -i -E "s/\-e(\s+)\./-e certbot/g"
* git grep -lE "\.\[dev\]" | xargs sed -i -E "s/\.\[dev\]/certbot[dev]/g"
* git grep -lE "\.\[dev3\]" | xargs sed -i -E "s/\.\[dev3\]/certbot[dev3]/g"
* Remove replacement of certbot into . in install_and_test.py
* copy license back out to main folder
* remove linter_plugin.py and CONTRIBUTING.md from certbot/MANIFEST.in because these files are not under certbot/
* Move README back into main folder, and make the version inside certbot/ a symlink
* symlink certbot READMEs the other way around
* move testdata into the public api certbot zone
* update source_paths in tox.ini to certbot/certbot to find the right subfolder for tests
* certbot version has been bumped down a directory level
* make certbot tests directory not a package and import sibling as module
* Remove unused script cruft
* change . to certbot in test_sdists
* remove outdated comment referencing a command that doesn't work
* Install instructions should reference an existing file
* update file paths in Dockerfile
* some package named in tox.ini were manually specified, change those to certbot
* new directory format doesn't work easily with pyargs according to http://doc.pytest.org/en/latest/goodpractices.html#tests-as-part-of-application-code
* remove other instance of pyargs
* fix up some references in _release.sh by searching for ' . ' and manual check
* another stray . in tox.ini
* fix paths in tools/_release.sh
* Remove final --pyargs call, and now-unnecessary call to modules instead of local files, since that's fixed by certbot's code being one layer deeper
* Create public shim around main and make that the entry point
* without pyargs, tests cannot be run from an empty directory
* Remove cruft for running certbot directly from main
* Have main shim take real arg
* add docs/api file for main, and fix up main comment
* Update certbot/docs/install.rst
Co-Authored-By: Brad Warren <bmw@users.noreply.github.com>
* Fix comments in readthedocs requirements files to refer to current package
* Update .[docs] reference in contributing.rst
* Move plugins tests to certbot tests directory
* add certbot tests to MANIFEST.in so packagers can run python setup.py test
* move examples directory inside certbot/
* Move CHANGELOG into certbot, and create a top-level symlink
* Remove unused sys and logging from main shim
* nginx http01 test no longer relies on certbot plugins common test
2019-11-25 17:28:06 -05:00
|
|
|
AUTH_KEY = jose.JWKRSA.load(test_util.load_vector("rsa512_key.pem"))
|
|
|
|
|
|
2018-01-11 20:06:23 -05:00
|
|
|
|
|
|
|
|
class HttpPerformTest(util.NginxTest):
|
|
|
|
|
"""Test the NginxHttp01 challenge."""
|
|
|
|
|
|
Refactor certbot/ and certbot/tests/ to use the same structure as the other packages (#7544)
Summary of changes in this PR:
- Refactor files involved in the `certbot` module to be of a similar structure to every other package; that is, inside a directory inside the main repo root (see below).
- Make repo root README symlink to `certbot` README.
- Pull tests outside of the distributed module.
- Make `certbot/tests` not be a module so that `certbot` isn't added to Python's path for module discovery.
- Remove `--pyargs` from test calls, and make sure to call tests from repo root since without `--pyargs`, `pytest` takes directory names rather than package names as arguments.
- Replace mentions of `.` with `certbot` when referring to packages to install, usually editably.
- Clean up some unused code around executing tests in a different directory.
- Create public shim around main and make that the entry point.
New directory structure summary:
```
repo root ("certbot", probably, but for clarity all files I mention are relative to here)
├── certbot
│ ├── setup.py
│ ├── certbot
│ │ ├── __init__.py
│ │ ├── achallenges.py
│ │ ├── _internal
│ │ │ ├── __init__.py
│ │ │ ├── account.py
│ │ │ ├── ...
│ │ ├── ...
│ ├── tests
│ │ ├── account_test.py
│ │ ├── display
│ │ │ ├── __init__.py
│ │ │ ├── ...
│ │ ├── ... # note no __init__.py at this level
│ ├── ...
├── acme
│ ├── ...
├── certbot-apache
│ ├── ...
├── ...
```
* refactor certbot/ and certbot/tests/ to use the same structure as the other packages
* git grep -lE "\-e(\s+)\." | xargs sed -i -E "s/\-e(\s+)\./-e certbot/g"
* git grep -lE "\.\[dev\]" | xargs sed -i -E "s/\.\[dev\]/certbot[dev]/g"
* git grep -lE "\.\[dev3\]" | xargs sed -i -E "s/\.\[dev3\]/certbot[dev3]/g"
* Remove replacement of certbot into . in install_and_test.py
* copy license back out to main folder
* remove linter_plugin.py and CONTRIBUTING.md from certbot/MANIFEST.in because these files are not under certbot/
* Move README back into main folder, and make the version inside certbot/ a symlink
* symlink certbot READMEs the other way around
* move testdata into the public api certbot zone
* update source_paths in tox.ini to certbot/certbot to find the right subfolder for tests
* certbot version has been bumped down a directory level
* make certbot tests directory not a package and import sibling as module
* Remove unused script cruft
* change . to certbot in test_sdists
* remove outdated comment referencing a command that doesn't work
* Install instructions should reference an existing file
* update file paths in Dockerfile
* some package named in tox.ini were manually specified, change those to certbot
* new directory format doesn't work easily with pyargs according to http://doc.pytest.org/en/latest/goodpractices.html#tests-as-part-of-application-code
* remove other instance of pyargs
* fix up some references in _release.sh by searching for ' . ' and manual check
* another stray . in tox.ini
* fix paths in tools/_release.sh
* Remove final --pyargs call, and now-unnecessary call to modules instead of local files, since that's fixed by certbot's code being one layer deeper
* Create public shim around main and make that the entry point
* without pyargs, tests cannot be run from an empty directory
* Remove cruft for running certbot directly from main
* Have main shim take real arg
* add docs/api file for main, and fix up main comment
* Update certbot/docs/install.rst
Co-Authored-By: Brad Warren <bmw@users.noreply.github.com>
* Fix comments in readthedocs requirements files to refer to current package
* Update .[docs] reference in contributing.rst
* Move plugins tests to certbot tests directory
* add certbot tests to MANIFEST.in so packagers can run python setup.py test
* move examples directory inside certbot/
* Move CHANGELOG into certbot, and create a top-level symlink
* Remove unused sys and logging from main shim
* nginx http01 test no longer relies on certbot plugins common test
2019-11-25 17:28:06 -05:00
|
|
|
account_key = AUTH_KEY
|
2018-01-11 20:06:23 -05:00
|
|
|
achalls = [
|
|
|
|
|
achallenges.KeyAuthorizationAnnotatedChallenge(
|
|
|
|
|
challb=acme_util.chall_to_challb(
|
|
|
|
|
challenges.HTTP01(token=b"kNdwjwOeX0I_A8DXt9Msmg"), "pending"),
|
|
|
|
|
domain="www.example.com", account_key=account_key),
|
|
|
|
|
achallenges.KeyAuthorizationAnnotatedChallenge(
|
|
|
|
|
challb=acme_util.chall_to_challb(
|
|
|
|
|
challenges.HTTP01(
|
|
|
|
|
token=b"\xba\xa9\xda?<m\xaewmx\xea\xad\xadv\xf4\x02\xc9y"
|
|
|
|
|
b"\x80\xe2_X\t\xe7\xc7\xa4\t\xca\xf7&\x945"
|
|
|
|
|
), "pending"),
|
|
|
|
|
domain="ipv6.com", account_key=account_key),
|
|
|
|
|
achallenges.KeyAuthorizationAnnotatedChallenge(
|
|
|
|
|
challb=acme_util.chall_to_challb(
|
|
|
|
|
challenges.HTTP01(
|
|
|
|
|
token=b"\x8c\x8a\xbf_-f\\cw\xee\xd6\xf8/\xa5\xe3\xfd"
|
|
|
|
|
b"\xeb9\xf1\xf5\xb9\xefVM\xc9w\xa4u\x9c\xe1\x87\xb4"
|
|
|
|
|
), "pending"),
|
|
|
|
|
domain="www.example.org", account_key=account_key),
|
|
|
|
|
achallenges.KeyAuthorizationAnnotatedChallenge(
|
|
|
|
|
challb=acme_util.chall_to_challb(
|
|
|
|
|
challenges.HTTP01(token=b"kNdwjxOeX0I_A8DXt9Msmg"), "pending"),
|
|
|
|
|
domain="migration.com", account_key=account_key),
|
2021-02-26 16:43:22 -05:00
|
|
|
achallenges.KeyAuthorizationAnnotatedChallenge(
|
|
|
|
|
challb=acme_util.chall_to_challb(
|
|
|
|
|
challenges.HTTP01(token=b"kNdwjxOeX0I_A8DXt9Msmg"), "pending"),
|
|
|
|
|
domain="ipv6ssl.com", account_key=account_key),
|
2018-01-11 20:06:23 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
2021-04-08 16:04:51 -04:00
|
|
|
super().setUp()
|
2018-01-11 20:06:23 -05:00
|
|
|
|
2019-11-13 13:19:27 -05:00
|
|
|
config = self.get_nginx_configurator(
|
2018-01-11 20:06:23 -05:00
|
|
|
self.config_path, self.config_dir, self.work_dir, self.logs_dir)
|
|
|
|
|
|
2019-11-25 17:30:24 -05:00
|
|
|
from certbot_nginx._internal import http_01
|
2018-01-11 20:06:23 -05:00
|
|
|
self.http01 = http_01.NginxHttp01(config)
|
|
|
|
|
|
|
|
|
|
def test_perform0(self):
|
|
|
|
|
responses = self.http01.perform()
|
|
|
|
|
self.assertEqual([], responses)
|
|
|
|
|
|
2019-11-25 17:30:24 -05:00
|
|
|
@mock.patch("certbot_nginx._internal.configurator.NginxConfigurator.save")
|
2018-01-11 20:06:23 -05:00
|
|
|
def test_perform1(self, mock_save):
|
|
|
|
|
self.http01.add_chall(self.achalls[0])
|
|
|
|
|
response = self.achalls[0].response(self.account_key)
|
|
|
|
|
|
|
|
|
|
responses = self.http01.perform()
|
|
|
|
|
|
|
|
|
|
self.assertEqual([response], responses)
|
|
|
|
|
self.assertEqual(mock_save.call_count, 1)
|
|
|
|
|
|
|
|
|
|
def test_perform2(self):
|
|
|
|
|
acme_responses = []
|
|
|
|
|
for achall in self.achalls:
|
|
|
|
|
self.http01.add_chall(achall)
|
|
|
|
|
acme_responses.append(achall.response(self.account_key))
|
|
|
|
|
|
2019-10-31 13:17:29 -04:00
|
|
|
http_responses = self.http01.perform()
|
2018-01-11 20:06:23 -05:00
|
|
|
|
2021-02-26 16:43:22 -05:00
|
|
|
self.assertEqual(len(http_responses), 5)
|
|
|
|
|
for i in range(5):
|
2019-10-31 13:17:29 -04:00
|
|
|
self.assertEqual(http_responses[i], acme_responses[i])
|
2018-01-11 20:06:23 -05:00
|
|
|
|
|
|
|
|
def test_mod_config(self):
|
|
|
|
|
self.http01.add_chall(self.achalls[0])
|
|
|
|
|
self.http01.add_chall(self.achalls[2])
|
|
|
|
|
|
|
|
|
|
self.http01._mod_config() # pylint: disable=protected-access
|
|
|
|
|
|
|
|
|
|
self.http01.configurator.save()
|
|
|
|
|
|
|
|
|
|
self.http01.configurator.parser.load()
|
|
|
|
|
|
|
|
|
|
# vhosts = self.http01.configurator.parser.get_vhosts()
|
|
|
|
|
|
|
|
|
|
# for vhost in vhosts:
|
|
|
|
|
# pass
|
|
|
|
|
# if the name matches
|
|
|
|
|
# check that the location block is in there and is correct
|
|
|
|
|
|
|
|
|
|
# if vhost.addrs == set(v_addr1):
|
|
|
|
|
# response = self.achalls[0].response(self.account_key)
|
|
|
|
|
# else:
|
|
|
|
|
# response = self.achalls[2].response(self.account_key)
|
|
|
|
|
# self.assertEqual(vhost.addrs, set(v_addr2_print))
|
|
|
|
|
# self.assertEqual(vhost.names, set([response.z_domain.decode('ascii')]))
|
|
|
|
|
|
2021-02-26 16:43:22 -05:00
|
|
|
@mock.patch('certbot_nginx._internal.parser.NginxParser.add_server_directives')
|
|
|
|
|
def test_mod_config_http_and_https(self, mock_add_server_directives):
|
|
|
|
|
"""A server_name with both HTTP and HTTPS vhosts should get modded in both vhosts"""
|
|
|
|
|
self.configuration.https_port = 443
|
|
|
|
|
self.http01.add_chall(self.achalls[3]) # migration.com
|
|
|
|
|
self.http01._mod_config() # pylint: disable=protected-access
|
|
|
|
|
|
|
|
|
|
# Domain has an HTTP and HTTPS vhost
|
|
|
|
|
# 2 * 'rewrite' + 2 * 'return 200 keyauthz' = 4
|
|
|
|
|
self.assertEqual(mock_add_server_directives.call_count, 4)
|
|
|
|
|
|
|
|
|
|
@mock.patch('certbot_nginx._internal.parser.nginxparser.dump')
|
|
|
|
|
@mock.patch('certbot_nginx._internal.parser.NginxParser.add_server_directives')
|
|
|
|
|
def test_mod_config_only_https(self, mock_add_server_directives, mock_dump):
|
|
|
|
|
"""A server_name with only an HTTPS vhost should get modded"""
|
|
|
|
|
self.http01.add_chall(self.achalls[4]) # ipv6ssl.com
|
|
|
|
|
self.http01._mod_config() # pylint: disable=protected-access
|
|
|
|
|
|
|
|
|
|
# It should modify the existing HTTPS vhost
|
|
|
|
|
self.assertEqual(mock_add_server_directives.call_count, 2)
|
|
|
|
|
# since there was no suitable HTTP vhost or default HTTP vhost, a non-empty one
|
|
|
|
|
# should have been created and written to the challenge conf file
|
|
|
|
|
self.assertNotEqual(mock_dump.call_args[0][0], [])
|
|
|
|
|
|
|
|
|
|
@mock.patch('certbot_nginx._internal.parser.NginxParser.add_server_directives')
|
|
|
|
|
def test_mod_config_deduplicate(self, mock_add_server_directives):
|
|
|
|
|
"""A vhost that appears in both HTTP and HTTPS vhosts only gets modded once"""
|
|
|
|
|
achall = achallenges.KeyAuthorizationAnnotatedChallenge(
|
|
|
|
|
challb=acme_util.chall_to_challb(
|
|
|
|
|
challenges.HTTP01(token=b"kNdwjxOeX0I_A8DXt9Msmg"), "pending"),
|
|
|
|
|
domain="ssl.both.com", account_key=AUTH_KEY)
|
|
|
|
|
self.http01.add_chall(achall)
|
|
|
|
|
self.http01._mod_config() # pylint: disable=protected-access
|
|
|
|
|
|
|
|
|
|
# Should only get called 5 times, rather than 6, because two vhosts are the same
|
|
|
|
|
self.assertEqual(mock_add_server_directives.call_count, 5*2)
|
|
|
|
|
|
2022-02-10 23:40:14 -05:00
|
|
|
def test_mod_config_insert_bucket_directive(self):
|
|
|
|
|
nginx_conf = self.http01.configurator.parser.abs_path('nginx.conf')
|
|
|
|
|
|
|
|
|
|
expected = ['server_names_hash_bucket_size', '128']
|
|
|
|
|
original_conf = self.http01.configurator.parser.parsed[nginx_conf]
|
|
|
|
|
self.assertFalse(util.contains_at_depth(original_conf, expected, 2))
|
|
|
|
|
|
|
|
|
|
self.http01.add_chall(self.achalls[0])
|
|
|
|
|
self.http01._mod_config() # pylint: disable=protected-access
|
|
|
|
|
self.http01.configurator.save()
|
|
|
|
|
self.http01.configurator.parser.load()
|
|
|
|
|
|
|
|
|
|
generated_conf = self.http01.configurator.parser.parsed[nginx_conf]
|
|
|
|
|
self.assertTrue(util.contains_at_depth(generated_conf, expected, 2))
|
|
|
|
|
|
|
|
|
|
def test_mod_config_update_bucket_directive_in_included_file(self):
|
|
|
|
|
# save old example.com config
|
|
|
|
|
example_com_loc = self.http01.configurator.parser.abs_path('sites-enabled/example.com')
|
|
|
|
|
with open(example_com_loc) as f:
|
|
|
|
|
original_example_com = f.read()
|
|
|
|
|
|
|
|
|
|
# modify example.com config
|
|
|
|
|
modified_example_com = 'server_names_hash_bucket_size 64;\n' + original_example_com
|
|
|
|
|
with open(example_com_loc, 'w') as f:
|
|
|
|
|
f.write(modified_example_com)
|
|
|
|
|
self.http01.configurator.parser.load()
|
|
|
|
|
|
|
|
|
|
# run change
|
|
|
|
|
self.http01.add_chall(self.achalls[0])
|
|
|
|
|
self.http01._mod_config() # pylint: disable=protected-access
|
|
|
|
|
self.http01.configurator.save()
|
|
|
|
|
self.http01.configurator.parser.load()
|
|
|
|
|
|
|
|
|
|
# not in nginx.conf
|
|
|
|
|
expected = ['server_names_hash_bucket_size', '128']
|
|
|
|
|
nginx_conf_loc = self.http01.configurator.parser.abs_path('nginx.conf')
|
|
|
|
|
nginx_conf = self.http01.configurator.parser.parsed[nginx_conf_loc]
|
|
|
|
|
self.assertFalse(util.contains_at_depth(nginx_conf, expected, 2))
|
|
|
|
|
|
|
|
|
|
# is updated in example.com conf
|
|
|
|
|
generated_conf = self.http01.configurator.parser.parsed[example_com_loc]
|
|
|
|
|
self.assertTrue(util.contains_at_depth(generated_conf, expected, 0))
|
|
|
|
|
|
|
|
|
|
# put back example.com config
|
|
|
|
|
with open(example_com_loc, 'w') as f:
|
|
|
|
|
f.write(original_example_com)
|
|
|
|
|
self.http01.configurator.parser.load()
|
|
|
|
|
|
2019-11-25 17:30:24 -05:00
|
|
|
@mock.patch("certbot_nginx._internal.configurator.NginxConfigurator.ipv6_info")
|
2018-10-17 13:54:43 -04:00
|
|
|
def test_default_listen_addresses_no_memoization(self, ipv6_info):
|
|
|
|
|
# pylint: disable=protected-access
|
|
|
|
|
ipv6_info.return_value = (True, True)
|
|
|
|
|
self.http01._default_listen_addresses()
|
|
|
|
|
self.assertEqual(ipv6_info.call_count, 1)
|
|
|
|
|
ipv6_info.return_value = (False, False)
|
|
|
|
|
self.http01._default_listen_addresses()
|
|
|
|
|
self.assertEqual(ipv6_info.call_count, 2)
|
|
|
|
|
|
2019-11-25 17:30:24 -05:00
|
|
|
@mock.patch("certbot_nginx._internal.configurator.NginxConfigurator.ipv6_info")
|
2018-10-17 13:54:43 -04:00
|
|
|
def test_default_listen_addresses_t_t(self, ipv6_info):
|
|
|
|
|
# pylint: disable=protected-access
|
|
|
|
|
ipv6_info.return_value = (True, True)
|
|
|
|
|
addrs = self.http01._default_listen_addresses()
|
|
|
|
|
http_addr = Addr.fromstring("80")
|
|
|
|
|
http_ipv6_addr = Addr.fromstring("[::]:80")
|
|
|
|
|
self.assertEqual(addrs, [http_addr, http_ipv6_addr])
|
|
|
|
|
|
2019-11-25 17:30:24 -05:00
|
|
|
@mock.patch("certbot_nginx._internal.configurator.NginxConfigurator.ipv6_info")
|
2018-10-17 13:54:43 -04:00
|
|
|
def test_default_listen_addresses_t_f(self, ipv6_info):
|
|
|
|
|
# pylint: disable=protected-access
|
|
|
|
|
ipv6_info.return_value = (True, False)
|
|
|
|
|
addrs = self.http01._default_listen_addresses()
|
|
|
|
|
http_addr = Addr.fromstring("80")
|
|
|
|
|
http_ipv6_addr = Addr.fromstring("[::]:80 ipv6only=on")
|
|
|
|
|
self.assertEqual(addrs, [http_addr, http_ipv6_addr])
|
|
|
|
|
|
2019-11-25 17:30:24 -05:00
|
|
|
@mock.patch("certbot_nginx._internal.configurator.NginxConfigurator.ipv6_info")
|
2018-10-17 13:54:43 -04:00
|
|
|
def test_default_listen_addresses_f_f(self, ipv6_info):
|
|
|
|
|
# pylint: disable=protected-access
|
|
|
|
|
ipv6_info.return_value = (False, False)
|
|
|
|
|
addrs = self.http01._default_listen_addresses()
|
|
|
|
|
http_addr = Addr.fromstring("80")
|
|
|
|
|
self.assertEqual(addrs, [http_addr])
|
2018-01-11 20:06:23 -05:00
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
unittest.main() # pragma: no cover
|