Skip to content

Commit

Permalink
more integration tests, bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsasha committed Jan 15, 2019
1 parent 5eba418 commit 528d995
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 20 deletions.
44 changes: 37 additions & 7 deletions irrd/integration_tests/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,42 @@

from irrd.conf import config_init, PASSWORD_HASH_DUMMY_VALUE
from irrd.utils.rpsl_samples import (SAMPLE_MNTNER, SAMPLE_PERSON, SAMPLE_KEY_CERT, SIGNED_PERSON_UPDATE_VALID,
SIGNED_PERSON_UPDATE_INVALID, object_sample_mapping)
SIGNED_PERSON_UPDATE_INVALID, SAMPLE_AS_BLOCK,
SAMPLE_AS_SET, SAMPLE_AUT_NUM, SAMPLE_DOMAIN, SAMPLE_FILTER_SET, SAMPLE_INET_RTR,
SAMPLE_INET6NUM, SAMPLE_INETNUM, SAMPLE_PEERING_SET, SAMPLE_ROLE, SAMPLE_ROUTE,
SAMPLE_ROUTE_SET, SAMPLE_ROUTE6, SAMPLE_RTR_SET)
from irrd.utils.whois_client import whois_query, whois_query_irrd
from .data import EMAIL_SMTP_PORT, EMAIL_DISCARD_MSGS_COMMAND, EMAIL_RETURN_MSGS_COMMAND, EMAIL_SEPARATOR, EMAIL_END

IRRD_ROOT_PATH = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))
sys.path.append(IRRD_ROOT_PATH)

LARGE_UPDATE = '\n\n'.join(object_sample_mapping.values())
SAMPLE_MNTNER_CLEAN = SAMPLE_MNTNER.replace('mnt-by: OTHER1-MNT,OTHER2-MNT\n', '')
LARGE_UPDATE = '\n\n'.join([
SAMPLE_AS_BLOCK,
SAMPLE_AS_SET,
SAMPLE_AUT_NUM,
SAMPLE_AUT_NUM.replace('aut-num: as065537', 'aut-num: as65538'),
SAMPLE_AUT_NUM.replace('aut-num: as065537', 'aut-num: as65539'),
SAMPLE_AUT_NUM.replace('aut-num: as065537', 'aut-num: as65540'),
SAMPLE_DOMAIN,
SAMPLE_FILTER_SET,
SAMPLE_INET_RTR,
SAMPLE_INET6NUM,
SAMPLE_INETNUM,
SAMPLE_KEY_CERT,
SAMPLE_MNTNER_CLEAN,
SAMPLE_PEERING_SET,
SAMPLE_PERSON,
SAMPLE_PERSON.replace('PERSON-TEST', 'DUMY2-TEST'),
SAMPLE_ROLE,
SAMPLE_ROUTE,
SAMPLE_ROUTE_SET,
SAMPLE_ROUTE6,
SAMPLE_RTR_SET,

])


