Default clientId to registry's registrar in domain lock commands

All domain locks we've processed so far are as a result of the URS process, for
which the clientId is always that of the registry's registrar. So it makes sense
to default to that value, while still retaining the option to specify it if
required in case we ever support registrar-requested registry locks in the
future.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=199350120
This commit is contained in:
mcilwain 2018-06-05 13:39:24 -07:00 committed by Ben McIlwain
parent 897690119e
commit 5c7a20797e
4 changed files with 41 additions and 3 deletions

View file

@ -23,8 +23,10 @@ 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 google.registry.config.RegistryConfig.Config;
import google.registry.model.eppcommon.StatusValue;
import java.util.List;
import javax.inject.Inject;
/** Shared base class for commands to registry lock or unlock a domain via EPP. */
public abstract class LockOrUnlockDomainCommand extends MutatingEppToolCommand {
@ -35,14 +37,17 @@ public abstract class LockOrUnlockDomainCommand extends MutatingEppToolCommand {
@Parameter(
names = {"-c", "--client"},
description = "Client identifier of the registrar to execute the command as",
required = true
)
description =
"Client ID of the requesting registrar if applicable, otherwise the registry registrar")
String clientId;
@Parameter(description = "Names of the domains", required = true)
private List<String> mainParameters;
@Inject
@Config("registryAdminClientId")
String registryAdminClientId;
protected ImmutableSet<String> getDomains() {
return ImmutableSet.copyOf(mainParameters);
}
@ -51,6 +56,11 @@ public abstract class LockOrUnlockDomainCommand extends MutatingEppToolCommand {
protected void initEppToolCommand() throws Exception {
// Superuser status is required to update registry lock statuses.
superuser = true;
// Default clientId to the registry registrar account if otherwise unspecified.
if (clientId == null) {
clientId = registryAdminClientId;
}
String duplicates = Joiner.on(", ").join(findDuplicates(mainParameters));
checkArgument(duplicates.isEmpty(), "Duplicate domain arguments found: '%s'", duplicates);
initMutatingEppToolCommand();

View file

@ -91,12 +91,14 @@ interface RegistryToolComponent {
void inject(GetKeyringSecretCommand command);
void inject(GhostrydeCommand command);
void inject(ListCursorsCommand command);
void inject(LockDomainCommand command);
void inject(LoginCommand command);
void inject(LogoutCommand command);
void inject(PendingEscrowCommand command);
void inject(RenewDomainCommand command);
void inject(SendEscrowReportToIcannCommand command);
void inject(SetupOteCommand command);
void inject(UnlockDomainCommand command);
void inject(UpdateCursorsCommand command);
void inject(UpdateDomainCommand command);
void inject(UpdateKmsKeyringCommand command);

View file

@ -18,12 +18,14 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.eppcommon.StatusValue.SERVER_TRANSFER_PROHIBITED;
import static google.registry.testing.DatastoreHelper.newDomainResource;
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
import static google.registry.testing.DatastoreHelper.persistNewRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.tools.LockOrUnlockDomainCommand.REGISTRY_LOCK_STATUSES;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import google.registry.model.registrar.Registrar.Type;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
@ -35,6 +37,8 @@ public class LockDomainCommandTest extends EppToolCommandTestCase<LockDomainComm
@Before
public void before() {
eppVerifier.expectSuperuser();
persistNewRegistrar("adminreg", "Admin Registrar", Type.REAL, 693L);
command.registryAdminClientId = "adminreg";
}
@Test
@ -91,6 +95,15 @@ public class LockDomainCommandTest extends EppToolCommandTestCase<LockDomainComm
runCommandForced("--client=NewRegistrar", "example.tld");
}
@Test
public void testSuccess_defaultsToAdminRegistrar_ifUnspecified() throws Exception {
persistActiveDomain("example.tld");
runCommandForced("example.tld");
eppVerifier
.expectClientId("adminreg")
.verifySent("domain_lock.xml", ImmutableMap.of("DOMAIN", "example.tld"));
}
@Test
public void testFailure_duplicateDomainsAreSpecified() throws Exception {
IllegalArgumentException e =

View file

@ -20,12 +20,14 @@ import static google.registry.model.eppcommon.StatusValue.SERVER_TRANSFER_PROHIB
import static google.registry.model.eppcommon.StatusValue.SERVER_UPDATE_PROHIBITED;
import static google.registry.testing.DatastoreHelper.newDomainResource;
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
import static google.registry.testing.DatastoreHelper.persistNewRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import google.registry.model.registrar.Registrar.Type;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
@ -37,6 +39,8 @@ public class UnlockDomainCommandTest extends EppToolCommandTestCase<UnlockDomain
@Before
public void before() {
eppVerifier.expectSuperuser();
persistNewRegistrar("adminreg", "Admin Registrar", Type.REAL, 693L);
command.registryAdminClientId = "adminreg";
}
private static void persistLockedDomain(String domainName) {
@ -99,6 +103,15 @@ public class UnlockDomainCommandTest extends EppToolCommandTestCase<UnlockDomain
runCommandForced("--client=NewRegistrar", "example.tld");
}
@Test
public void testSuccess_defaultsToAdminRegistrar_ifUnspecified() throws Exception {
persistLockedDomain("example.tld");
runCommandForced("example.tld");
eppVerifier
.expectClientId("adminreg")
.verifySent("domain_unlock.xml", ImmutableMap.of("DOMAIN", "example.tld"));
}
@Test
public void testFailure_duplicateDomainsAreSpecified() throws Exception {
IllegalArgumentException e =