// Copyright 2016 The Nomulus Authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package google.registry.whois; import static com.google.common.net.MediaType.PLAIN_TEXT_UTF_8; import static com.google.common.truth.Truth.assertThat; import static google.registry.testing.DatastoreHelper.createTlds; import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistSimpleResources; import static google.registry.testing.FullFieldsTestEntityHelper.makeContactResource; import static google.registry.testing.FullFieldsTestEntityHelper.makeDomainResource; import static google.registry.testing.FullFieldsTestEntityHelper.makeHostResource; import static google.registry.testing.FullFieldsTestEntityHelper.makeRegistrar; import static google.registry.testing.FullFieldsTestEntityHelper.makeRegistrarContacts; import static google.registry.whois.WhoisHelper.loadWhoisTestFile; import google.registry.model.contact.ContactResource; import google.registry.model.ofy.Ofy; import google.registry.model.registrar.Registrar; import google.registry.model.registry.Registry; import google.registry.testing.AppEngineRule; import google.registry.testing.FakeClock; import google.registry.testing.FakeResponse; import google.registry.testing.InjectRule; import org.joda.time.DateTime; import org.joda.time.Duration; import org.junit.After; import org.junit.Before; import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; /** * Unit tests for {@link WhoisHttpServer}. * *
This class should be limited to testing the HTTP interface, as the bulk of the WHOIS testing * can be found in {@link WhoisServerTest}. */ @RunWith(JUnit4.class) public class WhoisHttpServerTest { @Rule public final AppEngineRule appEngine = AppEngineRule.builder() .withDatastore() .build(); @Rule public final InjectRule inject = new InjectRule(); 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 result = new WhoisHttpServer(); result.clock = clock; result.expires = Duration.standardHours(1); result.requestPath = WhoisHttpServer.PATH + pathInfo; result.response = response; result.disclaimer = "Doodle Disclaimer"; result.commandFactory = new WhoisCommandFactory(); return result; } @Before public void setUp() throws Exception { createTlds("lol", "xn--q9jyb4c", "1.test"); inject.setStaticField(Ofy.class, "clock", clock); } @After public void after() throws Exception { // Extra precaution to ensure HTML escaping is working securely. assertThat(response.getPayload()).doesNotContain("", "bog@cat.みんな")), 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(); assertThat(response.getPayload()).doesNotContain("