class TestIntegration:
"""
Expand All @@ -48,7 +76,7 @@ def test_irrd_integration(self, tmpdir):
# Load a regular mntner and person into the DB, and verify
# the contents of the result.
self._submit_update(self.config_path1,
SAMPLE_MNTNER + '\n\n' + SAMPLE_PERSON + '\n\npassword: md5-password')
SAMPLE_MNTNER_CLEAN + '\n\n' + SAMPLE_PERSON + '\n\npassword: md5-password')
messages = self._retrieve_mails()
assert len(messages) == 1
mail_text = self._extract_message_body(messages[0])
Expand Down Expand Up @@ -182,7 +210,7 @@ def test_irrd_integration(self, tmpdir):
# Submit a valid delete for all our new objects.
self._submit_update(self.config_path1,
f'{SAMPLE_PERSON}delete: delete\n\n{SAMPLE_KEY_CERT}delete: delete\n\n' +
f'{SAMPLE_MNTNER}delete: delete\npassword: crypt-password\n')
f'{SAMPLE_MNTNER_CLEAN}delete: delete\npassword: crypt-password\n')
messages = self._retrieve_mails()
# Expected mails are status, mnt-nfy on mntner (2x), and notify on mntner
assert len(messages) == 4
Expand Down Expand Up @@ -241,6 +269,7 @@ def test_irrd_integration(self, tmpdir):
messages = self._retrieve_mails()
assert len(messages) == 1
mail_text = self._extract_message_body(messages[0])
print(mail_text)
assert messages[0]['Subject'] == 'SUCCESS: my subject'
assert messages[0]['From'] == 'from@example.com'
assert messages[0]['To'] == 'Sasha <sasha@example.com>'
Expand Down Expand Up @@ -277,7 +306,7 @@ def test_irrd_integration(self, tmpdir):
query_result = whois_query_irrd('127.0.0.1', port, '!iRS-TEST')
assert query_result == '192.0.2.0/24 2001:db8::/48'
query_result = whois_query_irrd('127.0.0.1', port, '!iAS-SETTEST')
assert query_result == 'AS2602 AS42909 AS49624 AS51966'
assert query_result == 'AS65537 AS65538 AS65539 AS65540'
query_result = whois_query_irrd('127.0.0.1', port, '!maut-num,as65537')
assert 'AS65537' in query_result
assert 'TEST-AS' in query_result
Expand Down Expand Up @@ -312,11 +341,11 @@ def test_irrd_integration(self, tmpdir):
assert 'ROLE-TEST' in query_result

query_result = whois_query_irrd('127.0.0.1', self.port_whois1, '!j-*')
assert query_result == 'TEST:Y:1-24:24'
assert query_result == 'TEST:Y:1-28:28'
# irrd #2 missed the first two updates from NRTM, as they were done at
# the same time and loaded from the full export
query_result = whois_query_irrd('127.0.0.1', self.port_whois2, '!j-*')
assert query_result == 'TEST:Y:3-24:24'
assert query_result == 'TEST:Y:3-28:28'

def _start_mailserver(self):
self.pidfile_mailserver = str(self.tmpdir) + '/mailserver.pid'
Expand Down Expand Up @@ -495,6 +524,7 @@ def _retrieve_mails(self):
data = s.recv(1024 * 1024)
buffer += data
buffer = buffer.split(b'\n', 1)[1]
buffer = buffer.split(EMAIL_END, 1)[0]

s.sendall(f'{EMAIL_DISCARD_MSGS_COMMAND}\r\n'.encode('ascii'))
messages = [email.message_from_string(m.strip().decode('ascii')) for m in buffer.split(EMAIL_SEPARATOR.encode('ascii'))]
Expand Down
6 changes: 3 additions & 3 deletions irrd/rpsl/tests/test_rpsl_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,16 @@ def test_parse(self):
assert not obj.messages.errors()
assert obj.pk() == "AS-SETTEST"
assert obj.referred_objects() == [
('members', ['aut-num', 'as-set'], ['AS2602', 'AS42909', 'AS51966', 'AS49624']),
('members', ['aut-num', 'as-set'], ['AS65538', 'AS65539', 'AS65540', 'AS65537']),
('admin-c', ['role', 'person'], ['PERSON-TEST']),
('tech-c', ['role', 'person'], ['PERSON-TEST']),
('mnt-by', ['mntner'], ['TEST-MNT'])
]
assert obj.source() == 'TEST'

assert obj.parsed_data['members'] == ['AS2602', 'AS42909', 'AS51966', 'AS49624']
assert obj.parsed_data['members'] == ['AS65538', 'AS65539', 'AS65540', 'AS65537']
# Field parsing will cause our object to look slightly different than the original, hence the replace()
assert obj.render_rpsl_text() == rpsl_text.replace("AS2602, AS42909, AS51966", "AS2602,AS42909,AS51966")
assert obj.render_rpsl_text() == rpsl_text.replace("AS65538, AS65539, AS65540", "AS65538,AS65539,AS65540")


class TestRPSLAutNum:
Expand Down
4 changes: 2 additions & 2 deletions irrd/updates/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,8 @@ def test_user_report(self, prepare_mocks):
as-set: AS-SETTEST
descr: description
members: AS2602,AS42909,AS51966
members: AS49624
members: AS65538,AS65539,AS65540
members: AS65537
tech-c: PERSON-TEST
admin-c: PERSON-TEST
notify: notify@example.com
Expand Down
4 changes: 2 additions & 2 deletions irrd/updates/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ def _check_reference_to_others(self, object_classes: List[str], object_pk: str,
return False

query = RPSLDatabaseQuery().sources([source]).object_classes(object_classes).rpsl_pk(object_pk)
results = self.database_handler.execute_query(query)
results = list(self.database_handler.execute_query(query))
for result in results:
self._cache.add((result['object_class'], object_pk, source))
if results:
if len(results):
return True

return False
Expand Down
10 changes: 4 additions & 6 deletions irrd/utils/rpsl_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

SAMPLE_AS_SET = """as-set: AS-SETTEST
descr: description
members: AS2602, AS42909, AS51966
members: AS49624
members: AS65538, AS65539, AS65540
members: AS65537
tech-c: PERSON-TEST
admin-c: PERSON-TEST
notify: notify@example.com
Expand Down Expand Up @@ -587,10 +587,8 @@

SAMPLE_RTR_SET = """rtr-set: rtrs-settest
descr: rtr-set test
members: router1.example.com
members: router2.example.com
members: router3.example.com
members: rtrs-other-set
members: rtr.example.com
members: rtrs-settest
remarks:
tech-c: PERSON-TEST
admin-c: PERSON-TEST
Expand Down

0 comments on commit 528d995

Please sign in to comment.