From 1c3c134e7ed696ab8110efb994debbe2a58b8c3e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 14 Nov 2025 12:20:56 +0000 Subject: [PATCH 1/4] Initial plan From 9ba508e6bc25adeaab9daf2a283afd874aefaf63 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 14 Nov 2025 12:30:38 +0000 Subject: [PATCH 2/4] Fix error message for managing granted secrets (owner=None) Co-authored-by: dimaqq <662249+dimaqq@users.noreply.github.com> --- testing/src/scenario/mocking.py | 4 ++-- testing/tests/test_e2e/test_secrets.py | 28 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/testing/src/scenario/mocking.py b/testing/src/scenario/mocking.py index 512de0de7..fc6b9b4d7 100644 --- a/testing/src/scenario/mocking.py +++ b/testing/src/scenario/mocking.py @@ -448,8 +448,8 @@ def _check_can_manage_secret( ): if secret.owner is None: raise SecretNotFoundError( - 'this secret is not owned by this unit/app or granted to it. ' - 'Did you forget passing it to State.secrets?', + 'this secret is not owned by this unit/app. ' + 'Did you forget to set the owner?', ) if secret.owner == 'app' and not self.is_leader(): understandable_error = SecretNotFoundError( diff --git a/testing/tests/test_e2e/test_secrets.py b/testing/tests/test_e2e/test_secrets.py index 6b07a6097..a6151e0e8 100644 --- a/testing/tests/test_e2e/test_secrets.py +++ b/testing/tests/test_e2e/test_secrets.py @@ -454,6 +454,34 @@ def post_event(charm: CharmBase): ) +def test_cannot_manage_granted_secret(mycharm): + """Test that trying to manage a granted secret (owner=None) gives a clear error message.""" + secret = Secret( + {'a': 'b'}, + label='granted_secret', + owner=None, # This is a granted secret, not owned by this unit/app + ) + secret_id = secret.id + + def post_event(charm: CharmBase): + secret = charm.model.get_secret(id=secret_id) + + # Can view the secret + assert secret.get_content()['a'] == 'b' + + # Cannot manage it - should get a clear error message + with pytest.raises(SecretNotFoundError, match='this secret is not owned by this unit/app'): + secret.set_content({'new': 'content'}) + + trigger( + State(secrets={secret}), + 'update_status', + mycharm, + meta={'name': 'local'}, + post_event=post_event, + ) + + def test_add_grant_revoke_remove(): class GrantingCharm(CharmBase): pass From cde472c853327c7f6bf97eed08cf9390ed4d05da Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 14 Nov 2025 12:34:39 +0000 Subject: [PATCH 3/4] Apply code formatting (remove trailing whitespace) Co-authored-by: dimaqq <662249+dimaqq@users.noreply.github.com> --- testing/src/scenario/mocking.py | 3 +-- testing/tests/test_e2e/test_secrets.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/testing/src/scenario/mocking.py b/testing/src/scenario/mocking.py index fc6b9b4d7..169884409 100644 --- a/testing/src/scenario/mocking.py +++ b/testing/src/scenario/mocking.py @@ -448,8 +448,7 @@ def _check_can_manage_secret( ): if secret.owner is None: raise SecretNotFoundError( - 'this secret is not owned by this unit/app. ' - 'Did you forget to set the owner?', + 'this secret is not owned by this unit/app. Did you forget to set the owner?', ) if secret.owner == 'app' and not self.is_leader(): understandable_error = SecretNotFoundError( diff --git a/testing/tests/test_e2e/test_secrets.py b/testing/tests/test_e2e/test_secrets.py index a6151e0e8..a1e1a7185 100644 --- a/testing/tests/test_e2e/test_secrets.py +++ b/testing/tests/test_e2e/test_secrets.py @@ -465,10 +465,10 @@ def test_cannot_manage_granted_secret(mycharm): def post_event(charm: CharmBase): secret = charm.model.get_secret(id=secret_id) - + # Can view the secret assert secret.get_content()['a'] == 'b' - + # Cannot manage it - should get a clear error message with pytest.raises(SecretNotFoundError, match='this secret is not owned by this unit/app'): secret.set_content({'new': 'content'}) From ab4e79e21d82a6c626c90c65d75e2a435d788253 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 15 Nov 2025 13:56:44 +0000 Subject: [PATCH 4/4] Remove new test and keep original error message hint Co-authored-by: dimaqq <662249+dimaqq@users.noreply.github.com> --- testing/src/scenario/mocking.py | 3 ++- testing/tests/test_e2e/test_secrets.py | 28 -------------------------- 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/testing/src/scenario/mocking.py b/testing/src/scenario/mocking.py index 169884409..a686edbbd 100644 --- a/testing/src/scenario/mocking.py +++ b/testing/src/scenario/mocking.py @@ -448,7 +448,8 @@ def _check_can_manage_secret( ): if secret.owner is None: raise SecretNotFoundError( - 'this secret is not owned by this unit/app. Did you forget to set the owner?', + 'this secret is not owned by this unit/app. ' + 'Did you forget passing it to State.secrets?', ) if secret.owner == 'app' and not self.is_leader(): understandable_error = SecretNotFoundError( diff --git a/testing/tests/test_e2e/test_secrets.py b/testing/tests/test_e2e/test_secrets.py index a1e1a7185..6b07a6097 100644 --- a/testing/tests/test_e2e/test_secrets.py +++ b/testing/tests/test_e2e/test_secrets.py @@ -454,34 +454,6 @@ def post_event(charm: CharmBase): ) -def test_cannot_manage_granted_secret(mycharm): - """Test that trying to manage a granted secret (owner=None) gives a clear error message.""" - secret = Secret( - {'a': 'b'}, - label='granted_secret', - owner=None, # This is a granted secret, not owned by this unit/app - ) - secret_id = secret.id - - def post_event(charm: CharmBase): - secret = charm.model.get_secret(id=secret_id) - - # Can view the secret - assert secret.get_content()['a'] == 'b' - - # Cannot manage it - should get a clear error message - with pytest.raises(SecretNotFoundError, match='this secret is not owned by this unit/app'): - secret.set_content({'new': 'content'}) - - trigger( - State(secrets={secret}), - 'update_status', - mycharm, - meta={'name': 'local'}, - post_event=post_event, - ) - - def test_add_grant_revoke_remove(): class GrantingCharm(CharmBase): pass