-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add guard to recreate certificates on KV mismatch (#604)
* Add guard to recreate certificates on KV mismatch * Use spesific message * Add test
- Loading branch information
Showing
3 changed files
with
73 additions
and
2 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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import asyncio | ||
from datetime import timedelta | ||
from ssl import SSLError | ||
from unittest.mock import patch | ||
|
||
from acme import client, messages | ||
|
@@ -1032,3 +1033,56 @@ async def reset_acme(self): | |
assert remote._certificate_status is CertificateStatus.ERROR | ||
|
||
await remote.stop() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("reason", "should_reset"), | ||
( | ||
( | ||
"KEY_VALUES_MISMATCH", | ||
True, | ||
), | ||
( | ||
"Boom", | ||
False, | ||
), | ||
), | ||
) | ||
async def test_context_error_handling( | ||
auth_cloud_mock, | ||
mock_cognito, | ||
valid_acme_mock, | ||
aioclient_mock, | ||
snitun_mock, | ||
reason, | ||
should_reset, | ||
): | ||
"""Test that we reset if we hit an error reason that require resetting.""" | ||
auth_cloud_mock.servicehandlers_server = "test.local" | ||
|
||
remote = RemoteUI(auth_cloud_mock) | ||
|
||
aioclient_mock.post( | ||
"https://test.local/instance/register", | ||
json={ | ||
"domain": "test.dui.nabu.casa", | ||
"email": "[email protected]", | ||
"server": "rest-remote.nabu.casa", | ||
}, | ||
) | ||
|
||
ssl_error = SSLError() | ||
ssl_error.reason = reason | ||
|
||
with patch( | ||
"hass_nabucasa.remote.RemoteUI._create_context", | ||
side_effect=ssl_error, | ||
): | ||
assert remote._certificate_status is None | ||
await remote.load_backend() | ||
|
||
await asyncio.sleep(0.1) | ||
assert remote._acme.call_reset == should_reset | ||
assert remote._certificate_status is CertificateStatus.ERROR | ||
|
||
await remote.stop() |