Allow multiple domain creation in nomulus tool

This helps creating test domains. Also fixed a bunch of bad test cases.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=155864065
This commit is contained in:
jianglai 2017-05-12 07:17:26 -07:00 committed by Ben McIlwain
parent edb5240ff5
commit 6e6a340113
4 changed files with 108 additions and 56 deletions

View file

@ -160,21 +160,20 @@ To tie it all together, let's create a domain name that uses the above contact
and host. and host.
```shell ```shell
$ nomulus -e alpha create_domain -c acme --domain fake.example \ $ nomulus -e alpha create_domain fake.example --client acme --admin abcd1234 \
--admin abcd1234 --tech abcd1234 --registrant abcd1234 \ --tech abcd1234 --registrant abcd1234 --nameservers ns1.google.com
--nameservers ns1.google.com
[ ... snip EPP response ... ] [ ... snip EPP response ... ]
``` ```
Where: Where:
* `create_domain` is the subcommand to create a domain name. * `create_domain` is the subcommand to create a domain name. It accepts a
* `-c` is used to define the registrar. whitespace-separted list of domain names to be created
* `--domain` is used to identify the domain name to be created. * `--client` is used to define the registrar.
* `--admin` is the administrative contact's id. * `--admin` is the administrative contact's id.
* `--tech` is the technical contact's id. * `--tech` is the technical contact's id.
* `--registrant` is the registrant contact's id. * `--registrant` is the registrant contact's id.
* `--nameservers` identifies the host. * `--nameservers` is a comma-separated list of hosts.
Note how the same contact id is used for the administrative, technical, and Note how the same contact id is used for the administrative, technical, and
registrant contact. It is common for domain names to use the same details for registrant contact. It is common for domain names to use the same details for

View file

