-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: replace harness with scenario (#277)
Signed-off-by: guillaume <[email protected]>
- Loading branch information
Showing
14 changed files
with
2,256 additions
and
1,721 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 |
---|---|---|
|
@@ -7,3 +7,4 @@ pytest-asyncio==0.21.2 | |
pytest-dependency | ||
pytest-operator | ||
ruff | ||
ops-scenario |
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,63 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
import datetime | ||
|
||
from charms.tls_certificates_interface.v3.tls_certificates import ( | ||
ProviderCertificate, | ||
RequirerCSR, | ||
generate_ca, | ||
generate_certificate, | ||
generate_csr, | ||
generate_private_key, | ||
) | ||
|
||
|
||
def generate_example_provider_certificate( | ||
common_name: str, | ||
relation_id: int, | ||
) -> ProviderCertificate: | ||
private_key = generate_private_key() | ||
csr = generate_csr( | ||
private_key=private_key, | ||
subject=common_name, | ||
) | ||
ca_private_key = generate_private_key() | ||
ca_certificate = generate_ca( | ||
private_key=ca_private_key, | ||
subject="ca.com", | ||
validity=365, | ||
) | ||
certificate = generate_certificate( | ||
csr=csr, | ||
ca=ca_certificate, | ||
ca_key=ca_private_key, | ||
validity=365, | ||
) | ||
|
||
provider_certificate = ProviderCertificate( | ||
application_name="vault", | ||
relation_id=relation_id, | ||
csr=csr.decode(), | ||
certificate=certificate.decode(), | ||
ca=ca_certificate.decode(), | ||
chain=[ca_certificate.decode()], | ||
revoked=False, | ||
expiry_time=datetime.datetime.now(), | ||
) | ||
return provider_certificate | ||
|
||
|
||
def generate_example_requirer_csr(common_name: str, relation_id: int) -> RequirerCSR: | ||
private_key = generate_private_key() | ||
csr = generate_csr( | ||
private_key=private_key, | ||
subject=common_name, | ||
) | ||
return RequirerCSR( | ||
relation_id=relation_id, | ||
application_name="tls-requirer", | ||
unit_name="tls-requirer/0", | ||
csr=csr.decode(), | ||
is_ca=False, | ||
) |
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,105 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
from unittest.mock import patch | ||
|
||
import pytest | ||
import scenario | ||
from charms.data_platform_libs.v0.s3 import S3Requirer | ||
from charms.vault_k8s.v0.vault_client import Vault | ||
from charms.vault_k8s.v0.vault_s3 import S3 | ||
from charms.vault_k8s.v0.vault_tls import VaultTLSManager | ||
|
||
from charm import VaultOperatorCharm | ||
|
||
|
||
class VaultCharmFixtures: | ||
patcher_tls = patch("charm.VaultTLSManager", autospec=VaultTLSManager) | ||
patcher_vault = patch("charm.Vault", autospec=Vault) | ||
patcher_s3_requirer = patch("charm.S3Requirer", autospec=S3Requirer) | ||
patcher_s3 = patch("charm.S3", autospec=S3) | ||
patcher_socket_fqdn = patch("socket.getfqdn") | ||
patcher_pki_requirer_request_certificate_creation = patch( | ||
"charm.TLSCertificatesRequiresV3.request_certificate_creation" | ||
) | ||
patcher_pki_requirer_get_assigned_certificates = patch( | ||
"charm.TLSCertificatesRequiresV3.get_assigned_certificates" | ||
) | ||
patcher_pki_provider_get_outstanding_certificate_requests = patch( | ||
"charm.TLSCertificatesProvidesV3.get_outstanding_certificate_requests" | ||
) | ||
patcher_pki_provider_set_relation_certificate = patch( | ||
"charm.TLSCertificatesProvidesV3.set_relation_certificate" | ||
) | ||
patcher_autounseal_provides_get_outstanding_requests = patch( | ||
"charm.VaultAutounsealProvides.get_outstanding_requests" | ||
) | ||
patcher_autounseal_provides_set_data = patch( | ||
"charm.VaultAutounsealProvides.set_autounseal_data" | ||
) | ||
patcher_autounseal_requires_get_details = patch("charm.VaultAutounsealRequires.get_details") | ||
patcher_kv_provides_get_outstanding_kv_requests = patch( | ||
"charm.VaultKvProvides.get_outstanding_kv_requests" | ||
) | ||
patcher_kv_provides_set_ca_certificate = patch("charm.VaultKvProvides.set_ca_certificate") | ||
patcher_kv_provides_set_egress_subnets = patch("charm.VaultKvProvides.set_egress_subnets") | ||
patcher_kv_provides_set_vault_url = patch("charm.VaultKvProvides.set_vault_url") | ||
patcher_kv_provides_get_credentials = patch("charm.VaultKvProvides.get_credentials") | ||
patcher_snap_cache = patch("charm.snap.SnapCache") | ||
patcher_machine = patch("charm.Machine") | ||
patcher_get_common_name_from_csr = patch("charm.get_common_name_from_csr") | ||
|
||
@pytest.fixture(autouse=True) | ||
def setup(self): | ||
self.mock_tls = VaultCharmFixtures.patcher_tls.start().return_value | ||
self.mock_vault = VaultCharmFixtures.patcher_vault.start().return_value | ||
self.mock_s3_requirer = VaultCharmFixtures.patcher_s3_requirer.start().return_value | ||
self.mock_s3 = VaultCharmFixtures.patcher_s3.start() | ||
self.mock_socket_fqdn = VaultCharmFixtures.patcher_socket_fqdn.start() | ||
self.mock_pki_requirer_request_certificate_creation = ( | ||
VaultCharmFixtures.patcher_pki_requirer_request_certificate_creation.start() | ||
) | ||
self.mock_pki_requirer_get_assigned_certificates = ( | ||
VaultCharmFixtures.patcher_pki_requirer_get_assigned_certificates.start() | ||
) | ||
self.mock_pki_provider_get_outstanding_certificate_requests = ( | ||
VaultCharmFixtures.patcher_pki_provider_get_outstanding_certificate_requests.start() | ||
) | ||
self.mock_pki_provider_set_relation_certificate = ( | ||
VaultCharmFixtures.patcher_pki_provider_set_relation_certificate.start() | ||
) | ||
self.mock_autounseal_provides_get_outstanding_requests = ( | ||
VaultCharmFixtures.patcher_autounseal_provides_get_outstanding_requests.start() | ||
) | ||
self.mock_autounseal_provides_set_data = ( | ||
VaultCharmFixtures.patcher_autounseal_provides_set_data.start() | ||
) | ||
self.mock_autounseal_requires_get_details = ( | ||
VaultCharmFixtures.patcher_autounseal_requires_get_details.start() | ||
) | ||
self.mock_kv_provides_get_outstanding_kv_requests = ( | ||
VaultCharmFixtures.patcher_kv_provides_get_outstanding_kv_requests.start() | ||
) | ||
self.mock_kv_provides_set_ca_certificate = ( | ||
VaultCharmFixtures.patcher_kv_provides_set_ca_certificate.start() | ||
) | ||
self.mock_kv_provides_set_egress_subnets = ( | ||
VaultCharmFixtures.patcher_kv_provides_set_egress_subnets.start() | ||
) | ||
self.mock_kv_provides_set_vault_url = ( | ||
VaultCharmFixtures.patcher_kv_provides_set_vault_url.start() | ||
) | ||
self.mock_kv_provides_get_credentials = ( | ||
VaultCharmFixtures.patcher_kv_provides_get_credentials.start() | ||
) | ||
self.mock_snap_cache = VaultCharmFixtures.patcher_snap_cache.start() | ||
self.mock_machine = VaultCharmFixtures.patcher_machine.start().return_value | ||
self.mock_get_common_name_from_csr = ( | ||
VaultCharmFixtures.patcher_get_common_name_from_csr.start() | ||
) | ||
|
||
@pytest.fixture(autouse=True) | ||
def context(self): | ||
self.ctx = scenario.Context( | ||
charm_type=VaultOperatorCharm, | ||
) |
Oops, something went wrong.