Skip to content

Commit 0426f7d

Browse files
authored
Test with encryption enabled and fix key check (#774)
1 parent f33e2c0 commit 0426f7d

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

boefjes/boefjes/katalogus/tests/integration/test_sql_repositories.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from sqlalchemy.exc import OperationalError
77

88
from boefjes.config import settings
9-
from boefjes.katalogus.dependencies.encryption import IdentityMiddleware
109
from boefjes.katalogus.models import Organisation, Repository, Boefje
1110
from boefjes.katalogus.storage.interfaces import (
1211
OrganisationNotFound,
@@ -18,7 +17,7 @@
1817
from boefjes.sql.db import get_engine, SQL_BASE
1918
from boefjes.sql.organisation_storage import SQLOrganisationStorage
2019
from boefjes.sql.repository_storage import SQLRepositoryStorage
21-
from boefjes.sql.setting_storage import SQLSettingsStorage
20+
from boefjes.sql.setting_storage import SQLSettingsStorage, create_encrypter
2221
from boefjes.sql.plugin_enabled_storage import SQLPluginEnabledStorage
2322

2423

@@ -41,7 +40,7 @@ def setUp(self) -> None:
4140
session = sessionmaker(bind=self.engine)()
4241
self.organisation_storage = SQLOrganisationStorage(session, settings)
4342
self.repository_storage = SQLRepositoryStorage(session, settings)
44-
self.settings_storage = SQLSettingsStorage(session, IdentityMiddleware())
43+
self.settings_storage = SQLSettingsStorage(session, create_encrypter())
4544
self.plugin_state_storage = SQLPluginEnabledStorage(session, settings)
4645

4746
def tearDown(self) -> None:

boefjes/boefjes/sql/setting_storage.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,22 @@ def __init__(self, session: Session, encryption: EncryptMiddleware):
2525

2626
def get_by_key(self, key: str, organisation_id: str, plugin_id: str) -> str:
2727
instance = self._db_instance_by_id(organisation_id, plugin_id)
28+
values = json.loads(self.encryption.decode(instance.values))
2829

29-
if key not in instance.values:
30+
if key not in values:
3031
raise SettingsNotFound(organisation_id, plugin_id) from ObjectNotFoundException(
3132
SettingsInDB, organisation_id=organisation_id
3233
)
3334

34-
return json.loads(self.encryption.decode(instance.values))[key]
35+
return values[key]
3536

3637
def get_all(self, organisation_id: str, plugin_id: str) -> Dict[str, str]:
3738
try:
3839
instance = self._db_instance_by_id(organisation_id, plugin_id)
3940
except SettingsNotFound:
4041
return {}
4142

42-
return {key: value for key, value in json.loads(self.encryption.decode(instance.values)).items()}
43+
return json.loads(self.encryption.decode(instance.values))
4344

4445
def create(self, key: str, value, organisation_id: str, plugin_id: str) -> None:
4546
logger.info("Saving settings: %s for organisation %s", settings, organisation_id)

0 commit comments

Comments
 (0)