Skip to content

Commit

Permalink
REL: 0.10.1
Browse files Browse the repository at this point in the history
  • Loading branch information
wagner-intevation committed Aug 16, 2024
1 parent 9b42fb3 commit 0c54138
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 9 deletions.
9 changes: 8 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
## 0.9.2 to 0.9.3
## 0.10.0 to 0.10.1

* ContactDB: Deleting organisations:
The comparison of the organisation data stored in the database and the
organisation data provided by the frontend now ignores empty 'expires'
entries in all annotation types.

## 0.9.2 to 0.10.0

* For the Audit log `intelmq-certbund-contact` version 0.9.5 is
required for the `audit_log` database table.
Expand Down
2 changes: 1 addition & 1 deletion checkticket_api/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='0.10.0',
version='0.10.1',

description='A hug based microservice api to check intelmq tickets',

Expand Down
32 changes: 30 additions & 2 deletions contactdb_api/contactdb_api/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@
import logging
import os
import sys
from copy import deepcopy
from typing import List, Tuple, Union
from warnings import warn

from falcon import HTTP_BAD_REQUEST, HTTP_NOT_FOUND
import hug
import psycopg2
from psycopg2.extras import RealDictCursor
from psycopg2.extras import RealDictCursor, RealDictRow

from session import session

Expand Down Expand Up @@ -923,6 +924,33 @@ def _update_org(org, username: str):
return org_id


def _compare_org(org_a: dict, org_b: dict) -> bool:
""" Compare two organisation objects for equality.
Ignores empty expire fields.
Can be extended to other fields (emtpy conditions of inhibitions, empty network objects etc)
Returns True if both organisation objects are equal,
False otherwise"""
a = deepcopy(org_a)
b = deepcopy(org_b)
for org in (a, b):
if isinstance(org, RealDictRow):
org = dict(org)
for obj_type in ('asns', 'fqdns', 'networks'):
for obj_id, obj in enumerate(org[obj_type]):
for anno_id, anno in enumerate(org[obj_type][obj_id]['annotations']):
if anno.get('expires', None) == '':
print(f'{obj_type} anno empty expires')
del org[obj_type][obj_id]['annotations'][anno_id]['expires']
for anno_id, anno in enumerate(org['annotations']):
if anno.get('expires', None) == '':
print('org anno empty expires')
del org['annotations'][anno_id]['expires']

return a == b


