Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPKI parse tests #49

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

RPKI parse tests #49

wants to merge 4 commits into from

Conversation

jurraca
Copy link
Contributor

@jurraca jurraca commented Jan 18, 2025

Add initial tests for RPKI parsing: check that duplicates, incompletes, ROA type, and invalids are parsed correctly. Mostly, setting up a test Context and adjusting some setup.

Includes a RPKI fixture CSV and handles casting it to a rpki_raw.json file as expected by the parsing code.

rebased on #47

Copy link
Collaborator

@fjahr fjahr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a first look but will revisit once #47 is merged.

@@ -39,6 +37,12 @@ def __init__(self, args):
self.epoch = self.args.epoch
self.epoch_dir = "r" + self.args.epoch
self.epoch_datetime = repro_epoch
# This is only for testing, to set an epoch in the Test context.
# the CLI parser prevents this argument from existing without the 'reproduce' arg
elif self.args.epoch:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, couldn't we do this from outside of the context by mocking the epoch? Unless it's much more complex I would prefer not to add test specific code in the normal code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, had to do a small refactor to make this work here cfb044d.

Comment on lines +40 to +47
TEST_ARGS.epoch = epoch
context = Context(TEST_ARGS)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding to what I mentioned above, didn't test it though.

Suggested change
TEST_ARGS.epoch = epoch
context = Context(TEST_ARGS)
context = Context(TEST_ARGS)
context.epoch = epoch
context.epoch_dir = epoch
context.epoch_datetime = datetime.utcfromtimestamp(int(epoch))

kartograf/context.py Outdated Show resolved Hide resolved
@fjahr
Copy link
Collaborator

fjahr commented Jan 19, 2025

Needs rebase now that #47 is merged

@jurraca jurraca force-pushed the rpki-parse-tests branch 2 times, most recently from 8eaa02c to b2a23ff Compare January 21, 2025 17:14
@jurraca
Copy link
Contributor Author

jurraca commented Jan 21, 2025

I was intending to introduce just RPKI test fixtures here, but now each commit has some fairly independent changes in it:

  • changing f-strings to os.path.join should be harmless, just prevents us from having to manually set / path delimiters when creating paths.
  • cfb044d includes the RPKI fixtures and tests that check the parsing for those fixtures. In order to do so, it introduces a test Context in tests/context.py. It also modifies the epoch handling in the parsing code, in order to be able to mock it properly in this test context. (let me know if it makes sense to split this up).
  • b2a23ff fixes the path in the test context to properly create test data in the tmp_path.

Copy link
Collaborator

@fjahr fjahr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good, leaving a few comments that are mostly non-essential but the util file should be moved to the folder and renamed.

Don't forget to take it out of draft when you think it could be ready to merge.

tests/util.py Outdated
@@ -0,0 +1,9 @@
'''
Utilities for testing purposes only.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we now have a tests/util folder, this file location is probably influenced by an older state of the codebase.

If doing a reproduction run, we will prepend the directory name with a "r"
to separate it from the original run directory.
'''
if self.reproduce and self.args.epoch:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: sometimes using self.epoch and sometimes self.args.epoch in this function

