Refactor CreateDomainCommand and add UpdateDomainCommand

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=160282921
This commit is contained in:
bbilbo 2017-06-27 09:12:41 -07:00 committed by Ben McIlwain
parent 30d5d05fdf
commit bbdf9bfc38
18 changed files with 944 additions and 80 deletions

View file

@ -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",

View file

@ -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<String> 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<String> 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<String> 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));
}
}

View file

@ -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<String> mainParameters;
@Parameter(
names = {"-n", "--nameservers"},
description = "Comma-separated list of nameservers, up to 13."
)
List<String> nameservers = new ArrayList<>();
@Parameter(
names = {"-r", "--registrant"},
description = "Domain registrant."
)
String registrant;
@Parameter(
names = {"-a", "--admins"},
description = "Comma-separated list of admin contacts."
)
List<String> admins = new ArrayList<>();
@Parameter(
names = {"-t", "--techs"},
description = "Comma-separated list of technical contacts."
)
List<String> techs = new ArrayList<>();
@Parameter(
names = {"-p", "--password"},
description = "Password."
)
String password;
Set<String> 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();
}
}

View file

@ -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)

View file

@ -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);

View file

@ -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<String> 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<String> addNameservers = new ArrayList<>();
@Parameter(
names = "--add_admins",
description = "Admins to add. Cannot be set if --admins is set."
)
private List<String> addAdmins = new ArrayList<>();
@Parameter(names = "--add_techs", description = "Techs to add. Cannot be set if --techs is set.")
private List<String> addTechs = new ArrayList<>();
@Parameter(
names = "--add_statuses",
description = "Statuses to add. Cannot be set if --statuses is set."
)
private List<String> 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<String> removeNameservers = new ArrayList<>();
@Parameter(
names = "--remove_admins",
description = "Admins to remove. Cannot be set if --admins is set."
)
private List<String> removeAdmins = new ArrayList<>();
@Parameter(
names = "--remove_techs",
description = "Techs to remove. Cannot be set if --techs is set."
)
private List<String> removeTechs = new ArrayList<>();
@Parameter(
names = "--remove_statuses",
description = "Statuses to remove. Cannot be set if --statuses is set."
)
private List<String> 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<String> 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<String> existingAdmins =
getContactsOfType(domainResource, DesignatedContact.Type.ADMIN);
ImmutableSet<String> 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<String> 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<String> targetSet, Set<String> oldSet, List<String> addList, List<String> removeList) {
addList.addAll(Sets.difference(targetSet, oldSet));
removeList.addAll(Sets.difference(oldSet, targetSet));
}
ImmutableSet<String> getContactsOfType(
DomainResource domainResource, final DesignatedContact.Type contactType) {
return FluentIterable.from(domainResource.getContacts())
.filter(
new Predicate<DesignatedContact>() {
@Override
public boolean apply(DesignatedContact contact) {
return contact.getType().equals(contactType);
}
})
.transform(
new Function<DesignatedContact, String>() {
@Override
public String apply(DesignatedContact contact) {
return ofy().load().key(contact.getContactKey()).now().getContactId();
}
})
.toSet();
}
}

View file

@ -19,10 +19,10 @@
{template .domaincreate}
{@param domain: string}
{@param? period: string}
{@param? ns: list<string>}
{@param nameservers: list<string>}
{@param registrant: string}
{@param admin: string}
{@param tech: string}
{@param admins: list<string>}
{@param techs: list<string>}
{@param password: string}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@ -34,16 +34,20 @@
{if $period}
<domain:period unit="y">{$period}</domain:period>
{/if}
{if $ns}
{if length($nameservers) > 0}
<domain:ns>
{foreach $s in $ns}
{foreach $s in $nameservers}
<domain:hostObj>{$s}</domain:hostObj>
{/foreach}
</domain:ns>
{/if}
<domain:registrant>{$registrant}</domain:registrant>
{foreach $admin in $admins}
<domain:contact type="admin">{$admin}</domain:contact>
{/foreach}
{foreach $tech in $techs}
<domain:contact type="tech">{$tech}</domain:contact>
{/foreach}
<domain:authInfo>
<domain:pw>{$password}</domain:pw>
</domain:authInfo>

View file

