diff --git a/java/google/registry/tools/BUILD b/java/google/registry/tools/BUILD index b8c343411..13e285188 100644 --- a/java/google/registry/tools/BUILD +++ b/java/google/registry/tools/BUILD @@ -34,6 +34,7 @@ java_library( ]), visibility = [":allowed-tools"], deps = [ + "//java/com/google/common/flogger", "//java/google/registry/backup", "//java/google/registry/bigquery", "//java/google/registry/config", diff --git a/java/google/registry/tools/CreateDomainCommand.java b/java/google/registry/tools/CreateDomainCommand.java index 72c9d7534..0ce3157ca 100644 --- a/java/google/registry/tools/CreateDomainCommand.java +++ b/java/google/registry/tools/CreateDomainCommand.java @@ -16,66 +16,24 @@ 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 static google.registry.util.PreconditionsUtils.checkArgumentNotNull; 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. */ @Parameters(separators = " =", commandDescription = "Create a new domain via EPP.") -final class CreateDomainCommand extends MutatingEppToolCommand { - - @Parameter( - names = {"-c", "--client"}, - description = "Client identifier of the registrar to execute the command as", - required = true) - String clientId; - - @Parameter(description = "Names of the domains", required = true) - private List mainParameters; +final class CreateDomainCommand extends CreateOrUpdateDomainCommand { @Parameter( names = "--period", description = "Initial registration period, in years.") private Integer period; - @Parameter( - names = {"-n", "--nameservers"}, - description = "Comma-separated list of nameservers, up to 13." - ) - 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 StringGenerator passwordGenerator; @@ -83,13 +41,12 @@ final class CreateDomainCommand extends MutatingEppToolCommand { @Override protected void initMutatingEppToolCommand() { + checkArgumentNotNull(registrant, "Registrant must be specified"); + checkArgument(!admins.isEmpty(), "At least one admin must be specified"); + checkArgument(!techs.isEmpty(), "At least one tech must be specified"); if (isNullOrEmpty(password)) { 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 domains = ImmutableSet.copyOf(mainParameters); for (String domain : domains) { setSoyTemplate(DomainCreateSoyInfo.getInstance(), DomainCreateSoyInfo.DOMAINCREATE); @@ -98,10 +55,10 @@ final class CreateDomainCommand extends MutatingEppToolCommand { new SoyMapData( "domain", domain, "period", period == null ? null : period.toString(), - "ns", ns, + "nameservers", nameservers, "registrant", registrant, - "admin", admin, - "tech", tech, + "admins", admins, + "techs", techs, "password", password)); } } diff --git a/java/google/registry/tools/CreateOrUpdateDomainCommand.java b/java/google/registry/tools/CreateOrUpdateDomainCommand.java new file mode 100644 index 000000000..b5ca48fbb --- /dev/null +++ b/java/google/registry/tools/CreateOrUpdateDomainCommand.java @@ -0,0 +1,82 @@ +// Copyright 2017 The Nomulus 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 google.registry.util.CollectionUtils.findDuplicates; + +import com.beust.jcommander.Parameter; +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableSet; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +/** Shared base class for commands to create or update a Domain via EPP. */ +abstract class CreateOrUpdateDomainCommand extends MutatingEppToolCommand { + + @Parameter( + names = {"-c", "--client"}, + description = "Client identifier of the registrar to execute the command as", + required = true + ) + String clientId; + + @Parameter(description = "Names of the domains", required = true) + private List mainParameters; + + @Parameter( + names = {"-n", "--nameservers"}, + description = "Comma-separated list of nameservers, up to 13." + ) + List nameservers = new ArrayList<>(); + + @Parameter( + names = {"-r", "--registrant"}, + description = "Domain registrant." + ) + String registrant; + + @Parameter( + names = {"-a", "--admins"}, + description = "Comma-separated list of admin contacts." + ) + List admins = new ArrayList<>(); + + @Parameter( + names = {"-t", "--techs"}, + description = "Comma-separated list of technical contacts." + ) + List techs = new ArrayList<>(); + + @Parameter( + names = {"-p", "--password"}, + description = "Password." + ) + String password; + + Set domains; + + @Override + protected void initEppToolCommand() throws Exception { + checkArgument(nameservers.size() <= 13, "There can be at most 13 nameservers."); + + String duplicates = Joiner.on(", ").join(findDuplicates(mainParameters)); + checkArgument(duplicates.isEmpty(), "Duplicate arguments found: '%s'", duplicates); + domains = ImmutableSet.copyOf(mainParameters); + + initMutatingEppToolCommand(); + } +} diff --git a/java/google/registry/tools/RegistryTool.java b/java/google/registry/tools/RegistryTool.java index 9ca3d02f8..58fd44c7b 100644 --- a/java/google/registry/tools/RegistryTool.java +++ b/java/google/registry/tools/RegistryTool.java @@ -113,6 +113,7 @@ public final class RegistryTool { .put("update_application_status", UpdateApplicationStatusCommand.class) .put("update_claims_notice", UpdateClaimsNoticeCommand.class) .put("update_cursors", UpdateCursorsCommand.class) + .put("update_domain", UpdateDomainCommand.class) .put("update_kms_keyring", UpdateKmsKeyringCommand.class) .put("update_premium_list", UpdatePremiumListCommand.class) .put("update_registrar", UpdateRegistrarCommand.class) diff --git a/java/google/registry/tools/RegistryToolComponent.java b/java/google/registry/tools/RegistryToolComponent.java index a08856490..204729bdf 100644 --- a/java/google/registry/tools/RegistryToolComponent.java +++ b/java/google/registry/tools/RegistryToolComponent.java @@ -94,6 +94,9 @@ interface RegistryToolComponent { void inject(SendEscrowReportToIcannCommand command); void inject(SetupOteCommand command); void inject(UpdateCursorsCommand command); + + void inject(UpdateDomainCommand command); + void inject(UpdateKmsKeyringCommand command); void inject(UpdateTldCommand command); void inject(ValidateEscrowDepositCommand command); diff --git a/java/google/registry/tools/UpdateDomainCommand.java b/java/google/registry/tools/UpdateDomainCommand.java new file mode 100644 index 000000000..2092f3b45 --- /dev/null +++ b/java/google/registry/tools/UpdateDomainCommand.java @@ -0,0 +1,235 @@ +// Copyright 2017 The Nomulus 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 google.registry.model.EppResourceUtils.loadByForeignKey; +import static google.registry.model.ofy.ObjectifyService.ofy; +import static org.joda.time.DateTimeZone.UTC; + +import com.beust.jcommander.Parameter; +import com.beust.jcommander.Parameters; +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSortedSet; +import com.google.common.collect.Sets; +import com.google.common.flogger.GoogleLogger; +import com.google.template.soy.data.SoyMapData; +import google.registry.model.domain.DesignatedContact; +import google.registry.model.domain.DomainResource; +import google.registry.model.eppcommon.StatusValue; +import google.registry.tools.soy.DomainUpdateSoyInfo; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.joda.time.DateTime; + +/** A command to update a new domain via EPP. */ +@Parameters(separators = " =", commandDescription = "Update a new domain via EPP.") +final class UpdateDomainCommand extends CreateOrUpdateDomainCommand { + + private static final GoogleLogger logger = GoogleLogger.forEnclosingClass(); + + @Parameter(names = "--statuses", description = "Comma-separated list of statuses to set.") + private List statuses = new ArrayList<>(); + + @Parameter( + names = "--add_nameservers", + description = + "Comma-separated list of nameservers to add, up to 13. " + + "Cannot be set if --nameservers is set." + ) + private List addNameservers = new ArrayList<>(); + + @Parameter( + names = "--add_admins", + description = "Admins to add. Cannot be set if --admins is set." + ) + private List addAdmins = new ArrayList<>(); + + @Parameter(names = "--add_techs", description = "Techs to add. Cannot be set if --techs is set.") + private List addTechs = new ArrayList<>(); + + @Parameter( + names = "--add_statuses", + description = "Statuses to add. Cannot be set if --statuses is set." + ) + private List addStatuses = new ArrayList<>(); + + @Parameter( + names = "--remove_nameservers", + description = + "Comma-separated list of nameservers to remove, up to 13. " + + "Cannot be set if --nameservers is set." + ) + private List removeNameservers = new ArrayList<>(); + + @Parameter( + names = "--remove_admins", + description = "Admins to remove. Cannot be set if --admins is set." + ) + private List removeAdmins = new ArrayList<>(); + + @Parameter( + names = "--remove_techs", + description = "Techs to remove. Cannot be set if --techs is set." + ) + private List removeTechs = new ArrayList<>(); + + @Parameter( + names = "--remove_statuses", + description = "Statuses to remove. Cannot be set if --statuses is set." + ) + private List removeStatuses = new ArrayList<>(); + + @Override + protected void initMutatingEppToolCommand() { + if (!nameservers.isEmpty()) { + checkArgument( + addNameservers.isEmpty() && removeNameservers.isEmpty(), + "If you provide the nameservers flag, " + + "you cannot use the add_nameservers and remove_nameservers flags."); + } else { + checkArgument(addNameservers.size() <= 13, "You can add at most 13 nameservers."); + } + if (!admins.isEmpty()) { + checkArgument( + addAdmins.isEmpty() && removeAdmins.isEmpty(), + "If you provide the admins flag, you cannot use the add_admins and remove_admins flags."); + } + if (!techs.isEmpty()) { + checkArgument( + addTechs.isEmpty() && removeTechs.isEmpty(), + "If you provide the techs flag, you cannot use the add_techs and remove_techs flags."); + } + if (!statuses.isEmpty()) { + checkArgument( + addStatuses.isEmpty() && removeStatuses.isEmpty(), + "If you provide the statuses flag, " + + "you cannot use the add_statuses and remove_statuses flags."); + } + + for (String domain : domains) { + if (!nameservers.isEmpty() || !admins.isEmpty() || !techs.isEmpty() || !statuses.isEmpty()) { + DateTime now = DateTime.now(UTC); + DomainResource domainResource = loadByForeignKey(DomainResource.class, domain, now); + checkArgument(domainResource != null, "Domain '%s' does not exist", domain); + if (!nameservers.isEmpty()) { + ImmutableSortedSet existingNameservers = + domainResource.loadNameserverFullyQualifiedHostNames(); + populateAddRemoveLists( + ImmutableSet.copyOf(nameservers), + existingNameservers, + addNameservers, + removeNameservers); + checkArgument( + existingNameservers.size() + addNameservers.size() - removeNameservers.size() <= 13, + "The resulting nameservers count for domain %s would be more than 13", + domain); + } + if (!admins.isEmpty() || !techs.isEmpty()) { + ImmutableSet existingAdmins = + getContactsOfType(domainResource, DesignatedContact.Type.ADMIN); + ImmutableSet existingTechs = + getContactsOfType(domainResource, DesignatedContact.Type.TECH); + + if (!admins.isEmpty()) { + populateAddRemoveLists( + ImmutableSet.copyOf(admins), existingAdmins, addAdmins, removeAdmins); + } + if (!techs.isEmpty()) { + populateAddRemoveLists( + ImmutableSet.copyOf(techs), existingTechs, addTechs, removeTechs); + } + } + if (!statuses.isEmpty()) { + Set currentStatusValues = new HashSet<>(); + for (StatusValue statusValue : domainResource.getStatusValues()) { + currentStatusValues.add(statusValue.getXmlName()); + } + populateAddRemoveLists( + ImmutableSet.copyOf(statuses), currentStatusValues, addStatuses, removeStatuses); + } + } + + boolean add = + !addNameservers.isEmpty() + || !addAdmins.isEmpty() + || !addTechs.isEmpty() + || !addStatuses.isEmpty(); + + boolean remove = + !removeNameservers.isEmpty() + || !removeAdmins.isEmpty() + || !removeTechs.isEmpty() + || !removeStatuses.isEmpty(); + + boolean change = registrant != null || password != null; + + if (!add && !remove && !change) { + logger.atInfo().log("No changes need to be made to domain %s", domain); + continue; + } + + setSoyTemplate(DomainUpdateSoyInfo.getInstance(), DomainUpdateSoyInfo.DOMAINUPDATE); + addSoyRecord( + clientId, + new SoyMapData( + "domain", domain, + "add", add, + "addNameservers", addNameservers, + "addAdmins", addAdmins, + "addTechs", addTechs, + "addStatuses", addStatuses, + "remove", remove, + "removeNameservers", removeNameservers, + "removeAdmins", removeAdmins, + "removeTechs", removeTechs, + "removeStatuses", removeStatuses, + "change", change, + "registrant", registrant, + "password", password)); + } + } + + protected void populateAddRemoveLists( + Set targetSet, Set oldSet, List addList, List removeList) { + addList.addAll(Sets.difference(targetSet, oldSet)); + removeList.addAll(Sets.difference(oldSet, targetSet)); + } + + ImmutableSet getContactsOfType( + DomainResource domainResource, final DesignatedContact.Type contactType) { + return FluentIterable.from(domainResource.getContacts()) + .filter( + new Predicate() { + @Override + public boolean apply(DesignatedContact contact) { + return contact.getType().equals(contactType); + } + }) + .transform( + new Function() { + @Override + public String apply(DesignatedContact contact) { + return ofy().load().key(contact.getContactKey()).now().getContactId(); + } + }) + .toSet(); + } +} diff --git a/java/google/registry/tools/soy/DomainCreate.soy b/java/google/registry/tools/soy/DomainCreate.soy index ef83d565b..f859e1169 100644 --- a/java/google/registry/tools/soy/DomainCreate.soy +++ b/java/google/registry/tools/soy/DomainCreate.soy @@ -19,10 +19,10 @@ {template .domaincreate} {@param domain: string} {@param? period: string} - {@param? ns: list} + {@param nameservers: list} {@param registrant: string} - {@param admin: string} - {@param tech: string} + {@param admins: list} + {@param techs: list} {@param password: string} @@ -34,16 +34,20 @@ {if $period} {$period} {/if} - {if $ns} + {if length($nameservers) > 0} - {foreach $s in $ns} + {foreach $s in $nameservers} {$s} {/foreach} {/if} {$registrant} - {$admin} - {$tech} + {foreach $admin in $admins} + {$admin} + {/foreach} + {foreach $tech in $techs} + {$tech} + {/foreach} {$password} diff --git a/java/google/registry/tools/soy/DomainUpdate.soy b/java/google/registry/tools/soy/DomainUpdate.soy new file mode 100644 index 000000000..81e4b673d --- /dev/null +++ b/java/google/registry/tools/soy/DomainUpdate.soy @@ -0,0 +1,98 @@ +// Copyright 2017 The Nomulus 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"} +/** + * Update domain + */ +{template .domainupdate} + {@param domain: string} + {@param add: bool} + {@param addNameservers: list} + {@param addAdmins: list} + {@param addTechs: list} + {@param addStatuses: list} + {@param remove: bool} + {@param removeNameservers: list} + {@param removeAdmins: list} + {@param removeTechs: list} + {@param removeStatuses: list} + {@param change: bool} + {@param? registrant: string} + {@param? password: string} + + + + + + + {$domain} + {if $add} + + {if length($addNameservers) > 0} + + {foreach $s in $addNameservers} + {$s} + {/foreach} + + {/if} + {foreach $admin in $addAdmins} + {$admin} + {/foreach} + {foreach $tech in $addTechs} + {$tech} + {/foreach} + {foreach $status in $addStatuses} + + {/foreach} + + {/if} + {if $remove} + + {if length($removeNameservers) > 0} + + {foreach $s in $removeNameservers} + {$s} + {/foreach} + + {/if} + {foreach $admin in $removeAdmins} + {$admin} + {/foreach} + {foreach $tech in $removeTechs} + {$tech} + {/foreach} + {foreach $status in $removeStatuses} + + {/foreach} + + {/if} + {if $change} + + {if $registrant} + {$registrant} + {/if} + {if $password} + + {$password} + + {/if} + + {/if} + + + RegistryTool + + +{/template} diff --git a/javatests/google/registry/tools/CreateDomainCommandTest.java b/javatests/google/registry/tools/CreateDomainCommandTest.java index 8a0556b05..885e07589 100644 --- a/javatests/google/registry/tools/CreateDomainCommandTest.java +++ b/javatests/google/registry/tools/CreateDomainCommandTest.java @@ -34,8 +34,8 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase { + + @Test + public void testSuccess_complete() throws Exception { + runCommandForced( + "--client=NewRegistrar", + "--add_nameservers=ns2.zdns.google,ns3.zdns.google", + "--add_admins=crr-admin2", + "--add_techs=crr-tech2", + "--add_statuses=serverDeleteProhibited", + "--remove_nameservers=ns4.zdns.google", + "--remove_admins=crr-admin1", + "--remove_techs=crr-tech1", + "--remove_statuses=serverHold", + "--registrant=crr-admin", + "--password=2fooBAR", + "example.tld"); + eppVerifier().verifySent("domain_update_complete.xml"); + } + + @Test + public void testSuccess_multipleDomains() throws Exception { + runCommandForced( + "--client=NewRegistrar", + "--add_nameservers=ns2.zdns.google,ns3.zdns.google", + "--add_admins=crr-admin2", + "--add_techs=crr-tech2", + "--add_statuses=serverDeleteProhibited", + "--remove_nameservers=ns4.zdns.google", + "--remove_admins=crr-admin1", + "--remove_techs=crr-tech1", + "--remove_statuses=serverHold", + "--registrant=crr-admin", + "--password=2fooBAR", + "example.tld", + "example.abc"); + eppVerifier().verifySent("domain_update_complete.xml", "domain_update_complete_abc.xml"); + } + + @Test + public void testSuccess_add() throws Exception { + runCommandForced( + "--client=NewRegistrar", + "--add_nameservers=ns2.zdns.google,ns3.zdns.google", + "--add_admins=crr-admin2", + "--add_techs=crr-tech2", + "--add_statuses=serverDeleteProhibited", + "example.tld"); + eppVerifier().verifySent("domain_update_add.xml"); + } + + @Test + public void testSuccess_remove() throws Exception { + runCommandForced( + "--client=NewRegistrar", + "--remove_nameservers=ns4.zdns.google", + "--remove_admins=crr-admin1", + "--remove_techs=crr-tech1", + "--remove_statuses=serverHold", + "example.tld"); + eppVerifier().verifySent("domain_update_remove.xml"); + } + + @Test + public void testSuccess_change() throws Exception { + runCommandForced( + "--client=NewRegistrar", "--registrant=crr-admin", "--password=2fooBAR", "example.tld"); + eppVerifier().verifySent("domain_update_change.xml"); + } + + @Test + public void testSuccess_setNameservers() throws Exception { + HostResource host1 = persistActiveHost("ns1.zdns.google"); + HostResource host2 = persistActiveHost("ns2.zdns.google"); + ImmutableSet> nameservers = + ImmutableSet.of(Key.create(host1), Key.create(host2)); + persistResource( + newDomainResource("example.tld").asBuilder().setNameservers(nameservers).build()); + runCommandForced( + "--client=NewRegistrar", "--nameservers=ns2.zdns.google,ns3.zdns.google", "example.tld"); + eppVerifier().verifySent("domain_update_set_nameservers.xml"); + } + + @Test + public void testSuccess_setContacts() throws Exception { + ContactResource adminContact1 = persistResource(newContactResource("crr-admin1")); + ContactResource adminContact2 = persistResource(newContactResource("crr-admin2")); + ContactResource techContact1 = persistResource(newContactResource("crr-tech1")); + ContactResource techContact2 = persistResource(newContactResource("crr-tech2")); + Key adminResourceKey1 = Key.create(adminContact1); + Key adminResourceKey2 = Key.create(adminContact2); + Key techResourceKey1 = Key.create(techContact1); + Key techResourceKey2 = Key.create(techContact2); + + persistResource( + newDomainResource("example.tld") + .asBuilder() + .setContacts( + ImmutableSet.of( + DesignatedContact.create(DesignatedContact.Type.ADMIN, adminResourceKey1), + DesignatedContact.create(DesignatedContact.Type.ADMIN, adminResourceKey2), + DesignatedContact.create(DesignatedContact.Type.TECH, techResourceKey1), + DesignatedContact.create(DesignatedContact.Type.TECH, techResourceKey2))) + .build()); + + runCommandForced( + "--client=NewRegistrar", + "--admins=crr-admin2,crr-admin3", + "--techs=crr-tech2,crr-tech3", + "example.tld"); + eppVerifier().verifySent("domain_update_set_contacts.xml"); + } + + @Test + public void testSuccess_setStatuses() throws Exception { + HostResource host = persistActiveHost("ns1.zdns.google"); + ImmutableSet> nameservers = ImmutableSet.of(Key.create(host)); + persistResource( + newDomainResource("example.tld") + .asBuilder() + .setStatusValues( + ImmutableSet.of( + StatusValue.CLIENT_RENEW_PROHIBITED, StatusValue.SERVER_UPDATE_PROHIBITED)) + .setNameservers(nameservers) + .build()); + + runCommandForced( + "--client=NewRegistrar", "--statuses=clientRenewProhibited,serverHold", "example.tld"); + eppVerifier().verifySent("domain_update_set_statuses.xml"); + } + + @Test + public void testFailure_duplicateDomains() throws Exception { + thrown.expect(IllegalArgumentException.class, "Duplicate arguments found"); + runCommandForced( + "--client=NewRegistrar", + "--registrant=crr-admin", + "--password=2fooBAR", + "example.tld", + "example.tld"); + } + + @Test + public void testFailure_missingDomain() throws Exception { + thrown.expect(ParameterException.class, "Main parameters are required"); + runCommandForced("--client=NewRegistrar", "--registrant=crr-admin", "--password=2fooBAR"); + } + + @Test + public void testFailure_missingClientId() throws Exception { + thrown.expect(ParameterException.class, "--client"); + runCommandForced("--registrant=crr-admin", "--password=2fooBAR", "example.tld"); + } + + @Test + public void testFailure_addTooManyNameServers() throws Exception { + thrown.expect(IllegalArgumentException.class, "You can add at most 13 nameservers"); + runCommandForced( + "--client=NewRegistrar", + "--add_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", + "--add_admins=crr-admin2", + "--add_techs=crr-tech2", + "--add_statuses=serverDeleteProhibited", + "example.tld"); + } + + @Test + public void testFailure_providedNameserversAndAddNameservers() throws Exception { + thrown.expect( + IllegalArgumentException.class, + "If you provide the nameservers flag, " + + "you cannot use the add_nameservers and remove_nameservers flags."); + runCommandForced( + "--client=NewRegistrar", + "--add_nameservers=ns1.zdns.google", + "--nameservers=ns2.zdns.google,ns3.zdns.google", + "example.tld"); + } + + @Test + public void testFailure_providedNameserversAndRemoveNameservers() throws Exception { + thrown.expect( + IllegalArgumentException.class, + "If you provide the nameservers flag, " + + "you cannot use the add_nameservers and remove_nameservers flags."); + runCommandForced( + "--client=NewRegistrar", + "--remove_nameservers=ns1.zdns.google", + "--nameservers=ns2.zdns.google,ns3.zdns.google", + "example.tld"); + } + + @Test + public void testFailure_providedAdminsAndAddAdmins() throws Exception { + thrown.expect( + IllegalArgumentException.class, + "If you provide the admins flag, you cannot use the add_admins and remove_admins flags."); + runCommandForced( + "--client=NewRegistrar", "--add_admins=crr-admin2", "--admins=crr-admin2", "example.tld"); + } + + @Test + public void testFailure_providedAdminsAndRemoveAdmins() throws Exception { + thrown.expect( + IllegalArgumentException.class, + "If you provide the admins flag, you cannot use the add_admins and remove_admins flags."); + runCommandForced( + "--client=NewRegistrar", + "--remove_admins=crr-admin2", + "--admins=crr-admin2", + "example.tld"); + } + + @Test + public void testFailure_providedTechsAndAddTechs() throws Exception { + thrown.expect( + IllegalArgumentException.class, + "If you provide the techs flag, you cannot use the add_techs and remove_techs flags."); + runCommandForced( + "--client=NewRegistrar", "--add_techs=crr-tech2", "--techs=crr-tech2", "example.tld"); + } + + @Test + public void testFailure_providedTechsAndRemoveTechs() throws Exception { + thrown.expect( + IllegalArgumentException.class, + "If you provide the techs flag, you cannot use the add_techs and remove_techs flags."); + runCommandForced( + "--client=NewRegistrar", "--remove_techs=crr-tech2", "--techs=crr-tech2", "example.tld"); + } + + @Test + public void testFailure_providedStatusesAndAddStatuses() throws Exception { + thrown.expect( + IllegalArgumentException.class, + "If you provide the statuses flag, " + + "you cannot use the add_statuses and remove_statuses flags."); + runCommandForced( + "--client=NewRegistrar", + "--add_statuses=serverHold", + "--statuses=crr-serverHold", + "example.tld"); + } + + @Test + public void testFailure_providedStatusesAndRemoveStatuses() throws Exception { + thrown.expect( + IllegalArgumentException.class, + "If you provide the statuses flag, " + + "you cannot use the add_statuses and remove_statuses flags."); + runCommandForced( + "--client=NewRegistrar", + "--remove_statuses=serverHold", + "--statuses=crr-serverHold", + "example.tld"); + } +} diff --git a/javatests/google/registry/tools/testdata/domain_update_add.xml b/javatests/google/registry/tools/testdata/domain_update_add.xml new file mode 100644 index 000000000..9b2ca3d9e --- /dev/null +++ b/javatests/google/registry/tools/testdata/domain_update_add.xml @@ -0,0 +1,21 @@ + + + + + + example.tld + + + ns2.zdns.google + ns3.zdns.google + + crr-admin2 + crr-tech2 + + + + + RegistryTool + + diff --git a/javatests/google/registry/tools/testdata/domain_update_change.xml b/javatests/google/registry/tools/testdata/domain_update_change.xml new file mode 100644 index 000000000..79ffda5ef --- /dev/null +++ b/javatests/google/registry/tools/testdata/domain_update_change.xml @@ -0,0 +1,18 @@ + + + + + + example.tld + + crr-admin + + 2fooBAR + + + + + RegistryTool + + diff --git a/javatests/google/registry/tools/testdata/domain_update_complete.xml b/javatests/google/registry/tools/testdata/domain_update_complete.xml new file mode 100644 index 000000000..f3af0e25c --- /dev/null +++ b/javatests/google/registry/tools/testdata/domain_update_complete.xml @@ -0,0 +1,35 @@ + + + + + + example.tld + + + ns2.zdns.google + ns3.zdns.google + + crr-admin2 + crr-tech2 + + + + + ns4.zdns.google + + crr-admin1 + crr-tech1 + + + + crr-admin + + 2fooBAR + + + + + RegistryTool + + diff --git a/javatests/google/registry/tools/testdata/domain_update_complete_abc.xml b/javatests/google/registry/tools/testdata/domain_update_complete_abc.xml new file mode 100644 index 000000000..8ef8853c0 --- /dev/null +++ b/javatests/google/registry/tools/testdata/domain_update_complete_abc.xml @@ -0,0 +1,35 @@ + + + + + + example.abc + + + ns2.zdns.google + ns3.zdns.google + + crr-admin2 + crr-tech2 + + + + + ns4.zdns.google + + crr-admin1 + crr-tech1 + + + + crr-admin + + 2fooBAR + + + + + RegistryTool + + diff --git a/javatests/google/registry/tools/testdata/domain_update_remove.xml b/javatests/google/registry/tools/testdata/domain_update_remove.xml new file mode 100644 index 000000000..fab3206c5 --- /dev/null +++ b/javatests/google/registry/tools/testdata/domain_update_remove.xml @@ -0,0 +1,20 @@ + + + + + + example.tld + + + ns4.zdns.google + + crr-admin1 + crr-tech1 + + + + + RegistryTool + + diff --git a/javatests/google/registry/tools/testdata/domain_update_set_contacts.xml b/javatests/google/registry/tools/testdata/domain_update_set_contacts.xml new file mode 100644 index 000000000..a3fb89c33 --- /dev/null +++ b/javatests/google/registry/tools/testdata/domain_update_set_contacts.xml @@ -0,0 +1,20 @@ + + + + + + example.tld + + crr-admin3 + crr-tech3 + + + crr-admin1 + crr-tech1 + + + + RegistryTool + + diff --git a/javatests/google/registry/tools/testdata/domain_update_set_nameservers.xml b/javatests/google/registry/tools/testdata/domain_update_set_nameservers.xml new file mode 100644 index 000000000..54f5ccd1c --- /dev/null +++ b/javatests/google/registry/tools/testdata/domain_update_set_nameservers.xml @@ -0,0 +1,22 @@ + + + + + + example.tld + + + ns3.zdns.google + + + + + ns1.zdns.google + + + + + RegistryTool + + diff --git a/javatests/google/registry/tools/testdata/domain_update_set_statuses.xml b/javatests/google/registry/tools/testdata/domain_update_set_statuses.xml new file mode 100644 index 000000000..707274e3d --- /dev/null +++ b/javatests/google/registry/tools/testdata/domain_update_set_statuses.xml @@ -0,0 +1,18 @@ + + + + + + example.tld + + + + + + + + + RegistryTool + +