Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into renovate/ubuntu-24.x
Browse files Browse the repository at this point in the history
  • Loading branch information
amandahla committed Nov 19, 2024
2 parents 8a3eeba + ad0ce66 commit 4ea4799
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions .trivyignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ CVE-2023-45288
CVE-2024-24790
CVE-2024-29415
CVE-2024-34156
CVE-2024-21538
6 changes: 3 additions & 3 deletions src-docs/saml_observer.py.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The SAML integrator relation observer.
## <kbd>class</kbd> `SAMLObserver`
The SAML Integrator relation observer.

<a href="../src/saml_observer.py#L24"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/saml_observer.py#L25"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `__init__`

Expand All @@ -39,7 +39,7 @@ Shortcut for more simple access the model.

---

<a href="../src/saml_observer.py#L35"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/saml_observer.py#L39"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `get_charm`

Expand All @@ -56,7 +56,7 @@ Return the current charm.

---

<a href="../src/saml_observer.py#L54"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/saml_observer.py#L69"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `get_relation_as_saml_conf`

Expand Down
15 changes: 15 additions & 0 deletions src/saml_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import ops
from charms.saml_integrator.v0.saml import SamlDataAvailableEvent, SamlRequires
from ops.charm import RelationBrokenEvent
from ops.framework import Object

from charm_state import CharmBaseWithState, CharmState, inject_charm_state
Expand All @@ -31,6 +32,9 @@ def __init__(self, charm: CharmBaseWithState):
self._charm = charm
self.saml = SamlRequires(self._charm)
self.framework.observe(self.saml.on.saml_data_available, self._on_saml_data_available)
self.framework.observe(
charm.on[self.saml.relation_name].relation_broken, self._on_relation_broken
)

def get_charm(self) -> CharmBaseWithState:
"""Return the current charm.
Expand All @@ -51,6 +55,17 @@ def _on_saml_data_available(self, _: SamlDataAvailableEvent, charm_state: CharmS
logger.debug("_on_saml_data_available emitting reconcile")
self.get_charm().reconcile(charm_state)

@inject_charm_state
def _on_relation_broken(self, _: RelationBrokenEvent, charm_state: CharmState) -> None:
"""Handle SAML data available.
Args:
charm_state: The charm state.
"""
self.model.unit.status = ops.MaintenanceStatus("Reloading homeserver configuration")
logger.debug("_on_relation_broken emitting reconcile")
self.get_charm().reconcile(charm_state)

def get_relation_as_saml_conf(self) -> typing.Optional[SAMLConfiguration]:
"""Get SAML data from relation.
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import io
import json
import typing
from unittest.mock import MagicMock

import ops
Expand Down Expand Up @@ -473,3 +474,22 @@ def test_redis_enabled_reconcile_pebble_error(

assert isinstance(harness.model.unit.status, ops.BlockedStatus)
assert error_message in str(harness.model.unit.status)


def test_saml_on_relation_broken(
saml_configured: Harness, monkeypatch: pytest.MonkeyPatch
) -> None:
"""
arrange: start the Synapse charm with saml integration, set server_name, mock pebble.
act: remove the saml integration.
assert: Synapse charm should correctly reconcile.
"""
harness = saml_configured
harness.begin()
reconcile_mock = MagicMock()
monkeypatch.setattr(pebble, "reconcile", reconcile_mock)

relation = typing.cast(ops.model.Relation, harness.model.get_relation("saml"))
harness.remove_relation(relation.id)

reconcile_mock.assert_called_once()

0 comments on commit 4ea4799

Please sign in to comment.