mirror of
https://github.com/google/nomulus
synced 2026-01-07 14:05:44 +00:00
Change RL input to be a POST body (#2503)
This commit is contained in:
@@ -19,16 +19,13 @@ import static com.google.common.collect.ImmutableList.toImmutableList;
|
|||||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||||
import static google.registry.request.Action.Method.GET;
|
import static google.registry.request.Action.Method.GET;
|
||||||
import static google.registry.request.Action.Method.POST;
|
import static google.registry.request.Action.Method.POST;
|
||||||
import static google.registry.request.RequestParameters.extractBooleanParameter;
|
|
||||||
import static google.registry.request.RequestParameters.extractOptionalLongParameter;
|
|
||||||
import static google.registry.request.RequestParameters.extractOptionalParameter;
|
|
||||||
import static google.registry.request.RequestParameters.extractRequiredParameter;
|
|
||||||
import static google.registry.ui.server.registrar.RegistryLockPostAction.VERIFICATION_EMAIL_TEMPLATE;
|
import static google.registry.ui.server.registrar.RegistryLockPostAction.VERIFICATION_EMAIL_TEMPLATE;
|
||||||
import static jakarta.servlet.http.HttpServletResponse.SC_OK;
|
import static jakarta.servlet.http.HttpServletResponse.SC_OK;
|
||||||
import static jakarta.servlet.http.HttpServletResponse.SC_UNAUTHORIZED;
|
import static jakarta.servlet.http.HttpServletResponse.SC_UNAUTHORIZED;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.annotations.Expose;
|
||||||
import google.registry.flows.EppException;
|
import google.registry.flows.EppException;
|
||||||
import google.registry.flows.domain.DomainFlowUtils;
|
import google.registry.flows.domain.DomainFlowUtils;
|
||||||
import google.registry.groups.GmailClient;
|
import google.registry.groups.GmailClient;
|
||||||
@@ -46,8 +43,8 @@ import google.registry.ui.server.registrar.ConsoleApiParams;
|
|||||||
import google.registry.util.EmailMessage;
|
import google.registry.util.EmailMessage;
|
||||||
import jakarta.mail.internet.AddressException;
|
import jakarta.mail.internet.AddressException;
|
||||||
import jakarta.mail.internet.InternetAddress;
|
import jakarta.mail.internet.InternetAddress;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
|
|
||||||
@@ -69,6 +66,7 @@ public class ConsoleRegistryLockAction extends ConsoleApiAction {
|
|||||||
private final DomainLockUtils domainLockUtils;
|
private final DomainLockUtils domainLockUtils;
|
||||||
private final GmailClient gmailClient;
|
private final GmailClient gmailClient;
|
||||||
private final Gson gson;
|
private final Gson gson;
|
||||||
|
private final Optional<ConsoleRegistryLockPostInput> optionalPostInput;
|
||||||
private final String registrarId;
|
private final String registrarId;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -77,11 +75,14 @@ public class ConsoleRegistryLockAction extends ConsoleApiAction {
|
|||||||
DomainLockUtils domainLockUtils,
|
DomainLockUtils domainLockUtils,
|
||||||
GmailClient gmailClient,
|
GmailClient gmailClient,
|
||||||
Gson gson,
|
Gson gson,
|
||||||
|
@Parameter("consoleRegistryLockPostInput")
|
||||||
|
Optional<ConsoleRegistryLockPostInput> optionalPostInput,
|
||||||
@Parameter("registrarId") String registrarId) {
|
@Parameter("registrarId") String registrarId) {
|
||||||
super(consoleApiParams);
|
super(consoleApiParams);
|
||||||
this.domainLockUtils = domainLockUtils;
|
this.domainLockUtils = domainLockUtils;
|
||||||
this.gmailClient = gmailClient;
|
this.gmailClient = gmailClient;
|
||||||
this.gson = gson;
|
this.gson = gson;
|
||||||
|
this.optionalPostInput = optionalPostInput;
|
||||||
this.registrarId = registrarId;
|
this.registrarId = registrarId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +95,6 @@ public class ConsoleRegistryLockAction extends ConsoleApiAction {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void postHandler(User user) {
|
protected void postHandler(User user) {
|
||||||
HttpServletRequest req = consoleApiParams.request();
|
|
||||||
Response response = consoleApiParams.response();
|
Response response = consoleApiParams.response();
|
||||||
// User must have the proper permission on the registrar
|
// User must have the proper permission on the registrar
|
||||||
checkPermission(user, registrarId, ConsolePermission.REGISTRY_LOCK);
|
checkPermission(user, registrarId, ConsolePermission.REGISTRY_LOCK);
|
||||||
@@ -107,10 +107,12 @@ public class ConsoleRegistryLockAction extends ConsoleApiAction {
|
|||||||
registrarId);
|
registrarId);
|
||||||
|
|
||||||
// Retrieve and validate the necessary params
|
// Retrieve and validate the necessary params
|
||||||
String domainName = extractRequiredParameter(req, "domainName");
|
ConsoleRegistryLockPostInput postInput =
|
||||||
boolean isLock = extractBooleanParameter(req, "isLock");
|
optionalPostInput.orElseThrow(() -> new IllegalArgumentException("No POST input provided"));
|
||||||
Optional<String> maybePassword = extractOptionalParameter(req, "password");
|
String domainName = postInput.domainName();
|
||||||
Optional<Long> relockDurationMillis = extractOptionalLongParameter(req, "relockDurationMillis");
|
boolean isLock = postInput.isLock();
|
||||||
|
Optional<String> maybePassword = Optional.ofNullable(postInput.password());
|
||||||
|
Optional<Long> relockDurationMillis = Optional.ofNullable(postInput.relockDurationMillis());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DomainFlowUtils.validateDomainName(domainName);
|
DomainFlowUtils.validateDomainName(domainName);
|
||||||
@@ -176,4 +178,10 @@ public class ConsoleRegistryLockAction extends ConsoleApiAction {
|
|||||||
.filter(lock -> !lock.isLockRequestExpired(tm().getTransactionTime()))
|
.filter(lock -> !lock.isLockRequestExpired(tm().getTransactionTime()))
|
||||||
.collect(toImmutableList()));
|
.collect(toImmutableList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public record ConsoleRegistryLockPostInput(
|
||||||
|
@Expose String domainName,
|
||||||
|
@Expose boolean isLock,
|
||||||
|
@Expose @Nullable String password,
|
||||||
|
@Expose @Nullable Long relockDurationMillis) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import google.registry.request.auth.AuthResult;
|
|||||||
import google.registry.security.XsrfTokenManager;
|
import google.registry.security.XsrfTokenManager;
|
||||||
import google.registry.ui.server.SendEmailUtils;
|
import google.registry.ui.server.SendEmailUtils;
|
||||||
import google.registry.ui.server.console.ConsoleEppPasswordAction.EppPasswordData;
|
import google.registry.ui.server.console.ConsoleEppPasswordAction.EppPasswordData;
|
||||||
|
import google.registry.ui.server.console.ConsoleRegistryLockAction.ConsoleRegistryLockPostInput;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
@@ -242,4 +243,11 @@ public final class RegistrarConsoleModule {
|
|||||||
Gson gson, @OptionalJsonPayload Optional<JsonElement> payload) {
|
Gson gson, @OptionalJsonPayload Optional<JsonElement> payload) {
|
||||||
return payload.map(s -> gson.fromJson(s, EppPasswordData.class));
|
return payload.map(s -> gson.fromJson(s, EppPasswordData.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Parameter("consoleRegistryLockPostInput")
|
||||||
|
public static Optional<ConsoleRegistryLockPostInput> provideRegistryLockPostInput(
|
||||||
|
Gson gson, @OptionalJsonPayload Optional<JsonElement> payload) {
|
||||||
|
return payload.map(e -> gson.fromJson(e, ConsoleRegistryLockPostInput.class));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import static google.registry.testing.DatabaseHelper.persistResource;
|
|||||||
import static google.registry.testing.SqlHelper.getMostRecentRegistryLockByRepoId;
|
import static google.registry.testing.SqlHelper.getMostRecentRegistryLockByRepoId;
|
||||||
import static google.registry.testing.SqlHelper.saveRegistryLock;
|
import static google.registry.testing.SqlHelper.saveRegistryLock;
|
||||||
import static google.registry.tools.LockOrUnlockDomainCommand.REGISTRY_LOCK_STATUSES;
|
import static google.registry.tools.LockOrUnlockDomainCommand.REGISTRY_LOCK_STATUSES;
|
||||||
|
import static google.registry.ui.server.console.ConsoleRegistryLockAction.ConsoleRegistryLockPostInput;
|
||||||
import static jakarta.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
|
import static jakarta.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
|
||||||
import static jakarta.servlet.http.HttpServletResponse.SC_FORBIDDEN;
|
import static jakarta.servlet.http.HttpServletResponse.SC_FORBIDDEN;
|
||||||
import static jakarta.servlet.http.HttpServletResponse.SC_OK;
|
import static jakarta.servlet.http.HttpServletResponse.SC_OK;
|
||||||
@@ -309,10 +310,7 @@ public class ConsoleRegistryLockActionTest {
|
|||||||
persistResource(defaultDomain.asBuilder().setStatusValues(REGISTRY_LOCK_STATUSES).build());
|
persistResource(defaultDomain.asBuilder().setStatusValues(REGISTRY_LOCK_STATUSES).build());
|
||||||
action =
|
action =
|
||||||
createPostAction(
|
createPostAction(
|
||||||
"example.test",
|
"example.test", false, "registryLockPassword", Duration.standardDays(1).getMillis());
|
||||||
false,
|
|
||||||
"registryLockPassword",
|
|
||||||
Optional.of(Duration.standardDays(1).getMillis()));
|
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(SC_OK);
|
assertThat(response.getStatus()).isEqualTo(SC_OK);
|
||||||
verifyEmail();
|
verifyEmail();
|
||||||
@@ -348,7 +346,7 @@ public class ConsoleRegistryLockActionTest {
|
|||||||
.setUserRoles(
|
.setUserRoles(
|
||||||
new UserRoles.Builder().setGlobalRole(GlobalRole.FTE).setIsAdmin(true).build())
|
new UserRoles.Builder().setGlobalRole(GlobalRole.FTE).setIsAdmin(true).build())
|
||||||
.build();
|
.build();
|
||||||
action = createPostAction("example.test", true, "", Optional.empty());
|
action = createPostAction("example.test", true, "", null);
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(SC_OK);
|
assertThat(response.getStatus()).isEqualTo(SC_OK);
|
||||||
verifyEmail();
|
verifyEmail();
|
||||||
@@ -414,8 +412,7 @@ public class ConsoleRegistryLockActionTest {
|
|||||||
.setCreationRegistrarId("NewRegistrar")
|
.setCreationRegistrarId("NewRegistrar")
|
||||||
.setPersistedCurrentSponsorRegistrarId("NewRegistrar")
|
.setPersistedCurrentSponsorRegistrarId("NewRegistrar")
|
||||||
.build());
|
.build());
|
||||||
action =
|
action = createPostAction("otherregistrar.test", true, "registryLockPassword", null);
|
||||||
createPostAction("otherregistrar.test", true, "registryLockPassword", Optional.empty());
|
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(SC_BAD_REQUEST);
|
assertThat(response.getStatus()).isEqualTo(SC_BAD_REQUEST);
|
||||||
assertThat(response.getPayload())
|
assertThat(response.getPayload())
|
||||||
@@ -444,7 +441,7 @@ public class ConsoleRegistryLockActionTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testPost_failure_badPassword() throws Exception {
|
void testPost_failure_badPassword() throws Exception {
|
||||||
action = createPostAction("example.test", true, "badPassword", Optional.empty());
|
action = createPostAction("example.test", true, "badPassword", null);
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(SC_UNAUTHORIZED);
|
assertThat(response.getStatus()).isEqualTo(SC_UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
@@ -483,29 +480,25 @@ public class ConsoleRegistryLockActionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ConsoleRegistryLockAction createDefaultPostAction(boolean isLock) {
|
private ConsoleRegistryLockAction createDefaultPostAction(boolean isLock) {
|
||||||
return createPostAction("example.test", isLock, "registryLockPassword", Optional.empty());
|
return createPostAction("example.test", isLock, "registryLockPassword", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConsoleRegistryLockAction createPostAction(
|
private ConsoleRegistryLockAction createPostAction(
|
||||||
String domainName, boolean isLock, String password, Optional<Long> relockDurationMillis) {
|
String domainName, boolean isLock, String password, Long relockDurationMillis) {
|
||||||
ConsoleApiParams params = createParams();
|
ConsoleApiParams params = createParams();
|
||||||
when(params.request().getParameter("domainName")).thenReturn(domainName);
|
ConsoleRegistryLockPostInput postInput =
|
||||||
when(params.request().getParameterMap())
|
new ConsoleRegistryLockPostInput(domainName, isLock, password, relockDurationMillis);
|
||||||
.thenReturn(ImmutableMap.of("isLock", new String[] {String.valueOf(isLock)}));
|
return createGenericAction(params, "POST", Optional.of(postInput));
|
||||||
when(params.request().getParameter("isLock")).thenReturn(String.valueOf(isLock));
|
|
||||||
when(params.request().getParameter("password")).thenReturn(password);
|
|
||||||
relockDurationMillis.ifPresent(
|
|
||||||
duration ->
|
|
||||||
when(params.request().getParameter("relockDurationMillis"))
|
|
||||||
.thenReturn(String.valueOf(duration)));
|
|
||||||
return createGenericAction(params, "POST");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConsoleRegistryLockAction createGetAction() throws IOException {
|
private ConsoleRegistryLockAction createGetAction() throws IOException {
|
||||||
return createGenericAction(createParams(), "GET");
|
return createGenericAction(createParams(), "GET", Optional.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConsoleRegistryLockAction createGenericAction(ConsoleApiParams params, String method) {
|
private ConsoleRegistryLockAction createGenericAction(
|
||||||
|
ConsoleApiParams params,
|
||||||
|
String method,
|
||||||
|
Optional<ConsoleRegistryLockPostInput> optionalPostInput) {
|
||||||
when(params.request().getMethod()).thenReturn(method);
|
when(params.request().getMethod()).thenReturn(method);
|
||||||
when(params.request().getServerName()).thenReturn("registrarconsole.tld");
|
when(params.request().getServerName()).thenReturn("registrarconsole.tld");
|
||||||
when(params.request().getParameter("registrarId")).thenReturn("TheRegistrar");
|
when(params.request().getParameter("registrarId")).thenReturn("TheRegistrar");
|
||||||
@@ -516,7 +509,7 @@ public class ConsoleRegistryLockActionTest {
|
|||||||
new CloudTasksHelper(fakeClock).getTestCloudTasksUtils());
|
new CloudTasksHelper(fakeClock).getTestCloudTasksUtils());
|
||||||
response = (FakeResponse) params.response();
|
response = (FakeResponse) params.response();
|
||||||
return new ConsoleRegistryLockAction(
|
return new ConsoleRegistryLockAction(
|
||||||
params, domainLockUtils, gmailClient, GSON, "TheRegistrar");
|
params, domainLockUtils, gmailClient, GSON, optionalPostInput, "TheRegistrar");
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConsoleApiParams createParams() {
|
private ConsoleApiParams createParams() {
|
||||||
|
|||||||
Reference in New Issue
Block a user