Change WHOIS functionality to return PDT registrars

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=120448012
This commit is contained in:
mcilwain 2016-04-21 08:53:52 -07:00 committed by Justine Tunney
parent 9ca191f3d4
commit 9e7934684e
2 changed files with 33 additions and 14 deletions

View file

@ -23,6 +23,7 @@ import static com.google.common.base.Predicates.notNull;
import static com.google.common.base.Strings.emptyToNull; import static com.google.common.base.Strings.emptyToNull;
import static com.google.common.base.Strings.isNullOrEmpty; import static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.common.base.Strings.nullToEmpty; import static com.google.common.base.Strings.nullToEmpty;
import static com.google.common.collect.Sets.immutableEnumSet;
import static com.google.common.io.BaseEncoding.base64; import static com.google.common.io.BaseEncoding.base64;
import static com.google.domain.registry.model.common.EntityGroupRoot.getCrossTldKey; import static com.google.domain.registry.model.common.EntityGroupRoot.getCrossTldKey;
import static com.google.domain.registry.model.ofy.ObjectifyService.ofy; import static com.google.domain.registry.model.ofy.ObjectifyService.ofy;
@ -179,13 +180,13 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
/** /**
* The types for which a {@link Registrar} should be included in WHOIS and RDAP output. We exclude * The types for which a {@link Registrar} should be included in WHOIS and RDAP output. We exclude
* PDT and TEST. We considered excluding INTERNAL as well, but decided that troubleshooting would * registrars of type TEST. We considered excluding INTERNAL as well, but decided that
* be easier with INTERNAL registrars visible. * troubleshooting would be easier with INTERNAL registrars visible.
*/ */
//TODO(b/27274151): Expand documentation of this field. //TODO(b/27274151): Expand documentation of this field.
private static final ImmutableSet<Type> PUBLICLY_VISIBLE_TYPES = private static final ImmutableSet<Type> PUBLICLY_VISIBLE_TYPES =
Sets.immutableEnumSet( immutableEnumSet(
Type.REAL, Type.OTE, Type.EXTERNAL_MONITORING, Type.MONITORING, Type.INTERNAL); Type.REAL, Type.PDT, Type.OTE, Type.EXTERNAL_MONITORING, Type.MONITORING, Type.INTERNAL);
@Parent @Parent
Key<EntityGroupRoot> parent = getCrossTldKey(); Key<EntityGroupRoot> parent = getCrossTldKey();

View file

@ -15,6 +15,8 @@
package com.google.domain.registry.whois; package com.google.domain.registry.whois;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.domain.registry.model.registrar.Registrar.State.ACTIVE;
import static com.google.domain.registry.model.registrar.Registrar.Type.PDT;
import static com.google.domain.registry.testing.DatastoreHelper.createTlds; import static com.google.domain.registry.testing.DatastoreHelper.createTlds;
import static com.google.domain.registry.testing.DatastoreHelper.persistResource; import static com.google.domain.registry.testing.DatastoreHelper.persistResource;
import static com.google.domain.registry.testing.DatastoreHelper.persistSimpleGlobalResources; import static com.google.domain.registry.testing.DatastoreHelper.persistSimpleGlobalResources;
@ -85,7 +87,7 @@ public class WhoisServerTest {
@Test @Test
public void testRun_domainQuery_works() throws Exception { public void testRun_domainQuery_works() throws Exception {
Registrar registrar = persistResource(makeRegistrar( Registrar registrar = persistResource(makeRegistrar(
"evilregistrar", "Yes Virginia <script>", Registrar.State.ACTIVE)); "evilregistrar", "Yes Virginia <script>", ACTIVE));
persistResource(makeDomainResource( persistResource(makeDomainResource(
"cat.lol", "cat.lol",
persistResource(makeContactResource("5372808-ERL", "Goblin Market", "lol@cat.lol")), persistResource(makeContactResource("5372808-ERL", "Goblin Market", "lol@cat.lol")),
@ -103,7 +105,7 @@ public class WhoisServerTest {
@Test @Test
public void testRun_idnDomain_works() throws Exception { public void testRun_idnDomain_works() throws Exception {
Registrar registrar = persistResource(makeRegistrar( Registrar registrar = persistResource(makeRegistrar(
"evilregistrar", "Yes Virginia <script>", Registrar.State.ACTIVE)); "evilregistrar", "Yes Virginia <script>", ACTIVE));
persistResource(makeDomainResource( persistResource(makeDomainResource(
"cat.みんな", "cat.みんな",
persistResource(makeContactResource("5372808-ERL", "(◕‿◕)", "lol@cat.みんな")), persistResource(makeContactResource("5372808-ERL", "(◕‿◕)", "lol@cat.みんな")),
@ -121,7 +123,7 @@ public class WhoisServerTest {
@Test @Test
public void testRun_punycodeDomain_works() throws Exception { public void testRun_punycodeDomain_works() throws Exception {
Registrar registrar = persistResource(makeRegistrar( Registrar registrar = persistResource(makeRegistrar(
"evilregistrar", "Yes Virginia <script>", Registrar.State.ACTIVE)); "evilregistrar", "Yes Virginia <script>", ACTIVE));
persistResource(makeDomainResource( persistResource(makeDomainResource(
"cat.みんな", "cat.みんな",
persistResource(makeContactResource("5372808-ERL", "(◕‿◕)", "lol@cat.みんな")), persistResource(makeContactResource("5372808-ERL", "(◕‿◕)", "lol@cat.みんな")),
@ -150,7 +152,7 @@ public class WhoisServerTest {
public void testRun_domainInTestTld_isConsideredNotFound() throws Exception { public void testRun_domainInTestTld_isConsideredNotFound() throws Exception {
persistResource(Registry.get("lol").asBuilder().setTldType(Registry.TldType.TEST).build()); persistResource(Registry.get("lol").asBuilder().setTldType(Registry.TldType.TEST).build());
Registrar registrar = persistResource(makeRegistrar( Registrar registrar = persistResource(makeRegistrar(
"evilregistrar", "Yes Virginia <script>", Registrar.State.ACTIVE)); "evilregistrar", "Yes Virginia <script>", ACTIVE));
persistResource(makeDomainResource( persistResource(makeDomainResource(
"cat.lol", "cat.lol",
persistResource(makeContactResource("5372808-ERL", "Goblin Market", "lol@cat.lol")), persistResource(makeContactResource("5372808-ERL", "Goblin Market", "lol@cat.lol")),
@ -179,7 +181,7 @@ public class WhoisServerTest {
persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4")), persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4")),
persistResource(makeHostResource("ns2.cat.lol", "bad:f00d:cafe::15:beef")), persistResource(makeHostResource("ns2.cat.lol", "bad:f00d:cafe::15:beef")),
persistResource( persistResource(
(registrar = makeRegistrar("example", "Example Registrar", Registrar.State.ACTIVE)))) (registrar = makeRegistrar("example", "Example Registrar", ACTIVE))))
.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); .asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
persistSimpleGlobalResources(makeRegistrarContacts(registrar)); persistSimpleGlobalResources(makeRegistrarContacts(registrar));
newWhoisServer("domain cat.lol\r\n").run(); newWhoisServer("domain cat.lol\r\n").run();
@ -205,7 +207,7 @@ public class WhoisServerTest {
persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4")), persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4")),
persistResource(makeHostResource("ns2.cat.lol", "bad:f00d:cafe::15:beef")), persistResource(makeHostResource("ns2.cat.lol", "bad:f00d:cafe::15:beef")),
persistResource( persistResource(
makeRegistrar("example", "Example Registrar", Registrar.State.ACTIVE))).asBuilder() makeRegistrar("example", "Example Registrar", ACTIVE))).asBuilder()
.setCreationTimeForTest(DateTime.now().minusDays(2)) .setCreationTimeForTest(DateTime.now().minusDays(2))
.setDeletionTime(DateTime.now().minusDays(1)).build()); .setDeletionTime(DateTime.now().minusDays(1)).build());
DomainResource domain2 = persistResource(makeDomainResource("cat.lol", DomainResource domain2 = persistResource(makeDomainResource("cat.lol",
@ -219,7 +221,7 @@ public class WhoisServerTest {
persistResource(makeHostResource("ns1.google.lol", "9.9.9.9")), persistResource(makeHostResource("ns1.google.lol", "9.9.9.9")),
persistResource(makeHostResource("ns2.google.lol", "4311::f143")), persistResource(makeHostResource("ns2.google.lol", "4311::f143")),
persistResource((registrar = makeRegistrar( persistResource((registrar = makeRegistrar(
"example", "Example Registrar", Registrar.State.ACTIVE)))).asBuilder() "example", "Example Registrar", ACTIVE)))).asBuilder()
.setCreationTimeForTest(DateTime.now()).build()); .setCreationTimeForTest(DateTime.now()).build());
persistSimpleGlobalResources(makeRegistrarContacts(registrar)); persistSimpleGlobalResources(makeRegistrarContacts(registrar));
assertThat(domain1.getRepoId()).isNotEqualTo(domain2.getRepoId()); assertThat(domain1.getRepoId()).isNotEqualTo(domain2.getRepoId());
@ -366,7 +368,23 @@ public class WhoisServerTest {
@Test @Test
public void testRun_registrarLookup_works() throws Exception { public void testRun_registrarLookup_works() throws Exception {
Registrar registrar = persistResource( Registrar registrar = persistResource(
makeRegistrar("example", "Example Registrar, Inc.", Registrar.State.ACTIVE)); makeRegistrar("example", "Example Registrar, Inc.", ACTIVE));
persistSimpleGlobalResources(makeRegistrarContacts(registrar));
// Notice the partial search without "inc".
newWhoisServer("registrar example registrar").run();
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getPayload()).isEqualTo(loadWhoisTestFile("whois_server_registrar.txt"));
}
@Test
public void testRun_pdtRegistrarLookup_works() throws Exception {
Registrar registrar =
persistResource(
makeRegistrar("example", "Example Registrar, Inc.", ACTIVE)
.asBuilder()
.setIanaIdentifier(9995L)
.setType(PDT)
.build());
persistSimpleGlobalResources(makeRegistrarContacts(registrar)); persistSimpleGlobalResources(makeRegistrarContacts(registrar));
// Notice the partial search without "inc". // Notice the partial search without "inc".
newWhoisServer("registrar example registrar").run(); newWhoisServer("registrar example registrar").run();
@ -388,7 +406,7 @@ public class WhoisServerTest {
@Test @Test
public void testRun_registrarLookupWithTestType_returnsNotFound() throws Exception { public void testRun_registrarLookupWithTestType_returnsNotFound() throws Exception {
Registrar registrar = persistResource( Registrar registrar = persistResource(
makeRegistrar("example", "Example Registrar, Inc.", Registrar.State.ACTIVE) makeRegistrar("example", "Example Registrar, Inc.", ACTIVE)
.asBuilder() .asBuilder()
.setIanaIdentifier(null) .setIanaIdentifier(null)
.setType(Registrar.Type.TEST) .setType(Registrar.Type.TEST)
@ -403,7 +421,7 @@ public class WhoisServerTest {
@Test @Test
public void testRun_multilevelDomain_isNotConsideredAHostname() throws Exception { public void testRun_multilevelDomain_isNotConsideredAHostname() throws Exception {
Registrar registrar = Registrar registrar =
persistResource(makeRegistrar("example", "Example Registrar", Registrar.State.ACTIVE)); persistResource(makeRegistrar("example", "Example Registrar", ACTIVE));
persistResource(makeDomainResource("cat.1.test", persistResource(makeDomainResource("cat.1.test",
persistResource(makeContactResource("5372808-ERL", "(◕‿◕)", "lol@cat.1.test")), persistResource(makeContactResource("5372808-ERL", "(◕‿◕)", "lol@cat.1.test")),
persistResource(makeContactResource("5372808-IRL", "Santa Claus", "BOFH@cat.1.test")), persistResource(makeContactResource("5372808-IRL", "Santa Claus", "BOFH@cat.1.test")),