def _delete_org(org, username: str) -> int:
"""Delete an manual org from the contactdb.
Expand All @@ -936,7 +964,7 @@ def _delete_org(org, username: str) -> int:

org_in_db = __db_query_org(org_id_rm, "")

if not org_in_db == org:
if not _compare_org(org_in_db, org):
log.warn("org_in_db = %r; org = %r", org_in_db, org)
raise CommitError("Org to be deleted differs from db entry.")

Expand Down
2 changes: 1 addition & 1 deletion contactdb_api/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='0.10.0',
version='0.10.1',

description='A hug based microservice api to intelmq-certbund-contact.',

Expand Down
56 changes: 56 additions & 0 deletions contactdb_api/test_serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import tempfile
import unittest

from psycopg2.extras import RealDictRow
from copy import deepcopy

from contactdb_api import serve


Expand Down Expand Up @@ -127,3 +130,56 @@ def test_annotation_diff_change(self):
def test_annotation_diff_warn(self):
with self.assertWarnsRegex(UserWarning, '^_annotation_diff: Modification detection disabled for performance reasons'):
serve._annotation_diff([self.TAG_1] * 30, [], False)


ORG_DB_SIMPLE = RealDictRow([('organisation_id', 11), ('name', 'delete me'), ('sector_id', None), ('comment', ''), ('ripe_org_hdl', ''), ('ti_handle', ''), ('first_handle', ''), ('asns', []), ('contacts', []), ('national_certs', []), ('networks', []), ('fqdns', []), ('annotations', [])])
ORG_PY_SIMPLE = {'organisation_id': 11, 'name': 'delete me', 'sector_id': None, 'comment': '', 'ripe_org_hdl': '', 'ti_handle': '', 'first_handle': '', 'asns': [], 'contacts': [], 'national_certs': [], 'networks': [], 'fqdns': [], 'annotations': []}

ORG_DB_CONTACT = RealDictRow([('organisation_id', 12), ('name', 'delete me'), ('sector_id', None), ('comment', ''), ('ripe_org_hdl', ''), ('ti_handle', ''), ('first_handle', ''), ('asns', []), ('contacts', [RealDictRow([('contact_id', 58), ('firstname', ''), ('lastname', ''), ('tel', ''), ('openpgp_fpr', ''), ('email', 'abuse@example.com'), ('comment', ''), ('organisation_id', 12)])]), ('national_certs', []), ('networks', []), ('fqdns', []), ('annotations', [])])
ORG_PY_CONTACT = {'organisation_id': 12, 'name': 'delete me', 'sector_id': None, 'comment': '', 'ripe_org_hdl': '', 'ti_handle': '', 'first_handle': '', 'asns': [], 'contacts': [{'contact_id': 58, 'firstname': '', 'lastname': '', 'tel': '', 'openpgp_fpr': '', 'email': 'abuse@example.com', 'comment': '', 'organisation_id': 12}], 'national_certs': [], 'networks': [], 'fqdns': [], 'annotations': []}

ORG_DB_NETWORK_TAG = RealDictRow([('organisation_id', 13), ('name', 'delete me'), ('sector_id', None), ('comment', ''), ('ripe_org_hdl', ''), ('ti_handle', ''), ('first_handle', ''), ('asns', []), ('contacts', []), ('national_certs', []), ('networks', [RealDictRow([('network_id', 10), ('address', '10.0.0.1/32'), ('comment', ''), ('annotations', [{'tag': 'example_tag', 'expires': ''}])])]), ('fqdns', []), ('annotations', [])])
ORG_PY_NETWORK_TAG = {'organisation_id': 13, 'name': 'delete me', 'sector_id': None, 'comment': '', 'ripe_org_hdl': '', 'ti_handle': '', 'first_handle': '', 'asns': [], 'contacts': [], 'national_certs': [], 'networks': [{'network_id': 10, 'address': '10.0.0.1/32', 'comment': '', 'annotations': [{'tag': 'example_tag', 'expires': ''}]}], 'fqdns': [], 'annotations': []}
ORG_DB_NETWORK_TAG_EXPIRES = RealDictRow([('organisation_id', 13), ('name', 'delete me'), ('sector_id', None), ('comment', ''), ('ripe_org_hdl', ''), ('ti_handle', ''), ('first_handle', ''), ('asns', []), ('contacts', []), ('national_certs', []), ('networks', [RealDictRow([('network_id', 10), ('address', '10.0.0.1/32'), ('comment', ''), ('annotations', [{'tag': 'example_tag', 'expires': '2024-01-01'}])])]), ('fqdns', []), ('annotations', [])])
ORG_PY_NETWORK_TAG_EXPIRES = {'organisation_id': 13, 'name': 'delete me', 'sector_id': None, 'comment': '', 'ripe_org_hdl': '', 'ti_handle': '', 'first_handle': '', 'asns': [], 'contacts': [], 'national_certs': [], 'networks': [{'network_id': 10, 'address': '10.0.0.1/32', 'comment': '', 'annotations': [{'tag': 'example_tag', 'expires': '2024-01-01'}]}], 'fqdns': [], 'annotations': []}

ORG_DB = RealDictRow([('organisation_id', 14), ('name', 'delete me'), ('sector_id', None), ('comment', ''), ('ripe_org_hdl', ''), ('ti_handle', ''), ('first_handle', ''), ('asns', []), ('contacts', []), ('national_certs', []),
('asns', [RealDictRow([('asn', 1), ('annotations', [{'tag': 'else'}])])]),
('networks', [RealDictRow([('network_id', 11), ('address', '10.0.0.1/32'), ('comment', 'because'), ('annotations', [{'tag': 'Whitelist:Malware'}])])]),
('fqdns', [RealDictRow([('fqdn_id', 4), ('fqdn', 'example.com'), ('comment', ''), ('annotations', [{'tag': 'inhibition', 'condition': ['eq', ['event_field', 'foo'], 'bar']}])])]),
('annotations', [{'tag': 'Whitelist:All'}])])
ORG_PY = {'organisation_id': 14, 'name': 'delete me', 'sector_id': None, 'comment': '', 'ripe_org_hdl': '', 'ti_handle': '', 'first_handle': '',
'asns': [{'annotations': [{'tag': 'else'}], 'asn': 1}],
'contacts': [],
'national_certs': [],
'networks': [{'network_id': 11, 'address': '10.0.0.1/32', 'comment': 'because', 'annotations': [{'tag': 'Whitelist:Malware'}]}],
'fqdns': [{'fqdn_id': 4, 'fqdn': 'example.com', 'comment': '', 'annotations': [{'tag': 'inhibition', 'condition': ['eq', ['event_field', 'foo'], 'bar']}]}],
'annotations': [{'tag': 'Whitelist:All'}]}

ORG_PY_ASN_EXPIRES = deepcopy(ORG_PY)
ORG_PY_ASN_EXPIRES['asns'][0]['annotations'][0]['expires'] = ''
ORG_PY_FQDN_EXPIRES = deepcopy(ORG_PY)
ORG_PY_FQDN_EXPIRES['fqdns'][0]['annotations'][0]['expires'] = ''
ORG_PY_NET_EXPIRES = deepcopy(ORG_PY)
ORG_PY_NET_EXPIRES['networks'][0]['annotations'][0]['expires'] = ''
ORG_PY_ORG_EXPIRES = deepcopy(ORG_PY)
ORG_PY_ORG_EXPIRES['annotations'][0]['expires'] = ''


class TestOrgComparison(unittest.TestCase):
maxDiff = None

def test_org_equal(self):
"Simple comparisons, nothing special"
self.assertTrue(serve._compare_org(ORG_DB_SIMPLE, ORG_PY_SIMPLE))
self.assertTrue(serve._compare_org(ORG_DB_CONTACT, ORG_PY_CONTACT))
self.assertTrue(serve._compare_org(ORG_DB_NETWORK_TAG, ORG_PY_NETWORK_TAG))
self.assertTrue(serve._compare_org(ORG_DB_NETWORK_TAG_EXPIRES, ORG_PY_NETWORK_TAG_EXPIRES))
self.assertTrue(serve._compare_org(ORG_DB, ORG_PY))

def test_org_equal_expires(self):
"Tests with empty expire fields in each category"
self.assertTrue(serve._compare_org(ORG_DB, ORG_PY_ASN_EXPIRES))
self.assertTrue(serve._compare_org(ORG_DB, ORG_PY_FQDN_EXPIRES))
self.assertTrue(serve._compare_org(ORG_DB, ORG_PY_NET_EXPIRES))
self.assertTrue(serve._compare_org(ORG_DB, ORG_PY_ORG_EXPIRES))
9 changes: 9 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
intelmq-fody-backend (0.10.1) stable; urgency=medium

* ContactDB: Deleting organisations:
The comparison of the organisation data stored in the database and the
organisation data provided by the frontend now ignores empty 'expires'
entries in all annotation types.

-- Sebastian Wagner <swagner@intevation.de> Fri, 16 Aug 2024 14:06:07 +0200

intelmq-fody-backend (0.10.0-1) stable; urgency=medium

* contactdb: audit log for all annotation changes
Expand Down
2 changes: 1 addition & 1 deletion events_api/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='0.10.0',
version='0.10.1',

description='A hug based microservice api to intelmq.',

Expand Down
2 changes: 1 addition & 1 deletion session/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='0.10.0',
version='0.10.1',

description='A hug based microservice api to intelmq.',

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name='intelmq-fody-backend',
# version shall be compatible with PEP440 and as close to
# Semantic Versioning 2.0.0 as we can, to be similar to fody's versioning
version='0.10.0',
version='0.10.1',
packages=[
'checkticket_api.checkticket_api',
'contactdb_api.contactdb_api',
Expand Down
2 changes: 1 addition & 1 deletion tickets_api/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='0.10.0',
version='0.10.1',

description='A hug based microservice api to intelmq-mailgen tickets.',

Expand Down

0 comments on commit 0c54138

Please sign in to comment.