@ -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<string>}
{@param addAdmins: list<string>}
{@param addTechs: list<string>}
{@param addStatuses: list<string>}
{@param remove: bool}
{@param removeNameservers: list<string>}
{@param removeAdmins: list<string>}
{@param removeTechs: list<string>}
{@param removeStatuses: list<string>}
{@param change: bool}
{@param? registrant: string}
{@param? password: string}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<update>
<domain:update xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>{$domain}</domain:name>
{if $add}
<domain:add>
{if length($addNameservers) > 0}
<domain:ns>
{foreach $s in $addNameservers}
<domain:hostObj>{$s}</domain:hostObj>
{/foreach}
</domain:ns>
{/if}
{foreach $admin in $addAdmins}
<domain:contact type="admin">{$admin}</domain:contact>
{/foreach}
{foreach $tech in $addTechs}
<domain:contact type="tech">{$tech}</domain:contact>
{/foreach}
{foreach $status in $addStatuses}
<domain:status s="{$status}"/>
{/foreach}
</domain:add>
{/if}
{if $remove}
<domain:rem>
{if length($removeNameservers) > 0}
<domain:ns>
{foreach $s in $removeNameservers}
<domain:hostObj>{$s}</domain:hostObj>
{/foreach}
</domain:ns>
{/if}
{foreach $admin in $removeAdmins}
<domain:contact type="admin">{$admin}</domain:contact>
{/foreach}
{foreach $tech in $removeTechs}
<domain:contact type="tech">{$tech}</domain:contact>
{/foreach}
{foreach $status in $removeStatuses}
<domain:status s="{$status}"/>
{/foreach}
</domain:rem>
{/if}
{if $change}
<domain:chg>
{if $registrant}
<domain:registrant>{$registrant}</domain:registrant>
{/if}
{if $password}
<domain:authInfo>
<domain:pw>{$password}</domain:pw>
</domain:authInfo>
{/if}
</domain:chg>
{/if}
</domain:update>
</update>
<clTRID>RegistryTool</clTRID>
</command>
</epp>
{/template}

View file

@ -34,8 +34,8 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
"--period=1",
"--nameservers=ns1.zdns.google,ns2.zdns.google,ns3.zdns.google,ns4.zdns.google",
"--registrant=crr-admin",
"--admin=crr-admin",
"--tech=crr-tech",
"--admins=crr-admin",
"--techs=crr-tech",
"--password=2fooBAR",
"example.tld");
eppVerifier().verifySent("domain_create_complete.xml");
@ -47,8 +47,8 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
runCommandForced(
"--client=NewRegistrar",
"--registrant=crr-admin",
"--admin=crr-admin",
"--tech=crr-tech",
"--admins=crr-admin",
"--techs=crr-tech",
"example.tld");
eppVerifier().verifySent("domain_create_minimal.xml");
}
@ -58,8 +58,8 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
runCommandForced(
"--client=NewRegistrar",
"--registrant=crr-admin",
"--admin=crr-admin",
"--tech=crr-tech",
"--admins=crr-admin",
"--techs=crr-tech",
"example.tld",
"example.abc");
eppVerifier().verifySent("domain_create_minimal.xml", "domain_create_minimal_abc.xml");
@ -71,8 +71,8 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
runCommandForced(
"--client=NewRegistrar",
"--registrant=crr-admin",
"--admin=crr-admin",
"--tech=crr-tech",
"--admins=crr-admin",
"--techs=crr-tech",
"example.tld",
"example.tld");
}
@ -81,35 +81,38 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
public void testFailure_missingDomain() throws Exception {
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",
"--admins=crr-admin",
"--techs=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");
"--admins=crr-admin", "--techs=crr-tech", "--registrant=crr-admin", "example.tld");
}
@Test
public void testFailure_missingRegistrant() throws Exception {
thrown.expect(ParameterException.class, "--registrant");
thrown.expect(IllegalArgumentException.class, "Registrant must be specified");
runCommandForced(
"--client=NewRegistrar", "--admin=crr-admin", "--tech=crr-tech", "example.tld");
"--client=NewRegistrar", "--admins=crr-admin", "--techs=crr-tech", "example.tld");
}
@Test
public void testFailure_missingAdmin() throws Exception {
thrown.expect(ParameterException.class, "--admin");
public void testFailure_missingAdmins() throws Exception {
thrown.expect(IllegalArgumentException.class, "At least one admin must be specified");
runCommandForced(
"--client=NewRegistrar", "--registrant=crr-admin", "--tech=crr-tech", "example.tld");
"--client=NewRegistrar", "--registrant=crr-admin", "--techs=crr-tech", "example.tld");
}
@Test
public void testFailure_missingTech() throws Exception {
thrown.expect(ParameterException.class, "--tech");
public void testFailure_missingTechs() throws Exception {
thrown.expect(IllegalArgumentException.class, "At least one tech must be specified");
runCommandForced(
"--client=NewRegistrar", "--registrant=crr-admin", "--admin=crr-admin", "example.tld");
"--client=NewRegistrar", "--registrant=crr-admin", "--admins=crr-admin", "example.tld");
}
@Test
@ -118,8 +121,8 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
runCommandForced(
"--client=NewRegistrar",
"--registrant=crr-admin",
"--admin=crr-admin",
"--tech=crr-tech",
"--admins=crr-admin",
"--techs=crr-tech",
"--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,"
@ -133,8 +136,8 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
runCommandForced(
"--client=NewRegistrar",
"--registrant=crr-admin",
"--admin=crr-admin",
"--tech=crr-tech",
"--admins=crr-admin",
"--techs=crr-tech",
"--period=x",
"--domain=example.tld");
}

View file

