-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #151 from infinityofspace/unit_tests
added proper unit tests closes #149
- Loading branch information
Showing
4 changed files
with
136 additions
and
290 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ setuptools>=41.6.0 | |
requests>=2.20.0,<3.0 | ||
certbot>=1.18.0,<4.0 | ||
dnspython>=2.0.0,<3.0 | ||
responses~=0.25 |
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,132 @@ | ||
import unittest | ||
from argparse import Namespace | ||
|
||
import responses | ||
from certbot.configuration import NamespaceConfig | ||
from certbot.errors import PluginError | ||
|
||
from certbot_dns_duckdns.cert.client import Authenticator | ||
|
||
|
||
class TestCertClient(unittest.TestCase): | ||
@responses.activate | ||
def test_valid_auth(self): | ||
api_token = "token" | ||
domain = "example.duckdns.org" | ||
txt_value = "ABCDEF" | ||
|
||
responses.get( | ||
url=f"https://www.duckdns.org/update?token={api_token}&domains={domain}&txt={txt_value}", | ||
body="OK", | ||
) | ||
|
||
namespace = Namespace( | ||
duckdns_token=api_token, | ||
duckdns_token_token_env="DUCKDNS_TOKEN", | ||
duckdns_no_txt_restore=False, | ||
config_dir="config_dir", | ||
work_dir="work_dir", | ||
logs_dir="logs_dir", | ||
http01_port=80, | ||
https_port=443, | ||
domains=["example.duckdns.org"], | ||
) | ||
config = NamespaceConfig(namespace) | ||
|
||
authenticator = Authenticator(config, name="duckdns") | ||
|
||
authenticator._perform( | ||
domain=domain, validation_name="", validation=txt_value | ||
) | ||
|
||
@responses.activate | ||
def test_invalid_auth(self): | ||
api_token = "token" | ||
domain = "example.duckdns.org" | ||
txt_value = "ABCDEF" | ||
|
||
responses.get( | ||
url=f"https://www.duckdns.org/update?token={api_token}&domains={domain}&txt={txt_value}", | ||
body="OK", | ||
) | ||
|
||
namespace = Namespace( | ||
duckdns_token=api_token + "invalid", | ||
duckdns_token_token_env="DUCKDNS_TOKEN", | ||
duckdns_no_txt_restore=False, | ||
config_dir="config_dir", | ||
work_dir="work_dir", | ||
logs_dir="logs_dir", | ||
http01_port=80, | ||
https_port=443, | ||
domains=["example.duckdns.org"], | ||
) | ||
config = NamespaceConfig(namespace) | ||
|
||
authenticator = Authenticator(config, name="duckdns") | ||
|
||
with self.assertRaises(PluginError): | ||
authenticator._perform( | ||
domain=domain, validation_name="", validation=txt_value | ||
) | ||
|
||
@responses.activate | ||
def test_invalid_duckdns_domain(self): | ||
api_token = "token" | ||
domain = "example.org" | ||
txt_value = "ABCDEF" | ||
|
||
responses.get( | ||
url=f"https://www.duckdns.org/update?token={api_token}&domains={domain}&txt={txt_value}", | ||
body="OK", | ||
) | ||
|
||
namespace = Namespace( | ||
duckdns_token=api_token, | ||
duckdns_token_token_env="DUCKDNS_TOKEN", | ||
duckdns_no_txt_restore=False, | ||
config_dir="config_dir", | ||
work_dir="work_dir", | ||
logs_dir="logs_dir", | ||
http01_port=80, | ||
https_port=443, | ||
domains=[domain], | ||
) | ||
config = NamespaceConfig(namespace) | ||
|
||
authenticator = Authenticator(config, name="duckdns") | ||
|
||
with self.assertRaises(PluginError): | ||
authenticator._perform( | ||
domain=domain, validation_name="", validation=txt_value | ||
) | ||
|
||
@responses.activate | ||
def test_cleanup(self): | ||
api_token = "token" | ||
domain = "example.duckdns.org" | ||
txt_value = "ABCDEF" | ||
|
||
responses.get( | ||
url=f"https://www.duckdns.org/update?token={api_token}&domains={domain}&txt=&clear=true", | ||
body="OK", | ||
) | ||
|
||
namespace = Namespace( | ||
duckdns_token=api_token, | ||
duckdns_token_token_env="DUCKDNS_TOKEN", | ||
duckdns_no_txt_restore=False, | ||
config_dir="config_dir", | ||
work_dir="work_dir", | ||
logs_dir="logs_dir", | ||
http01_port=80, | ||
https_port=443, | ||
domains=["example.duckdns.org"], | ||
) | ||
config = NamespaceConfig(namespace) | ||
|
||
authenticator = Authenticator(config, name="duckdns") | ||
|
||
authenticator._cleanup( | ||
domain=domain, validation_name="", validation=txt_value | ||
) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.