certbot-dns-kas 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- certbot_dns_kas-0.1.1/LICENSE +21 -0
- certbot_dns_kas-0.1.1/PKG-INFO +40 -0
- certbot_dns_kas-0.1.1/README.md +70 -0
- certbot_dns_kas-0.1.1/certbot_dns_kas/__init__.py +0 -0
- certbot_dns_kas-0.1.1/certbot_dns_kas/_internal/__init__.py +0 -0
- certbot_dns_kas-0.1.1/certbot_dns_kas/_internal/dns_kas.py +114 -0
- certbot_dns_kas-0.1.1/certbot_dns_kas.egg-info/PKG-INFO +40 -0
- certbot_dns_kas-0.1.1/certbot_dns_kas.egg-info/SOURCES.txt +14 -0
- certbot_dns_kas-0.1.1/certbot_dns_kas.egg-info/dependency_links.txt +1 -0
- certbot_dns_kas-0.1.1/certbot_dns_kas.egg-info/entry_points.txt +2 -0
- certbot_dns_kas-0.1.1/certbot_dns_kas.egg-info/requires.txt +3 -0
- certbot_dns_kas-0.1.1/certbot_dns_kas.egg-info/top_level.txt +2 -0
- certbot_dns_kas-0.1.1/setup.cfg +4 -0
- certbot_dns_kas-0.1.1/setup.py +45 -0
- certbot_dns_kas-0.1.1/tests/__init__.py +0 -0
- certbot_dns_kas-0.1.1/tests/test_dns_kas.py +79 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Andreas Biesel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: certbot-dns-kas
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: All-Inkl KAS DNS Authenticator plugin for Certbot
|
|
5
|
+
Home-page: https://github.com/mobilandi/certbot-dns-kas
|
|
6
|
+
Author: Antigravity
|
|
7
|
+
Author-email: antigravity@example.com
|
|
8
|
+
License: Apache License 2.0
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Environment :: Plugins
|
|
11
|
+
Classifier: Intended Audience :: System Administrators
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
14
|
+
Classifier: Programming Language :: Python
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
22
|
+
Classifier: Topic :: Security
|
|
23
|
+
Classifier: Topic :: System :: Installation/Setup
|
|
24
|
+
Classifier: Topic :: System :: Networking
|
|
25
|
+
Classifier: Topic :: System :: Systems Administration
|
|
26
|
+
Classifier: Topic :: Utilities
|
|
27
|
+
Requires-Python: >=3.6
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: certbot>=1.18.0
|
|
30
|
+
Requires-Dist: zope.interface
|
|
31
|
+
Requires-Dist: kasserver
|
|
32
|
+
Dynamic: author
|
|
33
|
+
Dynamic: author-email
|
|
34
|
+
Dynamic: classifier
|
|
35
|
+
Dynamic: home-page
|
|
36
|
+
Dynamic: license
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
Dynamic: requires-dist
|
|
39
|
+
Dynamic: requires-python
|
|
40
|
+
Dynamic: summary
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Certbot DNS All-Inkl (KAS) Plugin
|
|
2
|
+
|
|
3
|
+
This is a Certbot plugin for the **All-Inkl** DNS service (KAS).
|
|
4
|
+
It automates the process of completing `dns-01` challenges by creating and removing TXT records via the KAS API.
|
|
5
|
+
|
|
6
|
+
> **Disclaimer:** This plugin was developed with the assistance of AI. While it has been verified to work in production environments, please review the code and test carefully before using it in critical systems. Use at your own risk.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
### Via Pip (PyPI)
|
|
11
|
+
```bash
|
|
12
|
+
pip install certbot-dns-kas
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### From Source
|
|
16
|
+
```bash
|
|
17
|
+
pip install git+https://github.com/mobilandi/certbot-dns-kas.git
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
1. **Create a credentials file** (e.g., `credentials.ini`):
|
|
23
|
+
```ini
|
|
24
|
+
dns_kas_user = your_kas_login
|
|
25
|
+
dns_kas_password = your_kas_password
|
|
26
|
+
```
|
|
27
|
+
*(Ensure this file is only readable by root/owner: `chmod 600 credentials.ini`)*
|
|
28
|
+
|
|
29
|
+
2. **Run Certbot:**
|
|
30
|
+
```bash
|
|
31
|
+
certbot certonly \
|
|
32
|
+
--authenticator dns-kas \
|
|
33
|
+
--dns-kas-credentials credentials.ini \
|
|
34
|
+
-d example.com -d *.example.com
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Nginx Proxy Manager Integration
|
|
38
|
+
|
|
39
|
+
To use this plugin with [Nginx Proxy Manager](https://nginxproxymanager.com/), you can install it into the running container.
|
|
40
|
+
|
|
41
|
+
1. **Enter the container and install:**
|
|
42
|
+
```bash
|
|
43
|
+
docker exec -it nginx-proxy-manager sh -c "export SETUPTOOLS_USE_DISTUTILS=stdlib && pip install git+https://github.com/mobilandi/certbot-dns-kas.git"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
2. **Configure `dns-plugins.json`** (usually in `/app/certbot/dns-plugins.json`):
|
|
47
|
+
```json
|
|
48
|
+
"kas": {
|
|
49
|
+
"name": "All-Inkl (KAS)",
|
|
50
|
+
"package_name": "certbot-dns-kas",
|
|
51
|
+
"version": "==0.1.1",
|
|
52
|
+
"dependencies": "kasserver",
|
|
53
|
+
"credentials": "dns_kas_user = your_kas_user\ndns_kas_password = your_kas_password",
|
|
54
|
+
"full_plugin_name": "dns-kas"
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
3. **Restart the container.**
|
|
59
|
+
|
|
60
|
+
## Development
|
|
61
|
+
|
|
62
|
+
### Running Tests
|
|
63
|
+
```bash
|
|
64
|
+
pip install -e .
|
|
65
|
+
pip install pytest mock certbot
|
|
66
|
+
python -m pytest tests
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Credits
|
|
70
|
+
Based on the `kasserver` python library.
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from typing import Any
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
import zope.interface
|
|
6
|
+
|
|
7
|
+
from certbot import errors
|
|
8
|
+
from certbot import interfaces
|
|
9
|
+
from certbot.plugins import dns_common
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
from kasserver import KasServer
|
|
13
|
+
except ImportError:
|
|
14
|
+
# Allow import for basic setuptools operations even if kasserver is missing
|
|
15
|
+
KasServer = None
|
|
16
|
+
|
|
17
|
+
logger = logging.getLogger(__name__)
|
|
18
|
+
|
|
19
|
+
@zope.interface.implementer(interfaces.IAuthenticator)
|
|
20
|
+
@zope.interface.provider(interfaces.IPluginFactory)
|
|
21
|
+
class Authenticator(dns_common.DNSAuthenticator):
|
|
22
|
+
"""DNS Authenticator for All-Inkl."""
|
|
23
|
+
|
|
24
|
+
description = 'Obtain certificates using a DNS TXT record with All-Inkl (KAS).'
|
|
25
|
+
# ttl = 60 # Library 'kasserver' does not support setting TTL via add_dns_record
|
|
26
|
+
|
|
27
|
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
28
|
+
super().__init__(*args, **kwargs)
|
|
29
|
+
self._kas_client = None
|
|
30
|
+
|
|
31
|
+
@classmethod
|
|
32
|
+
def add_parser_arguments(cls, add: Any, default_propagation_seconds: int = 120) -> None:
|
|
33
|
+
super().add_parser_arguments(add, default_propagation_seconds)
|
|
34
|
+
add('credentials', help='All-Inkl KAS credentials INI file.')
|
|
35
|
+
|
|
36
|
+
def _setup_credentials(self) -> None:
|
|
37
|
+
self.credentials = self._configure_credentials(
|
|
38
|
+
'credentials',
|
|
39
|
+
'All-Inkl credentials INI file',
|
|
40
|
+
{
|
|
41
|
+
'kas_user': 'KAS username/login',
|
|
42
|
+
'kas_password': 'KAS password',
|
|
43
|
+
}
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
def _perform(self, domain: str, validation_name: str, validation: str) -> None:
|
|
47
|
+
# Note: 'record_aux' is typically priority. KAS API usually expects 0 for TXT.
|
|
48
|
+
# TTL is not evidently exposed in add_dns_record signature (fqdn, record_type, record_data, record_aux).
|
|
49
|
+
self._get_kas_client().add_dns_record(
|
|
50
|
+
fqdn=validation_name,
|
|
51
|
+
record_type='TXT',
|
|
52
|
+
record_data=validation,
|
|
53
|
+
record_aux=0
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
def _cleanup(self, domain: str, validation_name: str, validation: str) -> None:
|
|
57
|
+
client = self._get_kas_client()
|
|
58
|
+
_, zone_name = client._split_fqdn(validation_name)
|
|
59
|
+
|
|
60
|
+
try:
|
|
61
|
+
# Safe Cleanup: Find the specific record ID matching the validation token
|
|
62
|
+
records = client.get_dns_records(zone_name)
|
|
63
|
+
record_id = None
|
|
64
|
+
|
|
65
|
+
# The API returns 'prefix' for record_name, e.g. '_acme-challenge' for '_acme-challenge.example.com'
|
|
66
|
+
# We must match both name and content to be sure.
|
|
67
|
+
target_name = validation_name.removesuffix(f".{zone_name}")
|
|
68
|
+
if target_name.endswith('.'):
|
|
69
|
+
target_name = target_name[:-1]
|
|
70
|
+
|
|
71
|
+
for item in records:
|
|
72
|
+
if (item.get('name') == target_name and
|
|
73
|
+
item.get('type') == 'TXT' and
|
|
74
|
+
item.get('data') == validation):
|
|
75
|
+
record_id = item.get('id')
|
|
76
|
+
break
|
|
77
|
+
|
|
78
|
+
if record_id:
|
|
79
|
+
logger.info(f"Deleting TXT record for {validation_name} (ID: {record_id})")
|
|
80
|
+
# accessing protected method _request to delete by ID, because
|
|
81
|
+
# public delete_dns_record() is unsafe (deletes first match)
|
|
82
|
+
client._request("delete_dns_settings", {"record_id": record_id})
|
|
83
|
+
else:
|
|
84
|
+
logger.warning(f"Could not find TXT record for {validation_name} to delete.")
|
|
85
|
+
|
|
86
|
+
except Exception as e:
|
|
87
|
+
logger.warning('Failed to delete DNS record: %s', e)
|
|
88
|
+
|
|
89
|
+
def _get_kas_client(self) -> "KasServer":
|
|
90
|
+
import os
|
|
91
|
+
if not self._kas_client:
|
|
92
|
+
if KasServer is None:
|
|
93
|
+
raise errors.PluginError("kasserver library is not installed.")
|
|
94
|
+
|
|
95
|
+
# kasserver uses environment variables for configuration.
|
|
96
|
+
# We set them temporarily for instantiation and clear them immediately
|
|
97
|
+
# to minimize side effects / leakage.
|
|
98
|
+
env_user = self.credentials.conf('kas_user')
|
|
99
|
+
env_pass = self.credentials.conf('kas_password')
|
|
100
|
+
|
|
101
|
+
os.environ['KASSERVER_USER'] = env_user
|
|
102
|
+
os.environ['KASSERVER_PASSWORD'] = env_pass
|
|
103
|
+
|
|
104
|
+
try:
|
|
105
|
+
self._kas_client = KasServer()
|
|
106
|
+
finally:
|
|
107
|
+
# Cleanup environment variables
|
|
108
|
+
# We use pop with default None to avoid errors if they were already missing
|
|
109
|
+
if os.environ.get('KASSERVER_USER') == env_user:
|
|
110
|
+
os.environ.pop('KASSERVER_USER', None)
|
|
111
|
+
if os.environ.get('KASSERVER_PASSWORD') == env_pass:
|
|
112
|
+
os.environ.pop('KASSERVER_PASSWORD', None)
|
|
113
|
+
|
|
114
|
+
return self._kas_client
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: certbot-dns-kas
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: All-Inkl KAS DNS Authenticator plugin for Certbot
|
|
5
|
+
Home-page: https://github.com/mobilandi/certbot-dns-kas
|
|
6
|
+
Author: Antigravity
|
|
7
|
+
Author-email: antigravity@example.com
|
|
8
|
+
License: Apache License 2.0
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Environment :: Plugins
|
|
11
|
+
Classifier: Intended Audience :: System Administrators
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
14
|
+
Classifier: Programming Language :: Python
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
22
|
+
Classifier: Topic :: Security
|
|
23
|
+
Classifier: Topic :: System :: Installation/Setup
|
|
24
|
+
Classifier: Topic :: System :: Networking
|
|
25
|
+
Classifier: Topic :: System :: Systems Administration
|
|
26
|
+
Classifier: Topic :: Utilities
|
|
27
|
+
Requires-Python: >=3.6
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: certbot>=1.18.0
|
|
30
|
+
Requires-Dist: zope.interface
|
|
31
|
+
Requires-Dist: kasserver
|
|
32
|
+
Dynamic: author
|
|
33
|
+
Dynamic: author-email
|
|
34
|
+
Dynamic: classifier
|
|
35
|
+
Dynamic: home-page
|
|
36
|
+
Dynamic: license
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
Dynamic: requires-dist
|
|
39
|
+
Dynamic: requires-python
|
|
40
|
+
Dynamic: summary
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
setup.py
|
|
4
|
+
certbot_dns_kas/__init__.py
|
|
5
|
+
certbot_dns_kas.egg-info/PKG-INFO
|
|
6
|
+
certbot_dns_kas.egg-info/SOURCES.txt
|
|
7
|
+
certbot_dns_kas.egg-info/dependency_links.txt
|
|
8
|
+
certbot_dns_kas.egg-info/entry_points.txt
|
|
9
|
+
certbot_dns_kas.egg-info/requires.txt
|
|
10
|
+
certbot_dns_kas.egg-info/top_level.txt
|
|
11
|
+
certbot_dns_kas/_internal/__init__.py
|
|
12
|
+
certbot_dns_kas/_internal/dns_kas.py
|
|
13
|
+
tests/__init__.py
|
|
14
|
+
tests/test_dns_kas.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from setuptools import setup
|
|
2
|
+
from setuptools import find_packages
|
|
3
|
+
|
|
4
|
+
setup(
|
|
5
|
+
name='certbot-dns-kas',
|
|
6
|
+
version='0.1.1',
|
|
7
|
+
description='All-Inkl KAS DNS Authenticator plugin for Certbot',
|
|
8
|
+
url='https://github.com/mobilandi/certbot-dns-kas',
|
|
9
|
+
author='Antigravity',
|
|
10
|
+
author_email='antigravity@example.com',
|
|
11
|
+
license='Apache License 2.0',
|
|
12
|
+
python_requires='>=3.6',
|
|
13
|
+
classifiers=[
|
|
14
|
+
'Development Status :: 3 - Alpha',
|
|
15
|
+
'Environment :: Plugins',
|
|
16
|
+
'Intended Audience :: System Administrators',
|
|
17
|
+
'License :: OSI Approved :: Apache Software License',
|
|
18
|
+
'Operating System :: POSIX :: Linux',
|
|
19
|
+
'Programming Language :: Python',
|
|
20
|
+
'Programming Language :: Python :: 3',
|
|
21
|
+
'Programming Language :: Python :: 3.6',
|
|
22
|
+
'Programming Language :: Python :: 3.7',
|
|
23
|
+
'Programming Language :: Python :: 3.8',
|
|
24
|
+
'Programming Language :: Python :: 3.9',
|
|
25
|
+
'Programming Language :: Python :: 3.10',
|
|
26
|
+
'Topic :: Internet :: WWW/HTTP',
|
|
27
|
+
'Topic :: Security',
|
|
28
|
+
'Topic :: System :: Installation/Setup',
|
|
29
|
+
'Topic :: System :: Networking',
|
|
30
|
+
'Topic :: System :: Systems Administration',
|
|
31
|
+
'Topic :: Utilities',
|
|
32
|
+
],
|
|
33
|
+
packages=find_packages(),
|
|
34
|
+
include_package_data=True,
|
|
35
|
+
install_requires=[
|
|
36
|
+
'certbot>=1.18.0',
|
|
37
|
+
'zope.interface',
|
|
38
|
+
'kasserver',
|
|
39
|
+
],
|
|
40
|
+
entry_points={
|
|
41
|
+
'certbot.plugins': [
|
|
42
|
+
'dns-kas = certbot_dns_kas._internal.dns_kas:Authenticator',
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import unittest
|
|
3
|
+
try:
|
|
4
|
+
from unittest import mock
|
|
5
|
+
except ImportError:
|
|
6
|
+
import mock
|
|
7
|
+
|
|
8
|
+
# from certbot.plugins import dns_test_common
|
|
9
|
+
# from certbot.plugins import dns_common_test
|
|
10
|
+
# from certbot.tests import util as test_util
|
|
11
|
+
|
|
12
|
+
from certbot_dns_kas._internal.dns_kas import Authenticator
|
|
13
|
+
|
|
14
|
+
class AuthenticatorTest(unittest.TestCase):
|
|
15
|
+
|
|
16
|
+
def setUp(self):
|
|
17
|
+
super().setUp()
|
|
18
|
+
self.config = mock.MagicMock(dns_allinkl_credentials='path/to/credentials.ini')
|
|
19
|
+
self.auth = Authenticator(self.config, 'dns-allinkl')
|
|
20
|
+
|
|
21
|
+
self.auth.credentials = mock.MagicMock()
|
|
22
|
+
self.auth.credentials.conf.side_effect = lambda x: 'mock_value'
|
|
23
|
+
|
|
24
|
+
self.mock_client = mock.MagicMock()
|
|
25
|
+
# Mock the _kas_client property or the class instantiation
|
|
26
|
+
self.auth._kas_client = self.mock_client
|
|
27
|
+
|
|
28
|
+
def test_perform(self):
|
|
29
|
+
self.auth._perform('example.com', '_acme-challenge.example.com', 'token')
|
|
30
|
+
self.mock_client.add_dns_record.assert_called_with(
|
|
31
|
+
fqdn='_acme-challenge.example.com',
|
|
32
|
+
record_type='TXT',
|
|
33
|
+
record_data='token',
|
|
34
|
+
record_aux=0
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
def test_cleanup_found(self):
|
|
38
|
+
# Setup: Mock get_dns_records to return a match
|
|
39
|
+
self.mock_client.get_dns_records.return_value = [
|
|
40
|
+
{'name': '_acme-challenge', 'type': 'MX', 'data': 'other', 'id': '99'},
|
|
41
|
+
{'name': '_acme-challenge', 'type': 'TXT', 'data': 'token', 'id': '123'},
|
|
42
|
+
{'name': 'other', 'type': 'TXT', 'data': 'token', 'id': '456'},
|
|
43
|
+
]
|
|
44
|
+
self.mock_client._split_fqdn.return_value = ('_acme-challenge', 'example.com')
|
|
45
|
+
|
|
46
|
+
self.auth._cleanup('example.com', '_acme-challenge.example.com', 'token')
|
|
47
|
+
|
|
48
|
+
# Verify loop logic found the right one
|
|
49
|
+
self.mock_client.get_dns_records.assert_called_with('example.com')
|
|
50
|
+
# Expect _request to be called with ID 123
|
|
51
|
+
self.mock_client._request.assert_called_with(
|
|
52
|
+
"delete_dns_settings", {"record_id": "123"}
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
def test_cleanup_not_found(self):
|
|
56
|
+
# Setup: No match
|
|
57
|
+
self.mock_client.get_dns_records.return_value = []
|
|
58
|
+
self.mock_client._split_fqdn.return_value = ('_acme-challenge', 'example.com')
|
|
59
|
+
|
|
60
|
+
self.auth._cleanup('example.com', '_acme-challenge.example.com', 'token')
|
|
61
|
+
|
|
62
|
+
self.mock_client._request.assert_not_called()
|
|
63
|
+
|
|
64
|
+
@mock.patch('certbot_dns_kas._internal.dns_kas.KasServer')
|
|
65
|
+
@mock.patch.dict('os.environ', {}, clear=True)
|
|
66
|
+
def test_get_kas_client(self, mock_kas):
|
|
67
|
+
self.auth._kas_client = None
|
|
68
|
+
self.auth._get_kas_client()
|
|
69
|
+
|
|
70
|
+
import os
|
|
71
|
+
# Verify credentials were used during init (via mock expectation if feasible, or relying on logic below)
|
|
72
|
+
# But crucially, verify they are GONE after the call
|
|
73
|
+
self.assertIsNone(os.environ.get('KASSERVER_USER'))
|
|
74
|
+
self.assertIsNone(os.environ.get('KASSERVER_PASSWORD'))
|
|
75
|
+
mock_kas.assert_called_once()
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if __name__ == '__main__':
|
|
79
|
+
unittest.main()
|