You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by cc...@apache.org on 2026/08/31 19:28:59 UTC
(allura) 03/03: [#8617] Cover encrypted-only tool data reads and cleanup
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch cc/8617-part2
in repository https://gitbox.apache.org/repos/asf/allura.git
commit abdd831b9e3d4b966b12bc1aaac0a1fd49c7ecbe
Author: Carlos Cruz <ca...@slashdotmedia.com>
AuthorDate: Mon Aug 31 13:14:44 2026 -0600
[#8617] Cover encrypted-only tool data reads and cleanup
---
Allura/allura/tests/model/test_auth.py | 17 ++++++++++++
.../tests/scripts/test_convert_encrypted_field.py | 30 ++++++++++++++++++++++
2 files changed, 47 insertions(+)
diff --git a/Allura/allura/tests/model/test_auth.py b/Allura/allura/tests/model/test_auth.py
index e41e36c1c..c8beaab64 100644
--- a/Allura/allura/tests/model/test_auth.py
+++ b/Allura/allura/tests/model/test_auth.py
@@ -556,6 +556,23 @@ def test_get_tool_data_can_decrypt_encrypted_value(self):
assert user.get_tool_data(
'test_tool', 'field', decrypt=True) == 'new field'
+ def test_get_tool_data_decrypts_without_plaintext(self):
+ user = M.User(
+ username='tool-data-encrypted-only-getter-test',
+ tool_data={'test_tool': {'field_encrypted': M.User.encr('field value')}},
+ )
+
+ assert user.get_tool_data('test_tool', 'field', decrypt=True) == 'field value'
+
+ def test_get_tool_data_decrypt_falls_back_to_plaintext(self):
+ user = M.User(
+ username='tool-data-plaintext-getter-test',
+ tool_data={'test_tool': {'field': 'field value'}},
+ )
+
+ assert user.get_tool_data('test_tool', 'field', decrypt=True) == 'field value'
+ assert user.get_tool_data('test_tool', 'missing', 'default', decrypt=True) == 'default'
+
def test_personal_data_fields_are_stored_encrypted_on_creation(self):
user = M.User(
username='personal-data-encrypted-create-test',
diff --git a/Allura/allura/tests/scripts/test_convert_encrypted_field.py b/Allura/allura/tests/scripts/test_convert_encrypted_field.py
index 9ede77ad5..aac046f97 100644
--- a/Allura/allura/tests/scripts/test_convert_encrypted_field.py
+++ b/Allura/allura/tests/scripts/test_convert_encrypted_field.py
@@ -20,11 +20,15 @@
from ming import schema as S
from ming.encryption import NestedEncryptedProperty
from ming.odm import FieldProperty
+from ming.odm.odmsession import ThreadLocalODMSession
+from allura import model as M
+from alluratest.controller import setup_basic_test
from scripts.convert_encrypted_field import (
_encryption_schema_info,
_encrypt_nested_array_value,
_remove_nested_array_value,
+ main,
)
@@ -92,6 +96,32 @@ def test_encryption_schema_info_rejects_dynamic_field_without_opt_in():
)
+def test_remove_unencrypted_dynamic_field_preserves_ciphertext():
+ setup_basic_test()
+ user = M.User(
+ username='dynamic-field-conversion-test',
+ tool_data={'test_tool': {
+ 'field': 'field value',
+ 'field_encrypted': M.User.encr('field value'),
+ }},
+ )
+ ThreadLocalODMSession.flush_all()
+ user_id = user._id
+
+ main(
+ 'allura.model.auth.User',
+ 'tool_data.test_tool.field',
+ remove_unencrypted=True,
+ encrypt_dynamic_field=True,
+ )
+ ThreadLocalODMSession.close_all()
+
+ user = M.User.query.get(_id=user_id)
+ raw_tool_data = user.tool_data.test_tool
+ assert 'field' not in raw_tool_data
+ assert raw_tool_data.field_encrypted == M.User.encr('field value')
+
+
def test_encrypt_nested_array_value_updates_every_item():
socialnetworks = [
{'socialnetwork': 'Mastodon', 'accounturl': 'https://example.com/@user'},