diff --git a/java/google/registry/tools/CreateContactCommand.java b/java/google/registry/tools/CreateContactCommand.java index 96fc55920..2ba0d6176 100644 --- a/java/google/registry/tools/CreateContactCommand.java +++ b/java/google/registry/tools/CreateContactCommand.java @@ -37,43 +37,43 @@ final class CreateContactCommand extends MutatingEppToolCommand implements Gtech String clientIdentifier; @Parameter( - names = {"--id"}, + names = {"-i", "--id"}, description = "Contact ID.") private String id; @Parameter( - names = {"--name"}, + names = {"-n", "--name"}, description = "Contact name.") private String name; @Parameter( - names = {"--org"}, + names = {"-o", "--org"}, description = "Organization") private String org; @Parameter( - names = {"--street"}, + names = "--street", description = "Street lines of address. Can take up to 3 lines.", variableArity = true) private List street; @Parameter( - names = {"--city"}, + names = "--city", description = "City of address.") private String city; @Parameter( - names = {"--state"}, + names = "--state", description = "State of address.") private String state; @Parameter( - names = {"--zip"}, + names = {"-z", "--zip"}, description = "Postal code of address.") private String zip; @Parameter( - names = {"--cc"}, + names = "--cc", description = "Country code of address.") private String cc; @@ -92,12 +92,12 @@ final class CreateContactCommand extends MutatingEppToolCommand implements Gtech String fax; @Parameter( - names = {"--email"}, + names = {"-e", "--email"}, description = "Email address.") private String email; @Parameter( - names = {"--password"}, + names = {"-p", "--password"}, description = "Password. Optional, randomly generated if not provided.") private String password; diff --git a/java/google/registry/tools/CreateDomainCommand.java b/java/google/registry/tools/CreateDomainCommand.java new file mode 100644 index 000000000..dde1ab496 --- /dev/null +++ b/java/google/registry/tools/CreateDomainCommand.java @@ -0,0 +1,99 @@ +// Copyright 2016 The Domain Registry Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package google.registry.tools; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Strings.isNullOrEmpty; + +import com.beust.jcommander.Parameter; +import com.beust.jcommander.Parameters; +import com.google.template.soy.data.SoyMapData; +import google.registry.tools.Command.GtechCommand; +import google.registry.tools.soy.CreateDomainSoyInfo; +import java.util.List; +import javax.inject.Inject; + +/** A command to create a new domain via EPP. */ +@Parameters(separators = " =", commandDescription = "Create a new domain via EPP.") +final class CreateDomainCommand extends MutatingEppToolCommand implements GtechCommand { + @Parameter(names = {"-c", "--client"}, + description = "Client identifier of the registrar to execute the command as", + required = true) + String clientIdentifier; + + @Parameter( + names = "--domain", + description = "Domain name", + required = true) + private String domain; + + @Parameter( + names = "--period", + description = "Initial registration period, in years.") + private Integer period; + + @Parameter( + names = {"-n", "--nameservers"}, + description = "List of nameservers, up to 13.", + variableArity = true) + private List ns; + + @Parameter( + names = {"-r", "--registrant"}, + description = "Domain registrant.", + required = true) + private String registrant; + + @Parameter( + names = {"-a", "--admin"}, + description = "Admin contact.", + required = true) + private String admin; + + @Parameter( + names = {"-t", "--tech"}, + description = "Technical contact.", + required = true) + private String tech; + + @Parameter( + names = {"-p", "--password"}, + description = "Password. Optional, randomly generated if not provided.") + private String password; + + @Inject + PasswordGenerator passwordGenerator; + + private static final int PASSWORD_LENGTH = 16; + + @Override + protected void initMutatingEppToolCommand() { + if (isNullOrEmpty(password)) { + password = passwordGenerator.createPassword(PASSWORD_LENGTH); + } + + checkArgument(ns == null || ns.size() <= 13, "There can be at most 13 nameservers."); + + setSoyTemplate(CreateDomainSoyInfo.getInstance(), CreateDomainSoyInfo.CREATEDOMAIN); + addSoyRecord(clientIdentifier, new SoyMapData( + "domain", domain, + "period", period == null ? null : period.toString(), + "ns", ns, + "registrant", registrant, + "admin", admin, + "tech", tech, + "password", password)); + } +} diff --git a/java/google/registry/tools/GtechTool.java b/java/google/registry/tools/GtechTool.java index 055d32e6d..51aec666b 100644 --- a/java/google/registry/tools/GtechTool.java +++ b/java/google/registry/tools/GtechTool.java @@ -36,6 +36,7 @@ public final class GtechTool { .put("create_contact", CreateContactCommand.class) .put("create_credit", CreateCreditCommand.class) .put("create_credit_balance", CreateCreditBalanceCommand.class) + .put("create_domain", CreateDomainCommand.class) .put("create_registrar_groups", CreateRegistrarGroupsCommand.class) .put("create_registrar", CreateRegistrarCommand.class) .put("create_sandbox_tld", CreateSandboxTldCommand.class) diff --git a/java/google/registry/tools/RegistryToolComponent.java b/java/google/registry/tools/RegistryToolComponent.java index 332ff931c..a0c57267e 100644 --- a/java/google/registry/tools/RegistryToolComponent.java +++ b/java/google/registry/tools/RegistryToolComponent.java @@ -50,6 +50,7 @@ import google.registry.util.SystemClock.SystemClockModule; interface RegistryToolComponent { void inject(CreateAnchorTenantCommand command); void inject(CreateContactCommand command); + void inject(CreateDomainCommand command); void inject(CreateTldCommand command); void inject(EncryptEscrowDepositCommand command); void inject(GenerateApplicationsReportCommand command); diff --git a/java/google/registry/tools/soy/CreateDomain.soy b/java/google/registry/tools/soy/CreateDomain.soy new file mode 100644 index 000000000..8cf1220bd --- /dev/null +++ b/java/google/registry/tools/soy/CreateDomain.soy @@ -0,0 +1,56 @@ +// Copyright 2016 The Domain Registry Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +{namespace domain.registry.tools autoescape="strict"} +/** + * Create domain + */ +{template .createdomain} + {@param domain: string} + {@param? period: string} + {@param? ns: list} + {@param registrant: string} + {@param admin: string} + {@param tech: string} + {@param password: string} + + + + + + + {$domain} + {if $period} + {$period} + {/if} + {if $ns} + + {foreach $s in $ns} + {$s} + {/foreach} + + {/if} + {$registrant} + {$admin} + {$tech} + + {$password} + + + + GTechTool + + +{/template} + diff --git a/javatests/google/registry/tools/CreateContactCommandTest.java b/javatests/google/registry/tools/CreateContactCommandTest.java index 55fc12836..21e35a487 100644 --- a/javatests/google/registry/tools/CreateContactCommandTest.java +++ b/javatests/google/registry/tools/CreateContactCommandTest.java @@ -19,8 +19,7 @@ import org.junit.Before; import org.junit.Test; /** Unit tests for {@link CreateContactCommand}. */ -public class CreateContactCommandTest - extends EppToolCommandTestCase { +public class CreateContactCommandTest extends EppToolCommandTestCase { @Before public void initCommand() { diff --git a/javatests/google/registry/tools/CreateDomainCommandTest.java b/javatests/google/registry/tools/CreateDomainCommandTest.java new file mode 100644 index 000000000..be915a13d --- /dev/null +++ b/javatests/google/registry/tools/CreateDomainCommandTest.java @@ -0,0 +1,120 @@ +// Copyright 2016 The Domain Registry Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package google.registry.tools; + +import com.beust.jcommander.ParameterException; +import org.junit.Before; +import org.junit.Test; + +/** Unit tests for {@link CreateDomainCommand}. */ +public class CreateDomainCommandTest extends EppToolCommandTestCase { + + @Before + public void initCommand() { + command.passwordGenerator = new FakePasswordGenerator("abcdefghijklmnopqrstuvwxyz"); + } + + @Test + 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"); + eppVerifier().verifySent("domain_create_complete.xml"); + } + + @Test + public void testSuccess_minimal() throws Exception { + // 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"); + eppVerifier().verifySent("domain_create_minimal.xml"); + } + + @Test + public void testFailure_missingClientId() throws Exception { + thrown.expect(ParameterException.class); + runCommandForced( + "--domain=example.tld", + "--registrant=crr-admin"); + runCommandForced(); + } + + @Test + public void testFailure_missingDomain() throws Exception { + thrown.expect(ParameterException.class); + runCommandForced( + "--client=NewRegistrar", + "--registrant=crr-admin", + "--admin=crr-admin", + "--tech=crr-tech"); + + runCommandForced(); + } + + @Test + public void testFailure_missingRegistrant() throws Exception { + thrown.expect(ParameterException.class); + runCommandForced( + "--client=NewRegistrar", + "--domain=example.tld", + "--admin=crr-admin", + "--tech=crr-tech"); + + runCommandForced(); + } + + @Test + public void testFailure_tooManyNameServers() throws Exception { + thrown.expect(IllegalArgumentException.class); + 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"); + } + + @Test + public void testFailure_badPeriod() throws Exception { + thrown.expect(ParameterException.class); + 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"); + } +} diff --git a/javatests/google/registry/tools/testdata/domain_create_complete.xml b/javatests/google/registry/tools/testdata/domain_create_complete.xml new file mode 100644 index 000000000..322a98bf3 --- /dev/null +++ b/javatests/google/registry/tools/testdata/domain_create_complete.xml @@ -0,0 +1,25 @@ + + + + + + example.tld + 1 + + ns1.zdns.google + ns2.zdns.google + ns3.zdns.google + ns4.zdns.google + + crr-admin + crr-admin + crr-tech + + 2fooBAR + + + + GTechTool + + diff --git a/javatests/google/registry/tools/testdata/domain_create_minimal.xml b/javatests/google/registry/tools/testdata/domain_create_minimal.xml new file mode 100644 index 000000000..2d3dbcc80 --- /dev/null +++ b/javatests/google/registry/tools/testdata/domain_create_minimal.xml @@ -0,0 +1,18 @@ + + + + + + example.tld + crr-admin + crr-admin + crr-tech + + abcdefghijklmnop + + + + GTechTool + +