From bbd5421d5f1b3beba567e63b34ae9b448c41f70b Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Tue, 2 Oct 2018 11:12:36 +0300 Subject: [PATCH 01/10] Add serializer for domain objects --- lib/serializers/registrant_api/domain.rb | 45 ++++++++++++++++ .../serializers/registrant_api/domain_test.rb | 54 +++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 lib/serializers/registrant_api/domain.rb create mode 100644 test/lib/serializers/registrant_api/domain_test.rb diff --git a/lib/serializers/registrant_api/domain.rb b/lib/serializers/registrant_api/domain.rb new file mode 100644 index 000000000..02dbbca64 --- /dev/null +++ b/lib/serializers/registrant_api/domain.rb @@ -0,0 +1,45 @@ +module Serializers + module RegistrantApi + class Domain + attr_reader :domain + + def initialize(domain) + @domain = domain + end + + def to_json + { + id: @domain.uuid, + name: @domain.name, + registrar: @domain.registrar.name, + registered_at: @domain.registered_at, + valid_to: @domain.valid_to, + created_at: @domain.created_at, + updated_at: @domain.updated_at, + registrant: @domain.registrant_name, + transfer_code: @domain.transfer_code, + name_dirty: @domain.name_dirty, + name_puny: @domain.name_puny, + period: @domain.period, + period_unit: @domain.period_unit, + creator_str: @domain.creator_str, + updator_str: @domain.updator_str, + legacy_id: @domain.legacy_id, + legacy_registrar_id: @domain.legacy_registrar_id, + legacy_registrant_id: @domain.legacy_registrant_id, + outzone_at: @domain.outzone_at, + delete_at: @domain.delete_at, + registrant_verification_asked_at: @domain.registrant_verification_asked_at, + registrant_verification_token: @domain.registrant_verification_token, + pending_json: @domain.pending_json, + force_delete_at: @domain.force_delete_at, + statuses: @domain.statuses, + locked_by_registrant_at: @domain.locked_by_registrant_at, + reserved: @domain.reserved, + status_notes: @domain.status_notes, + nameservers: @domain.nameservers.map(&:hostname), + } + end + end + end +end diff --git a/test/lib/serializers/registrant_api/domain_test.rb b/test/lib/serializers/registrant_api/domain_test.rb new file mode 100644 index 000000000..74facf87c --- /dev/null +++ b/test/lib/serializers/registrant_api/domain_test.rb @@ -0,0 +1,54 @@ +require 'test_helper' +require 'serializers/registrant_api/domain' + +class SerializersRegistrantApiDomainTest < ApplicationIntegrationTest + def setup + @domain = domains(:airport) + @serializer = Serializers::RegistrantApi::Domain.new(@domain) + @json = @serializer.to_json + end + + def test_returns_uuid_as_id + assert_equal(@domain.uuid, @json[:id]) + end + + def test_returns_domain_locked_by_registrant_time_or_nil + assert_not(@json[:locked_by_registrant_at]) + + travel_to Time.zone.parse('2010-07-05 10:30') + @domain.apply_registry_lock + serializer_for_locked_domain = Serializers::RegistrantApi::Domain.new(@domain.reload) + new_json = serializer_for_locked_domain.to_json + + assert_equal(Time.zone.parse('2010-07-05 10:30'), new_json[:locked_by_registrant_at]) + travel_back + end + + def test_returns_registrar_name + assert_equal('Best Names', @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) + + other_domain = domains(:hospital) + other_serializer = Serializers::RegistrantApi::Domain.new(other_domain) + new_json = other_serializer.to_json + + assert_equal([], new_json[:nameservers]) + end + + def test_other_fields_are_also_present + keys = %i[id name registrar registered_at valid_to created_at updated_at + registrant transfer_code name_dirty name_puny period period_unit + creator_str updator_str legacy_id legacy_registrar_id legacy_registrant_id + outzone_at delete_at registrant_verification_asked_at + registrant_verification_token pending_json force_delete_at statuses + locked_by_registrant_at reserved status_notes nameservers] + + pp @json + + assert_equal(keys, @json.keys & keys) + end +end From ed0316dd83ae4ccc2c8ece57f118864e9211816c Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Tue, 2 Oct 2018 11:13:13 +0300 Subject: [PATCH 02/10] Fix broken domain fixture --- test/fixtures/domains.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/test/fixtures/domains.yml b/test/fixtures/domains.yml index 5c4744e49..792953bbd 100644 --- a/test/fixtures/domains.yml +++ b/test/fixtures/domains.yml @@ -48,6 +48,7 @@ metro: hospital: name: hospital.test + name_dirty: hospital.test registrar: goodnames registrant: john transfer_code: 23118v2 From ce8451d00478d12cfe05afb85864629ef09bd9cf Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Tue, 2 Oct 2018 11:36:44 +0300 Subject: [PATCH 03/10] Update domains controller to return serialized domains now --- .../api/v1/registrant/domains_controller.rb | 13 ++- doc/registrant-api/v1/domain.md | 85 ++++++++++++------- .../registrant/registrant_api_domains_test.rb | 8 ++ 3 files changed, 73 insertions(+), 33 deletions(-) diff --git a/app/controllers/api/v1/registrant/domains_controller.rb b/app/controllers/api/v1/registrant/domains_controller.rb index a416aaec0..4e5c8bb28 100644 --- a/app/controllers/api/v1/registrant/domains_controller.rb +++ b/app/controllers/api/v1/registrant/domains_controller.rb @@ -1,3 +1,5 @@ +require 'serializers/registrant_api/domain' + module Api module V1 module Registrant @@ -17,7 +19,13 @@ module Api end @domains = associated_domains(current_registrant_user).limit(limit).offset(offset) - render json: @domains + + serialized_domains = @domains.map do |item| + serializer = Serializers::RegistrantApi::Domain.new(item) + serializer.to_json + end + + render json: serialized_domains end def show @@ -25,7 +33,8 @@ module Api @domain = domain_pool.find_by(uuid: params[:uuid]) if @domain - render json: @domain + serializer = Serializers::RegistrantApi::Domain.new(@domain) + render json: serializer.to_json else render json: { errors: [{ base: ['Domain not found'] }] }, status: :not_found end diff --git a/doc/registrant-api/v1/domain.md b/doc/registrant-api/v1/domain.md index 09495220d..f56bb6014 100644 --- a/doc/registrant-api/v1/domain.md +++ b/doc/registrant-api/v1/domain.md @@ -11,15 +11,6 @@ Returns domains of the current registrant. | ---------- | -------- | ---- | -------------- | ----------- | | limit | false | Integer | [1..200] | How many domains to show | | offset | false | Integer | | Domain number to start at | -| details | false | String | ["true", "false"] | Whether to include details | - -#### Request -``` -GET api/v1/registrant/domains?limit=1&details=true HTTP/1.1 -Accept: application/json -Authorization: Bearer Z2l0bGFiOmdoeXQ5ZTRmdQ== -Content-Type: application/json -``` #### Response ``` @@ -27,13 +18,11 @@ HTTP/1.1 200 Content-Type: application/json { - "domains": [ + [ { - "uuid": "98d1083a-8863-4153-93e4-caee4a013535", + "id": "98d1083a-8863-4153-93e4-caee4a013535", "name": "domain0.ee", - "registrar_id": 2, - "registered_at": "2015-09-09T09:11:14.861Z", - "status": null, + "registrar": "Best Names", "valid_from": "2015-09-09T09:11:14.861Z", "valid_to": "2016-09-09T09:11:14.861Z", "registrant_id": 1, @@ -53,23 +42,28 @@ Content-Type: application/json "delete_at": "2016-10-24T09:11:14.861Z", "registrant_verification_asked_at": null, "registrant_verification_token": null, - "pending_json": { - }, + "locked_by_registrant_at": "2015-09-09T09:11:14.861Z", + "pending_json": {}, "force_delete_at": null, "statuses": [ "ok" ], "reserved": false, - "status_notes": { - }, - "statuses_backup": [ - ] + "status_notes": {}, + "statuses_backup": [] } - ], - "total_number_of_records": 2 + ] } ``` +#### Request +``` +GET api/v1/registrant/domains HTTP/1.1 +Accept: application/json +Authorization: Bearer Z2l0bGFiOmdoeXQ5ZTRmdQ== +Content-Type: application/json +``` + ## GET api/v1/registrant/domains Returns domain names with offset. @@ -77,7 +71,7 @@ Returns domain names with offset. #### Request ``` -GET api/v1/registrant/domains?offset=1 HTTP/1.1 +GET api/v1/registrant/domains?offset=1&limit=1 HTTP/1.1 Accept: application/json Authorization: Bearer Z2l0bGFiOmdoeXQ5ZTRmdQ== Content-Type: application/json @@ -89,10 +83,40 @@ HTTP/1.1 200 Content-Type: application/json { - "domains": [ - "domain1.ee" - ], - "total_number_of_records": 2 + [ + { + "id": "98d1083a-8863-4153-93e4-caee4a013535", + "name": "domain0.ee", + "registrar": "Best Names", + "valid_to": "2016-09-09T09:11:14.861Z", + "registrant_id": 1, + "transfer_code": "98oiewslkfkd", + "created_at": "2015-09-09T09:11:14.861Z", + "updated_at": "2015-09-09T09:11:14.860Z", + "name_dirty": "domain0.ee", + "name_puny": "domain0.ee", + "period": 1, + "period_unit": "y", + "creator_str": null, + "updator_str": null, + "legacy_id": null, + "legacy_registrar_id": null, + "legacy_registrant_id": null, + "outzone_at": "2016-09-24T09:11:14.861Z", + "delete_at": "2016-10-24T09:11:14.861Z", + "registrant_verification_asked_at": null, + "registrant_verification_token": null, + "locked_by_registrant_at": "2015-09-09T09:11:14.861Z", + "pending_json": {}, + "force_delete_at": null, + "statuses": [ + "ok" + ], + "reserved": false, + "status_notes": {}, + "statuses_backup": [] + } + ] } ``` @@ -116,12 +140,10 @@ HTTP/1.1 200 Content-Type: application/json { - "uuid": "98d1083a-8863-4153-93e4-caee4a013535", + "id": "98d1083a-8863-4153-93e4-caee4a013535", "name": "domain0.ee", - "registrar_id": 2, + "registrar": "Best Names", "registered_at": "2015-09-09T09:11:14.861Z", - "status": null, - "valid_from": "2015-09-09T09:11:14.861Z", "valid_to": "2016-09-09T09:11:14.861Z", "registrant_id": 1, "transfer_code": "98oiewslkfkd", @@ -140,6 +162,7 @@ Content-Type: application/json "delete_at": "2016-10-24T09:11:14.861Z", "registrant_verification_asked_at": null, "registrant_verification_token": null, + "locked_by_registrant_at": "2015-09-09T09:11:14.861Z", "pending_json": {}, "force_delete_at": null, "statuses": [ diff --git a/test/integration/api/registrant/registrant_api_domains_test.rb b/test/integration/api/registrant/registrant_api_domains_test.rb index 0764db3aa..3195514de 100644 --- a/test/integration/api/registrant/registrant_api_domains_test.rb +++ b/test/integration/api/registrant/registrant_api_domains_test.rb @@ -27,7 +27,12 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest assert_equal(200, response.status) domain = JSON.parse(response.body, symbolize_names: true) + assert_equal('hospital.test', domain[:name]) + assert_equal('5edda1a5-3548-41ee-8b65-6d60daf85a37', domain[:id]) + assert_equal('Good Names', domain[:registrar]) + assert_equal([], domain[:nameservers]) + assert(domain.has_key?(:locked_by_registrant_at)) end def test_get_non_existent_domain_details_by_uuid @@ -45,6 +50,9 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest response_json = JSON.parse(response.body, symbolize_names: true) array_of_domain_names = response_json.map { |x| x[:name] } 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')) end def test_root_accepts_limit_and_offset_parameters From 5e5162e44ea1e1a262b6d92b0edcaef93884c853 Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Tue, 2 Oct 2018 11:53:57 +0300 Subject: [PATCH 04/10] Update registry lock controller to also return special serialization --- .../api/v1/registrant/registry_locks_controller.rb | 8 ++++++-- doc/registrant-api/v1/domain.md | 3 ++- doc/registrant-api/v1/registry_lock.md | 14 ++++++-------- .../registrant_api_registry_locks_test.rb | 14 ++++++++++++++ test/lib/serializers/registrant_api/domain_test.rb | 2 -- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/app/controllers/api/v1/registrant/registry_locks_controller.rb b/app/controllers/api/v1/registrant/registry_locks_controller.rb index 27c98cc9f..5100cd748 100644 --- a/app/controllers/api/v1/registrant/registry_locks_controller.rb +++ b/app/controllers/api/v1/registrant/registry_locks_controller.rb @@ -1,3 +1,5 @@ +require 'serializers/registrant_api/domain' + module Api module V1 module Registrant @@ -7,7 +9,8 @@ module Api def create if @domain.apply_registry_lock - render json: @domain + serializer = Serializers::RegistrantApi::Domain.new(@domain) + render json: serializer.to_json else render json: { errors: [{ base: ['Domain cannot be locked'] }] }, status: :unprocessable_entity @@ -16,7 +19,8 @@ module Api def destroy if @domain.remove_registry_lock - render json: @domain + serializer = Serializers::RegistrantApi::Domain.new(@domain) + render json: serializer.to_json else render json: { errors: [{ base: ['Domain is not locked'] }] }, status: :unprocessable_entity diff --git a/doc/registrant-api/v1/domain.md b/doc/registrant-api/v1/domain.md index f56bb6014..5c309ce15 100644 --- a/doc/registrant-api/v1/domain.md +++ b/doc/registrant-api/v1/domain.md @@ -23,7 +23,7 @@ Content-Type: application/json "id": "98d1083a-8863-4153-93e4-caee4a013535", "name": "domain0.ee", "registrar": "Best Names", - "valid_from": "2015-09-09T09:11:14.861Z", + "registered_at": "2015-09-09T09:11:14.861Z", "valid_to": "2016-09-09T09:11:14.861Z", "registrant_id": 1, "transfer_code": "98oiewslkfkd", @@ -89,6 +89,7 @@ Content-Type: application/json "name": "domain0.ee", "registrar": "Best Names", "valid_to": "2016-09-09T09:11:14.861Z", + "registered_at": "2015-09-09T09:11:14.861Z", "registrant_id": 1, "transfer_code": "98oiewslkfkd", "created_at": "2015-09-09T09:11:14.861Z", diff --git a/doc/registrant-api/v1/registry_lock.md b/doc/registrant-api/v1/registry_lock.md index b8d440554..849b27db5 100644 --- a/doc/registrant-api/v1/registry_lock.md +++ b/doc/registrant-api/v1/registry_lock.md @@ -19,12 +19,10 @@ HTTP/1.1 200 Content-Type: application/json { - "uuid": "98d1083a-8863-4153-93e4-caee4a013535", + "id": "98d1083a-8863-4153-93e4-caee4a013535", "name": "domain0.ee", - "registrar_id": 2, + "registrar": "Best Names", "registered_at": "2015-09-09T09:11:14.861Z", - "status": null, - "valid_from": "2015-09-09T09:11:14.861Z", "valid_to": "2016-09-09T09:11:14.861Z", "registrant_id": 1, "transfer_code": "98oiewslkfkd", @@ -43,6 +41,7 @@ Content-Type: application/json "delete_at": "2016-10-24T09:11:14.861Z", "registrant_verification_asked_at": null, "registrant_verification_token": null, + "locked_by_registrant_at": "2015-09-09T09:11:14.861Z", "pending_json": {}, "force_delete_at": null, "statuses": [ @@ -113,12 +112,10 @@ HTTP/1.1 200 Content-Type: application/json { - "uuid": "98d1083a-8863-4153-93e4-caee4a013535", + "id": "98d1083a-8863-4153-93e4-caee4a013535", "name": "domain0.ee", - "registrar_id": 2, + "registrar": "Best Names", "registered_at": "2015-09-09T09:11:14.861Z", - "status": null, - "valid_from": "2015-09-09T09:11:14.861Z", "valid_to": "2016-09-09T09:11:14.861Z", "registrant_id": 1, "transfer_code": "98oiewslkfkd", @@ -137,6 +134,7 @@ Content-Type: application/json "delete_at": "2016-10-24T09:11:14.861Z", "registrant_verification_asked_at": null, "registrant_verification_token": null, + "locked_by_registrant_at": null, "pending_json": {}, "force_delete_at": null, "statuses": [ 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 bb50bdc1b..846bcb8e5 100644 --- a/test/integration/api/registrant/registrant_api_registry_locks_test.rb +++ b/test/integration/api/registrant/registrant_api_registry_locks_test.rb @@ -77,6 +77,7 @@ class RegistrantApiRegistryLocksTest < ApplicationIntegrationTest response_json = JSON.parse(response.body, symbolize_names: true) assert(response_json[:statuses].include?(DomainStatus::OK)) + refute(response_json[:locked_by_registrant_at]) @domain.reload refute(@domain.locked_by_registrant?) end @@ -121,6 +122,19 @@ class RegistrantApiRegistryLocksTest < ApplicationIntegrationTest assert(response_json[:statuses].include?(DomainStatus::SERVER_UPDATE_PROHIBITED)) end + def test_locking_domains_returns_serialized_domain_object + post '/api/v1/registrant/domains/1b3ee442-e8fe-4922-9492-8fcb9dccc69c/registry_lock', + {}, @auth_headers + + 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, + response_json[:nameservers].to_set) + assert_equal(Time.zone.parse('2010-07-05'), response_json[:locked_by_registrant_at]) + end + private def auth_token diff --git a/test/lib/serializers/registrant_api/domain_test.rb b/test/lib/serializers/registrant_api/domain_test.rb index 74facf87c..6a9b552d1 100644 --- a/test/lib/serializers/registrant_api/domain_test.rb +++ b/test/lib/serializers/registrant_api/domain_test.rb @@ -47,8 +47,6 @@ class SerializersRegistrantApiDomainTest < ApplicationIntegrationTest registrant_verification_token pending_json force_delete_at statuses locked_by_registrant_at reserved status_notes nameservers] - pp @json - assert_equal(keys, @json.keys & keys) end end From 2d8b196b1eed332777ea176b9763cecde7f46534 Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Tue, 2 Oct 2018 12:02:35 +0300 Subject: [PATCH 05/10] Add missing nameserver array to domain endpoint documentation --- doc/registrant-api/v1/domain.md | 12 ++++++++++++ doc/registrant-api/v1/registry_lock.md | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/doc/registrant-api/v1/domain.md b/doc/registrant-api/v1/domain.md index 5c309ce15..5a4e866be 100644 --- a/doc/registrant-api/v1/domain.md +++ b/doc/registrant-api/v1/domain.md @@ -48,6 +48,10 @@ Content-Type: application/json "statuses": [ "ok" ], + "nameservers": [ + "ns1.bestnames.test", + "ns2.bestnames.test" + ], "reserved": false, "status_notes": {}, "statuses_backup": [] @@ -113,6 +117,10 @@ Content-Type: application/json "statuses": [ "ok" ], + "nameservers": [ + "ns1.bestnames.test", + "ns2.bestnames.test" + ], "reserved": false, "status_notes": {}, "statuses_backup": [] @@ -169,6 +177,10 @@ Content-Type: application/json "statuses": [ "ok" ], + "nameservers": [ + "ns1.bestnames.test", + "ns2.bestnames.test" + ], "reserved": false, "status_notes": {}, "statuses_backup": [] diff --git a/doc/registrant-api/v1/registry_lock.md b/doc/registrant-api/v1/registry_lock.md index 849b27db5..956719ac2 100644 --- a/doc/registrant-api/v1/registry_lock.md +++ b/doc/registrant-api/v1/registry_lock.md @@ -49,6 +49,10 @@ Content-Type: application/json "serverDeleteProhibited", "serverTransferProhibited" ], + "nameservers": [ + "ns1.bestnames.test", + "ns2.bestnames.test" + ], "reserved": false, "status_notes": {}, "statuses_backup": [] @@ -140,6 +144,10 @@ Content-Type: application/json "statuses": [ "ok" ], + "nameservers": [ + "ns1.bestnames.test", + "ns2.bestnames.test" + ], "reserved": false, "status_notes": {}, "statuses_backup": [] From 63837c40bae945a3232441a0814a3a2992d802da Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Tue, 2 Oct 2018 12:05:10 +0300 Subject: [PATCH 06/10] Remove domains.status field It is empty anyway --- db/migrate/20181002090319_remove_domain_status_field.rb | 5 +++++ db/structure.sql | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20181002090319_remove_domain_status_field.rb diff --git a/db/migrate/20181002090319_remove_domain_status_field.rb b/db/migrate/20181002090319_remove_domain_status_field.rb new file mode 100644 index 000000000..29c4db931 --- /dev/null +++ b/db/migrate/20181002090319_remove_domain_status_field.rb @@ -0,0 +1,5 @@ +class RemoveDomainStatusField < ActiveRecord::Migration + def change + remove_column :domains, :status + end +end diff --git a/db/structure.sql b/db/structure.sql index 21d39236e..e9b0e7f43 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -885,7 +885,6 @@ CREATE TABLE public.domains ( name character varying, registrar_id integer NOT NULL, registered_at timestamp without time zone, - status character varying, valid_to timestamp without time zone NOT NULL, registrant_id integer NOT NULL, transfer_code character varying NOT NULL, @@ -4778,3 +4777,5 @@ INSERT INTO schema_migrations (version) VALUES ('20180824092855'); INSERT INTO schema_migrations (version) VALUES ('20180824102834'); +INSERT INTO schema_migrations (version) VALUES ('20181002090319'); + From 28304559fda1955b729a9d89494f5d7aa45050cf Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Tue, 2 Oct 2018 12:23:23 +0300 Subject: [PATCH 07/10] Remove code duplication --- .../api/v1/registrant/registry_locks_controller.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/v1/registrant/registry_locks_controller.rb b/app/controllers/api/v1/registrant/registry_locks_controller.rb index 5100cd748..d431b5cd0 100644 --- a/app/controllers/api/v1/registrant/registry_locks_controller.rb +++ b/app/controllers/api/v1/registrant/registry_locks_controller.rb @@ -9,8 +9,7 @@ module Api def create if @domain.apply_registry_lock - serializer = Serializers::RegistrantApi::Domain.new(@domain) - render json: serializer.to_json + render json: serialized_domain(@domain) else render json: { errors: [{ base: ['Domain cannot be locked'] }] }, status: :unprocessable_entity @@ -19,8 +18,7 @@ module Api def destroy if @domain.remove_registry_lock - serializer = Serializers::RegistrantApi::Domain.new(@domain) - render json: serializer.to_json + render json: serialized_domain(@domain) else render json: { errors: [{ base: ['Domain is not locked'] }] }, status: :unprocessable_entity @@ -46,6 +44,11 @@ module Api ] }, status: :unauthorized and return end + + def serialized_domain(domain) + serializer = Serializers::RegistrantApi::Domain.new(domain) + serializer.to_json + end end end end From 2a4995226f269062eb2f13f1bca73426e9a1a857 Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Wed, 3 Oct 2018 16:34:26 +0300 Subject: [PATCH 08/10] 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) From b6cc22dbfc145373b4085b48f96c76a371eaa332 Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Wed, 3 Oct 2018 16:38:20 +0300 Subject: [PATCH 09/10] Use push instead of << for adding new items to array --- lib/serializers/registrant_api/domain.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/serializers/registrant_api/domain.rb b/lib/serializers/registrant_api/domain.rb index b2490e04b..5a91dcde8 100644 --- a/lib/serializers/registrant_api/domain.rb +++ b/lib/serializers/registrant_api/domain.rb @@ -50,8 +50,8 @@ module Serializers array_of_nameservers = Array.new @domain.nameservers.map do |nameserver| - array_of_nameservers << { hostname: nameserver.hostname, ipv4: nameserver.ipv4, - ipv6: nameserver.ipv6 } + array_of_nameservers.push({ hostname: nameserver.hostname, ipv4: nameserver.ipv4, + ipv6: nameserver.ipv6 }) end array_of_nameservers From f551140a0dfaa5b3eca647d0f78b5094dc6f6b2c Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Thu, 4 Oct 2018 09:54:52 +0300 Subject: [PATCH 10/10] Fix #1000 * Return contacts inside domain object * Return registrant uuid and name inside domain object --- doc/registrant-api/v1/domain.md | 391 +++++++++++------- doc/registrant-api/v1/registry_lock.md | 230 +++++++---- lib/serializers/registrant_api/domain.rb | 90 ++-- .../registrant/registrant_api_domains_test.rb | 5 + .../registrant_api_registry_locks_test.rb | 5 + .../serializers/registrant_api/domain_test.rb | 18 +- 6 files changed, 484 insertions(+), 255 deletions(-) diff --git a/doc/registrant-api/v1/domain.md b/doc/registrant-api/v1/domain.md index ec32772df..eeb1bfccc 100644 --- a/doc/registrant-api/v1/domain.md +++ b/doc/registrant-api/v1/domain.md @@ -17,58 +17,94 @@ Returns domains of the current registrant. HTTP/1.1 200 Content-Type: application/json -{ - [ - { - "id": "98d1083a-8863-4153-93e4-caee4a013535", - "name": "domain0.ee", - "registrar": { - "name": "Best Names", - "website": "example.com" +[ + { + "id":"98d1083a-8863-4153-93e4-caee4a013535", + "name":"domain0.ee", + "registrar":{ + "name":"Best Names", + "website":"example.com" + }, + "valid_to":"2016-09-09T09:11:14.861Z", + "registered_at":"2015-09-09T09:11:14.861Z", + "registrant":{ + "name":"John Smith", + "id":"acadf23e-47c4-4606-8f67-76e071a1cca2" + }, + "admin_contacts":[ + { + "name":"John Smith", + "id":"62015e7d-42c8-4d68-8164-e9b71680fd95" }, - "registered_at": "2015-09-09T09:11:14.861Z", - "valid_to": "2016-09-09T09:11:14.861Z", - "registrant_id": 1, - "transfer_code": "98oiewslkfkd", - "created_at": "2015-09-09T09:11:14.861Z", - "updated_at": "2015-09-09T09:11:14.860Z", - "name_dirty": "domain0.ee", - "name_puny": "domain0.ee", - "period": 1, - "period_unit": "y", - "creator_str": null, - "updator_str": null, - "legacy_id": null, - "legacy_registrar_id": null, - "legacy_registrant_id": null, - "outzone_at": "2016-09-24T09:11:14.861Z", - "delete_at": "2016-10-24T09:11:14.861Z", - "registrant_verification_asked_at": null, - "registrant_verification_token": null, - "locked_by_registrant_at": "2015-09-09T09:11:14.861Z", - "pending_json": {}, - "force_delete_at": null, - "statuses": [ - "ok" - ], - "nameservers": [ - { - "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": {}, - "statuses_backup": [] - } - ] -} + { + "name":"William Smith", + "id":"a041c5b6-7772-4fac-83cd-fbce3b2c8867" + } + ], + "tech_contacts":[ + { + "name":"John Smith", + "id":"62015e7d-42c8-4d68-8164-e9b71680fd95" + }, + { + "name":"William Smith", + "id":"a041c5b6-7772-4fac-83cd-fbce3b2c8867" + } + ], + "transfer_code":"98oiewslkfkd", + "created_at":"2015-09-09T09:11:14.861Z", + "updated_at":"2015-09-09T09:11:14.860Z", + "name_dirty":"domain0.ee", + "name_puny":"domain0.ee", + "period":1, + "period_unit":"y", + "creator_str":null, + "updator_str":null, + "legacy_id":null, + "legacy_registrar_id":null, + "legacy_registrant_id":null, + "outzone_at":"2016-09-24T09:11:14.861Z", + "delete_at":"2016-10-24T09:11:14.861Z", + "registrant_verification_asked_at":null, + "registrant_verification_token":null, + "locked_by_registrant_at":"2015-09-09T09:11:14.861Z", + "pending_json":{ + + }, + "force_delete_at":null, + "statuses":[ + "ok" + ], + "nameservers":[ + { + "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":{ + + }, + "statuses_backup":[ + + ] + } +] ``` #### Request @@ -97,58 +133,94 @@ Content-Type: application/json HTTP/1.1 200 Content-Type: application/json -{ - [ - { - "id": "98d1083a-8863-4153-93e4-caee4a013535", - "name": "domain0.ee", - "registrar": { - "name": "Best Names", - "website": "example.com" +[ + { + "id":"98d1083a-8863-4153-93e4-caee4a013535", + "name":"domain0.ee", + "registrar":{ + "name":"Best Names", + "website":"example.com" + }, + "valid_to":"2016-09-09T09:11:14.861Z", + "registered_at":"2015-09-09T09:11:14.861Z", + "registrant":{ + "name":"John Smith", + "id":"acadf23e-47c4-4606-8f67-76e071a1cca2" + }, + "admin_contacts":[ + { + "name":"John Smith", + "id":"62015e7d-42c8-4d68-8164-e9b71680fd95" }, - "valid_to": "2016-09-09T09:11:14.861Z", - "registered_at": "2015-09-09T09:11:14.861Z", - "registrant_id": 1, - "transfer_code": "98oiewslkfkd", - "created_at": "2015-09-09T09:11:14.861Z", - "updated_at": "2015-09-09T09:11:14.860Z", - "name_dirty": "domain0.ee", - "name_puny": "domain0.ee", - "period": 1, - "period_unit": "y", - "creator_str": null, - "updator_str": null, - "legacy_id": null, - "legacy_registrar_id": null, - "legacy_registrant_id": null, - "outzone_at": "2016-09-24T09:11:14.861Z", - "delete_at": "2016-10-24T09:11:14.861Z", - "registrant_verification_asked_at": null, - "registrant_verification_token": null, - "locked_by_registrant_at": "2015-09-09T09:11:14.861Z", - "pending_json": {}, - "force_delete_at": null, - "statuses": [ - "ok" - ], - "nameservers": [ - { - "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": {}, - "statuses_backup": [] - } - ] -} + { + "name":"William Smith", + "id":"a041c5b6-7772-4fac-83cd-fbce3b2c8867" + } + ], + "tech_contacts":[ + { + "name":"John Smith", + "id":"62015e7d-42c8-4d68-8164-e9b71680fd95" + }, + { + "name":"William Smith", + "id":"a041c5b6-7772-4fac-83cd-fbce3b2c8867" + } + ], + "transfer_code":"98oiewslkfkd", + "created_at":"2015-09-09T09:11:14.861Z", + "updated_at":"2015-09-09T09:11:14.860Z", + "name_dirty":"domain0.ee", + "name_puny":"domain0.ee", + "period":1, + "period_unit":"y", + "creator_str":null, + "updator_str":null, + "legacy_id":null, + "legacy_registrar_id":null, + "legacy_registrant_id":null, + "outzone_at":"2016-09-24T09:11:14.861Z", + "delete_at":"2016-10-24T09:11:14.861Z", + "registrant_verification_asked_at":null, + "registrant_verification_token":null, + "locked_by_registrant_at":"2015-09-09T09:11:14.861Z", + "pending_json":{ + + }, + "force_delete_at":null, + "statuses":[ + "ok" + ], + "nameservers":[ + { + "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":{ + + }, + "statuses_backup":[ + + ] + } +] ``` ## GET api/v1/registrant/domains/$UUID @@ -171,52 +243,89 @@ HTTP/1.1 200 Content-Type: application/json { - "id": "98d1083a-8863-4153-93e4-caee4a013535", - "name": "domain0.ee", - "registrar": { - "name": "Best Names", - "website": "example.com" + "id":"98d1083a-8863-4153-93e4-caee4a013535", + "name":"domain0.ee", + "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, - "transfer_code": "98oiewslkfkd", - "created_at": "2015-09-09T09:11:14.861Z", - "updated_at": "2015-09-09T09:11:14.860Z", - "name_dirty": "domain0.ee", - "name_puny": "domain0.ee", - "period": 1, - "period_unit": "y", - "creator_str": null, - "updator_str": null, - "legacy_id": null, - "legacy_registrar_id": null, - "legacy_registrant_id": null, - "outzone_at": "2016-09-24T09:11:14.861Z", - "delete_at": "2016-10-24T09:11:14.861Z", - "registrant_verification_asked_at": null, - "registrant_verification_token": null, - "locked_by_registrant_at": "2015-09-09T09:11:14.861Z", - "pending_json": {}, - "force_delete_at": null, - "statuses": [ + "valid_to":"2016-09-09T09:11:14.861Z", + "registered_at":"2015-09-09T09:11:14.861Z", + "registrant":{ + "name":"John Smith", + "id":"acadf23e-47c4-4606-8f67-76e071a1cca2" + }, + "admin_contacts":[ + { + "name":"John Smith", + "id":"62015e7d-42c8-4d68-8164-e9b71680fd95" + }, + { + "name":"William Smith", + "id":"a041c5b6-7772-4fac-83cd-fbce3b2c8867" + } + ], + "tech_contacts":[ + { + "name":"John Smith", + "id":"62015e7d-42c8-4d68-8164-e9b71680fd95" + }, + { + "name":"William Smith", + "id":"a041c5b6-7772-4fac-83cd-fbce3b2c8867" + } + ], + "transfer_code":"98oiewslkfkd", + "created_at":"2015-09-09T09:11:14.861Z", + "updated_at":"2015-09-09T09:11:14.860Z", + "name_dirty":"domain0.ee", + "name_puny":"domain0.ee", + "period":1, + "period_unit":"y", + "creator_str":null, + "updator_str":null, + "legacy_id":null, + "legacy_registrar_id":null, + "legacy_registrant_id":null, + "outzone_at":"2016-09-24T09:11:14.861Z", + "delete_at":"2016-10-24T09:11:14.861Z", + "registrant_verification_asked_at":null, + "registrant_verification_token":null, + "locked_by_registrant_at":"2015-09-09T09:11:14.861Z", + "pending_json":{ + + }, + "force_delete_at":null, + "statuses":[ "ok" ], - "nameservers": [ + "nameservers":[ { - "hostname": "ns1.bestnames.test", - "ipv4": ["173.245.58.41"], - "ipv6": ["2400:cb00:2049:1::adf5:3a33"] + "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"] - }, + "hostname":"ns1.bestnames.test", + "ipv4":[ + "173.245.58.51" + ], + "ipv6":[ + "2400:cb00:2049:1::adf5:3b29" + ] + } ], - "reserved": false, - "status_notes": {}, - "statuses_backup": [] + "reserved":false, + "status_notes":{ + + }, + "statuses_backup":[ + + ] } ``` diff --git a/doc/registrant-api/v1/registry_lock.md b/doc/registrant-api/v1/registry_lock.md index 1b0dd828b..553c7b28e 100644 --- a/doc/registrant-api/v1/registry_lock.md +++ b/doc/registrant-api/v1/registry_lock.md @@ -19,54 +19,91 @@ HTTP/1.1 200 Content-Type: application/json { - "id": "98d1083a-8863-4153-93e4-caee4a013535", - "name": "domain0.ee", - "registrar": { - "name": "Best Names", - "website": "example.com" + "id":"98d1083a-8863-4153-93e4-caee4a013535", + "name":"domain0.ee", + "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, - "transfer_code": "98oiewslkfkd", - "created_at": "2015-09-09T09:11:14.861Z", - "updated_at": "2015-09-09T09:11:14.860Z", - "name_dirty": "domain0.ee", - "name_puny": "domain0.ee", - "period": 1, - "period_unit": "y", - "creator_str": null, - "updator_str": null, - "legacy_id": null, - "legacy_registrar_id": null, - "legacy_registrant_id": null, - "outzone_at": "2016-09-24T09:11:14.861Z", - "delete_at": "2016-10-24T09:11:14.861Z", - "registrant_verification_asked_at": null, - "registrant_verification_token": null, - "locked_by_registrant_at": "2015-09-09T09:11:14.861Z", - "pending_json": {}, - "force_delete_at": null, - "statuses": [ + "registrant":{ + "name":"John Smith", + "id":"acadf23e-47c4-4606-8f67-76e071a1cca2" + }, + "admin_contacts":[ + { + "name":"John Smith", + "id":"62015e7d-42c8-4d68-8164-e9b71680fd95" + }, + { + "name":"William Smith", + "id":"a041c5b6-7772-4fac-83cd-fbce3b2c8867" + } + ], + "tech_contacts":[ + { + "name":"John Smith", + "id":"62015e7d-42c8-4d68-8164-e9b71680fd95" + }, + { + "name":"William Smith", + "id":"a041c5b6-7772-4fac-83cd-fbce3b2c8867" + } + ], + "registered_at":"2015-09-09T09:11:14.861Z", + "valid_to":"2016-09-09T09:11:14.861Z", + "transfer_code":"98oiewslkfkd", + "created_at":"2015-09-09T09:11:14.861Z", + "updated_at":"2015-09-09T09:11:14.860Z", + "name_dirty":"domain0.ee", + "name_puny":"domain0.ee", + "period":1, + "period_unit":"y", + "creator_str":null, + "updator_str":null, + "legacy_id":null, + "legacy_registrar_id":null, + "legacy_registrant_id":null, + "outzone_at":"2016-09-24T09:11:14.861Z", + "delete_at":"2016-10-24T09:11:14.861Z", + "registrant_verification_asked_at":null, + "registrant_verification_token":null, + "locked_by_registrant_at":"2015-09-09T09:11:14.861Z", + "pending_json":{ + + }, + "force_delete_at":null, + "statuses":[ "serverUpdateProhibited", "serverDeleteProhibited", "serverTransferProhibited" ], - "nameservers": [ + "nameservers":[ { - "hostname": "ns1.bestnames.test", - "ipv4": ["173.245.58.41"], - "ipv6": ["2400:cb00:2049:1::adf5:3a33"] + "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"] - }, + "hostname":"ns1.bestnames.test", + "ipv4":[ + "173.245.58.51" + ], + "ipv6":[ + "2400:cb00:2049:1::adf5:3b29" + ] + } ], - "reserved": false, - "status_notes": {}, - "statuses_backup": [] + "reserved":false, + "status_notes":{ + + }, + "statuses_backup":[ + + ] } ``` @@ -127,52 +164,89 @@ HTTP/1.1 200 Content-Type: application/json { - "id": "98d1083a-8863-4153-93e4-caee4a013535", - "name": "domain0.ee", - "registrar": { - "name": "Best Names", - "website": "example.com" + "id":"98d1083a-8863-4153-93e4-caee4a013535", + "name":"domain0.ee", + "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, - "transfer_code": "98oiewslkfkd", - "created_at": "2015-09-09T09:11:14.861Z", - "updated_at": "2015-09-09T09:11:14.860Z", - "name_dirty": "domain0.ee", - "name_puny": "domain0.ee", - "period": 1, - "period_unit": "y", - "creator_str": null, - "updator_str": null, - "legacy_id": null, - "legacy_registrar_id": null, - "legacy_registrant_id": null, - "outzone_at": "2016-09-24T09:11:14.861Z", - "delete_at": "2016-10-24T09:11:14.861Z", - "registrant_verification_asked_at": null, - "registrant_verification_token": null, - "locked_by_registrant_at": null, - "pending_json": {}, - "force_delete_at": null, - "statuses": [ + "registered_at":"2015-09-09T09:11:14.861Z", + "valid_to":"2016-09-09T09:11:14.861Z", + "registrant":{ + "name":"John Smith", + "id":"acadf23e-47c4-4606-8f67-76e071a1cca2" + }, + "admin_contacts":[ + { + "name":"John Smith", + "id":"62015e7d-42c8-4d68-8164-e9b71680fd95" + }, + { + "name":"William Smith", + "id":"a041c5b6-7772-4fac-83cd-fbce3b2c8867" + } + ], + "tech_contacts":[ + { + "name":"John Smith", + "id":"62015e7d-42c8-4d68-8164-e9b71680fd95" + }, + { + "name":"William Smith", + "id":"a041c5b6-7772-4fac-83cd-fbce3b2c8867" + } + ], + "transfer_code":"98oiewslkfkd", + "created_at":"2015-09-09T09:11:14.861Z", + "updated_at":"2015-09-09T09:11:14.860Z", + "name_dirty":"domain0.ee", + "name_puny":"domain0.ee", + "period":1, + "period_unit":"y", + "creator_str":null, + "updator_str":null, + "legacy_id":null, + "legacy_registrar_id":null, + "legacy_registrant_id":null, + "outzone_at":"2016-09-24T09:11:14.861Z", + "delete_at":"2016-10-24T09:11:14.861Z", + "registrant_verification_asked_at":null, + "registrant_verification_token":null, + "locked_by_registrant_at":null, + "pending_json":{ + + }, + "force_delete_at":null, + "statuses":[ "ok" ], - "nameservers": [ + "nameservers":[ { - "hostname": "ns1.bestnames.test", - "ipv4": ["173.245.58.41"], - "ipv6": ["2400:cb00:2049:1::adf5:3a33"] + "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"] - }, + "hostname":"ns1.bestnames.test", + "ipv4":[ + "173.245.58.51" + ], + "ipv6":[ + "2400:cb00:2049:1::adf5:3b29" + ] + } ], - "reserved": false, - "status_notes": {}, - "statuses_backup": [] + "reserved":false, + "status_notes":{ + + }, + "statuses_backup":[ + + ] } ``` diff --git a/lib/serializers/registrant_api/domain.rb b/lib/serializers/registrant_api/domain.rb index 5a91dcde8..d6adf61ee 100644 --- a/lib/serializers/registrant_api/domain.rb +++ b/lib/serializers/registrant_api/domain.rb @@ -9,49 +9,71 @@ module Serializers def to_json { - id: @domain.uuid, - name: @domain.name, + id: domain.uuid, + name: domain.name, registrar: { - name: @domain.registrar.name, - website: @domain.registrar.website, + name: domain.registrar.name, + website: domain.registrar.website, }, - registered_at: @domain.registered_at, - valid_to: @domain.valid_to, - created_at: @domain.created_at, - updated_at: @domain.updated_at, - registrant: @domain.registrant_name, - transfer_code: @domain.transfer_code, - name_dirty: @domain.name_dirty, - name_puny: @domain.name_puny, - period: @domain.period, - period_unit: @domain.period_unit, - creator_str: @domain.creator_str, - updator_str: @domain.updator_str, - legacy_id: @domain.legacy_id, - legacy_registrar_id: @domain.legacy_registrar_id, - legacy_registrant_id: @domain.legacy_registrant_id, - outzone_at: @domain.outzone_at, - delete_at: @domain.delete_at, - registrant_verification_asked_at: @domain.registrant_verification_asked_at, - registrant_verification_token: @domain.registrant_verification_token, - pending_json: @domain.pending_json, - force_delete_at: @domain.force_delete_at, - statuses: @domain.statuses, - locked_by_registrant_at: @domain.locked_by_registrant_at, - reserved: @domain.reserved, - status_notes: @domain.status_notes, + registered_at: domain.registered_at, + valid_to: domain.valid_to, + created_at: domain.created_at, + updated_at: domain.updated_at, + registrant: { + name: domain.registrant.name, + id: domain.registrant.uuid, + }, + tech_contacts: contacts(:tech), + admin_contacts: contacts(:admin), + transfer_code: domain.transfer_code, + name_dirty: domain.name_dirty, + name_puny: domain.name_puny, + period: domain.period, + period_unit: domain.period_unit, + creator_str: domain.creator_str, + updator_str: domain.updator_str, + legacy_id: domain.legacy_id, + legacy_registrar_id: domain.legacy_registrar_id, + legacy_registrant_id: domain.legacy_registrant_id, + outzone_at: domain.outzone_at, + delete_at: domain.delete_at, + registrant_verification_asked_at: domain.registrant_verification_asked_at, + registrant_verification_token: domain.registrant_verification_token, + pending_json: domain.pending_json, + force_delete_at: domain.force_delete_at, + statuses: domain.statuses, + locked_by_registrant_at: domain.locked_by_registrant_at, + reserved: domain.reserved, + status_notes: domain.status_notes, nameservers: nameservers, } end private - def nameservers - array_of_nameservers = Array.new + def contacts(type) + contact_pool = begin + if type == :tech + domain.tech_contacts + elsif type == :admin + domain.admin_contacts + end + end - @domain.nameservers.map do |nameserver| - array_of_nameservers.push({ hostname: nameserver.hostname, ipv4: nameserver.ipv4, - ipv6: nameserver.ipv6 }) + array_of_contacts = [] + contact_pool.map do |contact| + array_of_contacts.push(name: contact.name, id: contact.uuid) + end + + array_of_contacts + end + + def nameservers + array_of_nameservers = [] + + domain.nameservers.map do |nameserver| + array_of_nameservers.push(hostname: nameserver.hostname, ipv4: nameserver.ipv4, + ipv6: nameserver.ipv6) end array_of_nameservers diff --git a/test/integration/api/registrant/registrant_api_domains_test.rb b/test/integration/api/registrant/registrant_api_domains_test.rb index 51ca403b0..9720373a1 100644 --- a/test/integration/api/registrant/registrant_api_domains_test.rb +++ b/test/integration/api/registrant/registrant_api_domains_test.rb @@ -30,6 +30,11 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest assert_equal('hospital.test', domain[:name]) assert_equal('5edda1a5-3548-41ee-8b65-6d60daf85a37', domain[:id]) + assert_equal({name: 'John', id: 'eb2f2766-b44c-4e14-9f16-32ab1a7cb957'}, domain[:registrant]) + assert_equal([{name: 'John', id: 'eb2f2766-b44c-4e14-9f16-32ab1a7cb957'}], + domain[:admin_contacts]) + assert_equal([{name: 'John', id: 'eb2f2766-b44c-4e14-9f16-32ab1a7cb957'}], + domain[:tech_contacts]) assert_equal({ name: 'Good Names', website: nil }, domain[:registrar]) assert_equal([], domain[:nameservers]) assert(domain.has_key?(:locked_by_registrant_at)) 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 b028acc90..d35952a73 100644 --- a/test/integration/api/registrant/registrant_api_registry_locks_test.rb +++ b/test/integration/api/registrant/registrant_api_registry_locks_test.rb @@ -130,6 +130,11 @@ class RegistrantApiRegistryLocksTest < ApplicationIntegrationTest response_json = JSON.parse(response.body, symbolize_names: true) assert_equal({ name: 'Best Names', website: 'bestnames.test' }, response_json[:registrar]) + assert_equal({name: 'John', id: 'eb2f2766-b44c-4e14-9f16-32ab1a7cb957'}, response_json[:registrant]) + assert_equal([{name: 'Jane', id: '9db3de62-2414-4487-bee2-d5c155567768'}], response_json[:admin_contacts]) + assert_equal([{name: 'William', id: '0aa54704-d6f7-4ca9-b8ca-2827d9a4e4eb'}, + {name: 'Acme Ltd', id: 'f1dd365c-5be9-4b3d-a44e-3fa002465e4d'}], + response_json[:tech_contacts]) 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, diff --git a/test/lib/serializers/registrant_api/domain_test.rb b/test/lib/serializers/registrant_api/domain_test.rb index 2408283be..bddb0efd7 100644 --- a/test/lib/serializers/registrant_api/domain_test.rb +++ b/test/lib/serializers/registrant_api/domain_test.rb @@ -28,6 +28,20 @@ class SerializersRegistrantApiDomainTest < ApplicationIntegrationTest assert_equal({name: 'Best Names', website: 'bestnames.test' }, @json[:registrar]) end + def test_returns_registrant_name_and_uuid + assert_equal({name: 'John', id: 'eb2f2766-b44c-4e14-9f16-32ab1a7cb957'}, + @json[:registrant]) + end + + def test_returns_contacts_name_and_uuid + assert_equal([{name: 'John', id: 'eb2f2766-b44c-4e14-9f16-32ab1a7cb957'}, + {name: 'William', id: '0aa54704-d6f7-4ca9-b8ca-2827d9a4e4eb'}].to_set, + @json[:admin_contacts].to_set) + + assert_equal([{name: 'William', id: '0aa54704-d6f7-4ca9-b8ca-2827d9a4e4eb'}].to_set, + @json[:tech_contacts].to_set) + end + def test_returns_nameserver_hostnames_or_an_empty_array expected_nameserver_1 = { hostname: 'ns1.bestnames.test', @@ -53,8 +67,8 @@ class SerializersRegistrantApiDomainTest < ApplicationIntegrationTest def test_other_fields_are_also_present keys = %i[id name registrar registered_at valid_to created_at updated_at - registrant transfer_code name_dirty name_puny period period_unit - creator_str updator_str legacy_id legacy_registrar_id legacy_registrant_id + registrant tech_contacts admin_contacts transfer_code name_dirty name_puny period + period_unit creator_str updator_str legacy_id legacy_registrar_id legacy_registrant_id outzone_at delete_at registrant_verification_asked_at registrant_verification_token pending_json force_delete_at statuses locked_by_registrant_at reserved status_notes nameservers]