From 2a4995226f269062eb2f13f1bca73426e9a1a857 Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Wed, 3 Oct 2018 16:34:26 +0300 Subject: [PATCH] Expand on the response about registrar and nameservers * Return website for registrar * Return IPv4 and IPv6 addresses for nameservers --- doc/registrant-api/v1/domain.md | 51 +++++++++++++++---- doc/registrant-api/v1/registry_lock.md | 34 ++++++++++--- lib/serializers/registrant_api/domain.rb | 20 +++++++- test/fixtures/nameservers.yml | 10 ++++ test/fixtures/registrars.yml | 3 +- .../registrant/registrant_api_domains_test.rb | 4 +- .../registrant_api_registry_locks_test.rb | 6 ++- .../serializers/registrant_api/domain_test.rb | 18 +++++-- 8 files changed, 121 insertions(+), 25 deletions(-) diff --git a/doc/registrant-api/v1/domain.md b/doc/registrant-api/v1/domain.md index 5a4e866be..ec32772df 100644 --- a/doc/registrant-api/v1/domain.md +++ b/doc/registrant-api/v1/domain.md @@ -22,7 +22,10 @@ Content-Type: application/json { "id": "98d1083a-8863-4153-93e4-caee4a013535", "name": "domain0.ee", - "registrar": "Best Names", + "registrar": { + "name": "Best Names", + "website": "example.com" + }, "registered_at": "2015-09-09T09:11:14.861Z", "valid_to": "2016-09-09T09:11:14.861Z", "registrant_id": 1, @@ -49,8 +52,16 @@ Content-Type: application/json "ok" ], "nameservers": [ - "ns1.bestnames.test", - "ns2.bestnames.test" + { + "hostname": "ns1.bestnames.test", + "ipv4": ["173.245.58.41"], + "ipv6": ["2400:cb00:2049:1::adf5:3a33"] + }, + { + "hostname": "ns1.bestnames.test", + "ipv4": ["173.245.58.51"], + "ipv6": ["2400:cb00:2049:1::adf5:3b29"] + }, ], "reserved": false, "status_notes": {}, @@ -91,7 +102,10 @@ Content-Type: application/json { "id": "98d1083a-8863-4153-93e4-caee4a013535", "name": "domain0.ee", - "registrar": "Best Names", + "registrar": { + "name": "Best Names", + "website": "example.com" + }, "valid_to": "2016-09-09T09:11:14.861Z", "registered_at": "2015-09-09T09:11:14.861Z", "registrant_id": 1, @@ -118,8 +132,16 @@ Content-Type: application/json "ok" ], "nameservers": [ - "ns1.bestnames.test", - "ns2.bestnames.test" + { + "hostname": "ns1.bestnames.test", + "ipv4": ["173.245.58.41"], + "ipv6": ["2400:cb00:2049:1::adf5:3a33"] + }, + { + "hostname": "ns1.bestnames.test", + "ipv4": ["173.245.58.51"], + "ipv6": ["2400:cb00:2049:1::adf5:3b29"] + }, ], "reserved": false, "status_notes": {}, @@ -151,7 +173,10 @@ Content-Type: application/json { "id": "98d1083a-8863-4153-93e4-caee4a013535", "name": "domain0.ee", - "registrar": "Best Names", + "registrar": { + "name": "Best Names", + "website": "example.com" + }, "registered_at": "2015-09-09T09:11:14.861Z", "valid_to": "2016-09-09T09:11:14.861Z", "registrant_id": 1, @@ -178,8 +203,16 @@ Content-Type: application/json "ok" ], "nameservers": [ - "ns1.bestnames.test", - "ns2.bestnames.test" + { + "hostname": "ns1.bestnames.test", + "ipv4": ["173.245.58.41"], + "ipv6": ["2400:cb00:2049:1::adf5:3a33"] + }, + { + "hostname": "ns1.bestnames.test", + "ipv4": ["173.245.58.51"], + "ipv6": ["2400:cb00:2049:1::adf5:3b29"] + }, ], "reserved": false, "status_notes": {}, diff --git a/doc/registrant-api/v1/registry_lock.md b/doc/registrant-api/v1/registry_lock.md index 956719ac2..1b0dd828b 100644 --- a/doc/registrant-api/v1/registry_lock.md +++ b/doc/registrant-api/v1/registry_lock.md @@ -21,7 +21,10 @@ Content-Type: application/json { "id": "98d1083a-8863-4153-93e4-caee4a013535", "name": "domain0.ee", - "registrar": "Best Names", + "registrar": { + "name": "Best Names", + "website": "example.com" + }, "registered_at": "2015-09-09T09:11:14.861Z", "valid_to": "2016-09-09T09:11:14.861Z", "registrant_id": 1, @@ -50,8 +53,16 @@ Content-Type: application/json "serverTransferProhibited" ], "nameservers": [ - "ns1.bestnames.test", - "ns2.bestnames.test" + { + "hostname": "ns1.bestnames.test", + "ipv4": ["173.245.58.41"], + "ipv6": ["2400:cb00:2049:1::adf5:3a33"] + }, + { + "hostname": "ns1.bestnames.test", + "ipv4": ["173.245.58.51"], + "ipv6": ["2400:cb00:2049:1::adf5:3b29"] + }, ], "reserved": false, "status_notes": {}, @@ -118,7 +129,10 @@ Content-Type: application/json { "id": "98d1083a-8863-4153-93e4-caee4a013535", "name": "domain0.ee", - "registrar": "Best Names", + "registrar": { + "name": "Best Names", + "website": "example.com" + }, "registered_at": "2015-09-09T09:11:14.861Z", "valid_to": "2016-09-09T09:11:14.861Z", "registrant_id": 1, @@ -145,8 +159,16 @@ Content-Type: application/json "ok" ], "nameservers": [ - "ns1.bestnames.test", - "ns2.bestnames.test" + { + "hostname": "ns1.bestnames.test", + "ipv4": ["173.245.58.41"], + "ipv6": ["2400:cb00:2049:1::adf5:3a33"] + }, + { + "hostname": "ns1.bestnames.test", + "ipv4": ["173.245.58.51"], + "ipv6": ["2400:cb00:2049:1::adf5:3b29"] + }, ], "reserved": false, "status_notes": {}, diff --git a/lib/serializers/registrant_api/domain.rb b/lib/serializers/registrant_api/domain.rb index 02dbbca64..b2490e04b 100644 --- a/lib/serializers/registrant_api/domain.rb +++ b/lib/serializers/registrant_api/domain.rb @@ -11,7 +11,10 @@ module Serializers { id: @domain.uuid, name: @domain.name, - registrar: @domain.registrar.name, + registrar: { + name: @domain.registrar.name, + website: @domain.registrar.website, + }, registered_at: @domain.registered_at, valid_to: @domain.valid_to, created_at: @domain.created_at, @@ -37,9 +40,22 @@ module Serializers locked_by_registrant_at: @domain.locked_by_registrant_at, reserved: @domain.reserved, status_notes: @domain.status_notes, - nameservers: @domain.nameservers.map(&:hostname), + nameservers: nameservers, } end + + private + + def nameservers + array_of_nameservers = Array.new + + @domain.nameservers.map do |nameserver| + array_of_nameservers << { hostname: nameserver.hostname, ipv4: nameserver.ipv4, + ipv6: nameserver.ipv6 } + end + + array_of_nameservers + end end end end diff --git a/test/fixtures/nameservers.yml b/test/fixtures/nameservers.yml index 344f7894d..97e2a3c1c 100644 --- a/test/fixtures/nameservers.yml +++ b/test/fixtures/nameservers.yml @@ -16,10 +16,20 @@ shop_ns2: airport_ns1: hostname: ns1.bestnames.test + ipv4: + - 192.0.2.2 + ipv6: + - 2001:db8::2 domain: airport airport_ns2: hostname: ns2.bestnames.test + ipv4: + - 192.0.2.0 + - 192.0.2.3 + - 192.0.2.1 + ipv6: + - 2001:db8::1 domain: airport metro_ns1: diff --git a/test/fixtures/registrars.yml b/test/fixtures/registrars.yml index d3d6b1c20..038046220 100644 --- a/test/fixtures/registrars.yml +++ b/test/fixtures/registrars.yml @@ -11,6 +11,7 @@ bestnames: accounting_customer_code: bestnames language: en billing_email: billing@example.com + website: bestnames.test goodnames: name: Good Names @@ -41,4 +42,4 @@ complete: language: en vat_no: US12345 vat_rate: 0.05 - billing_email: billing@bestnames.test \ No newline at end of file + billing_email: billing@bestnames.test diff --git a/test/integration/api/registrant/registrant_api_domains_test.rb b/test/integration/api/registrant/registrant_api_domains_test.rb index 3195514de..51ca403b0 100644 --- a/test/integration/api/registrant/registrant_api_domains_test.rb +++ b/test/integration/api/registrant/registrant_api_domains_test.rb @@ -30,7 +30,7 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest assert_equal('hospital.test', domain[:name]) assert_equal('5edda1a5-3548-41ee-8b65-6d60daf85a37', domain[:id]) - assert_equal('Good Names', domain[:registrar]) + assert_equal({ name: 'Good Names', website: nil }, domain[:registrar]) assert_equal([], domain[:nameservers]) assert(domain.has_key?(:locked_by_registrant_at)) end @@ -52,7 +52,7 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest assert(array_of_domain_names.include?('hospital.test')) array_of_domain_registrars = response_json.map { |x| x[:registrar] } - assert(array_of_domain_registrars.include?('Good Names')) + assert(array_of_domain_registrars.include?({name: 'Good Names', website: nil})) end def test_root_accepts_limit_and_offset_parameters diff --git a/test/integration/api/registrant/registrant_api_registry_locks_test.rb b/test/integration/api/registrant/registrant_api_registry_locks_test.rb index 846bcb8e5..b028acc90 100644 --- a/test/integration/api/registrant/registrant_api_registry_locks_test.rb +++ b/test/integration/api/registrant/registrant_api_registry_locks_test.rb @@ -129,8 +129,10 @@ class RegistrantApiRegistryLocksTest < ApplicationIntegrationTest assert_equal(200, response.status) response_json = JSON.parse(response.body, symbolize_names: true) - assert_equal('Best Names', response_json[:registrar]) - assert_equal(['ns1.bestnames.test', 'ns2.bestnames.test'].to_set, + assert_equal({ name: 'Best Names', website: 'bestnames.test' }, response_json[:registrar]) + assert_equal( + [{hostname: 'ns1.bestnames.test', ipv4: ['192.0.2.1'], ipv6: ['2001:db8::1']}, + {hostname: 'ns2.bestnames.test', ipv4: ['192.0.2.2'], ipv6: ['2001:db8::2']}].to_set, response_json[:nameservers].to_set) assert_equal(Time.zone.parse('2010-07-05'), response_json[:locked_by_registrant_at]) end diff --git a/test/lib/serializers/registrant_api/domain_test.rb b/test/lib/serializers/registrant_api/domain_test.rb index 6a9b552d1..2408283be 100644 --- a/test/lib/serializers/registrant_api/domain_test.rb +++ b/test/lib/serializers/registrant_api/domain_test.rb @@ -25,12 +25,24 @@ class SerializersRegistrantApiDomainTest < ApplicationIntegrationTest end def test_returns_registrar_name - assert_equal('Best Names', @json[:registrar]) + assert_equal({name: 'Best Names', website: 'bestnames.test' }, @json[:registrar]) end def test_returns_nameserver_hostnames_or_an_empty_array - expected_nameservers = ['ns1.bestnames.test', 'ns2.bestnames.test'] - assert_equal(expected_nameservers.to_set, @json[:nameservers].to_set) + expected_nameserver_1 = { + hostname: 'ns1.bestnames.test', + ipv4: ['192.0.2.2'], + ipv6: ['2001:db8::2'] + } + + expected_nameserver_2 = { + hostname: 'ns2.bestnames.test', + ipv4: ['192.0.2.0', '192.0.2.3', '192.0.2.1'], + ipv6: ['2001:db8::1'] + } + + assert(@json[:nameservers].include?(expected_nameserver_1)) + assert(@json[:nameservers].include?(expected_nameserver_2)) other_domain = domains(:hospital) other_serializer = Serializers::RegistrantApi::Domain.new(other_domain)