-
Notifications
You must be signed in to change notification settings - Fork 41
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
Fixed timestamp fields comparison #198
Conversation
Avoids raising an exception when the comparison of timestamp values gives a wrong negative validation
I'm struggling with this one a bit. Since I wasn't a maintainer when the pull request was made, I cannot force it to re-run the tests to see if the workflow failures were due an intermittent failure. Locally the tests are also failing, some for unrelated reasons, but it looks like this commit may be impacting the sightings test cases in stix2validator/test/v21/sighting_tests.py |
@chrisr3d Can you make another commit to this pull request? Perhaps update it to the latest upstream code, please. The tests failed and since the PR was made before I became maintainer, I am not allowed to request that they be re-run. But if you add another commit, then I can re-run the failed tests and get this PR added. |
I see my changes are causing an issue with the tests on invalid timestamps. |
- Checking if a timestamp is properly formatted before trying to load it as a datetime object
…ong timestamp format
- One could still be str if it is not properly formatted
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #198 +/- ##
==========================================
+ Coverage 94.45% 94.49% +0.03%
==========================================
Files 66 66
Lines 6173 6208 +35
==========================================
+ Hits 5831 5866 +35
Misses 342 342 ☔ View full report in Codecov by Sentry. |
@ejratl This makes sense for me as it was more the issue of precision in the timestamp which now should be fixed. Is it ok for you if I merge it? |
@adulau Yes, please go ahead and do merge it. I was waiting for it to pass the tests and it has done so. |
Any chance you could add a unit test or two for this? |
- Including missing tests for timestamp values format as well as tests for timestamp values comparison
…ffic - The test for the `end` and `is_active` fields is enough here as there is no check on the start and end time
I added some checks in the v2.0 validator for some timestamp properties that are also tested in v2.1 with the TIMESTAMP_COMPARE mapping. And I added unit tests for different STIX objects
|
Thank you! |
I just discovered this kind of behavior can happen when 2 timestamp values don't have the same time precision:
I did not find in the standard any rule to forbid this difference in time precision, so I guess it should be valid.
The issue comes from the python comparison operators used to compare strings, which will always consider a timestamp value with fewer digits later than the same value with more digits.
I just added an additional test to compare the datetime formatted values before raising a validation exception due to this particular behavior of the strings comparison