mirror of
https://github.com/google/nomulus.git
synced 2025-05-21 03:39:36 +02:00
Reimplement the RDAP Json creation using Jsonables
Currently we try to reimplemnet the same behavior of the existing code as much as possible. We only fix issues that go against the RFC7483, but we don't yet update the code to follow the latest (15feb19) RDAP Response Profile. That will require a much bigger change especially for the test files, so it'll wait for a followup CL. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=246948018
This commit is contained in:
parent
e382299212
commit
bdc41edd34
85 changed files with 2589 additions and 2367 deletions
|
@ -16,9 +16,12 @@ package google.registry.rdap;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.config.RdapNoticeDescriptor;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
@ -28,6 +31,12 @@ import org.json.simple.JSONObject;
|
|||
|
||||
public class RdapTestHelper {
|
||||
|
||||
private static final Gson GSON = new GsonBuilder().create();
|
||||
|
||||
static JsonElement createJson(String... lines) {
|
||||
return GSON.fromJson(Joiner.on("\n").join(lines), JsonElement.class);
|
||||
}
|
||||
|
||||
enum ContactNoticeType {
|
||||
NONE,
|
||||
DOMAIN,
|
||||
|
@ -46,48 +55,13 @@ public class RdapTestHelper {
|
|||
}
|
||||
|
||||
static ImmutableList<ImmutableMap<String, Object>> createNotices(String linkBase) {
|
||||
return createNotices(linkBase, ContactNoticeType.NONE, null);
|
||||
return createNotices(linkBase, null);
|
||||
}
|
||||
|
||||
static ImmutableList<ImmutableMap<String, Object>> createNotices(
|
||||
String linkBase, ContactNoticeType contactNoticeType, @Nullable Object otherNotices) {
|
||||
String linkBase, @Nullable Object otherNotices) {
|
||||
ImmutableList.Builder<ImmutableMap<String, Object>> noticesBuilder =
|
||||
getBuilderWithOthersAdded(otherNotices);
|
||||
switch (contactNoticeType) {
|
||||
case DOMAIN:
|
||||
noticesBuilder.add(
|
||||
ImmutableMap.of(
|
||||
"title", "Contacts Hidden",
|
||||
"description",
|
||||
ImmutableList.of("Domain contacts are visible only to the owning registrar."),
|
||||
"type", "object truncated due to unexplainable reasons"));
|
||||
break;
|
||||
case CONTACT:
|
||||
noticesBuilder.add(
|
||||
ImmutableMap.of(
|
||||
"title",
|
||||
"Data Policy",
|
||||
"description",
|
||||
ImmutableList.of(
|
||||
"Some of the data in this object has been removed.",
|
||||
"Contact personal data is visible only to the owning registrar."),
|
||||
"type",
|
||||
"object truncated due to authorization",
|
||||
"links",
|
||||
ImmutableList.of(
|
||||
ImmutableMap.of(
|
||||
"value",
|
||||
"https://github.com/google/nomulus/blob/master/docs/rdap.md#authentication",
|
||||
"rel",
|
||||
"alternate",
|
||||
"href",
|
||||
"https://github.com/google/nomulus/blob/master/docs/rdap.md#authentication",
|
||||
"type",
|
||||
"text/html"))));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
noticesBuilder.add(
|
||||
ImmutableMap.of(
|
||||
"title", "RDAP Terms of Service",
|
||||
|
@ -142,28 +116,13 @@ public class RdapTestHelper {
|
|||
}
|
||||
|
||||
static void addDomainBoilerplateNotices(ImmutableMap.Builder<String, Object> builder) {
|
||||
addDomainBoilerplateNotices(builder, false, null);
|
||||
addDomainBoilerplateNotices(builder, null);
|
||||
}
|
||||
|
||||
static void addDomainBoilerplateNotices(
|
||||
ImmutableMap.Builder<String, Object> builder, @Nullable Object otherNotices) {
|
||||
addDomainBoilerplateNotices(builder, false, otherNotices);
|
||||
}
|
||||
|
||||
static void addDomainBoilerplateNotices(
|
||||
ImmutableMap.Builder<String, Object> builder,
|
||||
boolean addNoContactRemark,
|
||||
@Nullable Object otherNotices) {
|
||||
ImmutableList.Builder<ImmutableMap<String, Object>> noticesBuilder =
|
||||
getBuilderWithOthersAdded(otherNotices);
|
||||
if (addNoContactRemark) {
|
||||
noticesBuilder.add(
|
||||
ImmutableMap.of(
|
||||
"title", "Contacts Hidden",
|
||||
"description",
|
||||
ImmutableList.of("Domain contacts are visible only to the owning registrar."),
|
||||
"type", "object truncated due to unexplainable reasons"));
|
||||
}
|
||||
noticesBuilder.add(
|
||||
ImmutableMap.of(
|
||||
"description",
|
||||
|
@ -214,57 +173,31 @@ public class RdapTestHelper {
|
|||
|
||||
static RdapJsonFormatter getTestRdapJsonFormatter() {
|
||||
RdapJsonFormatter rdapJsonFormatter = new RdapJsonFormatter();
|
||||
rdapJsonFormatter.rdapTosPath = "/tos";
|
||||
rdapJsonFormatter.rdapHelpMap =
|
||||
ImmutableMap.of(
|
||||
"/",
|
||||
RdapNoticeDescriptor.builder()
|
||||
.setTitle("RDAP Help")
|
||||
.setDescription(
|
||||
ImmutableList.of(
|
||||
"domain/XXXX",
|
||||
"nameserver/XXXX",
|
||||
"entity/XXXX",
|
||||
"domains?name=XXXX",
|
||||
"domains?nsLdhName=XXXX",
|
||||
"domains?nsIp=XXXX",
|
||||
"nameservers?name=XXXX",
|
||||
"nameservers?ip=XXXX",
|
||||
"entities?fn=XXXX",
|
||||
"entities?handle=XXXX",
|
||||
"help/XXXX"))
|
||||
.setLinkValueSuffix("help/")
|
||||
.setLinkHrefUrlString("https://github.com/google/nomulus/blob/master/docs/rdap.md")
|
||||
.build(),
|
||||
"/tos",
|
||||
RdapNoticeDescriptor.builder()
|
||||
.setTitle("RDAP Terms of Service")
|
||||
.setDescription(
|
||||
ImmutableList.of(
|
||||
"By querying our Domain Database, you are agreeing to comply with these"
|
||||
+ " terms so please read them carefully.",
|
||||
"Any information provided is 'as is' without any guarantee of accuracy.",
|
||||
"Please do not misuse the Domain Database. It is intended solely for"
|
||||
+ " query-based access.",
|
||||
"Don't use the Domain Database to allow, enable, or otherwise support the"
|
||||
+ " transmission of mass unsolicited, commercial advertising or"
|
||||
+ " solicitations.",
|
||||
"Don't access our Domain Database through the use of high volume, automated"
|
||||
+ " electronic processes that send queries or data to the systems of"
|
||||
+ " any ICANN-accredited registrar.",
|
||||
"You may only use the information contained in the Domain Database for"
|
||||
+ " lawful purposes.",
|
||||
"Do not compile, repackage, disseminate, or otherwise use the information"
|
||||
+ " contained in the Domain Database in its entirety, or in any"
|
||||
+ " substantial portion, without our prior written permission.",
|
||||
"We may retain certain details about queries to our Domain Database for the"
|
||||
+ " purposes of detecting and preventing misuse.",
|
||||
"We reserve the right to restrict or deny your access to the database if we"
|
||||
+ " suspect that you have failed to comply with these terms.",
|
||||
"We reserve the right to modify this agreement at any time."))
|
||||
.setLinkValueSuffix("help/tos")
|
||||
.setLinkHrefUrlString("https://www.registry.tld/about/rdap/tos.html")
|
||||
.build());
|
||||
rdapJsonFormatter.fullServletPath = "https://example.tld/rdap/";
|
||||
rdapJsonFormatter.rdapTos =
|
||||
ImmutableList.of(
|
||||
"By querying our Domain Database, you are agreeing to comply with these"
|
||||
+ " terms so please read them carefully.",
|
||||
"Any information provided is 'as is' without any guarantee of accuracy.",
|
||||
"Please do not misuse the Domain Database. It is intended solely for"
|
||||
+ " query-based access.",
|
||||
"Don't use the Domain Database to allow, enable, or otherwise support the"
|
||||
+ " transmission of mass unsolicited, commercial advertising or"
|
||||
+ " solicitations.",
|
||||
"Don't access our Domain Database through the use of high volume, automated"
|
||||
+ " electronic processes that send queries or data to the systems of"
|
||||
+ " any ICANN-accredited registrar.",
|
||||
"You may only use the information contained in the Domain Database for"
|
||||
+ " lawful purposes.",
|
||||
"Do not compile, repackage, disseminate, or otherwise use the information"
|
||||
+ " contained in the Domain Database in its entirety, or in any"
|
||||
+ " substantial portion, without our prior written permission.",
|
||||
"We may retain certain details about queries to our Domain Database for the"
|
||||
+ " purposes of detecting and preventing misuse.",
|
||||
"We reserve the right to restrict or deny your access to the database if we"
|
||||
+ " suspect that you have failed to comply with these terms.",
|
||||
"We reserve the right to modify this agreement at any time.");
|
||||
rdapJsonFormatter.rdapTosStaticUrl = "https://www.registry.tld/about/rdap/tos.html";
|
||||
return rdapJsonFormatter;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue