Add validator for IP address/inet columns
What does this MR do?
Adds an IP Address validator, for use alongside the PostgreSQL inet
column type.
I wanted to add this validator as part of !39652 (merged), but the MR would have been too lengthy. I decided it wasn't a necessary piece to the MVC and followed up on that here.
When using column type inet
Rails will silently return the value as nil
when the value is not valid according to its type cast
using IpAddr
. See https://github.com/rails/rails/pull/11574#issuecomment-21453340 for the PR and comment which suggested this behavior. I guess it is also the case for created_at/updated_at timestamps, although it's not as common to validate those so I have never encountered this before.
It's not very user friendly to return an error
"IP Address can't be blank" when a value was clearly given but
was not the right format. This validator will look at the value
before Rails type casts it when the value itself is nil
.
This enables the validator to return a specific and useful error message.
Screenshots
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team