-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for the ClouDNS Authenticator.
Adds testing for the Authenticator that follow the conventions of the upstream certbot repository. This should ensure compatibility if this was ever merged upstream.
- Loading branch information
Showing
7 changed files
with
464 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"python.testing.pytestArgs": [ | ||
"certbot_dns_cloudns" | ||
], | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.pytestEnabled": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""certbot-dns-cloudns tests""" |
127 changes: 127 additions & 0 deletions
127
certbot_dns_cloudns/_internal/tests/authenticator_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
"""Tests for certbot_dns_cloudns._internal.authenticator.""" | ||
|
||
import sys | ||
from unittest import mock | ||
|
||
import pytest | ||
|
||
from certbot import errors | ||
from certbot.compat import os | ||
from certbot.plugins import dns_test_common | ||
from certbot.plugins.dns_test_common import DOMAIN | ||
from certbot.tests import util as test_util | ||
|
||
AUTH_ID = "1234" | ||
SUB_AUTH_ID = "5678" | ||
SUB_AUTH_USER = "tester" | ||
AUTH_PASSWORD = "foobar" | ||
|
||
|
||
class AuthenticatorTest( | ||
test_util.TempDirTestCase, dns_test_common.BaseAuthenticatorTest | ||
): | ||
def setUp(self): | ||
from certbot_dns_cloudns._internal.authenticator import Authenticator | ||
|
||
super().setUp() | ||
|
||
path = os.path.join(self.tempdir, "file.ini") | ||
dns_test_common.write( | ||
{ | ||
"cloudns_auth_id": AUTH_ID, | ||
"cloudns_auth_password": AUTH_PASSWORD, | ||
}, | ||
path, | ||
) | ||
|
||
self.config = mock.MagicMock( | ||
cloudns_credentials=path, | ||
cloudns_propagation_seconds=0, # don't wait during tests | ||
cloudns_nameserver="1.1.1.1", # nameserver is required for parsing | ||
) | ||
self.auth = Authenticator(self.config, "cloudns") | ||
self.mock_client = mock.MagicMock() | ||
self.auth._get_client = mock.MagicMock(return_value=self.mock_client) | ||
|
||
@test_util.patch_display_util() | ||
def test_perform(self, unused_mock_get_utility): | ||
self.auth._change_txt_record = mock.MagicMock() | ||
self.auth._wait_for_change = mock.MagicMock() | ||
self.auth.perform([self.achall]) | ||
|
||
expected = [ | ||
mock.call.add_txt_record( | ||
DOMAIN, "_acme-challenge." + DOMAIN, mock.ANY, mock.ANY | ||
) | ||
] | ||
assert expected == self.mock_client.mock_calls | ||
|
||
def test_cleanup(self): | ||
self.auth._attempt_cleanup = True | ||
self.auth.cleanup([self.achall]) | ||
|
||
expected = [ | ||
mock.call.del_txt_record( | ||
DOMAIN, "_acme-challenge." + DOMAIN, mock.ANY | ||
) | ||
] | ||
assert expected == self.mock_client.mock_calls | ||
|
||
@test_util.patch_display_util() | ||
def test_sub_auth_user(self, unused_mock_get_utility): | ||
dns_test_common.write( | ||
{ | ||
"cloudns_sub_auth_user": SUB_AUTH_USER, | ||
"cloudns_auth_password": AUTH_PASSWORD, | ||
}, | ||
self.config.cloudns_credentials, | ||
) | ||
self.auth.perform([self.achall]) | ||
|
||
expected = [ | ||
mock.call.add_txt_record( | ||
DOMAIN, "_acme-challenge." + DOMAIN, mock.ANY, mock.ANY | ||
) | ||
] | ||
assert expected == self.mock_client.mock_calls | ||
|
||
@test_util.patch_display_util() | ||
def test_sub_auth_id(self, unused_mock_get_utility): | ||
dns_test_common.write( | ||
{ | ||
"cloudns_sub_auth_id": SUB_AUTH_ID, | ||
"cloudns_auth_password": AUTH_PASSWORD, | ||
}, | ||
self.config.cloudns_credentials, | ||
) | ||
self.auth.perform([self.achall]) | ||
|
||
expected = [ | ||
mock.call.add_txt_record( | ||
DOMAIN, "_acme-challenge." + DOMAIN, mock.ANY, mock.ANY | ||
) | ||
] | ||
assert expected == self.mock_client.mock_calls | ||
|
||
def test_no_creds(self): | ||
dns_test_common.write({}, self.config.cloudns_credentials) | ||
with pytest.raises(errors.PluginError): | ||
self.auth.perform([self.achall]) | ||
|
||
def test_missing_auth_password_or_auth_id(self): | ||
dns_test_common.write( | ||
{"cloudns_auth_id": AUTH_ID}, self.config.cloudns_credentials | ||
) | ||
with pytest.raises(errors.PluginError): | ||
self.auth.perform([self.achall]) | ||
|
||
dns_test_common.write( | ||
{"clouds_auth_password": AUTH_PASSWORD}, | ||
self.config.cloudns_credentials, | ||
) | ||
with pytest.raises(errors.PluginError): | ||
self.auth.perform([self.achall]) | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(pytest.main(sys.argv[1:] + [__file__])) # pragma: no cover |
Oops, something went wrong.