Allow a --token option when checking a domain (#556)

* Allow a --token option when checking a domain
This commit is contained in:
gbrodman 2020-04-14 10:20:27 -04:00 committed by GitHub
parent dfeed63c40
commit 6990d6058f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 1 deletions

View file

@ -14,6 +14,8 @@
package google.registry.tools;
import static com.google.common.base.Strings.isNullOrEmpty;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.google.common.collect.Multimap;
@ -39,6 +41,11 @@ final class CheckDomainCommand extends NonMutatingEppToolCommand {
required = true)
private List<String> mainParameters;
@Parameter(
names = {"-t", "--token"},
description = "Allocation token to use in the command, if desired")
private String allocationToken;
@Inject
@Config("registryAdminClientId")
String registryAdminClientId;
@ -53,7 +60,11 @@ final class CheckDomainCommand extends NonMutatingEppToolCommand {
Multimap<String, String> domainNameMap = validateAndGroupDomainNamesByTld(mainParameters);
for (Collection<String> values : domainNameMap.asMap().values()) {
setSoyTemplate(DomainCheckSoyInfo.getInstance(), DomainCheckSoyInfo.DOMAINCHECK);
addSoyRecord(clientId, new SoyMapData("domainNames", values));
SoyMapData soyMapData = new SoyMapData("domainNames", values);
if (!isNullOrEmpty(allocationToken)) {
soyMapData.put("allocationToken", allocationToken);
}
addSoyRecord(clientId, soyMapData);
}
}
}

View file

@ -19,6 +19,7 @@
*/
{template .domaincheck stricthtml="false"}
{@param domainNames: list<string>}
{@param? allocationToken: string|null}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
@ -39,6 +40,12 @@
</fee:domain>
{/for}
</fee:check>
{if isNonnull($allocationToken)}
<allocationToken:allocationToken
xmlns:allocationToken="urn:ietf:params:xml:ns:allocationToken-1.0">
{$allocationToken}
</allocationToken:allocationToken>
{/if}
</extension>
<clTRID>RegistryTool</clTRID>
</command>

View file

@ -76,6 +76,12 @@ public class CheckDomainCommandTest extends EppToolCommandTestCase<CheckDomainCo
eppVerifier.expectDryRun().expectClientId("adminreg").verifySent("domain_check_fee.xml");
}
@Test
public void testSuccess_allocationToken_reserved() throws Exception {
runCommand("--client=NewRegistrar", "--token=abc123", "example.tld");
eppVerifier.expectDryRun().verifySent("domain_check_fee_allocationtoken.xml");
}
@Test
public void testFailure_NoMainParameter() {
assertThrows(ParameterException.class, () -> runCommand("--client=NewRegistrar"));

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<check>
<domain:check xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.tld</domain:name>
</domain:check>
</check>
<extension>
<fee:check xmlns:fee="urn:ietf:params:xml:ns:fee-0.6">
<fee:domain>
<fee:name>example.tld</fee:name>
<fee:command>create</fee:command>
<fee:period unit="y">1</fee:period>
</fee:domain>
</fee:check>
<allocationToken:allocationToken
xmlns:allocationToken="urn:ietf:params:xml:ns:allocationToken-1.0">
abc123
</allocationToken:allocationToken>
</extension>
<clTRID>RegistryTool</clTRID>
</command>
</epp>