Add reason and requestedByRegistrar to domain renew flow (#1378)

* Resolve merge conflict

* Include reason and requestedByRegistrar in URS test file

* Modify test cases for new parameters in renew flow

* Add reason and registrar_request to renew domain command

* Update comments for new params in renew flow

* Make changes based on feedback
This commit is contained in:
Rachel Guan
2021-10-13 11:41:02 -04:00
committed by GitHub
parent 35fd61f771
commit 2aff72b3b6
11 changed files with 331 additions and 17 deletions
@@ -42,6 +42,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
import google.registry.flows.EppException;
import google.registry.flows.EppRequestSource;
import google.registry.flows.FlowUtils.UnknownCurrencyEppException;
import google.registry.flows.ResourceFlowTestCase;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
@@ -533,6 +534,55 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, DomainBa
.build());
}
@TestOfyAndSql
void testSuccess_metaData_withReasonAndRequestedByRegistrar() throws Exception {
eppRequestSource = EppRequestSource.TOOL;
setEppInput(
"domain_renew_metadata_with_reason_and_requestedByRegistrar.xml",
ImmutableMap.of(
"DOMAIN",
"example.tld",
"EXPDATE",
"2000-04-03",
"YEARS",
"1",
"REASON",
"domain-renew-test",
"REQUESTED",
"false"));
persistDomain();
runFlow();
DomainBase domain = reloadResourceByForeignKey();
assertAboutDomains()
.that(domain)
.hasOneHistoryEntryEachOfTypes(
HistoryEntry.Type.DOMAIN_CREATE, HistoryEntry.Type.DOMAIN_RENEW);
assertAboutHistoryEntries()
.that(getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_RENEW))
.hasMetadataReason("domain-renew-test")
.and()
.hasMetadataRequestedByRegistrar(false);
}
@TestOfyAndSql
void testSuccess_metaData_withRequestedByRegistrarOnly() throws Exception {
eppRequestSource = EppRequestSource.TOOL;
setEppInput("domain_renew_metadata_with_requestedByRegistrar_only.xml");
persistDomain();
runFlow();
DomainBase domain1 = reloadResourceByForeignKey();
assertAboutDomains()
.that(domain1)
.hasOneHistoryEntryEachOfTypes(
HistoryEntry.Type.DOMAIN_CREATE, HistoryEntry.Type.DOMAIN_RENEW);
assertAboutHistoryEntries()
.that(getOnlyHistoryEntryOfType(domain1, HistoryEntry.Type.DOMAIN_RENEW))
.hasMetadataReason(null)
.and()
.hasMetadataRequestedByRegistrar(true);
}
@TestOfyAndSql
void testFailure_neverExisted() throws Exception {
ResourceDoesNotExistException thrown =
@@ -132,6 +132,55 @@ public class RenewDomainCommandTest extends EppToolCommandTestCase<RenewDomainCo
.verifyNoMoreSent();
}
@Test
void testSuccess_withReasonAndRegistrarRequest() throws Exception {
persistActiveDomain(
"domain.tld",
DateTime.parse("2014-09-05T05:05:05Z"),
DateTime.parse("2015-09-05T05:05:05Z"));
runCommandForced(
"domain.tld", "--period=1", "--reason=Renewing test domain", "--registrar_request=true");
eppVerifier
.expectRegistrarId("TheRegistrar")
.verifySent(
"domain_renew_via_urs.xml",
ImmutableMap.of(
"DOMAIN",
"domain.tld",
"EXPDATE",
"2015-09-05",
"YEARS",
"1",
"REASON",
"Renewing test domain",
"REQUESTED",
"true"));
}
@Test
void testSuccess_withReqistrarRequestOnly() throws Exception {
persistActiveDomain(
"domain.tld",
DateTime.parse("2014-09-05T05:05:05Z"),
DateTime.parse("2015-09-05T05:05:05Z"));
runCommandForced("domain.tld", "--period=1", "--registrar_request=true");
eppVerifier
.expectRegistrarId("TheRegistrar")
.verifySent(
"domain_renew_with_metadata_requestedByRegistrar_only.xml",
ImmutableMap.of(
"DOMAIN",
"domain.tld",
"EXPDATE",
"2015-09-05",
"YEARS",
"1",
"REQUESTED",
"true"));
}
@Test
void testFailure_domainDoesntExist() {
IllegalArgumentException e =
@@ -173,4 +222,19 @@ public class RenewDomainCommandTest extends EppToolCommandTestCase<RenewDomainCo
void testFailure_missingDomainNames() {
assertThrows(ParameterException.class, () -> runCommand("--period 4"));
}
@Test
void testFailure_registrarRequestIsRequiredWhenReasonIsPresent() {
persistActiveDomain(
"domain.tld",
DateTime.parse("2014-09-05T05:05:05Z"),
DateTime.parse("2015-09-05T05:05:05Z"));
IllegalArgumentException e =
assertThrows(
IllegalArgumentException.class,
() -> runCommandForced("domain.tld", "--period=1", "--reason=testing_only"));
assertThat(e)
.hasMessageThat()
.isEqualTo("--registrar_request is required when --reason is specified");
}
}
@@ -242,13 +242,44 @@ class UniformRapidSuspensionCommandTest
}
@Test
void testRenewOneYear_renewFlowIsTriggered() throws Exception {
// this test case was written based on an existing test case,
// testUndo_removesLocksReplacesHostsAndDsData() but two things were modified to test the
// renew workflow, which were:
// 1) a different domain that contains creation time and expiration time
// 2) renew_one_year is set to true
void testRenewOneYearWithoutUndo_verifyReasonWithoutUndo() throws Exception {
persistDomainWithHosts(
newDomainBase("evil.tld")
.asBuilder()
.setCreationTimeForTest(DateTime.parse("2021-10-01T05:01:11Z"))
.setRegistrationExpirationTime(DateTime.parse("2022-10-01T05:01:11Z"))
.setPersistedCurrentSponsorRegistrarId("CharlestonRoad")
.build(),
defaultDsData,
urs1,
urs2);
runCommandForced(
"--domain_name=evil.tld",
"--hosts=ns1.example.com,ns2.example.com",
"--renew_one_year=true");
eppVerifier
.expectRegistrarId("CharlestonRoad")
.expectSuperuser()
.verifySent(
"domain_renew_via_urs.xml",
ImmutableMap.of(
"DOMAIN",
"evil.tld",
"EXPDATE",
"2022-10-01",
"YEARS",
"1",
"REASON",
"Uniform Rapid Suspension",
"REQUESTED",
"false"))
.verifySentAny();
}
@Test
void testRenewOneYearWithUndo_verifyReasonWithUndo() throws Exception {
persistDomainWithHosts(
newDomainBase("evil.tld")
.asBuilder()
@@ -266,21 +297,65 @@ class UniformRapidSuspensionCommandTest
"--hosts=ns1.example.com,ns2.example.com",
"--renew_one_year=true");
// verify if renew flow is triggered
eppVerifier
.expectRegistrarId("CharlestonRoad")
.expectSuperuser()
.verifySent(
"domain_renew.xml",
ImmutableMap.of("DOMAIN", "evil.tld", "EXPDATE", "2022-10-01", "YEARS", "1"));
"domain_renew_via_urs.xml",
ImmutableMap.of(
"DOMAIN",
"evil.tld",
"EXPDATE",
"2022-10-01",
"YEARS",
"1",
"REASON",
"Undo Uniform Rapid Suspension",
"REQUESTED",
"false"))
.verifySentAny();
}
@Test
void testRenewOneYear_verifyBothRenewAndUpdateFlowsAreTriggered() throws Exception {
persistDomainWithHosts(
newDomainBase("evil.tld")
.asBuilder()
.setCreationTimeForTest(DateTime.parse("2021-10-01T05:01:11Z"))
.setRegistrationExpirationTime(DateTime.parse("2022-10-01T05:01:11Z"))
.setPersistedCurrentSponsorRegistrarId("CharlestonRoad")
.build(),
defaultDsData,
urs1,
urs2);
runCommandForced(
"--domain_name=evil.tld",
"--undo",
"--hosts=ns1.example.com,ns2.example.com",
"--renew_one_year=true");
// verify if update flow is triggered
eppVerifier
.expectRegistrarId("CharlestonRoad")
.expectSuperuser()
.verifySent("uniform_rapid_suspension_undo.xml")
.verifyNoMoreSent();
assertNotInStdout("--undo"); // Undo shouldn't print a new undo command.
.verifySent(
"domain_renew_via_urs.xml",
ImmutableMap.of(
"DOMAIN",
"evil.tld",
"EXPDATE",
"2022-10-01",
"YEARS",
"1",
"REASON",
"Undo Uniform Rapid Suspension",
"REQUESTED",
"false"));
eppVerifier
.expectRegistrarId("CharlestonRoad")
.expectSuperuser()
.verifySent("uniform_rapid_suspension_undo.xml");
// verify that no other flows are triggered after the renew and update flows
eppVerifier.verifyNoMoreSent();
@@ -0,0 +1,19 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<renew>
<domain:renew
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>%DOMAIN%</domain:name>
<domain:curExpDate>%EXPDATE%</domain:curExpDate>
<domain:period unit="y">%YEARS%</domain:period>
</domain:renew>
</renew>
<extension>
<metadata:metadata xmlns:metadata="urn:google:params:xml:ns:metadata-1.0">
<metadata:reason>%REASON%</metadata:reason>
<metadata:requestedByRegistrar>%REQUESTED%</metadata:requestedByRegistrar>
</metadata:metadata>
</extension>
<clTRID>ABC-12345</clTRID>
</command>
</epp>
@@ -0,0 +1,18 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<renew>
<domain:renew
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.tld</domain:name>
<domain:curExpDate>2000-04-03</domain:curExpDate>
<domain:period unit="y">1</domain:period>
</domain:renew>
</renew>
<extension>
<metadata:metadata xmlns:metadata="urn:google:params:xml:ns:metadata-1.0">
<metadata:requestedByRegistrar>true</metadata:requestedByRegistrar>
</metadata:metadata>
</extension>
<clTRID>ABC-12345</clTRID>
</command>
</epp>
@@ -0,0 +1,19 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<renew>
<domain:renew
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>%DOMAIN%</domain:name>
<domain:curExpDate>%EXPDATE%</domain:curExpDate>
<domain:period unit="y">%YEARS%</domain:period>
</domain:renew>
</renew>
<extension>
<metadata:metadata xmlns:metadata="urn:google:params:xml:ns:metadata-1.0">
<metadata:reason>%REASON%</metadata:reason>
<metadata:requestedByRegistrar>%REQUESTED%</metadata:requestedByRegistrar>
</metadata:metadata>
</extension>
<clTRID>RegistryTool</clTRID>
</command>
</epp>
@@ -0,0 +1,18 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<renew>
<domain:renew
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>%DOMAIN%</domain:name>
<domain:curExpDate>%EXPDATE%</domain:curExpDate>
<domain:period unit="y">%YEARS%</domain:period>
</domain:renew>
</renew>
<extension>
<metadata:metadata xmlns:metadata="urn:google:params:xml:ns:metadata-1.0">
<metadata:requestedByRegistrar>%REQUESTED%</metadata:requestedByRegistrar>
</metadata:metadata>
</extension>
<clTRID>RegistryTool</clTRID>
</command>
</epp>