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:
guyben 2018-03-27 08:18:47 -07:00 committed by jianglai
parent c1ca88ac9e
commit 422ec9b97a
15 changed files with 892 additions and 1054 deletions

View file

@ -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();
}
}