@ -0,0 +1,291 @@
// 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 google.registry.testing.DatastoreHelper.newContactResource;
import static google.registry.testing.DatastoreHelper.newDomainResource;
import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistResource;
import com.beust.jcommander.ParameterException;
import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key;
import google.registry.model.contact.ContactResource;
import google.registry.model.domain.DesignatedContact;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource;
import org.junit.Test;
/** Unit tests for {@link UpdateDomainCommand}. */
public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand> {
@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<Key<HostResource>> 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<ContactResource> adminResourceKey1 = Key.create(adminContact1);
Key<ContactResource> adminResourceKey2 = Key.create(adminContact2);
Key<ContactResource> techResourceKey1 = Key.create(techContact1);
Key<ContactResource> 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<Key<HostResource>> 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");
}
}

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<update>
<domain:update
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.tld</domain:name>
<domain:add>
<domain:ns>
<domain:hostObj>ns2.zdns.google</domain:hostObj>
<domain:hostObj>ns3.zdns.google</domain:hostObj>
</domain:ns>
<domain:contact type="admin">crr-admin2</domain:contact>
<domain:contact type="tech">crr-tech2</domain:contact>
<domain:status s="serverDeleteProhibited"/>
</domain:add>
</domain:update>
</update>
<clTRID>RegistryTool</clTRID>
</command>
</epp>

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>
<update>
<domain:update
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.tld</domain:name>
<domain:chg>
<domain:registrant>crr-admin</domain:registrant>
<domain:authInfo>
<domain:pw>2fooBAR</domain:pw>
</domain:authInfo>
</domain:chg>
</domain:update>
</update>
<clTRID>RegistryTool</clTRID>
</command>
</epp>

View file

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<update>
<domain:update
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.tld</domain:name>
<domain:add>
<domain:ns>
<domain:hostObj>ns2.zdns.google</domain:hostObj>
<domain:hostObj>ns3.zdns.google</domain:hostObj>
</domain:ns>
<domain:contact type="admin">crr-admin2</domain:contact>
<domain:contact type="tech">crr-tech2</domain:contact>
<domain:status s="serverDeleteProhibited"/>
</domain:add>
<domain:rem>
<domain:ns>
<domain:hostObj>ns4.zdns.google</domain:hostObj>
</domain:ns>
<domain:contact type="admin">crr-admin1</domain:contact>
<domain:contact type="tech">crr-tech1</domain:contact>
<domain:status s="serverHold"/>
</domain:rem>
<domain:chg>
<domain:registrant>crr-admin</domain:registrant>
<domain:authInfo>
<domain:pw>2fooBAR</domain:pw>
</domain:authInfo>
</domain:chg>
</domain:update>
</update>
<clTRID>RegistryTool</clTRID>
</command>
</epp>

View file

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<update>
<domain:update
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.abc</domain:name>
<domain:add>
<domain:ns>
<domain:hostObj>ns2.zdns.google</domain:hostObj>
<domain:hostObj>ns3.zdns.google</domain:hostObj>
</domain:ns>
<domain:contact type="admin">crr-admin2</domain:contact>
<domain:contact type="tech">crr-tech2</domain:contact>
<domain:status s="serverDeleteProhibited"/>
</domain:add>
<domain:rem>
<domain:ns>
<domain:hostObj>ns4.zdns.google</domain:hostObj>
</domain:ns>
<domain:contact type="admin">crr-admin1</domain:contact>
<domain:contact type="tech">crr-tech1</domain:contact>
<domain:status s="serverHold"/>
</domain:rem>
<domain:chg>
<domain:registrant>crr-admin</domain:registrant>
<domain:authInfo>
<domain:pw>2fooBAR</domain:pw>
</domain:authInfo>
</domain:chg>
</domain:update>
</update>
<clTRID>RegistryTool</clTRID>
</command>
</epp>

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<update>
<domain:update
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.tld</domain:name>
<domain:rem>
<domain:ns>
<domain:hostObj>ns4.zdns.google</domain:hostObj>
</domain:ns>
<domain:contact type="admin">crr-admin1</domain:contact>
<domain:contact type="tech">crr-tech1</domain:contact>
<domain:status s="serverHold"/>
</domain:rem>
</domain:update>
</update>
<clTRID>RegistryTool</clTRID>
</command>
</epp>

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<update>
<domain:update
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.tld</domain:name>
<domain:add>
<domain:contact type="admin">crr-admin3</domain:contact>
<domain:contact type="tech">crr-tech3</domain:contact>
</domain:add>
<domain:rem>
<domain:contact type="admin">crr-admin1</domain:contact>
<domain:contact type="tech">crr-tech1</domain:contact>
</domain:rem>
</domain:update>
</update>
<clTRID>RegistryTool</clTRID>
</command>
</epp>

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<update>
<domain:update
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.tld</domain:name>
<domain:add>
<domain:ns>
<domain:hostObj>ns3.zdns.google</domain:hostObj>
</domain:ns>
</domain:add>
<domain:rem>
<domain:ns>
<domain:hostObj>ns1.zdns.google</domain:hostObj>
</domain:ns>
</domain:rem>
</domain:update>
</update>
<clTRID>RegistryTool</clTRID>
</command>
</epp>

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>
<update>
<domain:update
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.tld</domain:name>
<domain:add>
<domain:status s="serverHold"/>
</domain:add>
<domain:rem>
<domain:status s="serverUpdateProhibited"/>
</domain:rem>
</domain:update>
</update>
<clTRID>RegistryTool</clTRID>
</command>
</epp>