diff --git a/app/controllers/repp/v1/white_ips_controller.rb b/app/controllers/repp/v1/white_ips_controller.rb
index beb3cde03..c7ab1dc84 100644
--- a/app/controllers/repp/v1/white_ips_controller.rb
+++ b/app/controllers/repp/v1/white_ips_controller.rb
@@ -58,7 +58,7 @@ module Repp
return
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
end
diff --git a/app/views/mailers/white_ip_mailer/api_ip_address_deleted.html.erb b/app/views/mailers/white_ip_mailer/api_ip_address_deleted.html.erb
index 789d79bb5..fe558d5e4 100644
--- a/app/views/mailers/white_ip_mailer/api_ip_address_deleted.html.erb
+++ b/app/views/mailers/white_ip_mailer/api_ip_address_deleted.html.erb
@@ -1,6 +1,7 @@
This email is to inform you that an API Whitelisted IP address was deleted by Registrar Portal API user. Please review the details below:
+ - Registrar: <%= @api_user.registrar.name %>
- API User: <%= @api_user.username %>
- IP Address: <%= @white_ip.ipv4.presence || @white_ip.ipv6 %>
- Interface: <%= @white_ip.interfaces.join(', ') %>
diff --git a/app/views/mailers/white_ip_mailer/api_ip_address_deleted.text.erb b/app/views/mailers/white_ip_mailer/api_ip_address_deleted.text.erb
index d7554c703..73eca3594 100644
--- a/app/views/mailers/white_ip_mailer/api_ip_address_deleted.text.erb
+++ b/app/views/mailers/white_ip_mailer/api_ip_address_deleted.text.erb
@@ -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:
+Registrar: <%= @api_user.registrar.name %>
API User: <%= @api_user.username %>
IP Address: <%= @white_ip.ipv4.presence || @white_ip.ipv6 %>
Interface: <%= @white_ip.interfaces.join(', ') %>
diff --git a/app/views/mailers/white_ip_mailer/api_ip_address_updated.html.erb b/app/views/mailers/white_ip_mailer/api_ip_address_updated.html.erb
index 3e71d3253..927adc50f 100644
--- a/app/views/mailers/white_ip_mailer/api_ip_address_updated.html.erb
+++ b/app/views/mailers/white_ip_mailer/api_ip_address_updated.html.erb
@@ -1,6 +1,7 @@
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 %>
- IP Address: <%= @white_ip.ipv4.presence || @white_ip.ipv6 %>
- Interface: <%= @white_ip.interfaces.join(', ') %>
diff --git a/app/views/mailers/white_ip_mailer/api_ip_address_updated.text.erb b/app/views/mailers/white_ip_mailer/api_ip_address_updated.text.erb
index d7554c703..73eca3594 100644
--- a/app/views/mailers/white_ip_mailer/api_ip_address_updated.text.erb
+++ b/app/views/mailers/white_ip_mailer/api_ip_address_updated.text.erb
@@ -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:
+Registrar: <%= @api_user.registrar.name %>
API User: <%= @api_user.username %>
IP Address: <%= @white_ip.ipv4.presence || @white_ip.ipv6 %>
Interface: <%= @white_ip.interfaces.join(', ') %>
diff --git a/test/integration/repp/v1/white_ips/create_test.rb b/test/integration/repp/v1/white_ips/create_test.rb
index 326edbdfe..fcbe5e987 100644
--- a/test/integration/repp/v1/white_ips/create_test.rb
+++ b/test/integration/repp/v1/white_ips/create_test.rb
@@ -16,7 +16,7 @@ class ReppV1WhiteIpsCreateTest < ActionDispatch::IntegrationTest
request_body = {
white_ip: {
address: '127.1.1.1',
- interfaces: ['API'],
+ interfaces: ['api'],
},
}
@@ -31,13 +31,41 @@ class ReppV1WhiteIpsCreateTest < ActionDispatch::IntegrationTest
assert white_ip.present?
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
def test_validates_ip_max_count
request_body = {
white_ip: {
address: '2001:db8::/120',
- interfaces: ['API'],
+ interfaces: ['api'],
},
}
@@ -55,7 +83,7 @@ class ReppV1WhiteIpsCreateTest < ActionDispatch::IntegrationTest
request_body = {
white_ip: {
address: '127.0.0.1',
- interfaces: ['API'],
+ interfaces: ['api'],
},
}
diff --git a/test/integration/repp/v1/white_ips/delete_test.rb b/test/integration/repp/v1/white_ips/delete_test.rb
index e37d346e5..8300e2b4d 100644
--- a/test/integration/repp/v1/white_ips/delete_test.rb
+++ b/test/integration/repp/v1/white_ips/delete_test.rb
@@ -21,6 +21,9 @@ class ReppV1WhiteIpsDeleteTest < ActionDispatch::IntegrationTest
assert_equal 1000, json[:code]
assert_equal 'Command completed successfully', json[:message]
refute WhiteIp.exists?(ip.id)
+
+ last_email = ActionMailer::Base.deliveries.last
+ assert last_email.subject.include?('Whitelisted IP Address Removal Notification')
end
def test_returns_error_response_if_throttled
diff --git a/test/integration/repp/v1/white_ips/update_test.rb b/test/integration/repp/v1/white_ips/update_test.rb
index b04d357be..a38aba671 100644
--- a/test/integration/repp/v1/white_ips/update_test.rb
+++ b/test/integration/repp/v1/white_ips/update_test.rb
@@ -16,7 +16,7 @@ class ReppV1ApiWhiteIpsUpdateTest < ActionDispatch::IntegrationTest
def test_updates_white_ip
request_body = {
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]
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
def test_returns_error_if_ipv4_wrong_format