mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 00:47:11 +02:00
Refactor assertCommandAndResponse to be "fluent"
This is in preparation for automatic EPP consolidation. The assertion will now look like: assertThatCommand("file.xml"[, substitution]) .atTime(time) .hasResponse("file2.xml"[, substitution]); Also, added convenience functions for often reused commands (login and logout) ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=190617505
This commit is contained in:
parent
c1ca88ac9e
commit
422ec9b97a
15 changed files with 892 additions and 1054 deletions
|
@ -22,7 +22,6 @@ import static google.registry.testing.EppMetricSubject.assertThat;
|
|||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -40,13 +39,12 @@ public class EppLifecycleContactTest extends EppTestCase {
|
|||
|
||||
@Test
|
||||
public void testContactLifecycle() throws Exception {
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
assertCommandAndResponse(
|
||||
"contact_create_sh8013.xml",
|
||||
ImmutableMap.of(),
|
||||
"contact_create_response_sh8013.xml",
|
||||
ImmutableMap.of("CRDATE", "2000-06-01T00:00:00Z"),
|
||||
DateTime.parse("2000-06-01T00:00:00Z"));
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
assertThatCommand("contact_create_sh8013.xml")
|
||||
.atTime("2000-06-01T00:00:00Z")
|
||||
.hasResponse(
|
||||
"contact_create_response_sh8013.xml",
|
||||
ImmutableMap.of("CRDATE", "2000-06-01T00:00:00Z"));
|
||||
assertThat(getRecordedEppMetric())
|
||||
.hasClientId("NewRegistrar")
|
||||
.and()
|
||||
|
@ -57,10 +55,9 @@ public class EppLifecycleContactTest extends EppTestCase {
|
|||
.hasEppTarget("sh8013")
|
||||
.and()
|
||||
.hasStatus(SUCCESS);
|
||||
assertCommandAndResponse(
|
||||
"contact_info.xml",
|
||||
"contact_info_from_create_response.xml",
|
||||
DateTime.parse("2000-06-01T00:01:00Z"));
|
||||
assertThatCommand("contact_info.xml")
|
||||
.atTime("2000-06-01T00:01:00Z")
|
||||
.hasResponse("contact_info_from_create_response.xml");
|
||||
assertThat(getRecordedEppMetric())
|
||||
.hasClientId("NewRegistrar")
|
||||
.and()
|
||||
|
@ -69,7 +66,8 @@ public class EppLifecycleContactTest extends EppTestCase {
|
|||
.hasEppTarget("sh8013")
|
||||
.and()
|
||||
.hasStatus(SUCCESS);
|
||||
assertCommandAndResponse("contact_delete_sh8013.xml", "contact_delete_response_sh8013.xml");
|
||||
assertThatCommand("contact_delete_sh8013.xml")
|
||||
.hasResponse("contact_delete_response_sh8013.xml");
|
||||
assertThat(getRecordedEppMetric())
|
||||
.hasClientId("NewRegistrar")
|
||||
.and()
|
||||
|
@ -78,52 +76,46 @@ public class EppLifecycleContactTest extends EppTestCase {
|
|||
.hasEppTarget("sh8013")
|
||||
.and()
|
||||
.hasStatus(SUCCESS_WITH_ACTION_PENDING);
|
||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||
assertThatLogoutSucceeds();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContactTransferPollMessage() throws Exception {
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
assertCommandAndResponse(
|
||||
"contact_create_sh8013.xml",
|
||||
ImmutableMap.of(),
|
||||
"contact_create_response_sh8013.xml",
|
||||
ImmutableMap.of("CRDATE", "2000-06-01T00:00:00Z"),
|
||||
DateTime.parse("2000-06-01T00:00:00Z"));
|
||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
assertThatCommand("contact_create_sh8013.xml")
|
||||
.atTime("2000-06-01T00:00:00Z")
|
||||
.hasResponse(
|
||||
"contact_create_response_sh8013.xml",
|
||||
ImmutableMap.of("CRDATE", "2000-06-01T00:00:00Z"));
|
||||
assertThatLogoutSucceeds();
|
||||
|
||||
// Initiate a transfer of the newly created contact.
|
||||
assertCommandAndResponse("login2_valid.xml", "login_response.xml");
|
||||
assertCommandAndResponse(
|
||||
"contact_transfer_request.xml",
|
||||
"contact_transfer_request_response_alternate.xml",
|
||||
DateTime.parse("2000-06-08T22:00:00Z"));
|
||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||
assertThatLoginSucceeds("TheRegistrar", "password2");
|
||||
assertThatCommand("contact_transfer_request.xml")
|
||||
.atTime("2000-06-08T22:00:00Z")
|
||||
.hasResponse("contact_transfer_request_response_alternate.xml");
|
||||
assertThatLogoutSucceeds();
|
||||
|
||||
// Log back in with the losing registrar, read the poll message, and then ack it.
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
assertCommandAndResponse(
|
||||
"poll.xml",
|
||||
"poll_response_contact_transfer.xml",
|
||||
DateTime.parse("2000-06-08T22:01:00Z"));
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
assertThatCommand("poll.xml")
|
||||
.atTime("2000-06-08T22:01:00Z")
|
||||
.hasResponse("poll_response_contact_transfer.xml");
|
||||
assertThat(getRecordedEppMetric())
|
||||
.hasClientId("NewRegistrar")
|
||||
.and()
|
||||
.hasCommandName("PollRequest")
|
||||
.and()
|
||||
.hasStatus(SUCCESS_WITH_ACK_MESSAGE);
|
||||
assertCommandAndResponse(
|
||||
"poll_ack.xml",
|
||||
ImmutableMap.of("ID", "2-1-ROID-3-6-2000"),
|
||||
"poll_ack_response_empty.xml",
|
||||
ImmutableMap.of(),
|
||||
DateTime.parse("2000-06-08T22:02:00Z"));
|
||||
assertThatCommand("poll_ack.xml", ImmutableMap.of("ID", "2-1-ROID-3-6-2000"))
|
||||
.atTime("2000-06-08T22:02:00Z")
|
||||
.hasResponse("poll_ack_response_empty.xml");
|
||||
assertThat(getRecordedEppMetric())
|
||||
.hasClientId("NewRegistrar")
|
||||
.and()
|
||||
.hasCommandName("PollAck")
|
||||
.and()
|
||||
.hasStatus(SUCCESS_WITH_NO_MESSAGES);
|
||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||
assertThatLogoutSucceeds();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,83 +50,72 @@ public class EppLifecycleDomainApplicationTest extends EppTestCase {
|
|||
/** Create the two administrative contacts and two hosts. */
|
||||
void createContactsAndHosts() throws Exception {
|
||||
DateTime startTime = DateTime.parse("2000-06-01T00:00:00Z");
|
||||
assertCommandAndResponse(
|
||||
"contact_create_sh8013.xml",
|
||||
ImmutableMap.of(),
|
||||
"contact_create_response_sh8013.xml",
|
||||
ImmutableMap.of("CRDATE", "2000-06-01T00:00:00Z"),
|
||||
startTime);
|
||||
assertCommandAndResponse(
|
||||
"contact_create_jd1234.xml",
|
||||
"contact_create_response_jd1234.xml",
|
||||
startTime.plusMinutes(1));
|
||||
assertCommandAndResponse(
|
||||
"host_create.xml",
|
||||
ImmutableMap.of("HOSTNAME", "ns1.example.external"),
|
||||
"host_create_response.xml",
|
||||
ImmutableMap.of(
|
||||
"HOSTNAME", "ns1.example.external", "CRDATE", startTime.plusMinutes(2).toString()),
|
||||
startTime.plusMinutes(2));
|
||||
assertCommandAndResponse(
|
||||
"host_create.xml",
|
||||
ImmutableMap.of("HOSTNAME", "ns2.example.external"),
|
||||
"host_create_response.xml",
|
||||
ImmutableMap.of(
|
||||
"HOSTNAME", "ns2.example.external", "CRDATE", startTime.plusMinutes(3).toString()),
|
||||
startTime.plusMinutes(3));
|
||||
assertThatCommand("contact_create_sh8013.xml")
|
||||
.atTime(startTime)
|
||||
.hasResponse(
|
||||
"contact_create_response_sh8013.xml",
|
||||
ImmutableMap.of("CRDATE", "2000-06-01T00:00:00Z"));
|
||||
assertThatCommand("contact_create_jd1234.xml")
|
||||
.atTime(startTime.plusMinutes(1))
|
||||
.hasResponse("contact_create_response_jd1234.xml");
|
||||
assertThatCommand("host_create.xml", ImmutableMap.of("HOSTNAME", "ns1.example.external"))
|
||||
.atTime(startTime.plusMinutes(2))
|
||||
.hasResponse(
|
||||
"host_create_response.xml",
|
||||
ImmutableMap.of(
|
||||
"HOSTNAME", "ns1.example.external", "CRDATE", startTime.plusMinutes(2).toString()));
|
||||
assertThatCommand("host_create.xml", ImmutableMap.of("HOSTNAME", "ns2.example.external"))
|
||||
.atTime(startTime.plusMinutes(3))
|
||||
.hasResponse(
|
||||
"host_create_response.xml",
|
||||
ImmutableMap.of(
|
||||
"HOSTNAME", "ns2.example.external", "CRDATE", startTime.plusMinutes(3).toString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplicationDuringSunrise_doesntCreateDomainWithoutAllocation() throws Exception {
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
createContactsAndHosts();
|
||||
// Note that the trademark is valid from 2013-08-09 to 2017-07-23, hence the creation in 2014.
|
||||
assertCommandAndResponse(
|
||||
"domain_create_sunrise_encoded_mark.xml",
|
||||
"domain_create_sunrise_encoded_signed_mark_response.xml",
|
||||
DateTime.parse("2014-01-01T00:00:00Z"));
|
||||
assertCommandAndResponse(
|
||||
"domain_info_testvalidate.xml",
|
||||
ImmutableMap.of(),
|
||||
"response_error.xml",
|
||||
ImmutableMap.of(
|
||||
"MSG", "The domain with given ID (test-validate.example) doesn't exist.",
|
||||
"CODE", "2303"),
|
||||
DateTime.parse("2014-01-01T00:01:00Z"));
|
||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||
assertThatCommand("domain_create_sunrise_encoded_mark.xml")
|
||||
.atTime("2014-01-01T00:00:00Z")
|
||||
.hasResponse("domain_create_sunrise_encoded_signed_mark_response.xml");
|
||||
assertThatCommand("domain_info_testvalidate.xml")
|
||||
.atTime("2014-01-01T00:01:00Z")
|
||||
.hasResponse(
|
||||
"response_error.xml",
|
||||
ImmutableMap.of(
|
||||
"CODE", "2303",
|
||||
"MSG", "The domain with given ID (test-validate.example) doesn't exist."));
|
||||
assertThatLogoutSucceeds();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDomainAllocation_succeedsOnlyAsSuperuser() throws Exception {
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
createContactsAndHosts();
|
||||
assertCommandAndResponse(
|
||||
"domain_create_sunrise_encoded_mark.xml",
|
||||
"domain_create_sunrise_encoded_signed_mark_response.xml",
|
||||
DateTime.parse("2014-01-01T00:00:00Z"));
|
||||
assertCommandAndResponse(
|
||||
"domain_info_testvalidate.xml",
|
||||
ImmutableMap.of(),
|
||||
"response_error.xml",
|
||||
ImmutableMap.of(
|
||||
"MSG", "The domain with given ID (test-validate.example) doesn't exist.",
|
||||
"CODE", "2303"),
|
||||
DateTime.parse("2014-01-01T00:01:00Z"));
|
||||
assertCommandAndResponse(
|
||||
"domain_allocate_testvalidate.xml",
|
||||
ImmutableMap.of(),
|
||||
"response_error.xml",
|
||||
ImmutableMap.of("MSG", "Only a superuser can allocate domains", "CODE", "2201"),
|
||||
START_OF_GA.plusDays(1));
|
||||
assertThatCommand("domain_create_sunrise_encoded_mark.xml")
|
||||
.atTime("2014-01-01T00:00:00Z")
|
||||
.hasResponse("domain_create_sunrise_encoded_signed_mark_response.xml");
|
||||
assertThatCommand("domain_info_testvalidate.xml")
|
||||
.atTime("2014-01-01T00:01:00Z")
|
||||
.hasResponse(
|
||||
"response_error.xml",
|
||||
ImmutableMap.of(
|
||||
"CODE", "2303",
|
||||
"MSG", "The domain with given ID (test-validate.example) doesn't exist."));
|
||||
assertThatCommand("domain_allocate_testvalidate.xml")
|
||||
.atTime(START_OF_GA.plusDays(1))
|
||||
.hasResponse(
|
||||
"response_error.xml",
|
||||
ImmutableMap.of("CODE", "2201", "MSG", "Only a superuser can allocate domains"));
|
||||
setIsSuperuser(true);
|
||||
assertCommandAndResponse(
|
||||
"domain_allocate_testvalidate.xml",
|
||||
"domain_allocate_response_testvalidate.xml",
|
||||
START_OF_GA.plusDays(1).plusMinutes(1));
|
||||
assertThatCommand("domain_allocate_testvalidate.xml")
|
||||
.atTime(START_OF_GA.plusDays(1).plusMinutes(1))
|
||||
.hasResponse("domain_allocate_response_testvalidate.xml");
|
||||
setIsSuperuser(false);
|
||||
assertCommandAndResponse(
|
||||
"domain_info_testvalidate.xml",
|
||||
"domain_info_response_testvalidate_ok.xml",
|
||||
START_OF_GA.plusDays(1).plusMinutes(2));
|
||||
assertThatCommand("domain_info_testvalidate.xml")
|
||||
.atTime(START_OF_GA.plusDays(1).plusMinutes(2))
|
||||
.hasResponse("domain_info_response_testvalidate_ok.xml");
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -46,13 +46,10 @@ public class EppLifecycleHostTest extends EppTestCase {
|
|||
|
||||
@Test
|
||||
public void testLifecycle() throws Exception {
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
assertCommandAndResponse(
|
||||
"hello.xml",
|
||||
ImmutableMap.of(),
|
||||
"greeting.xml",
|
||||
ImmutableMap.of("DATE", "2000-06-02T00:00:00Z"),
|
||||
DateTime.parse("2000-06-02T00:00:00Z"));
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
assertThatCommand("hello.xml")
|
||||
.atTime("2000-06-02T00:00:00Z")
|
||||
.hasResponse("greeting.xml", ImmutableMap.of("DATE", "2000-06-02T00:00:00Z"));
|
||||
// Note that Hello commands don't set a status code on the response.
|
||||
assertThat(getRecordedEppMetric())
|
||||
.hasClientId("NewRegistrar")
|
||||
|
@ -60,12 +57,11 @@ public class EppLifecycleHostTest extends EppTestCase {
|
|||
.hasCommandName("Hello")
|
||||
.and()
|
||||
.hasNoStatus();
|
||||
assertCommandAndResponse(
|
||||
"host_create.xml",
|
||||
ImmutableMap.of("HOSTNAME", "ns1.example.tld"),
|
||||
"host_create_response.xml",
|
||||
ImmutableMap.of("HOSTNAME", "ns1.example.tld", "CRDATE", "2000-06-02T00:01:00Z"),
|
||||
DateTime.parse("2000-06-02T00:01:00Z"));
|
||||
assertThatCommand("host_create.xml", ImmutableMap.of("HOSTNAME", "ns1.example.tld"))
|
||||
.atTime("2000-06-02T00:01:00Z")
|
||||
.hasResponse(
|
||||
"host_create_response.xml",
|
||||
ImmutableMap.of("HOSTNAME", "ns1.example.tld", "CRDATE", "2000-06-02T00:01:00Z"));
|
||||
assertThat(getRecordedEppMetric())
|
||||
.hasClientId("NewRegistrar")
|
||||
.and()
|
||||
|
@ -74,13 +70,12 @@ public class EppLifecycleHostTest extends EppTestCase {
|
|||
.hasEppTarget("ns1.example.tld")
|
||||
.and()
|
||||
.hasStatus(SUCCESS);
|
||||
assertCommandAndResponse(
|
||||
"host_info.xml",
|
||||
ImmutableMap.of("HOSTNAME", "ns1.example.tld"),
|
||||
"host_info_response.xml",
|
||||
ImmutableMap.of(
|
||||
"HOSTNAME", "ns1.example.tld", "ROID", "1-ROID", "CRDATE", "2000-06-02T00:01:00Z"),
|
||||
DateTime.parse("2000-06-02T00:02:00Z"));
|
||||
assertThatCommand("host_info.xml", ImmutableMap.of("HOSTNAME", "ns1.example.tld"))
|
||||
.atTime("2000-06-02T00:02:00Z")
|
||||
.hasResponse(
|
||||
"host_info_response.xml",
|
||||
ImmutableMap.of(
|
||||
"HOSTNAME", "ns1.example.tld", "ROID", "1-ROID", "CRDATE", "2000-06-02T00:01:00Z"));
|
||||
assertThat(getRecordedEppMetric())
|
||||
.hasClientId("NewRegistrar")
|
||||
.and()
|
||||
|
@ -89,12 +84,9 @@ public class EppLifecycleHostTest extends EppTestCase {
|
|||
.hasEppTarget("ns1.example.tld")
|
||||
.and()
|
||||
.hasStatus(SUCCESS);
|
||||
assertCommandAndResponse(
|
||||
"host_delete.xml",
|
||||
ImmutableMap.of("HOSTNAME", "ns1.example.tld"),
|
||||
"generic_success_action_pending_response.xml",
|
||||
ImmutableMap.of(),
|
||||
DateTime.parse("2000-06-02T00:03:00Z"));
|
||||
assertThatCommand("host_delete.xml", ImmutableMap.of("HOSTNAME", "ns1.example.tld"))
|
||||
.atTime("2000-06-02T00:03:00Z")
|
||||
.hasResponse("generic_success_action_pending_response.xml");
|
||||
assertThat(getRecordedEppMetric())
|
||||
.hasClientId("NewRegistrar")
|
||||
.and()
|
||||
|
@ -103,140 +95,128 @@ public class EppLifecycleHostTest extends EppTestCase {
|
|||
.hasEppTarget("ns1.example.tld")
|
||||
.and()
|
||||
.hasStatus(SUCCESS_WITH_ACTION_PENDING);
|
||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||
assertThatLogoutSucceeds();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenamingHostToExistingHost_fails() throws Exception {
|
||||
createTld("example");
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
// Create the fakesite domain.
|
||||
assertCommandAndResponse(
|
||||
"contact_create_sh8013.xml",
|
||||
ImmutableMap.of(),
|
||||
"contact_create_response_sh8013.xml",
|
||||
ImmutableMap.of("CRDATE", "2000-06-01T00:00:00Z"),
|
||||
DateTime.parse("2000-06-01T00:00:00Z"));
|
||||
assertCommandAndResponse(
|
||||
"contact_create_jd1234.xml",
|
||||
"contact_create_response_jd1234.xml",
|
||||
DateTime.parse("2000-06-01T00:01:00Z"));
|
||||
assertCommandAndResponse(
|
||||
"domain_create_fakesite_no_nameservers.xml",
|
||||
ImmutableMap.of(),
|
||||
"domain_create_response.xml",
|
||||
ImmutableMap.of(
|
||||
"NAME", "fakesite.example",
|
||||
"CRDATE", "2000-06-01T00:04:00.0Z",
|
||||
"EXDATE", "2002-06-01T00:04:00.0Z"),
|
||||
DateTime.parse("2000-06-01T00:04:00Z"));
|
||||
assertCommandAndResponse(
|
||||
"domain_info_fakesite.xml",
|
||||
"domain_info_response_fakesite_inactive.xml",
|
||||
DateTime.parse("2000-06-05T00:02:00Z"));
|
||||
assertThatCommand("contact_create_sh8013.xml")
|
||||
.atTime("2000-06-01T00:00:00Z")
|
||||
.hasResponse(
|
||||
"contact_create_response_sh8013.xml",
|
||||
ImmutableMap.of("CRDATE", "2000-06-01T00:00:00Z"));
|
||||
assertThatCommand("contact_create_jd1234.xml")
|
||||
.atTime("2000-06-01T00:01:00Z")
|
||||
.hasResponse("contact_create_response_jd1234.xml");
|
||||
assertThatCommand("domain_create_fakesite_no_nameservers.xml")
|
||||
.atTime("2000-06-01T00:04:00Z")
|
||||
.hasResponse(
|
||||
"domain_create_response.xml",
|
||||
ImmutableMap.of(
|
||||
"NAME", "fakesite.example",
|
||||
"CRDATE", "2000-06-01T00:04:00.0Z",
|
||||
"EXDATE", "2002-06-01T00:04:00.0Z"));
|
||||
assertThatCommand("domain_info_fakesite.xml")
|
||||
.atTime("2000-06-05T00:02:00Z")
|
||||
.hasResponse("domain_info_response_fakesite_inactive.xml");
|
||||
// Add the fakesite subordinate host (requires that domain is already created).
|
||||
assertCommandAndResponse(
|
||||
"host_create_fakesite.xml",
|
||||
"host_create_response_fakesite.xml",
|
||||
DateTime.parse("2000-06-06T00:01:00Z"));
|
||||
assertThatCommand("host_create_fakesite.xml")
|
||||
.atTime("2000-06-06T00:01:00Z")
|
||||
.hasResponse("host_create_response_fakesite.xml");
|
||||
// Add the 2nd fakesite subordinate host.
|
||||
assertCommandAndResponse(
|
||||
"host_create_fakesite2.xml",
|
||||
"host_create_response_fakesite2.xml",
|
||||
DateTime.parse("2000-06-09T00:01:00Z"));
|
||||
assertThatCommand("host_create_fakesite2.xml")
|
||||
.atTime("2000-06-09T00:01:00Z")
|
||||
.hasResponse("host_create_response_fakesite2.xml");
|
||||
// Attempt overwriting of 2nd fakesite subordinate host with the 1st.
|
||||
assertCommandAndResponse(
|
||||
"host_update_fakesite1_to_fakesite2.xml",
|
||||
ImmutableMap.of(),
|
||||
"response_error.xml",
|
||||
ImmutableMap.of(
|
||||
"MSG", "Object with given ID (ns4.fakesite.example) already exists", "CODE", "2302"),
|
||||
DateTime.parse("2000-06-10T00:01:00Z"));
|
||||
assertThatCommand("host_update_fakesite1_to_fakesite2.xml")
|
||||
.atTime("2000-06-10T00:01:00Z")
|
||||
.hasResponse(
|
||||
"response_error.xml",
|
||||
ImmutableMap.of(
|
||||
"CODE", "2302",
|
||||
"MSG", "Object with given ID (ns4.fakesite.example) already exists"));
|
||||
// Verify that fakesite hosts still exist in their unmodified states.
|
||||
assertCommandAndResponse(
|
||||
"host_info_fakesite.xml",
|
||||
"host_info_response_fakesite_ok.xml",
|
||||
DateTime.parse("2000-06-11T00:07:00Z"));
|
||||
assertCommandAndResponse(
|
||||
"host_info_fakesite2.xml",
|
||||
"host_info_response_fakesite2.xml",
|
||||
DateTime.parse("2000-06-11T00:08:00Z"));
|
||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||
assertThatCommand("host_info_fakesite.xml")
|
||||
.atTime("2000-06-11T00:07:00Z")
|
||||
.hasResponse("host_info_response_fakesite_ok.xml");
|
||||
assertThatCommand("host_info_fakesite2.xml")
|
||||
.atTime("2000-06-11T00:08:00Z")
|
||||
.hasResponse("host_info_response_fakesite2.xml");
|
||||
assertThatLogoutSucceeds();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_multipartTldsWithSharedSuffixes() throws Exception {
|
||||
createTlds("bar.foo.tld", "foo.tld", "tld");
|
||||
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
|
||||
assertCommandAndResponse(
|
||||
"contact_create_sh8013.xml",
|
||||
ImmutableMap.of(),
|
||||
"contact_create_response_sh8013.xml",
|
||||
ImmutableMap.of("CRDATE", "2000-06-01T00:00:00Z"),
|
||||
DateTime.parse("2000-06-01T00:00:00Z"));
|
||||
assertCommandAndResponse(
|
||||
"contact_create_jd1234.xml",
|
||||
"contact_create_response_jd1234.xml",
|
||||
DateTime.parse("2000-06-01T00:01:00Z"));
|
||||
assertThatCommand("contact_create_sh8013.xml")
|
||||
.atTime("2000-06-01T00:00:00Z")
|
||||
.hasResponse(
|
||||
"contact_create_response_sh8013.xml",
|
||||
ImmutableMap.of("CRDATE", "2000-06-01T00:00:00Z"));
|
||||
assertThatCommand("contact_create_jd1234.xml")
|
||||
.atTime("2000-06-01T00:01:00Z")
|
||||
.hasResponse("contact_create_response_jd1234.xml");
|
||||
|
||||
// Create domain example.bar.foo.tld
|
||||
assertCommandAndResponse(
|
||||
"domain_create_wildcard.xml",
|
||||
ImmutableMap.of("HOSTNAME", "example.bar.foo.tld"),
|
||||
"domain_create_response.xml",
|
||||
ImmutableMap.of(
|
||||
"NAME", "example.bar.foo.tld",
|
||||
"CRDATE", "2000-06-01T00:02:00Z",
|
||||
"EXDATE", "2002-06-01T00:02:00Z"),
|
||||
DateTime.parse("2000-06-01T00:02:00.000Z"));
|
||||
assertThatCommand(
|
||||
"domain_create_wildcard.xml", ImmutableMap.of("HOSTNAME", "example.bar.foo.tld"))
|
||||
.atTime("2000-06-01T00:02:00.000Z")
|
||||
.hasResponse(
|
||||
"domain_create_response.xml",
|
||||
ImmutableMap.of(
|
||||
"NAME", "example.bar.foo.tld",
|
||||
"CRDATE", "2000-06-01T00:02:00Z",
|
||||
"EXDATE", "2002-06-01T00:02:00Z"));
|
||||
|
||||
// Create domain example.foo.tld
|
||||
assertCommandAndResponse(
|
||||
"domain_create_wildcard.xml",
|
||||
ImmutableMap.of("HOSTNAME", "example.foo.tld"),
|
||||
"domain_create_response.xml",
|
||||
ImmutableMap.of(
|
||||
"NAME", "example.foo.tld",
|
||||
"CRDATE", "2000-06-01T00:02:00Z",
|
||||
"EXDATE", "2002-06-01T00:02:00Z"),
|
||||
DateTime.parse("2000-06-01T00:02:00.001Z"));
|
||||
assertThatCommand("domain_create_wildcard.xml", ImmutableMap.of("HOSTNAME", "example.foo.tld"))
|
||||
.atTime("2000-06-01T00:02:00.001Z")
|
||||
.hasResponse(
|
||||
"domain_create_response.xml",
|
||||
ImmutableMap.of(
|
||||
"NAME", "example.foo.tld",
|
||||
"CRDATE", "2000-06-01T00:02:00Z",
|
||||
"EXDATE", "2002-06-01T00:02:00Z"));
|
||||
|
||||
// Create domain example.tld
|
||||
assertCommandAndResponse(
|
||||
"domain_create_wildcard.xml",
|
||||
ImmutableMap.of("HOSTNAME", "example.tld"),
|
||||
"domain_create_response.xml",
|
||||
ImmutableMap.of(
|
||||
"NAME", "example.tld",
|
||||
"CRDATE", "2000-06-01T00:02:00Z",
|
||||
"EXDATE", "2002-06-01T00:02:00Z"),
|
||||
DateTime.parse("2000-06-01T00:02:00.002Z"));
|
||||
assertThatCommand("domain_create_wildcard.xml", ImmutableMap.of("HOSTNAME", "example.tld"))
|
||||
.atTime("2000-06-01T00:02:00.002Z")
|
||||
.hasResponse(
|
||||
"domain_create_response.xml",
|
||||
ImmutableMap.of(
|
||||
"NAME", "example.tld",
|
||||
"CRDATE", "2000-06-01T00:02:00Z",
|
||||
"EXDATE", "2002-06-01T00:02:00Z"));
|
||||
|
||||
// Create host ns1.example.bar.foo.tld
|
||||
assertCommandAndResponse(
|
||||
"host_create_with_ips.xml",
|
||||
ImmutableMap.of("HOSTNAME", "ns1.example.bar.foo.tld"),
|
||||
"host_create_response.xml",
|
||||
ImmutableMap.of("HOSTNAME", "ns1.example.bar.foo.tld", "CRDATE", "2000-06-01T00:03:00Z"),
|
||||
DateTime.parse("2000-06-01T00:03:00Z"));
|
||||
assertThatCommand(
|
||||
"host_create_with_ips.xml", ImmutableMap.of("HOSTNAME", "ns1.example.bar.foo.tld"))
|
||||
.atTime("2000-06-01T00:03:00Z")
|
||||
.hasResponse(
|
||||
"host_create_response.xml",
|
||||
ImmutableMap.of(
|
||||
"HOSTNAME", "ns1.example.bar.foo.tld", "CRDATE", "2000-06-01T00:03:00Z"));
|
||||
|
||||
// Create host ns1.example.foo.tld
|
||||
assertCommandAndResponse(
|
||||
"host_create_with_ips.xml",
|
||||
ImmutableMap.of("HOSTNAME", "ns1.example.foo.tld"),
|
||||
"host_create_response.xml",
|
||||
ImmutableMap.of("HOSTNAME", "ns1.example.foo.tld", "CRDATE", "2000-06-01T00:04:00Z"),
|
||||
DateTime.parse("2000-06-01T00:04:00Z"));
|
||||
assertThatCommand(
|
||||
"host_create_with_ips.xml", ImmutableMap.of("HOSTNAME", "ns1.example.foo.tld"))
|
||||
.atTime("2000-06-01T00:04:00Z")
|
||||
.hasResponse(
|
||||
"host_create_response.xml",
|
||||
ImmutableMap.of("HOSTNAME", "ns1.example.foo.tld", "CRDATE", "2000-06-01T00:04:00Z"));
|
||||
|
||||
// Create host ns1.example.tld
|
||||
assertCommandAndResponse(
|
||||
"host_create_with_ips.xml",
|
||||
ImmutableMap.of("HOSTNAME", "ns1.example.tld"),
|
||||
"host_create_response.xml",
|
||||
ImmutableMap.of("HOSTNAME", "ns1.example.tld", "CRDATE", "2000-06-01T00:05:00Z"),
|
||||
DateTime.parse("2000-06-01T00:05:00Z"));
|
||||
assertThatCommand("host_create_with_ips.xml", ImmutableMap.of("HOSTNAME", "ns1.example.tld"))
|
||||
.atTime("2000-06-01T00:05:00Z")
|
||||
.hasResponse(
|
||||
"host_create_response.xml",
|
||||
ImmutableMap.of("HOSTNAME", "ns1.example.tld", "CRDATE", "2000-06-01T00:05:00Z"));
|
||||
|
||||
DateTime timeAfterCreates = DateTime.parse("2000-06-01T00:06:00Z");
|
||||
|
||||
|
@ -266,6 +246,6 @@ public class EppLifecycleHostTest extends EppTestCase {
|
|||
assertAboutHosts().that(exampleTldHost).hasSuperordinateDomain(Key.create(exampleTldDomain));
|
||||
assertThat(exampleTldDomain.getSubordinateHosts()).containsExactly("ns1.example.tld");
|
||||
|
||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||
assertThatLogoutSucceeds();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,14 +34,14 @@ public class EppLifecycleLoginTest extends EppTestCase {
|
|||
|
||||
@Test
|
||||
public void testLoginAndLogout_recordsEppMetric() throws Exception {
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
assertThat(getRecordedEppMetric())
|
||||
.hasClientId("NewRegistrar")
|
||||
.and()
|
||||
.hasCommandName("Login")
|
||||
.and()
|
||||
.hasStatus(SUCCESS);
|
||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||
assertThatLogoutSucceeds();
|
||||
assertThat(getRecordedEppMetric())
|
||||
.hasClientId("NewRegistrar")
|
||||
.and()
|
||||
|
|
|
@ -37,25 +37,19 @@ public class EppLoggedOutTest extends EppTestCase {
|
|||
@Test
|
||||
public void testHello() throws Exception {
|
||||
DateTime now = DateTime.now(UTC);
|
||||
assertCommandAndResponse(
|
||||
"hello.xml",
|
||||
null,
|
||||
"greeting.xml",
|
||||
ImmutableMap.of("DATE", now.toString(dateTimeNoMillis())),
|
||||
now);
|
||||
assertThatCommand("hello.xml", null)
|
||||
.atTime(now)
|
||||
.hasResponse("greeting.xml", ImmutableMap.of("DATE", now.toString(dateTimeNoMillis())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSyntaxError() throws Exception {
|
||||
assertCommandAndResponse(
|
||||
"syntax_error.xml",
|
||||
ImmutableMap.of(),
|
||||
"response_error_no_cltrid.xml",
|
||||
ImmutableMap.of(
|
||||
"MSG",
|
||||
"Syntax error at line 4, column 65: cvc-complex-type.3.2.2: "
|
||||
+ "Attribute 'xsi:schemaLocation' is not allowed to appear in element 'epp'.",
|
||||
"CODE",
|
||||
"2001"));
|
||||
assertThatCommand("syntax_error.xml")
|
||||
.hasResponse(
|
||||
"response_error_no_cltrid.xml",
|
||||
ImmutableMap.of(
|
||||
"CODE", "2001",
|
||||
"MSG", "Syntax error at line 4, column 65: cvc-complex-type.3.2.2: "
|
||||
+ "Attribute 'xsi:schemaLocation' is not allowed to appear in element 'epp'."));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,23 +42,23 @@ public class EppLoginAdminUserTest extends EppTestCase {
|
|||
@Test
|
||||
public void testNonAuthedLogin_succeedsAsAdmin() throws Exception {
|
||||
// Login succeeds even though this user isn't listed on the registrar.
|
||||
assertCommandAndResponse("login2_valid.xml", "login_response.xml");
|
||||
assertThatLoginSucceeds("TheRegistrar", "password2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoginLogout_wrongPasswordStillWorks() throws Exception {
|
||||
// For user-based logins the password in the epp xml is ignored.
|
||||
assertCommandAndResponse("login_invalid_wrong_password.xml", "login_response.xml");
|
||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||
assertThatLoginSucceeds("NewRegistrar", "incorrect");
|
||||
assertThatLogoutSucceeds();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonAuthedMultiLogin_succeedsAsAdmin() throws Exception {
|
||||
// The admin can log in as different registrars.
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||
assertCommandAndResponse("login2_valid.xml", "login_response.xml");
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
assertThatLogoutSucceeds();
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
assertThatLogoutSucceeds();
|
||||
assertThatLoginSucceeds("TheRegistrar", "password2");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,67 +62,62 @@ public class EppLoginTlsTest extends EppTestCase {
|
|||
@Test
|
||||
public void testLoginLogout() throws Exception {
|
||||
setClientCertificateHash(CertificateSamples.SAMPLE_CERT_HASH);
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
assertThatLogoutSucceeds();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLogin_wrongPasswordFails() throws Exception {
|
||||
setClientCertificateHash(CertificateSamples.SAMPLE_CERT_HASH);
|
||||
// For TLS login, we also check the epp xml password.
|
||||
assertCommandAndResponse(
|
||||
"login_invalid_wrong_password.xml",
|
||||
ImmutableMap.of(),
|
||||
"response_error.xml",
|
||||
ImmutableMap.of("MSG", "Registrar password is incorrect", "CODE", "2200"));
|
||||
assertThatLogin("NewRegistrar", "incorrect")
|
||||
.hasResponse(
|
||||
"response_error.xml",
|
||||
ImmutableMap.of("CODE", "2200", "MSG", "Registrar password is incorrect"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiLogin() throws Exception {
|
||||
setClientCertificateHash(CertificateSamples.SAMPLE_CERT_HASH);
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||
assertCommandAndResponse(
|
||||
"login2_valid.xml",
|
||||
ImmutableMap.of(),
|
||||
"response_error.xml",
|
||||
ImmutableMap.of(
|
||||
"MSG", "Registrar certificate does not match stored certificate", "CODE", "2200"));
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
assertThatLogoutSucceeds();
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
assertThatLogoutSucceeds();
|
||||
assertThatLogin("TheRegistrar", "password2")
|
||||
.hasResponse(
|
||||
"response_error.xml",
|
||||
ImmutableMap.of(
|
||||
"CODE", "2200", "MSG", "Registrar certificate does not match stored certificate"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonAuthedLogin_fails() throws Exception {
|
||||
setClientCertificateHash(CertificateSamples.SAMPLE_CERT_HASH);
|
||||
assertCommandAndResponse(
|
||||
"login2_valid.xml",
|
||||
ImmutableMap.of(),
|
||||
"response_error.xml",
|
||||
ImmutableMap.of(
|
||||
"MSG", "Registrar certificate does not match stored certificate", "CODE", "2200"));
|
||||
assertThatLogin("TheRegistrar", "password2")
|
||||
.hasResponse(
|
||||
"response_error.xml",
|
||||
ImmutableMap.of(
|
||||
"CODE", "2200", "MSG", "Registrar certificate does not match stored certificate"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBadCertificate_failsBadCertificate2200() throws Exception {
|
||||
setClientCertificateHash("laffo");
|
||||
assertCommandAndResponse(
|
||||
"login_valid.xml",
|
||||
ImmutableMap.of(),
|
||||
"response_error.xml",
|
||||
ImmutableMap.of(
|
||||
"MSG", "Registrar certificate does not match stored certificate", "CODE", "2200"));
|
||||
assertThatLogin("NewRegistrar", "foo-BAR2")
|
||||
.hasResponse(
|
||||
"response_error.xml",
|
||||
ImmutableMap.of(
|
||||
"CODE", "2200", "MSG", "Registrar certificate does not match stored certificate"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGfeDidntProvideClientCertificate_failsMissingCertificate2200() throws Exception {
|
||||
setClientCertificateHash("");
|
||||
assertCommandAndResponse(
|
||||
"login_valid.xml",
|
||||
ImmutableMap.of(),
|
||||
"response_error.xml",
|
||||
ImmutableMap.of("MSG", "Registrar certificate not present", "CODE", "2200"));
|
||||
assertThatLogin("NewRegistrar", "foo-BAR2")
|
||||
.hasResponse(
|
||||
"response_error.xml",
|
||||
ImmutableMap.of("CODE", "2200", "MSG", "Registrar certificate not present"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -135,7 +130,7 @@ public class EppLoginTlsTest extends EppTestCase {
|
|||
.setClientCertificate(CertificateSamples.SAMPLE_CERT, now)
|
||||
.setFailoverClientCertificate(CertificateSamples.SAMPLE_CERT2, now)
|
||||
.build());
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -148,7 +143,7 @@ public class EppLoginTlsTest extends EppTestCase {
|
|||
.setClientCertificate(CertificateSamples.SAMPLE_CERT, now)
|
||||
.setFailoverClientCertificate(CertificateSamples.SAMPLE_CERT2, now)
|
||||
.build());
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -161,7 +156,7 @@ public class EppLoginTlsTest extends EppTestCase {
|
|||
.setClientCertificate(null, now)
|
||||
.setFailoverClientCertificate(CertificateSamples.SAMPLE_CERT2, now)
|
||||
.build());
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -174,6 +169,6 @@ public class EppLoginTlsTest extends EppTestCase {
|
|||
.setClientCertificate(null, now)
|
||||
.setFailoverClientCertificate(null, now)
|
||||
.build());
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public class EppLoginUserTest extends EppTestCase {
|
|||
@Rule
|
||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
||||
.withDatastore()
|
||||
.withUserService(UserInfo.create("person@example.com", "12345"))
|
||||
.withUserService(UserInfo.create("user@example.com", "12345"))
|
||||
.build();
|
||||
|
||||
@Before
|
||||
|
@ -55,40 +55,38 @@ public class EppLoginUserTest extends EppTestCase {
|
|||
|
||||
@Test
|
||||
public void testLoginLogout() throws Exception {
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
assertThatLogoutSucceeds();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonAuthedLogin_fails() throws Exception {
|
||||
assertCommandAndResponse(
|
||||
"login2_valid.xml",
|
||||
ImmutableMap.of(),
|
||||
"response_error.xml",
|
||||
ImmutableMap.of(
|
||||
"MSG", "User id is not allowed to login as requested registrar: person@example.com",
|
||||
"CODE", "2200"));
|
||||
assertThatLogin("TheRegistrar", "password2")
|
||||
.hasResponse(
|
||||
"response_error.xml",
|
||||
ImmutableMap.of(
|
||||
"CODE", "2200",
|
||||
"MSG", "User id is not allowed to login as requested registrar: user@example.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiLogin() throws Exception {
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||
assertCommandAndResponse(
|
||||
"login2_valid.xml",
|
||||
ImmutableMap.of(),
|
||||
"response_error.xml",
|
||||
ImmutableMap.of(
|
||||
"MSG", "User id is not allowed to login as requested registrar: person@example.com",
|
||||
"CODE", "2200"));
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
assertThatLogoutSucceeds();
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
assertThatLogoutSucceeds();
|
||||
assertThatLogin("TheRegistrar", "password2")
|
||||
.hasResponse(
|
||||
"response_error.xml",
|
||||
ImmutableMap.of(
|
||||
"CODE", "2200",
|
||||
"MSG", "User id is not allowed to login as requested registrar: user@example.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoginLogout_wrongPasswordStillWorks() throws Exception {
|
||||
// For user-based logins the password in the epp xml is ignored.
|
||||
assertCommandAndResponse("login_invalid_wrong_password.xml", "login_response.xml");
|
||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||
assertThatLoginSucceeds("NewRegistrar", "incorrect");
|
||||
assertThatLogoutSucceeds();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
|||
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.net.MediaType;
|
||||
import google.registry.flows.EppTestComponent.FakesAndMocksModule;
|
||||
import google.registry.model.ofy.Ofy;
|
||||
|
@ -32,6 +33,7 @@ import google.registry.testing.FakeResponse;
|
|||
import google.registry.testing.InjectRule;
|
||||
import google.registry.testing.ShardableTestCase;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
|
@ -72,30 +74,64 @@ public class EppTestCase extends ShardableTestCase {
|
|||
this.isSuperuser = isSuperuser;
|
||||
}
|
||||
|
||||
String assertCommandAndResponse(String inputFilename, String outputFilename) throws Exception {
|
||||
return assertCommandAndResponse(inputFilename, null, outputFilename, null);
|
||||
class CommandAsserter {
|
||||
private final String inputFilename;
|
||||
private @Nullable final Map<String, String> inputSubstitutions;
|
||||
private DateTime now;
|
||||
|
||||
private CommandAsserter(
|
||||
String inputFilename, @Nullable Map<String, String> inputSubstitutions) {
|
||||
this.inputFilename = inputFilename;
|
||||
this.inputSubstitutions = inputSubstitutions;
|
||||
this.now = DateTime.now(UTC);
|
||||
}
|
||||
|
||||
CommandAsserter atTime(DateTime now) {
|
||||
this.now = now;
|
||||
return this;
|
||||
}
|
||||
|
||||
CommandAsserter atTime(String now) {
|
||||
return atTime(DateTime.parse(now));
|
||||
}
|
||||
|
||||
String hasResponse(String outputFilename) throws Exception {
|
||||
return hasResponse(outputFilename, null);
|
||||
}
|
||||
|
||||
String hasResponse(String outputFilename, @Nullable Map<String, String> outputSubstitutions)
|
||||
throws Exception {
|
||||
return assertCommandAndResponse(
|
||||
inputFilename, inputSubstitutions, outputFilename, outputSubstitutions, now);
|
||||
}
|
||||
}
|
||||
|
||||
String assertCommandAndResponse(String inputFilename, String outputFilename, DateTime now)
|
||||
throws Exception {
|
||||
return assertCommandAndResponse(inputFilename, null, outputFilename, null, now);
|
||||
CommandAsserter assertThatCommand(String inputFilename) {
|
||||
return assertThatCommand(inputFilename, null);
|
||||
}
|
||||
|
||||
String assertCommandAndResponse(
|
||||
CommandAsserter assertThatCommand(
|
||||
String inputFilename, @Nullable Map<String, String> inputSubstitutions) {
|
||||
return new CommandAsserter(inputFilename, inputSubstitutions);
|
||||
}
|
||||
|
||||
CommandAsserter assertThatLogin(String clientId, String password) throws Exception {
|
||||
return assertThatCommand("login.xml", ImmutableMap.of("CLID", clientId, "PW", password));
|
||||
}
|
||||
|
||||
void assertThatLoginSucceeds(String clientId, String password) throws Exception {
|
||||
assertThatLogin(clientId, password).hasResponse("login_response.xml");
|
||||
}
|
||||
|
||||
void assertThatLogoutSucceeds() throws Exception {
|
||||
assertThatCommand("logout.xml").hasResponse("logout_response.xml");
|
||||
}
|
||||
|
||||
private String assertCommandAndResponse(
|
||||
String inputFilename,
|
||||
Map<String, String> inputSubstitutions,
|
||||
@Nullable Map<String, String> inputSubstitutions,
|
||||
String outputFilename,
|
||||
Map<String, String> outputSubstitutions)
|
||||
throws Exception {
|
||||
return assertCommandAndResponse(
|
||||
inputFilename, inputSubstitutions, outputFilename, outputSubstitutions, DateTime.now(UTC));
|
||||
}
|
||||
|
||||
String assertCommandAndResponse(
|
||||
String inputFilename,
|
||||
Map<String, String> inputSubstitutions,
|
||||
String outputFilename,
|
||||
Map<String, String> outputSubstitutions,
|
||||
@Nullable Map<String, String> outputSubstitutions,
|
||||
DateTime now)
|
||||
throws Exception {
|
||||
clock.setTo(now);
|
||||
|
|
|
@ -35,49 +35,40 @@ public class EppXxeAttackTest extends EppTestCase {
|
|||
|
||||
@Test
|
||||
public void testRemoteXmlExternalEntity() throws Exception {
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
assertCommandAndResponse(
|
||||
"contact_create_remote_xxe.xml",
|
||||
ImmutableMap.of(),
|
||||
"response_error_no_cltrid.xml",
|
||||
ImmutableMap.of(
|
||||
"MSG",
|
||||
"Syntax error at line 11, column 34: "
|
||||
+ "The entity "remote" was referenced, but not declared.",
|
||||
"CODE",
|
||||
"2001"));
|
||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
assertThatCommand("contact_create_remote_xxe.xml")
|
||||
.hasResponse(
|
||||
"response_error_no_cltrid.xml",
|
||||
ImmutableMap.of(
|
||||
"CODE", "2001",
|
||||
"MSG", "Syntax error at line 11, column 34: "
|
||||
+ "The entity "remote" was referenced, but not declared."));
|
||||
assertThatLogoutSucceeds();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocalXmlExtrernalEntity() throws Exception {
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
assertCommandAndResponse(
|
||||
"contact_create_local_xxe.xml",
|
||||
ImmutableMap.of(),
|
||||
"response_error_no_cltrid.xml",
|
||||
ImmutableMap.of(
|
||||
"MSG",
|
||||
"Syntax error at line 11, column 31: "
|
||||
+ "The entity "ent" was referenced, but not declared.",
|
||||
"CODE",
|
||||
"2001"));
|
||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
assertThatCommand("contact_create_local_xxe.xml")
|
||||
.hasResponse(
|
||||
"response_error_no_cltrid.xml",
|
||||
ImmutableMap.of(
|
||||
"CODE", "2001",
|
||||
"MSG", "Syntax error at line 11, column 31: "
|
||||
+ "The entity "ent" was referenced, but not declared."));
|
||||
assertThatLogoutSucceeds();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBillionLaughsAttack() throws Exception {
|
||||
assertCommandAndResponse("login_valid.xml", "login_response.xml");
|
||||
assertCommandAndResponse(
|
||||
"contact_create_billion_laughs.xml",
|
||||
ImmutableMap.of(),
|
||||
"response_error_no_cltrid.xml",
|
||||
ImmutableMap.of(
|
||||
"MSG",
|
||||
"Syntax error at line 20, column 32: "
|
||||
+ "The entity "lol9" was referenced, but not declared.",
|
||||
"CODE",
|
||||
"2001"));
|
||||
assertCommandAndResponse("logout.xml", "logout_response.xml");
|
||||
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
|
||||
assertThatCommand("contact_create_billion_laughs.xml")
|
||||
.hasResponse(
|
||||
"response_error_no_cltrid.xml",
|
||||
ImmutableMap.of(
|
||||
"CODE", "2001",
|
||||
"MSG", "Syntax error at line 20, column 32: "
|
||||
+ "The entity "lol9" was referenced, but not declared."));
|
||||
assertThatLogoutSucceeds();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<command>
|
||||
<login>
|
||||
<clID>NewRegistrar</clID>
|
||||
<pw>foo-BAR2</pw>
|
||||
<clID>%CLID%</clID>
|
||||
<pw>%PW%</pw>
|
||||
<options>
|
||||
<version>1.0</version>
|
||||
<lang>en</lang>
|
|
@ -1,22 +0,0 @@
|
|||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<command>
|
||||
<login>
|
||||
<clID>TheRegistrar</clID>
|
||||
<pw>password2</pw>
|
||||
<options>
|
||||
<version>1.0</version>
|
||||
<lang>en</lang>
|
||||
</options>
|
||||
<svcs>
|
||||
<objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
|
||||
<objURI>urn:ietf:params:xml:ns:domain-1.0</objURI>
|
||||
<objURI>urn:ietf:params:xml:ns:contact-1.0</objURI>
|
||||
<svcExtension>
|
||||
<extURI>urn:ietf:params:xml:ns:launch-1.0</extURI>
|
||||
<extURI>urn:ietf:params:xml:ns:rgp-1.0</extURI>
|
||||
</svcExtension>
|
||||
</svcs>
|
||||
</login>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
</command>
|
||||
</epp>
|
|
@ -1,22 +0,0 @@
|
|||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<command>
|
||||
<login>
|
||||
<clID>NewRegistrar</clID>
|
||||
<pw>incorrect</pw>
|
||||
<options>
|
||||
<version>1.0</version>
|
||||
<lang>en</lang>
|
||||
</options>
|
||||
<svcs>
|
||||
<objURI>urn:ietf:params:xml:ns:host-1.0</objURI>
|
||||
<objURI>urn:ietf:params:xml:ns:domain-1.0</objURI>
|
||||
<objURI>urn:ietf:params:xml:ns:contact-1.0</objURI>
|
||||
<svcExtension>
|
||||
<extURI>urn:ietf:params:xml:ns:launch-1.0</extURI>
|
||||
<extURI>urn:ietf:params:xml:ns:rgp-1.0</extURI>
|
||||
</svcExtension>
|
||||
</svcs>
|
||||
</login>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
</command>
|
||||
</epp>
|
|
@ -23,6 +23,7 @@ import com.google.common.io.ByteSource;
|
|||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/** Contains helper methods for dealing with test data. */
|
||||
public final class TestDataHelper {
|
||||
|
@ -56,7 +57,7 @@ public final class TestDataHelper {
|
|||
* context class, and substitutes in values for placeholders of the form <code>%tagname%</code>.
|
||||
*/
|
||||
public static String loadFile(
|
||||
Class<?> context, String filename, Map<String, String> substitutions) {
|
||||
Class<?> context, String filename, @Nullable Map<String, String> substitutions) {
|
||||
String fileContents = loadFile(context, filename);
|
||||
for (Entry<String, String> entry : nullToEmpty(substitutions).entrySet()) {
|
||||
fileContents = fileContents.replaceAll("%" + entry.getKey() + "%", entry.getValue());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue