-
Notifications
You must be signed in to change notification settings - Fork 39
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
Validate IP addresses in alert profiles #2649
Validate IP addresses in alert profiles #2649
Conversation
846ee92
to
3b9f306
Compare
Codecov Report
@@ Coverage Diff @@
## 5.6.x #2649 +/- ##
==========================================
+ Coverage 54.13% 54.24% +0.11%
==========================================
Files 558 558
Lines 40641 40667 +26
==========================================
+ Hits 22000 22059 +59
+ Misses 18641 18608 -33
... and 2 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Validation of IP addresses now works, both for a single one as well as multiple. But while adding form validation for that I broke being able to select multiple options of a given list (e.g. AlertType). Because now when trying to access that list of chosen alert types in |
More context please so I can reproduce. Is this caught by a test? What do you expect to be in |
It is not caught by a test yet. To reproduce follow the following steps:
|
I have now added a test that reproduces the error. Hope that helps |
Kudos, SonarCloud Quality Gate passed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm glad you're doing this cleanup :)
validated_ip_addresses = [] | ||
for ip in ip_list: | ||
try: | ||
IP(ip) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I would advise against using IPy.IP
for validation of strings, precisely because this library is extremely lenient in what is considered acceptable as input.
Case in point:
>>> from IPy import IP
>>> IP(42)
IP('0.0.0.42')
>>> IP('42')
IP('42.0.0.0')
>>> IP(23948234)
IP('1.109.107.202')
>> IP('100.200')
IP('100.200.0.0')
>>>
Please consider using nav.utils.is_valid_ip()
instead (possibly with the strict
flag set).
# If input was a IP adress we should replace space with | (pipe). | ||
# FIXME We might want some data checks here | ||
if match_field.data_type == MatchField.IP: | ||
# FIXME We might want to check that it is a valid IP adress. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, I love the fact that there was a FIXME comment here from before 😆
Replaced by #2667 |
Closes #1876