mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 08:27:14 +02:00
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:
parent
edb5240ff5
commit
6e6a340113
4 changed files with 108 additions and 56 deletions
|
@ -160,21 +160,20 @@ To tie it all together, let's create a domain name that uses the above contact
|
|||
and host.
|
||||
|
||||
```shell
|
||||
$ nomulus -e alpha create_domain -c acme --domain fake.example \
|
||||
--admin abcd1234 --tech abcd1234 --registrant abcd1234 \
|
||||
--nameservers ns1.google.com
|
||||
$ nomulus -e alpha create_domain fake.example --client acme --admin abcd1234 \
|
||||
--tech abcd1234 --registrant abcd1234 --nameservers ns1.google.com
|
||||
[ ... snip EPP response ... ]
|
||||
```
|
||||
|
||||
Where:
|
||||
|
||||
* `create_domain` is the subcommand to create a domain name.
|
||||
* `-c` is used to define the registrar.
|
||||
* `--domain` is used to identify the domain name to be created.
|
||||
* `create_domain` is the subcommand to create a domain name. It accepts a
|
||||
whitespace-separted list of domain names to be created
|
||||
* `--client` is used to define the registrar.
|
||||
* `--admin` is the administrative contact's id.
|
||||
* `--tech` is the technical 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
|
||||
registrant contact. It is common for domain names to use the same details for
|
||||
|
|
|
@ -16,13 +16,17 @@ package google.registry.tools;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Strings.isNullOrEmpty;
|
||||
import static google.registry.util.CollectionUtils.findDuplicates;
|
||||
|
||||
import com.beust.jcommander.Parameter;
|
||||
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 google.registry.tools.soy.DomainCreateSoyInfo;
|
||||
import google.registry.util.StringGenerator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/** A command to create a new domain via EPP. */
|
||||
|
@ -35,11 +39,8 @@ final class CreateDomainCommand extends MutatingEppToolCommand {
|
|||
required = true)
|
||||
String clientId;
|
||||
|
||||
@Parameter(
|
||||
names = "--domain",
|
||||
description = "Domain name",
|
||||
required = true)
|
||||
private String domain;
|
||||
@Parameter(description = "Names of the domains", required = true)
|
||||
private List<String> mainParameters;
|
||||
|
||||
@Parameter(
|
||||
names = "--period",
|
||||
|
@ -48,8 +49,8 @@ final class CreateDomainCommand extends MutatingEppToolCommand {
|
|||
|
||||
@Parameter(
|
||||
names = {"-n", "--nameservers"},
|
||||
description = "List of nameservers, up to 13.",
|
||||
variableArity = true)
|
||||
description = "Comma-separated list of nameservers, up to 13."
|
||||
)
|
||||
private List<String> ns;
|
||||
|
||||
@Parameter(
|
||||
|
@ -86,9 +87,15 @@ final class CreateDomainCommand extends MutatingEppToolCommand {
|
|||
password = passwordGenerator.createString(PASSWORD_LENGTH);
|
||||
}
|
||||
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);
|
||||
addSoyRecord(clientId, new SoyMapData(
|
||||
addSoyRecord(
|
||||
clientId,
|
||||
new SoyMapData(
|
||||
"domain", domain,
|
||||
"period", period == null ? null : period.toString(),
|
||||
"ns", ns,
|
||||
|
@ -97,4 +104,5 @@ final class CreateDomainCommand extends MutatingEppToolCommand {
|
|||
"tech", tech,
|
||||
"password", password));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,13 +31,13 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
|
|||
public void testSuccess_complete() throws Exception {
|
||||
runCommandForced(
|
||||
"--client=NewRegistrar",
|
||||
"--domain=example.tld",
|
||||
"--period=1",
|
||||
"--nameservers=ns1.zdns.google,ns2.zdns.google,ns3.zdns.google,ns4.zdns.google",
|
||||
"--registrant=crr-admin",
|
||||
"--admin=crr-admin",
|
||||
"--tech=crr-tech",
|
||||
"--password=2fooBAR");
|
||||
"--password=2fooBAR",
|
||||
"example.tld");
|
||||
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.
|
||||
runCommandForced(
|
||||
"--client=NewRegistrar",
|
||||
"--domain=example.tld",
|
||||
"--registrant=crr-admin",
|
||||
"--admin=crr-admin",
|
||||
"--tech=crr-tech");
|
||||
"--tech=crr-tech",
|
||||
"example.tld");
|
||||
eppVerifier().verifySent("domain_create_minimal.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_missingClientId() throws Exception {
|
||||
thrown.expect(ParameterException.class);
|
||||
runCommandForced("--domain=example.tld", "--registrant=crr-admin");
|
||||
public void testSuccess_multipleDomains() throws Exception {
|
||||
runCommandForced(
|
||||
"--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
|
||||
public void testFailure_missingDomain() throws Exception {
|
||||
thrown.expect(ParameterException.class);
|
||||
thrown.expect(ParameterException.class, "Main parameters are required");
|
||||
runCommandForced(
|
||||
"--client=NewRegistrar",
|
||||
"--registrant=crr-admin",
|
||||
"--admin=crr-admin",
|
||||
"--tech=crr-tech");
|
||||
"--client=NewRegistrar", "--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
|
||||
public void testFailure_missingRegistrant() throws Exception {
|
||||
thrown.expect(ParameterException.class);
|
||||
thrown.expect(ParameterException.class, "--registrant");
|
||||
runCommandForced(
|
||||
"--client=NewRegistrar",
|
||||
"--domain=example.tld",
|
||||
"--admin=crr-admin",
|
||||
"--tech=crr-tech");
|
||||
"--client=NewRegistrar", "--admin=crr-admin", "--tech=crr-tech", "example.tld");
|
||||
}
|
||||
|
||||
@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
|
||||
public void testFailure_tooManyNameServers() throws Exception {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expect(IllegalArgumentException.class, "There can be at most 13 nameservers");
|
||||
runCommandForced(
|
||||
"--client=NewRegistrar",
|
||||
"--domain=example.tld",
|
||||
"--registrant=crr-admin",
|
||||
"--admin=crr-admin",
|
||||
"--tech=crr-tech",
|
||||
"--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",
|
||||
"--nameservers=ns9.zdns.google,ns10.zdns.google,ns11.zdns.google,ns12.zdns.google",
|
||||
"--nameservers=ns13.zdns.google,ns14.zdns.google");
|
||||
"--nameservers=ns1.zdns.google,ns2.zdns.google,ns3.zdns.google,ns4.zdns.google,"
|
||||
+ "ns5.zdns.google,ns6.zdns.google,ns7.zdns.google,ns8.zdns.google,"
|
||||
+ "ns9.zdns.google,ns10.zdns.google,ns11.zdns.google,ns12.zdns.google,"
|
||||
+ "ns13.zdns.google,ns14.zdns.google",
|
||||
"example.tld");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_badPeriod() throws Exception {
|
||||
thrown.expect(ParameterException.class);
|
||||
thrown.expect(ParameterException.class, "--period");
|
||||
runCommandForced(
|
||||
"--client=NewRegistrar",
|
||||
"--domain=example.tld",
|
||||
"--registrant=crr-admin",
|
||||
"--admin=crr-admin",
|
||||
"--tech=crr-tech",
|
||||
"--period=x");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_badFax() throws Exception {
|
||||
thrown.expect(ParameterException.class);
|
||||
runCommandForced("--client=NewRegistrar", "--fax=3");
|
||||
"--period=x",
|
||||
"--domain=example.tld");
|
||||
}
|
||||
}
|
||||
|
|
18
javatests/google/registry/tools/testdata/domain_create_minimal_abc.xml
vendored
Normal file
18
javatests/google/registry/tools/testdata/domain_create_minimal_abc.xml
vendored
Normal 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>
|
Loading…
Add table
Add a link
Reference in a new issue