mirror of
https://github.com/internetee/registry.git
synced 2025-07-27 13:06:18 +02:00
Add admin mailers and tests to white_ips
This commit is contained in:
parent
149cbb6138
commit
f68d8e91c2
8 changed files with 45 additions and 6 deletions
|
@ -58,7 +58,7 @@ module Repp
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
uncommit_and_notify_admins(ip: ip, action: 'deleted') if ip.interfaces.include?(WhiteIp::API)
|
uncommit_and_notify_admins(ip: ip, action: 'deleted') if api_interface?(ip)
|
||||||
render_success
|
render_success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<p>This email is to inform you that an API Whitelisted IP address was deleted by Registrar Portal API user. Please review the details below:</p>
|
<p>This email is to inform you that an API Whitelisted IP address was deleted by Registrar Portal API user. Please review the details below:</p>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
|
<li>Registrar: <%= @api_user.registrar.name %></li>
|
||||||
<li>API User: <%= @api_user.username %></li>
|
<li>API User: <%= @api_user.username %></li>
|
||||||
<li>IP Address: <%= @white_ip.ipv4.presence || @white_ip.ipv6 %></li>
|
<li>IP Address: <%= @white_ip.ipv4.presence || @white_ip.ipv6 %></li>
|
||||||
<li>Interface: <%= @white_ip.interfaces.join(', ') %></li>
|
<li>Interface: <%= @white_ip.interfaces.join(', ') %></li>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
This email is to inform you about an API Whitelisted IP address change by Registrar Portal API user. Please review the details below:
|
This email is to inform you about an API Whitelisted IP address change by Registrar Portal API user. Please review the details below:
|
||||||
|
|
||||||
|
Registrar: <%= @api_user.registrar.name %>
|
||||||
API User: <%= @api_user.username %>
|
API User: <%= @api_user.username %>
|
||||||
IP Address: <%= @white_ip.ipv4.presence || @white_ip.ipv6 %>
|
IP Address: <%= @white_ip.ipv4.presence || @white_ip.ipv6 %>
|
||||||
Interface: <%= @white_ip.interfaces.join(', ') %>
|
Interface: <%= @white_ip.interfaces.join(', ') %>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<p>This email is to inform you about an API Whitelisted IP address change by Registrar Portal API user. Please review the details below:</p>
|
<p>This email is to inform you about an API Whitelisted IP address change by Registrar Portal API user. Please review the details below:</p>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
|
<li>Registrar: <%= @api_user.registrar.name %></li>
|
||||||
<li>API User: <%= @api_user.username %></li>
|
<li>API User: <%= @api_user.username %></li>
|
||||||
<li>IP Address: <%= @white_ip.ipv4.presence || @white_ip.ipv6 %></li>
|
<li>IP Address: <%= @white_ip.ipv4.presence || @white_ip.ipv6 %></li>
|
||||||
<li>Interface: <%= @white_ip.interfaces.join(', ') %></li>
|
<li>Interface: <%= @white_ip.interfaces.join(', ') %></li>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
This email is to inform you about an API Whitelisted IP address change by Registrar Portal API user. Please review the details below:
|
This email is to inform you about an API Whitelisted IP address change by Registrar Portal API user. Please review the details below:
|
||||||
|
|
||||||
|
Registrar: <%= @api_user.registrar.name %>
|
||||||
API User: <%= @api_user.username %>
|
API User: <%= @api_user.username %>
|
||||||
IP Address: <%= @white_ip.ipv4.presence || @white_ip.ipv6 %>
|
IP Address: <%= @white_ip.ipv4.presence || @white_ip.ipv6 %>
|
||||||
Interface: <%= @white_ip.interfaces.join(', ') %>
|
Interface: <%= @white_ip.interfaces.join(', ') %>
|
||||||
|
|
|
@ -16,7 +16,7 @@ class ReppV1WhiteIpsCreateTest < ActionDispatch::IntegrationTest
|
||||||
request_body = {
|
request_body = {
|
||||||
white_ip: {
|
white_ip: {
|
||||||
address: '127.1.1.1',
|
address: '127.1.1.1',
|
||||||
interfaces: ['API'],
|
interfaces: ['api'],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,13 +31,41 @@ class ReppV1WhiteIpsCreateTest < ActionDispatch::IntegrationTest
|
||||||
assert white_ip.present?
|
assert white_ip.present?
|
||||||
|
|
||||||
assert_equal(request_body[:white_ip][:address], white_ip.ipv4)
|
assert_equal(request_body[:white_ip][:address], white_ip.ipv4)
|
||||||
|
refute white_ip.committed
|
||||||
|
|
||||||
|
last_email = ActionMailer::Base.deliveries.last
|
||||||
|
assert last_email.subject.include?('Whitelisted IP Address Change Notification')
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_creates_new_white_ip_with_registrar_interface
|
||||||
|
request_body = {
|
||||||
|
white_ip: {
|
||||||
|
address: '127.1.1.1',
|
||||||
|
interfaces: ['registrar'],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
post '/repp/v1/white_ips', headers: @auth_headers, params: request_body
|
||||||
|
json = JSON.parse(response.body, symbolize_names: true)
|
||||||
|
|
||||||
|
assert_response :ok
|
||||||
|
assert_equal 1000, json[:code]
|
||||||
|
assert_equal 'Command completed successfully', json[:message]
|
||||||
|
|
||||||
|
white_ip = WhiteIp.find(json[:data][:ip][:id])
|
||||||
|
assert white_ip.present?
|
||||||
|
|
||||||
|
assert_equal(request_body[:white_ip][:address], white_ip.ipv4)
|
||||||
|
assert white_ip.committed
|
||||||
|
|
||||||
|
refute ActionMailer::Base.deliveries.last
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_validates_ip_max_count
|
def test_validates_ip_max_count
|
||||||
request_body = {
|
request_body = {
|
||||||
white_ip: {
|
white_ip: {
|
||||||
address: '2001:db8::/120',
|
address: '2001:db8::/120',
|
||||||
interfaces: ['API'],
|
interfaces: ['api'],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +83,7 @@ class ReppV1WhiteIpsCreateTest < ActionDispatch::IntegrationTest
|
||||||
request_body = {
|
request_body = {
|
||||||
white_ip: {
|
white_ip: {
|
||||||
address: '127.0.0.1',
|
address: '127.0.0.1',
|
||||||
interfaces: ['API'],
|
interfaces: ['api'],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,9 @@ class ReppV1WhiteIpsDeleteTest < ActionDispatch::IntegrationTest
|
||||||
assert_equal 1000, json[:code]
|
assert_equal 1000, json[:code]
|
||||||
assert_equal 'Command completed successfully', json[:message]
|
assert_equal 'Command completed successfully', json[:message]
|
||||||
refute WhiteIp.exists?(ip.id)
|
refute WhiteIp.exists?(ip.id)
|
||||||
|
|
||||||
|
last_email = ActionMailer::Base.deliveries.last
|
||||||
|
assert last_email.subject.include?('Whitelisted IP Address Removal Notification')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_returns_error_response_if_throttled
|
def test_returns_error_response_if_throttled
|
||||||
|
|
|
@ -16,7 +16,7 @@ class ReppV1ApiWhiteIpsUpdateTest < ActionDispatch::IntegrationTest
|
||||||
def test_updates_white_ip
|
def test_updates_white_ip
|
||||||
request_body = {
|
request_body = {
|
||||||
white_ip: {
|
white_ip: {
|
||||||
address: '127.0.0.1',
|
address: '127.0.0.2',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,11 @@ class ReppV1ApiWhiteIpsUpdateTest < ActionDispatch::IntegrationTest
|
||||||
assert_equal 'Command completed successfully', json[:message]
|
assert_equal 'Command completed successfully', json[:message]
|
||||||
|
|
||||||
ip = WhiteIp.find(json[:data][:ip][:id])
|
ip = WhiteIp.find(json[:data][:ip][:id])
|
||||||
assert_equal ip.ipv4, @white_ip.ipv4
|
assert_equal ip.ipv4, '127.0.0.2'
|
||||||
|
refute ip.committed
|
||||||
|
|
||||||
|
last_email = ActionMailer::Base.deliveries.last
|
||||||
|
assert last_email.subject.include?('Whitelisted IP Address Change Notification')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_returns_error_if_ipv4_wrong_format
|
def test_returns_error_if_ipv4_wrong_format
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue