diff --git a/java/google/registry/config/RegistryConfig.java b/java/google/registry/config/RegistryConfig.java index 8b57a034d..e4c734f89 100644 --- a/java/google/registry/config/RegistryConfig.java +++ b/java/google/registry/config/RegistryConfig.java @@ -852,7 +852,7 @@ public final class RegistryConfig { /** * Amount of time public HTTP proxies are permitted to cache our WHOIS responses. * - * @see google.registry.whois.WhoisHttpServer + * @see google.registry.whois.WhoisHttpAction */ @Provides @Config("whoisHttpExpires") diff --git a/java/google/registry/module/frontend/FrontendRequestComponent.java b/java/google/registry/module/frontend/FrontendRequestComponent.java index f6ff6ad22..52d504b54 100644 --- a/java/google/registry/module/frontend/FrontendRequestComponent.java +++ b/java/google/registry/module/frontend/FrontendRequestComponent.java @@ -42,9 +42,9 @@ import google.registry.ui.server.registrar.RegistrarPaymentAction; import google.registry.ui.server.registrar.RegistrarPaymentSetupAction; import google.registry.ui.server.registrar.RegistrarPremiumPriceAckAction; import google.registry.ui.server.registrar.RegistrarSettingsAction; -import google.registry.whois.WhoisHttpServer; +import google.registry.whois.WhoisAction; +import google.registry.whois.WhoisHttpAction; import google.registry.whois.WhoisModule; -import google.registry.whois.WhoisServer; /** Dagger component with per-request lifetime for "default" App Engine module. */ @RequestScope @@ -77,8 +77,10 @@ interface FrontendRequestComponent { RdapIpAction rdapDefaultAction(); RdapNameserverAction rdapNameserverAction(); RdapNameserverSearchAction rdapNameserverSearchAction(); - WhoisHttpServer whoisHttpServer(); - WhoisServer whoisServer(); + + WhoisHttpAction whoisHttpAction(); + + WhoisAction whoisAction(); @Subcomponent.Builder abstract class Builder implements RequestComponentBuilder { diff --git a/java/google/registry/whois/WhoisServer.java b/java/google/registry/whois/WhoisAction.java similarity index 94% rename from java/google/registry/whois/WhoisServer.java rename to java/google/registry/whois/WhoisAction.java index ca2d1d132..dc11fdd31 100644 --- a/java/google/registry/whois/WhoisServer.java +++ b/java/google/registry/whois/WhoisAction.java @@ -41,20 +41,16 @@ import org.joda.time.DateTime; *

All commands and responses conform to the WHOIS spec as defined in RFC 3912. Commands must be * sent via an HTTP POST in the request body. * - *

This servlet is meant to serve as a low level interface for the proxy app which forwards us + *

This action is meant to serve as a low level interface for the proxy app which forwards us * requests received on port 43. However this interface is technically higher level because it sends * back proper HTTP error codes such as 200, 400, 500, etc. These are discarded by the proxy because * WHOIS specifies no manner for differentiating successful and erroneous requests. * - * @see WhoisHttpServer + * @see WhoisHttpAction * @see RFC 3912: WHOIS Protocol Specification */ -@Action( - path = "/_dr/whois", - method = POST, - auth = Auth.AUTH_INTERNAL_OR_ADMIN -) -public class WhoisServer implements Runnable { +@Action(path = "/_dr/whois", method = POST, auth = Auth.AUTH_INTERNAL_OR_ADMIN) +public class WhoisAction implements Runnable { private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass(); @@ -75,7 +71,9 @@ public class WhoisServer implements Runnable { @Inject @Config("whoisDisclaimer") String disclaimer; @Inject WhoisMetric.Builder metricBuilder; @Inject WhoisMetrics whoisMetrics; - @Inject WhoisServer() {} + + @Inject + WhoisAction() {} @Override public void run() { diff --git a/java/google/registry/whois/WhoisHttpServer.java b/java/google/registry/whois/WhoisHttpAction.java similarity index 95% rename from java/google/registry/whois/WhoisHttpServer.java rename to java/google/registry/whois/WhoisHttpAction.java index 397c425c1..64371d6a3 100644 --- a/java/google/registry/whois/WhoisHttpServer.java +++ b/java/google/registry/whois/WhoisHttpAction.java @@ -48,12 +48,12 @@ import org.joda.time.Duration; /** * Human-Friendly HTTP WHOIS API * - *

This API uses easy to understand paths rather than {@link WhoisServer} which requires a POST + *

This API uses easy to understand paths rather than {@link WhoisAction} which requires a POST * request containing a WHOIS command. Because the typical WHOIS command is along the lines of - * {@code "domain google.lol"} or the equivalent {@code "google.lol}, this servlet is just going to + * {@code "domain google.lol"} or the equivalent {@code "google.lol}, this action is just going to * replace the slashes with spaces and let {@link WhoisReader} figure out what to do. * - *

This servlet accepts requests from any origin. + *

This action accepts requests from any origin. * *

You can send AJAX requests to our WHOIS API from your very own website using the * following embed code: @@ -93,14 +93,10 @@ import org.joda.time.Duration; * * * - * @see WhoisServer + * @see WhoisAction */ -@Action( - path = WhoisHttpServer.PATH, - isPrefix = true, - auth = Auth.AUTH_PUBLIC_ANONYMOUS -) -public final class WhoisHttpServer implements Runnable { +@Action(path = WhoisHttpAction.PATH, isPrefix = true, auth = Auth.AUTH_PUBLIC_ANONYMOUS) +public final class WhoisHttpAction implements Runnable { public static final String PATH = "/whois/"; @@ -142,7 +138,9 @@ public final class WhoisHttpServer implements Runnable { @Inject @RequestPath String requestPath; @Inject WhoisMetric.Builder metricBuilder; @Inject WhoisMetrics whoisMetrics; - @Inject WhoisHttpServer() {} + + @Inject + WhoisHttpAction() {} @Override public void run() { diff --git a/java/google/registry/whois/WhoisMetrics.java b/java/google/registry/whois/WhoisMetrics.java index 00ae53322..abcd32df1 100644 --- a/java/google/registry/whois/WhoisMetrics.java +++ b/java/google/registry/whois/WhoisMetrics.java @@ -31,7 +31,7 @@ import org.joda.time.DateTime; /** * Instrumentation for WHOIS requests. * - * @see WhoisServer + * @see WhoisAction */ public class WhoisMetrics { diff --git a/javatests/google/registry/module/frontend/testdata/frontend_routing.txt b/javatests/google/registry/module/frontend/testdata/frontend_routing.txt index 7c477095b..a0f942d3d 100644 --- a/javatests/google/registry/module/frontend/testdata/frontend_routing.txt +++ b/javatests/google/registry/module/frontend/testdata/frontend_routing.txt @@ -1,6 +1,6 @@ PATH CLASS METHODS OK AUTH_METHODS MIN USER_POLICY /_dr/epp EppTlsAction POST n INTERNAL,API APP ADMIN -/_dr/whois WhoisServer POST n INTERNAL,API APP ADMIN +/_dr/whois WhoisAction POST n INTERNAL,API APP ADMIN /check CheckApiAction GET n INTERNAL NONE PUBLIC /rdap/autnum/(*) RdapAutnumAction GET,HEAD n INTERNAL NONE PUBLIC /rdap/domain/(*) RdapDomainAction GET,HEAD n INTERNAL,API,LEGACY NONE PUBLIC @@ -17,4 +17,4 @@ PATH CLASS METHODS OK AUTH_MET /registrar-premium-price-ack RegistrarPremiumPriceAckAction POST n API,LEGACY USER PUBLIC /registrar-settings RegistrarSettingsAction POST n API,LEGACY USER PUBLIC /registrar-xhr EppConsoleAction POST n API,LEGACY USER PUBLIC -/whois/(*) WhoisHttpServer GET n INTERNAL NONE PUBLIC +/whois/(*) WhoisHttpAction GET n INTERNAL NONE PUBLIC diff --git a/javatests/google/registry/whois/WhoisServerTest.java b/javatests/google/registry/whois/WhoisActionTest.java similarity index 82% rename from javatests/google/registry/whois/WhoisServerTest.java rename to javatests/google/registry/whois/WhoisActionTest.java index 892d8690c..d226529f4 100644 --- a/javatests/google/registry/whois/WhoisServerTest.java +++ b/javatests/google/registry/whois/WhoisActionTest.java @@ -60,9 +60,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -/** Unit tests for {@link WhoisServer}. */ +/** Unit tests for {@link WhoisAction}. */ @RunWith(JUnit4.class) -public class WhoisServerTest { +public class WhoisActionTest { @Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build(); @Rule public final InjectRule inject = new InjectRule(); @@ -70,18 +70,18 @@ public class WhoisServerTest { private final FakeResponse response = new FakeResponse(); private final FakeClock clock = new FakeClock(DateTime.parse("2009-06-29T20:13:00Z")); - private WhoisServer newWhoisServer(String input) { - WhoisServer whoisServer = new WhoisServer(); - whoisServer.clock = clock; - whoisServer.input = new StringReader(input); - whoisServer.response = response; - whoisServer.whoisReader = new WhoisReader(new WhoisCommandFactory()); - whoisServer.whoisMetrics = new WhoisMetrics(); - whoisServer.metricBuilder = WhoisMetric.builderForRequest(clock); - whoisServer.disclaimer = + private WhoisAction newWhoisAction(String input) { + WhoisAction whoisAction = new WhoisAction(); + whoisAction.clock = clock; + whoisAction.input = new StringReader(input); + whoisAction.response = response; + whoisAction.whoisReader = new WhoisReader(new WhoisCommandFactory()); + whoisAction.whoisMetrics = new WhoisMetrics(); + whoisAction.metricBuilder = WhoisMetric.builderForRequest(clock); + whoisAction.disclaimer = "Doodle Disclaimer\nI exist so that carriage return\nin disclaimer can be tested."; - whoisServer.retrier = new Retrier(new FakeSleeper(clock), 3); - return whoisServer; + whoisAction.retrier = new Retrier(new FakeSleeper(clock), 3); + return whoisAction; } @Before @@ -92,9 +92,9 @@ public class WhoisServerTest { @Test public void testRun_badRequest_stillSends200() throws Exception { - newWhoisServer("\r\n").run(); + newWhoisAction("\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); - assertThat(response.getPayload()).isEqualTo(loadFile("whois_server_no_command.txt")); + assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_no_command.txt")); } @Test @@ -110,9 +110,9 @@ public class WhoisServerTest { persistResource(makeHostResource("ns2.cat.lol", "bad:f00d:cafe::15:beef")), registrar)); persistSimpleResources(makeRegistrarContacts(registrar)); - newWhoisServer("domain cat.lol\r\n").run(); + newWhoisAction("domain cat.lol\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); - assertThat(response.getPayload()).isEqualTo(loadFile("whois_server_domain.txt")); + assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_domain.txt")); } @Test @@ -128,9 +128,9 @@ public class WhoisServerTest { persistResource(makeHostResource("ns2.cat.みんな", "bad:f00d:cafe::15:beef")), registrar)); persistSimpleResources(makeRegistrarContacts(registrar)); - newWhoisServer("domain cat.みんな\r\n").run(); + newWhoisAction("domain cat.みんな\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); - assertThat(response.getPayload()).isEqualTo(loadFile("whois_server_idn_punycode.txt")); + assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_idn_punycode.txt")); } @Test @@ -146,17 +146,16 @@ public class WhoisServerTest { persistResource(makeHostResource("ns2.cat.みんな", "bad:f00d:cafe::15:beef")), registrar)); persistSimpleResources(makeRegistrarContacts(registrar)); - newWhoisServer("domain cat.xn--q9jyb4c\r\n").run(); + newWhoisAction("domain cat.xn--q9jyb4c\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); - assertThat(response.getPayload()).isEqualTo(loadFile("whois_server_idn_punycode.txt")); + assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_idn_punycode.txt")); } @Test public void testRun_domainNotFound_returns200OkAndPlainTextResponse() throws Exception { - newWhoisServer("domain cat.lol\r\n").run(); + newWhoisAction("domain cat.lol\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); - assertThat(response.getPayload()) - .isEqualTo(loadFile("whois_server_domain_not_found.txt")); + assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_domain_not_found.txt")); } // todo (b/27378695): reenable or delete this test @@ -175,10 +174,9 @@ public class WhoisServerTest { persistResource(makeHostResource("ns2.cat.lol", "bad:f00d:cafe::15:beef")), registrar)); persistSimpleResources(makeRegistrarContacts(registrar)); - newWhoisServer("domain cat.lol\r\n").run(); + newWhoisAction("domain cat.lol\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); - assertThat(response.getPayload()) - .isEqualTo(loadFile("whois_server_domain_not_found.txt")); + assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_domain_not_found.txt")); } @Test @@ -197,10 +195,9 @@ public class WhoisServerTest { (registrar = makeRegistrar("example", "Example Registrar", ACTIVE)))) .asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); persistSimpleResources(makeRegistrarContacts(registrar)); - newWhoisServer("domain cat.lol\r\n").run(); + newWhoisAction("domain cat.lol\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); - assertThat(response.getPayload()) - .isEqualTo(loadFile("whois_server_domain_not_found.txt")); + assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_domain_not_found.txt")); } /** @@ -238,7 +235,7 @@ public class WhoisServerTest { .setCreationTimeForTest(clock.nowUtc()).build()); persistSimpleResources(makeRegistrarContacts(registrar)); assertThat(domain1.getRepoId()).isNotEqualTo(domain2.getRepoId()); - newWhoisServer("domain cat.lol\r\n").run(); + newWhoisAction("domain cat.lol\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); assertThat(response.getPayload()).contains("Dr. Pablo"); assertThat(response.getPayload()).contains("ns1.google.lol"); @@ -247,15 +244,15 @@ public class WhoisServerTest { @Test public void testRun_nameserverQuery_works() throws Exception { persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4")); - newWhoisServer("nameserver ns1.cat.lol\r\n").run(); + newWhoisAction("nameserver ns1.cat.lol\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); - assertThat(response.getPayload()).isEqualTo(loadFile("whois_server_nameserver.txt")); + assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_nameserver.txt")); } @Test public void testRun_ipv6_displaysInCollapsedReadableFormat() throws Exception { persistResource(makeHostResource("ns1.cat.lol", "bad:f00d:cafe::15:beef")); - newWhoisServer("nameserver ns1.cat.lol\r\n").run(); + newWhoisAction("nameserver ns1.cat.lol\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); assertThat(response.getPayload()).contains("ns1.cat.lol"); // The most important thing this tests is that the outputted address is compressed! @@ -266,7 +263,7 @@ public class WhoisServerTest { @Test public void testRun_idnNameserver_works() throws Exception { persistResource(makeHostResource("ns1.cat.みんな", "1.2.3.4")); - newWhoisServer("nameserver ns1.cat.みんな\r\n").run(); + newWhoisAction("nameserver ns1.cat.みんな\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); assertThat(response.getPayload()).contains("ns1.cat.xn--q9jyb4c"); assertThat(response.getPayload()).contains("1.2.3.4"); @@ -275,7 +272,7 @@ public class WhoisServerTest { @Test public void testRun_punycodeNameserver_works() throws Exception { persistResource(makeHostResource("ns1.cat.みんな", "1.2.3.4")); - newWhoisServer("nameserver ns1.cat.xn--q9jyb4c\r\n").run(); + newWhoisAction("nameserver ns1.cat.xn--q9jyb4c\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); assertThat(response.getPayload()).contains("ns1.cat.xn--q9jyb4c"); assertThat(response.getPayload()).contains("1.2.3.4"); @@ -284,10 +281,9 @@ public class WhoisServerTest { @Test public void testRun_nameserverNotFound_returns200AndText() throws Exception { persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4")); - newWhoisServer("nameserver ns1.cat.lulz\r\n").run(); + newWhoisAction("nameserver ns1.cat.lulz\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); - assertThat(response.getPayload()) - .isEqualTo(loadFile("whois_server_nameserver_not_found.txt")); + assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_nameserver_not_found.txt")); } @Test @@ -295,16 +291,15 @@ public class WhoisServerTest { persistResource( makeHostResource("ns1.cat.lol", "1.2.3.4").asBuilder() .setDeletionTime(clock.nowUtc().minusDays(1)).build()); - newWhoisServer("nameserver ns1.cat.lol\r\n").run(); + newWhoisAction("nameserver ns1.cat.lol\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); - assertThat(response.getPayload()) - .isEqualTo(loadFile("whois_server_nameserver_not_found.txt")); + assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_nameserver_not_found.txt")); } @Test public void testRun_ipNameserverLookup_works() throws Exception { persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4")); - newWhoisServer("nameserver 1.2.3.4").run(); + newWhoisAction("nameserver 1.2.3.4").run(); assertThat(response.getStatus()).isEqualTo(200); assertThat(response.getPayload()).contains("ns1.cat.lol"); } @@ -313,7 +308,7 @@ public class WhoisServerTest { public void testRun_ipMapsToMultipleNameservers_theyAllGetReturned() throws Exception { persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4")); persistResource(makeHostResource("ns2.cat.lol", "1.2.3.4")); - newWhoisServer("nameserver 1.2.3.4").run(); + newWhoisAction("nameserver 1.2.3.4").run(); assertThat(response.getStatus()).isEqualTo(200); assertThat(response.getPayload()).contains("ns1.cat.lol"); assertThat(response.getPayload()).contains("ns2.cat.lol"); @@ -324,7 +319,7 @@ public class WhoisServerTest { persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4")); persistResource( makeHostResource("ns1.cat.xn--q9jyb4c", "1.2.3.4")); - newWhoisServer("nameserver 1.2.3.4").run(); + newWhoisAction("nameserver 1.2.3.4").run(); assertThat(response.getStatus()).isEqualTo(200); assertThat(response.getPayload()).contains("ns1.cat.lol"); assertThat(response.getPayload()).contains("ns1.cat.xn--q9jyb4c"); @@ -332,28 +327,27 @@ public class WhoisServerTest { @Test public void testRun_ipNameserverEntityDoesNotExist_returns200NotFound() throws Exception { - newWhoisServer("nameserver feed:a:bee::acab\r\n").run(); + newWhoisAction("nameserver feed:a:bee::acab\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); - assertThat(response.getPayload()).isEqualTo(loadFile("whois_server_ip_not_found.txt")); + assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_ip_not_found.txt")); } @Test public void testRun_ipMapsToNameserverUnderNonAuthoritativeTld_notFound() throws Exception { assertThat(getTlds()).doesNotContain("com"); persistResource(makeHostResource("ns1.google.com", "1.2.3.4")); - newWhoisServer("nameserver 1.2.3.4").run(); + newWhoisAction("nameserver 1.2.3.4").run(); assertThat(response.getStatus()).isEqualTo(200); - assertThat(response.getPayload()).isEqualTo(loadFile("whois_server_ip_not_found.txt")); + assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_ip_not_found.txt")); } @Test public void testRun_nameserverUnderNonAuthoritativeTld_notFound() throws Exception { assertThat(getTlds()).doesNotContain("com"); persistResource(makeHostResource("ns1.google.com", "1.2.3.4")); - newWhoisServer("nameserver ns1.google.com").run(); + newWhoisAction("nameserver ns1.google.com").run(); assertThat(response.getStatus()).isEqualTo(200); - assertThat(response.getPayload()) - .isEqualTo(loadFile("whois_server_nameserver_not_found.txt")); + assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_nameserver_not_found.txt")); } // todo (b/27378695): reenable or delete this test @@ -362,10 +356,9 @@ public class WhoisServerTest { public void testRun_nameserverInTestTld_notFound() throws Exception { persistResource(Registry.get("lol").asBuilder().setTldType(Registry.TldType.TEST).build()); persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4")); - newWhoisServer("nameserver ns1.cat.lol").run(); + newWhoisAction("nameserver ns1.cat.lol").run(); assertThat(response.getStatus()).isEqualTo(200); - assertThat(response.getPayload()) - .isEqualTo(loadFile("whois_server_nameserver_not_found.txt")); + assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_nameserver_not_found.txt")); } @Test @@ -374,9 +367,9 @@ public class WhoisServerTest { makeRegistrar("example", "Example Registrar, Inc.", ACTIVE)); persistSimpleResources(makeRegistrarContacts(registrar)); // Notice the partial search without "inc". - newWhoisServer("registrar example registrar").run(); + newWhoisAction("registrar example registrar").run(); assertThat(response.getStatus()).isEqualTo(200); - assertThat(response.getPayload()).isEqualTo(loadFile("whois_server_registrar.txt")); + assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_registrar.txt")); } @Test @@ -390,9 +383,9 @@ public class WhoisServerTest { .build()); persistSimpleResources(makeRegistrarContacts(registrar)); // Notice the partial search without "inc". - newWhoisServer("registrar example registrar").run(); + newWhoisAction("registrar example registrar").run(); assertThat(response.getStatus()).isEqualTo(200); - assertThat(response.getPayload()).isEqualTo(loadFile("whois_server_registrar.txt")); + assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_registrar.txt")); } @Test @@ -400,10 +393,9 @@ public class WhoisServerTest { Registrar registrar = persistResource( makeRegistrar("example", "Example Registrar, Inc.", Registrar.State.PENDING)); persistSimpleResources(makeRegistrarContacts(registrar)); - newWhoisServer("registrar Example Registrar, Inc.").run(); + newWhoisAction("registrar Example Registrar, Inc.").run(); assertThat(response.getStatus()).isEqualTo(200); - assertThat(response.getPayload()) - .isEqualTo(loadFile("whois_server_registrar_not_found.txt")); + assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_registrar_not_found.txt")); } @Test @@ -415,10 +407,9 @@ public class WhoisServerTest { .setType(Registrar.Type.TEST) .build()); persistSimpleResources(makeRegistrarContacts(registrar)); - newWhoisServer("registrar Example Registrar, Inc.").run(); + newWhoisAction("registrar Example Registrar, Inc.").run(); assertThat(response.getStatus()).isEqualTo(200); - assertThat(response.getPayload()) - .isEqualTo(loadFile("whois_server_registrar_not_found.txt")); + assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_registrar_not_found.txt")); } @Test @@ -434,7 +425,7 @@ public class WhoisServerTest { registrar)); persistSimpleResources(makeRegistrarContacts(registrar)); - newWhoisServer("domain cat.1.test\r\n").run(); + newWhoisAction("domain cat.1.test\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); assertThat(response.getPayload()).contains("Domain Name: cat.1.test\r\n"); } @@ -442,7 +433,7 @@ public class WhoisServerTest { @Test public void testRun_hostnameWithMultilevelTld_isStillConsideredHostname() throws Exception { persistResource(makeHostResource("ns1.cat.1.test", "1.2.3.4")); - newWhoisServer("nameserver ns1.cat.1.test\r\n").run(); + newWhoisAction("nameserver ns1.cat.1.test\r\n").run(); assertThat(response.getStatus()).isEqualTo(200); assertThat(response.getPayload()).contains("ns1.cat.1.test"); assertThat(response.getPayload()).contains("1.2.3.4"); @@ -452,57 +443,57 @@ public class WhoisServerTest { public void testRun_metricsLoggedForSuccessfulCommand() throws Exception { persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4")); persistResource(makeHostResource("ns2.cat.lol", "1.2.3.4")); - WhoisServer server = newWhoisServer("nameserver 1.2.3.4"); - server.whoisMetrics = mock(WhoisMetrics.class); - server.run(); + WhoisAction action = newWhoisAction("nameserver 1.2.3.4"); + action.whoisMetrics = mock(WhoisMetrics.class); + action.run(); WhoisMetric expected = WhoisMetric.builderForRequest(clock) .setCommandName("NameserverLookupByIp") .setNumResults(2) .setStatus(SC_OK) .build(); - verify(server.whoisMetrics).recordWhoisMetric(eq(expected)); + verify(action.whoisMetrics).recordWhoisMetric(eq(expected)); } @Test public void testRun_metricsLoggedForUnsuccessfulCommand() throws Exception { - WhoisServer server = newWhoisServer("domain cat.lol\r\n"); - server.whoisMetrics = mock(WhoisMetrics.class); - server.run(); + WhoisAction action = newWhoisAction("domain cat.lol\r\n"); + action.whoisMetrics = mock(WhoisMetrics.class); + action.run(); WhoisMetric expected = WhoisMetric.builderForRequest(clock) .setCommandName("DomainLookup") .setNumResults(0) .setStatus(SC_NOT_FOUND) .build(); - verify(server.whoisMetrics).recordWhoisMetric(eq(expected)); + verify(action.whoisMetrics).recordWhoisMetric(eq(expected)); } @Test public void testRun_metricsLoggedForInternalServerError() throws Exception { persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4")); - WhoisServer server = newWhoisServer("ns1.cat.lol"); - server.whoisReader = mock(WhoisReader.class); - when(server.whoisReader.readCommand(any(Reader.class), any(DateTime.class))) + WhoisAction action = newWhoisAction("ns1.cat.lol"); + action.whoisReader = mock(WhoisReader.class); + when(action.whoisReader.readCommand(any(Reader.class), any(DateTime.class))) .thenThrow(new IOException("missing cat interface")); - server.whoisMetrics = mock(WhoisMetrics.class); + action.whoisMetrics = mock(WhoisMetrics.class); - server.run(); + action.run(); WhoisMetric expected = WhoisMetric.builderForRequest(clock) .setNumResults(0) .setStatus(SC_INTERNAL_SERVER_ERROR) .build(); - verify(server.whoisMetrics).recordWhoisMetric(eq(expected)); + verify(action.whoisMetrics).recordWhoisMetric(eq(expected)); assertThat(response.getPayload()).isEqualTo("Internal Server Error"); } @Test public void testRun_retryOnTransientFailure() throws Exception { persistResource(makeHostResource("ns1.cat.lol", "1.2.3.4")); - WhoisServer server = newWhoisServer("ns1.cat.lol"); + WhoisAction action = newWhoisAction("ns1.cat.lol"); WhoisResponse expectedResponse = - server.whoisReader.readCommand(server.input, clock.nowUtc()).executeQuery(clock.nowUtc()); + action.whoisReader.readCommand(action.input, clock.nowUtc()).executeQuery(clock.nowUtc()); WhoisReader mockReader = mock(WhoisReader.class); WhoisCommand mockCommand = mock(WhoisCommand.class); @@ -512,8 +503,8 @@ public class WhoisServerTest { .thenThrow(new DatastoreTimeoutException("Expected transient exception #2")) .thenReturn(expectedResponse); - server.whoisReader = mockReader; - server.run(); - assertThat(response.getPayload()).isEqualTo(loadFile("whois_server_nameserver.txt")); + action.whoisReader = mockReader; + action.run(); + assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_nameserver.txt")); } } diff --git a/javatests/google/registry/whois/WhoisHttpServerTest.java b/javatests/google/registry/whois/WhoisHttpActionTest.java similarity index 82% rename from javatests/google/registry/whois/WhoisHttpServerTest.java rename to javatests/google/registry/whois/WhoisHttpActionTest.java index 595a2d58c..7c743256d 100644 --- a/javatests/google/registry/whois/WhoisHttpServerTest.java +++ b/javatests/google/registry/whois/WhoisHttpActionTest.java @@ -57,13 +57,13 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** - * Unit tests for {@link WhoisHttpServer}. + * Unit tests for {@link WhoisHttpAction}. * *

This class should be limited to testing the HTTP interface, as the bulk of the WHOIS testing - * can be found in {@link WhoisServerTest}. + * can be found in {@link WhoisActionTest}. */ @RunWith(JUnit4.class) -public class WhoisHttpServerTest { +public class WhoisHttpActionTest { @Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build(); @Rule public final InjectRule inject = new InjectRule(); @@ -71,18 +71,18 @@ public class WhoisHttpServerTest { private final FakeResponse response = new FakeResponse(); private final FakeClock clock = new FakeClock(DateTime.parse("2009-06-29T20:13:00Z")); - private WhoisHttpServer newWhoisHttpServer(String pathInfo) { - WhoisHttpServer whoisServer = new WhoisHttpServer(); - whoisServer.clock = clock; - whoisServer.expires = Duration.standardHours(1); - whoisServer.requestPath = WhoisHttpServer.PATH + pathInfo; - whoisServer.response = response; - whoisServer.whoisReader = new WhoisReader(new WhoisCommandFactory()); - whoisServer.whoisMetrics = new WhoisMetrics(); - whoisServer.metricBuilder = WhoisMetric.builderForRequest(clock); - whoisServer.disclaimer = + private WhoisHttpAction newWhoisHttpAction(String pathInfo) { + WhoisHttpAction whoisAction = new WhoisHttpAction(); + whoisAction.clock = clock; + whoisAction.expires = Duration.standardHours(1); + whoisAction.requestPath = WhoisHttpAction.PATH + pathInfo; + whoisAction.response = response; + whoisAction.whoisReader = new WhoisReader(new WhoisCommandFactory()); + whoisAction.whoisMetrics = new WhoisMetrics(); + whoisAction.metricBuilder = WhoisMetric.builderForRequest(clock); + whoisAction.disclaimer = "Doodle Disclaimer\nI exist so that carriage return\nin disclaimer can be tested."; - return whoisServer; + return whoisAction; } @Before @@ -99,28 +99,26 @@ public class WhoisHttpServerTest { @Test public void testRun_emptyQuery_returns400BadRequestWithPlainTextOutput() throws Exception { - newWhoisHttpServer("").run(); + newWhoisHttpAction("").run(); assertThat(response.getStatus()).isEqualTo(400); assertThat(response.getContentType()).isEqualTo(PLAIN_TEXT_UTF_8); - assertThat(response.getPayload()).isEqualTo(loadFile("whois_server_no_command.txt")); + assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_no_command.txt")); } @Test public void testRun_badUrlEncoding_returns400BadRequestWithPlainTextOutput() throws Exception { - newWhoisHttpServer("nic.%u307F%u3093%u306A").run(); + newWhoisHttpAction("nic.%u307F%u3093%u306A").run(); assertThat(response.getStatus()).isEqualTo(400); assertThat(response.getContentType()).isEqualTo(PLAIN_TEXT_UTF_8); - assertThat(response.getPayload()) - .isEqualTo(loadFile("whois_server_malformed_path.txt")); + assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_malformed_path.txt")); } @Test public void testRun_domainNotFound_returns404StatusAndPlainTextResponse() throws Exception { - newWhoisHttpServer("/domain/cat.lol").run(); + newWhoisHttpAction("/domain/cat.lol").run(); assertThat(response.getStatus()).isEqualTo(404); assertThat(response.getContentType()).isEqualTo(PLAIN_TEXT_UTF_8); - assertThat(response.getPayload()) - .isEqualTo(loadFile("whois_server_domain_not_found.txt")); + assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_domain_not_found.txt")); } // todo (b/27378695): reenable or delete this test @@ -139,11 +137,10 @@ public class WhoisHttpServerTest { persistResource(makeHostResource("ns2.cat.lol", "bad:f00d:cafe::15:beef")), registrar)); persistSimpleResources(makeRegistrarContacts(registrar)); - newWhoisHttpServer("/domain/cat.lol").run(); + newWhoisHttpAction("/domain/cat.lol").run(); assertThat(response.getStatus()).isEqualTo(404); assertThat(response.getContentType()).isEqualTo(PLAIN_TEXT_UTF_8); - assertThat(response.getPayload()) - .isEqualTo(loadFile("whois_server_domain_not_found.txt")); + assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_domain_not_found.txt")); } @Test @@ -159,9 +156,9 @@ public class WhoisHttpServerTest { persistResource(makeHostResource("ns2.cat.みんな", "bad:f00d:cafe::15:beef")), registrar)); persistSimpleResources(makeRegistrarContacts(registrar)); - newWhoisHttpServer("/domain/cat.みんな").run(); + newWhoisHttpAction("/domain/cat.みんな").run(); assertThat(response.getStatus()).isEqualTo(200); - assertThat(response.getPayload()).isEqualTo(loadFile("whois_server_idn_utf8.txt")); + assertThat(response.getPayload()).isEqualTo(loadFile("whois_action_idn_utf8.txt")); } @Test @@ -176,7 +173,7 @@ public class WhoisHttpServerTest { persistResource(makeHostResource("ns1.cat.みんな", "1.2.3.4")), persistResource(makeHostResource("ns2.cat.みんな", "bad:f00d:cafe::15:beef")), persistResource(makeRegistrar("example", "Example Registrar", Registrar.State.ACTIVE)))); - newWhoisHttpServer("/domain/cat.みんな").run(); + newWhoisHttpAction("/domain/cat.みんな").run(); assertThat(response.getPayload()).contains("Eric Schmidt"); } @@ -190,7 +187,7 @@ public class WhoisHttpServerTest { persistResource(makeHostResource("ns1.cat.みんな", "1.2.3.4")), persistResource(makeHostResource("ns2.cat.みんな", "bad:f00d:cafe::15:beef")), persistResource(makeRegistrar("example", "Example Registrar", Registrar.State.ACTIVE)))); - newWhoisHttpServer("cat.みんな").run(); + newWhoisHttpAction("cat.みんな").run(); assertThat(response.getStatus()).isEqualTo(200); assertThat(response.getPayload()).contains("Domain Name: cat.みんな\r\n"); } @@ -205,14 +202,14 @@ public class WhoisHttpServerTest { persistResource(makeHostResource("ns1.cat.みんな", "1.2.3.4")), persistResource(makeHostResource("ns2.cat.みんな", "bad:f00d:cafe::15:beef")), persistResource(makeRegistrar("example", "Example Registrar", Registrar.State.ACTIVE)))); - newWhoisHttpServer("cat.みんな").run(); + newWhoisHttpAction("cat.みんな").run(); assertThat(response.getPayload()).doesNotContain("