DigitalTrustCenter / sectxt

security.txt parser and validator
European Union Public License 1.2
17 stars 6 forks source link

Expiry validation fails on leap days #66

Closed mxsasha closed 9 months ago

mxsasha commented 9 months ago

The expiry check fails to run any expiry check on a leap day, like today: https://github.com/DigitalTrustCenter/sectxt/blob/27d8524/sectxt/__init__.py#L280

This should probably use now + datetime.timedelta(years=1)

The correct approach is probably expiry_line_date - datetime.datetime.now() <= datetime.timedelta(days=365).

Quick test (executed on leap day):

>>> datetime.datetime(2025, 2, 28) - datetime.datetime.now() <= datetime.timedelta(days=365)
True
>>> datetime.datetime(2025, 3, 1) - datetime.datetime.now() <= datetime.timedelta(days=365)
False
DigitalTrustCenter commented 9 months ago

Thank you for reporting this issue. Leap years did fail since it just added a 1 to the year value without accounting for these leap days. It has been improved by using the relativeDelta function on the dateutil package which does account for these leap years,

Your proposed solution would solve the breaking issue with the value error it would not be entirely correct, since it would count a year later in a leap year a day short. However it made it easier to come up with the solution that has been added now so thank you for offering a proposed solution.