From 21313bffdac80a00153584136309e6010d26cf0f Mon Sep 17 00:00:00 2001 From: mountford Date: Fri, 23 Feb 2018 11:26:06 -0800 Subject: [PATCH] RDAP: Add registrar entity for domains MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The RDAP Pilot Program operational profile document indicates that domain responses should list, in addition to their normal contacts, a special entity for the registrar. 1.5.12. The domain object in the RDAP response MUST contain an entity with the registrar role (called registrar entity in this section). The handle of the entity MUST be equal to the IANA Registrar ID. A valid fn member MUST be present in the registrar entity. Other members MAY be present in the entity (as specified in RFC6350, the vCard Format Specification and its corresponding JSON mapping RFC7095). Contracted parties MUST include an entity with the abuse role (called Abuse Entity in this section) within the registrar entity. The Abuse Entity MUST include tel and email members, and MAY include other members. 1.5.13. The entity with the registrar role in the RDAP response MUST contain a publicIDs member [RFC7483] to identify the IANA Registrar ID from the IANA’s Registrar ID registry (https://www.iana.org/assignments/registrar-ids/registrar-ids.xhtml). The type value of the publicID object MUST be equal to IANA Registrar ID. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=186797360 --- .../registry/rdap/RdapJsonFormatter.java | 40 +++++++ .../registry/rdap/RdapDomainActionTest.java | 26 ++++- .../rdap/RdapDomainSearchActionTest.java | 29 ++++- .../registry/rdap/testdata/rdap_domain.json | 87 ++++++++++++++ .../rdap/testdata/rdap_domain_cat2.json | 87 ++++++++++++++ .../rdap/testdata/rdap_domain_deleted.json | 87 ++++++++++++++ .../rdap/testdata/rdap_domain_unicode.json | 87 ++++++++++++++ .../rdap/testdata/rdapjson_domain_full.json | 106 ++++++++++++++++++ .../rdapjson_domain_no_nameservers.json | 106 ++++++++++++++++++ 9 files changed, 650 insertions(+), 5 deletions(-) diff --git a/java/google/registry/rdap/RdapJsonFormatter.java b/java/google/registry/rdap/RdapJsonFormatter.java index 5350980db..7eec9ca60 100644 --- a/java/google/registry/rdap/RdapJsonFormatter.java +++ b/java/google/registry/rdap/RdapJsonFormatter.java @@ -543,6 +543,14 @@ public class RdapJsonFormatter { outputDataType, authorization)) .collect(toImmutableList()); + entities = + addRegistrarEntity( + entities, + domainResource.getCurrentSponsorClientId(), + linkBase, + whoisServer, + now, + outputDataType); if (!entities.isEmpty()) { jsonBuilder.put("entities", entities); } @@ -574,6 +582,38 @@ public class RdapJsonFormatter { return jsonBuilder.build(); } + /** + * Adds a JSON object for the desired registrar to an existing array of JSON objects. + * + * @param clientId the registrar client ID + * @param linkBase the URL base to be used when creating links + * @param whoisServer the fully-qualified domain name of the WHOIS server to be listed in the + * port43 field; if null, port43 is not added to the object + * @param now the as-date + * @param outputDataType whether to generate full or summary data + */ + ImmutableList> addRegistrarEntity( + ImmutableList> entities, + @Nullable String clientId, + @Nullable String linkBase, + @Nullable String whoisServer, + DateTime now, + OutputDataType outputDataType) { + if (clientId == null) { + return entities; + } + Optional registrar = Registrar.loadByClientIdCached(clientId); + if (!registrar.isPresent()) { + return entities; + } + ImmutableList.Builder> builder = new ImmutableList.Builder<>(); + builder.addAll(entities); + builder.add( + makeRdapJsonForRegistrar( + registrar.get(), false /* isTopLevel */, linkBase, whoisServer, now, outputDataType)); + return builder.build(); + } + /** * Creates a JSON object for a {@link HostResource}. * diff --git a/javatests/google/registry/rdap/RdapDomainActionTest.java b/javatests/google/registry/rdap/RdapDomainActionTest.java index ecfa9a640..f55a70799 100644 --- a/javatests/google/registry/rdap/RdapDomainActionTest.java +++ b/javatests/google/registry/rdap/RdapDomainActionTest.java @@ -298,7 +298,8 @@ public class RdapDomainActionTest { String punycodeName, String handle, String expectedOutputFile) { - return generateExpectedJson(name, punycodeName, handle, null, null, null, expectedOutputFile); + return generateExpectedJson( + name, punycodeName, handle, null, null, null, null, expectedOutputFile); } private Object generateExpectedJson( @@ -308,6 +309,7 @@ public class RdapDomainActionTest { @Nullable List contactRoids, @Nullable List nameserverRoids, @Nullable List nameserverNames, + @Nullable String registrarName, String expectedOutputFile) { ImmutableMap.Builder substitutionsBuilder = new ImmutableMap.Builder<>(); substitutionsBuilder.put("NAME", name); @@ -316,6 +318,9 @@ public class RdapDomainActionTest { substitutionsBuilder.put("TYPE", "domain name"); substitutionsBuilder.put("NAMESERVER1ADDRESS", "1.2.3.4"); substitutionsBuilder.put("NAMESERVER2ADDRESS", "bad:f00d:cafe::15:beef"); + if (registrarName != null) { + substitutionsBuilder.put("REGISTRARNAME", registrarName); + } if (contactRoids != null) { for (int i = 0; i < contactRoids.size(); i++) { substitutionsBuilder.put("CONTACT" + (i + 1) + "ROID", contactRoids.get(i)); @@ -350,9 +355,17 @@ public class RdapDomainActionTest { String handle, @Nullable List contactRoids, @Nullable List nameserverRoids, + @Nullable String registrarName, String expectedOutputFile) { return generateExpectedJsonWithTopLevelEntries( - name, punycodeName, handle, contactRoids, nameserverRoids, null, expectedOutputFile); + name, + punycodeName, + handle, + contactRoids, + nameserverRoids, + null, + registrarName, + expectedOutputFile); } private Object generateExpectedJsonWithTopLevelEntries( String name, @@ -361,6 +374,7 @@ public class RdapDomainActionTest { @Nullable List contactRoids, @Nullable List nameserverRoids, @Nullable List nameserverNames, + @Nullable String registrarName, String expectedOutputFile) { Object obj = generateExpectedJson( @@ -370,6 +384,7 @@ public class RdapDomainActionTest { contactRoids, nameserverRoids, nameserverNames, + registrarName, expectedOutputFile); if (obj instanceof Map) { @SuppressWarnings("unchecked") @@ -412,6 +427,7 @@ public class RdapDomainActionTest { ? ImmutableList.of("4-ROID", "6-ROID", "2-ROID") : null, ImmutableList.of("8-ROID", "A-ROID"), + "Yes Virginia