Merge pull request #2771 from internetee/ipv6-whitelist-support

feat: support IPv6 /64 range in white IP validation
This commit is contained in:
Timo Võhmar 2025-03-28 14:25:33 +02:00 committed by GitHub
commit 8d33bd5de0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 67 additions and 21 deletions

View file

@ -61,7 +61,7 @@ class ReppV1WhiteIpsCreateTest < ActionDispatch::IntegrationTest
refute ActionMailer::Base.deliveries.last
end
def test_validates_ip_max_count
def test_validates_ipv6_range
request_body = {
white_ip: {
address: '2001:db8::/120',
@ -73,7 +73,7 @@ class ReppV1WhiteIpsCreateTest < ActionDispatch::IntegrationTest
json = JSON.parse(response.body, symbolize_names: true)
assert_response :bad_request
assert json[:message].include? 'IP address limit exceeded'
assert json[:message].include? 'IPv6 address must be either a single address or a /64 range'
end
def test_returns_error_response_if_throttled

View file

@ -53,6 +53,35 @@ class WhiteIpTest < ActiveSupport::TestCase
assert_not WhiteIp.include_ip?('192.168.1.1')
end
def test_validates_ipv6_64_range
white_ip = WhiteIp.new
white_ip.registrar = registrars(:bestnames)
white_ip.ipv6 = '2001:db8::/64'
assert white_ip.valid?, 'IPv6 /64 range should be valid'
end
def test_validates_ipv6_single_address
white_ip = WhiteIp.new
white_ip.registrar = registrars(:bestnames)
white_ip.ipv6 = '2001:db8::1'
assert white_ip.valid?, 'Single IPv6 address should be valid'
end
def test_rejects_invalid_ipv6_range
white_ip = WhiteIp.new
white_ip.registrar = registrars(:bestnames)
white_ip.ipv6 = '2001:db8::/48'
assert white_ip.invalid?, 'IPv6 /48 range should be invalid'
assert_includes white_ip.errors.full_messages, 'IPv6 address must be either a single address or a /64 range'
white_ip.ipv6 = '2001:db8::/96'
assert white_ip.invalid?, 'IPv6 /96 range should be invalid'
assert_includes white_ip.errors.full_messages, 'IPv6 address must be either a single address or a /64 range'
end
private
def valid_white_ip