mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-10 18:23:01 -04:00
Merge pull request #149 from GSA/graceful-encryption-errors
Gracefully handle decryption errors in past-7-days notification reports
This commit is contained in:
+7
-1
@@ -3,6 +3,9 @@ import itertools
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from flask import current_app, url_for
|
from flask import current_app, url_for
|
||||||
|
from notifications_utils.clients.encryption.encryption_client import (
|
||||||
|
EncryptionError,
|
||||||
|
)
|
||||||
from notifications_utils.insensitive_dict import InsensitiveDict
|
from notifications_utils.insensitive_dict import InsensitiveDict
|
||||||
from notifications_utils.letter_timings import get_letter_timings
|
from notifications_utils.letter_timings import get_letter_timings
|
||||||
from notifications_utils.postal_address import (
|
from notifications_utils.postal_address import (
|
||||||
@@ -1512,7 +1515,10 @@ class Notification(db.Model):
|
|||||||
@property
|
@property
|
||||||
def personalisation(self):
|
def personalisation(self):
|
||||||
if self._personalisation:
|
if self._personalisation:
|
||||||
return encryption.decrypt(self._personalisation)
|
try:
|
||||||
|
return encryption.decrypt(self._personalisation)
|
||||||
|
except EncryptionError:
|
||||||
|
current_app.logger.error("Error decrypting notification.personalisation, returning empty dict")
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
@personalisation.setter
|
@personalisation.setter
|
||||||
|
|||||||
@@ -160,6 +160,13 @@ def test_notification_personalisation_getter_always_returns_empty_dict(notify_ap
|
|||||||
assert noti.personalisation == {}
|
assert noti.personalisation == {}
|
||||||
|
|
||||||
|
|
||||||
|
def test_notification_personalisation_getter_returns_empty_dict_for_encryption_errors(notify_app):
|
||||||
|
noti = Notification()
|
||||||
|
# old _personalisation values were created with encryption.sign, which will trigger a decryption error
|
||||||
|
noti._personalisation = encryption.sign({"value": "PII"})
|
||||||
|
assert noti.personalisation == {}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('input_value', [
|
@pytest.mark.parametrize('input_value', [
|
||||||
None,
|
None,
|
||||||
{}
|
{}
|
||||||
|
|||||||
Reference in New Issue
Block a user