rsync://rpki.arin.net/repository/arin-rpki-ta/5e4a23ea-e80a-403e-b08c-2171da2157d3/f60c9f32-a87c-4339-a2f3-6299a3b02e29/1146938c-c605-4779-bf60-820a16fa701c/8f6916d463bfc5c35e4659c12889a337f3cc6f6b7fe978372b.cer,86:A9:90:76:61:0E:7C:08:AE:DD:CE:87:67:AA:5D:C4:52:8C:49:08,/CN=8f6916d463bfc5c35e4659c12889a337f3cc6f6b7fe978372b,775EA3FF97551B8DAB1870EE20B90C6D38AFE3F3,unable to get local issuer certificate,/home/kartograf/data/1730210400/rpki/cache/rpki.tools.westconnect.ca/repo/WestConnect-Pub/0/32332e3135342e38312e302f32342d3234203d3e203533333536.roa,7pPxkgwX/p8qZcZ4U4B6r43qRmLaDzJ9eipWTWYXVgQ=,rsync://rpki.tools.westconnect.ca/repo/WestConnect-Pub/0/32332e3135342e38312e302f32342d3234203d3e203533333536.roa,1702699880,98:23:C0:CD:73:C0:73:4B:88:4C:8E:A2:FE:FC:94:59:27:54:FC:CF,roa,1702699580,1734149480,OK,23.154.81.0/24,53356,24,valid
rsync://rpki.arin.net/repository/arin-rpki-ta/5e4a23ea-e80a-403e-b08c-2171da2157d3/f60c9f32-a87c-4339-a2f3-6299a3b02e29/1146938c-c605-4779-bf60-820a16fa701c/8f6916d463bfc5c35e4659c12889a337f3cc6f6b7fe978372b.cer,86:A9:90:76:61:0E:7C:08:AE:DD:CE:87:67:AA:5D:C4:52:8C:49:08,/CN=8f6916d463bfc5c35e4659c12889a337f3cc6f6b7fe978372b,66D4203E6D324EDF7DB13F151CE102BE0DBE1200,unable to get local issuer certificate,/home/kartograf/data/1730210400/rpki/cache/rpki.tools.westconnect.ca/repo/WestConnect-Pub/0/32332e3135342e38312e302f32342d3234203d3e20333936353033.roa,Wfz/lTUfLoaYSWzIWHHqfxFY68pwclupNoh7qMD/dy4=,rsync://rpki.tools.westconnect.ca/repo/WestConnect-Pub/0/32332e3135342e38312e302f32342d3234203d3e20333936353033.roa,1721069363,EF:A6:FD:C7:47:52:EA:52:97:81:CB:E6:BC:08:E1:89:74:01:CE:54,roa,1721069063,1752518963,OK,23.154.81.0/24,396503,24,duplicate of row above
rsync://rpki.arin.net/repository/arin-rpki-ta/5e4a23ea-e80a-403e-b08c-2171da2157d3/f60c9f32-a87c-4339-a2f3-6299a3b02e29/1146938c-c605-4779-bf60-820a16fa701c/8f6916d463bfc5c35e4659c12889a337f3cc6f6b7fe978372b.cer,86:A9:90:76:61:0E:7C:08:AE:DD:CE:87:67:AA:5D:C4:52:8C:49:08,/CN=8f6916d463bfc5c35e4659c12889a337f3cc6f6b7fe978372b,35802871A8C539AD5A498BEDDDEF0D3F70E27D85,unable to get local issuer certificate,/home/kartograf/data/1730210400/rpki/cache/rpki.tools.westconnect.ca/repo/WestConnect-Pub/0/32332e3135342e38302e302f32342d3234203d3e20323133313836.roa,5DOfCcd4V1zI0oWAJNiXnZVa/zwdfo+24eD0OBlrFy4=,rsync://rpki.tools.westconnect.ca/repo/WestConnect-Pub/0/32332e3135342e38302e302f32342d3234203d3e20323133313836.roa,1721921309,BA:47:CE:B1:56:FB:2F:78:B5:37:B4:63:10:F4:17:1F:BB:2C:6A:FB,err,1721921009,1753370909,OK,23.154.80.0/24,213186,24,type is not “roa”
rsync://rpki.arin.net/repository/arin-rpki-ta/5e4a23ea-e80a-403e-b08c-2171da2157d3/f60c9f32-a87c-4339-a2f3-6299a3b02e29/1146938c-c605-4779-bf60-820a16fa701c/8f6916d463bfc5c35e4659c12889a337f3cc6f6b7fe978372b.cer,86:A9:90:76:61:0E:7C:08:AE:DD:CE:87:67:AA:5D:C4:52:8C:49:08,/CN=8f6916d463bfc5c35e4659c12889a337f3cc6f6b7fe978372b,77C98DB3245AF48F037FF77D087EB06EC63AAC8D,unable to get local issuer certificate,/home/kartograf/data/1730210400/rpki/cache/rpki.tools.westconnect.ca/repo/WestConnect-Pub/0/3135382e35312e3131322e302f32342d3234203d3e20333936353033.roa,/pHsoAr4Krm+kx64aCsYjFRuk+JnfbiC6JA9UWV27TQ=,rsync://rpki.tools.westconnect.ca/repo/WestConnect-Pub/0/3135382e35312e3131322e302f32342d3234203d3e20333936353033.roa,1721069362,C5:65:B7:B3:AA:F9:59:32:0B:F5:50:24:70:01:09:71:4D:FC:20:24,roa,1721069062,1752518962,Failed,158.51.112.0/24,396503,24,failed validation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I am usually in favor of keeping realistic data in the fixtures but since the rsync and file paths are pretty long and make this file much harder to parse, I would maybe replace them with dummy values. But up to you!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea i'll fix this in a follow up. I used existing examples for authenticity's sake.

@@ -9,14 +9,14 @@ class Context:
def __init__(self, args):
self.args = args

# The epoch is used to keep artifacts seperated for each run. This
# The epoch is used to keep artifacts separated for each run. This
# makes cleanup and debugging easier.
if args.wait:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could update this to self.args.wait


if os.path.exists(self.data_dir) and not self.reproduce:
print("Not so fast, a folder with that epoch already exists.")
sys.exit()

self.data_dir_irr = os.path.join(self.data_dir, "irr")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of os.path.join could use Pathlib here too

@jurraca jurraca force-pushed the rpki-parse-tests branch 2 times, most recently from 2140739 to 79396c0 Compare January 30, 2025 15:19
@jurraca jurraca force-pushed the rpki-parse-tests branch 2 times, most recently from 8f15280 to 261b317 Compare January 30, 2025 16:14
@jurraca
Copy link
Contributor Author

jurraca commented Jan 30, 2025

I moved the pathlib / os.path changes to #54 for clarity, this PR is rebase on that, so let's merge that first. still many follow ups to be had with this, mainly in terms of fixtures and parsing scenarios...

@jurraca jurraca marked this pull request as ready for review January 30, 2025 16:15
@jurraca
Copy link
Contributor Author

jurraca commented Feb 3, 2025

do not merge yet -- found a bug #56

@jurraca
Copy link
Contributor Author

jurraca commented Feb 4, 2025

rebased on #56 , which should go first.

set up a test context to use with pytest's tmp_path
refactor epoch dir setup in order to handle mocking it.
Add a rpki_raw.json fixture, and a tests/util.py module.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants