diff options
| author | J08nY | 2025-12-09 12:11:39 +0100 |
|---|---|---|
| committer | J08nY | 2025-12-09 12:11:39 +0100 |
| commit | e45812df9f302ab22df96ef6b19838cdd7c2fb63 (patch) | |
| tree | cff856e3dd70da372a87263e974377f1b4ae6096 | |
| parent | 25d92e603feb8a5fcf93a589d8bc29e11926a443 (diff) | |
| download | sec-certs-page.tar.gz sec-certs-page.tar.zst sec-certs-page.zip | |
Fix and add tests for new certificate subscription.page
| -rw-r--r-- | sec_certs_page/common/tasks/notify.py | 4 | ||||
| -rw-r--r-- | tests/functional/cc/test_notifications.py | 31 | ||||
| -rw-r--r-- | tests/functional/fips/test_notifications.py | 31 |
3 files changed, 64 insertions, 2 deletions
diff --git a/sec_certs_page/common/tasks/notify.py b/sec_certs_page/common/tasks/notify.py index 3bb5b697..5d26ad70 100644 --- a/sec_certs_page/common/tasks/notify.py +++ b/sec_certs_page/common/tasks/notify.py @@ -84,9 +84,9 @@ class Notifier(DiffRenderer): def _collect_usernames(self, change_dgsts, new_dgsts): change_sub_emails = mongo.db.subs.find( - {"certificate.hashid": {"$in": change_dgsts}, "certificate.type": self.collection}, + {"type": "changes", "certificate.hashid": {"$in": change_dgsts}, "certificate.type": self.collection}, ) - new_sub_emails = mongo.db.subs.find({"updates": "new", "which": self.collection}) + new_sub_emails = mongo.db.subs.find({"type": "new", "which": self.collection}) return {sub["username"] for sub in change_sub_emails} | {sub["username"] for sub in new_sub_emails} def _load_bootstrap_parsed(self): diff --git a/tests/functional/cc/test_notifications.py b/tests/functional/cc/test_notifications.py index 1c731013..1ee6b7e3 100644 --- a/tests/functional/cc/test_notifications.py +++ b/tests/functional/cc/test_notifications.py @@ -68,3 +68,34 @@ def test_cve_notification(user, mocker, subscription): else: assert m.call_count == 0 m.reset_mock() + + +@pytest.fixture() +def subscription_new(user): + sub = { + "username": user[0].username, + "timestamp": datetime.now(timezone.utc), + "type": "new", + "which": "cc", + } + res = mongo.db.subs.insert_one(sub) + sub["_id"] = res.inserted_id + yield sub + mongo.db.subs.delete_one({"_id": res.inserted_id}) + + +def test_new_certificate_notification(user, mocker, certificate, subscription_new): + user, password = user + + dgst = certificate["_id"] + diffs = list(mongo.db.cc_diff.find({"type": "new", "dgst": dgst})) + m = mocker.patch.object(mail, "send") + + for diff in diffs: + notify(str(diff["run_id"])) + for call_args in m.call_args_list: + message = call_args.args[0] + if user.email in message.recipients: + break + else: + assert False diff --git a/tests/functional/fips/test_notifications.py b/tests/functional/fips/test_notifications.py index 50708771..3c1758ef 100644 --- a/tests/functional/fips/test_notifications.py +++ b/tests/functional/fips/test_notifications.py @@ -68,3 +68,34 @@ def test_cve_notification(user, mocker, subscription): else: assert m.call_count == 0 m.reset_mock() + + +@pytest.fixture() +def subscription_new(user): + sub = { + "username": user[0].username, + "timestamp": datetime.now(timezone.utc), + "type": "new", + "which": "fips", + } + res = mongo.db.subs.insert_one(sub) + sub["_id"] = res.inserted_id + yield sub + mongo.db.subs.delete_one({"_id": res.inserted_id}) + + +def test_new_certificate_notification(user, mocker, certificate, subscription_new): + user, password = user + + dgst = certificate["_id"] + diffs = list(mongo.db.cc_diff.find({"type": "new", "dgst": dgst})) + m = mocker.patch.object(mail, "send") + + for diff in diffs: + notify(str(diff["run_id"])) + for call_args in m.call_args_list: + message = call_args.args[0] + if user.email in message.recipients: + break + else: + assert False |