@ -16,13 +16,17 @@ package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.isNullOrEmpty; import static com.google.common.base.Strings.isNullOrEmpty;
import static google.registry.util.CollectionUtils.findDuplicates;
import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters; import com.beust.jcommander.Parameters;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableSet;
import com.google.template.soy.data.SoyMapData; import com.google.template.soy.data.SoyMapData;
import google.registry.tools.soy.DomainCreateSoyInfo; import google.registry.tools.soy.DomainCreateSoyInfo;
import google.registry.util.StringGenerator; import google.registry.util.StringGenerator;
import java.util.List; import java.util.List;
import java.util.Set;
import javax.inject.Inject; import javax.inject.Inject;
/** A command to create a new domain via EPP. */ /** A command to create a new domain via EPP. */
@ -35,11 +39,8 @@ final class CreateDomainCommand extends MutatingEppToolCommand {
required = true) required = true)
String clientId; String clientId;
@Parameter( @Parameter(description = "Names of the domains", required = true)
names = "--domain", private List<String> mainParameters;
description = "Domain name",
required = true)
private String domain;
@Parameter( @Parameter(
names = "--period", names = "--period",
@ -48,8 +49,8 @@ final class CreateDomainCommand extends MutatingEppToolCommand {
@Parameter( @Parameter(
names = {"-n", "--nameservers"}, names = {"-n", "--nameservers"},
description = "List of nameservers, up to 13.", description = "Comma-separated list of nameservers, up to 13."
variableArity = true) )
private List<String> ns; private List<String> ns;
@Parameter( @Parameter(
@ -86,9 +87,15 @@ final class CreateDomainCommand extends MutatingEppToolCommand {
password = passwordGenerator.createString(PASSWORD_LENGTH); password = passwordGenerator.createString(PASSWORD_LENGTH);
} }
checkArgument(ns == null || ns.size() <= 13, "There can be at most 13 nameservers."); checkArgument(ns == null || ns.size() <= 13, "There can be at most 13 nameservers.");
String duplicates = Joiner.on(", ").join(findDuplicates(mainParameters));
checkArgument(duplicates.isEmpty(), "Duplicate arguments found: '%s'", duplicates);
Set<String> domains = ImmutableSet.copyOf(mainParameters);
for (String domain : domains) {
setSoyTemplate(DomainCreateSoyInfo.getInstance(), DomainCreateSoyInfo.DOMAINCREATE); setSoyTemplate(DomainCreateSoyInfo.getInstance(), DomainCreateSoyInfo.DOMAINCREATE);
addSoyRecord(clientId, new SoyMapData( addSoyRecord(
clientId,
new SoyMapData(
"domain", domain, "domain", domain,
"period", period == null ? null : period.toString(), "period", period == null ? null : period.toString(),
"ns", ns, "ns", ns,
@ -98,3 +105,4 @@ final class CreateDomainCommand extends MutatingEppToolCommand {
"password", password)); "password", password));
} }
} }
}

View file

@ -31,13 +31,13 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
public void testSuccess_complete() throws Exception { public void testSuccess_complete() throws Exception {
runCommandForced( runCommandForced(
"--client=NewRegistrar", "--client=NewRegistrar",
"--domain=example.tld",
"--period=1", "--period=1",
"--nameservers=ns1.zdns.google,ns2.zdns.google,ns3.zdns.google,ns4.zdns.google", "--nameservers=ns1.zdns.google,ns2.zdns.google,ns3.zdns.google,ns4.zdns.google",
"--registrant=crr-admin", "--registrant=crr-admin",
"--admin=crr-admin", "--admin=crr-admin",
"--tech=crr-tech", "--tech=crr-tech",
"--password=2fooBAR"); "--password=2fooBAR",
"example.tld");
eppVerifier().verifySent("domain_create_complete.xml"); eppVerifier().verifySent("domain_create_complete.xml");
} }
@ -46,69 +46,96 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
// Test that each optional field can be omitted. Also tests the auto-gen password. // Test that each optional field can be omitted. Also tests the auto-gen password.
runCommandForced( runCommandForced(
"--client=NewRegistrar", "--client=NewRegistrar",
"--domain=example.tld",
"--registrant=crr-admin", "--registrant=crr-admin",
"--admin=crr-admin", "--admin=crr-admin",
"--tech=crr-tech"); "--tech=crr-tech",
"example.tld");
eppVerifier().verifySent("domain_create_minimal.xml"); eppVerifier().verifySent("domain_create_minimal.xml");
} }
@Test @Test
public void testFailure_missingClientId() throws Exception { public void testSuccess_multipleDomains() throws Exception {
thrown.expect(ParameterException.class); runCommandForced(
runCommandForced("--domain=example.tld", "--registrant=crr-admin"); "--client=NewRegistrar",
"--registrant=crr-admin",
"--admin=crr-admin",
"--tech=crr-tech",
"example.tld",
"example.abc");
eppVerifier().verifySent("domain_create_minimal.xml", "domain_create_minimal_abc.xml");
}
@Test
public void testFailure_duplicateDomains() throws Exception {
thrown.expect(IllegalArgumentException.class, "Duplicate arguments found: \'example.tld\'");
runCommandForced(
"--client=NewRegistrar",
"--registrant=crr-admin",
"--admin=crr-admin",
"--tech=crr-tech",
"example.tld",
"example.tld");
} }
@Test @Test
public void testFailure_missingDomain() throws Exception { public void testFailure_missingDomain() throws Exception {
thrown.expect(ParameterException.class); thrown.expect(ParameterException.class, "Main parameters are required");
runCommandForced( runCommandForced(
"--client=NewRegistrar", "--client=NewRegistrar", "--registrant=crr-admin", "--admin=crr-admin", "--tech=crr-tech");
"--registrant=crr-admin", }
"--admin=crr-admin",
"--tech=crr-tech"); @Test
public void testFailure_missingClientId() throws Exception {
thrown.expect(ParameterException.class, "--client");
runCommandForced(
"--admin=crr-admin", "--tech=crr-tech", "--registrant=crr-admin", "example.tld");
} }
@Test @Test
public void testFailure_missingRegistrant() throws Exception { public void testFailure_missingRegistrant() throws Exception {
thrown.expect(ParameterException.class); thrown.expect(ParameterException.class, "--registrant");
runCommandForced( runCommandForced(
"--client=NewRegistrar", "--client=NewRegistrar", "--admin=crr-admin", "--tech=crr-tech", "example.tld");
"--domain=example.tld", }
"--admin=crr-admin",
"--tech=crr-tech"); @Test
public void testFailure_missingAdmin() throws Exception {
thrown.expect(ParameterException.class, "--admin");
runCommandForced(
"--client=NewRegistrar", "--registrant=crr-admin", "--tech=crr-tech", "example.tld");
}
@Test
public void testFailure_missingTech() throws Exception {
thrown.expect(ParameterException.class, "--tech");
runCommandForced(
"--client=NewRegistrar", "--registrant=crr-admin", "--admin=crr-admin", "example.tld");
} }
@Test @Test
public void testFailure_tooManyNameServers() throws Exception { public void testFailure_tooManyNameServers() throws Exception {
thrown.expect(IllegalArgumentException.class); thrown.expect(IllegalArgumentException.class, "There can be at most 13 nameservers");
runCommandForced( runCommandForced(
"--client=NewRegistrar", "--client=NewRegistrar",
"--domain=example.tld",
"--registrant=crr-admin", "--registrant=crr-admin",
"--admin=crr-admin", "--admin=crr-admin",
"--tech=crr-tech", "--tech=crr-tech",
"--nameservers=ns1.zdns.google,ns2.zdns.google,ns3.zdns.google,ns4.zdns.google", "--nameservers=ns1.zdns.google,ns2.zdns.google,ns3.zdns.google,ns4.zdns.google,"
"--nameservers=ns5.zdns.google,ns6.zdns.google,ns7.zdns.google,ns8.zdns.google", + "ns5.zdns.google,ns6.zdns.google,ns7.zdns.google,ns8.zdns.google,"
"--nameservers=ns9.zdns.google,ns10.zdns.google,ns11.zdns.google,ns12.zdns.google", + "ns9.zdns.google,ns10.zdns.google,ns11.zdns.google,ns12.zdns.google,"
"--nameservers=ns13.zdns.google,ns14.zdns.google"); + "ns13.zdns.google,ns14.zdns.google",
"example.tld");
} }
@Test @Test
public void testFailure_badPeriod() throws Exception { public void testFailure_badPeriod() throws Exception {
thrown.expect(ParameterException.class); thrown.expect(ParameterException.class, "--period");
runCommandForced( runCommandForced(
"--client=NewRegistrar", "--client=NewRegistrar",
"--domain=example.tld",
"--registrant=crr-admin", "--registrant=crr-admin",
"--admin=crr-admin", "--admin=crr-admin",
"--tech=crr-tech", "--tech=crr-tech",
"--period=x"); "--period=x",
} "--domain=example.tld");
@Test
public void testFailure_badFax() throws Exception {
thrown.expect(ParameterException.class);
runCommandForced("--client=NewRegistrar", "--fax=3");
} }
} }

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<create>
<domain:create
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.abc</domain:name>
<domain:registrant>crr-admin</domain:registrant>
<domain:contact type="admin">crr-admin</domain:contact>
<domain:contact type="tech">crr-tech</domain:contact>
<domain:authInfo>
<domain:pw>abcdefghijklmnop</domain:pw>
</domain:authInfo>
</domain:create>
</create>
<clTRID>RegistryTool</clTRID>
</command>
</epp>