mirror of
https://github.com/google/nomulus
synced 2026-01-06 05:27:13 +00:00
Allow console access for FTE globar role (#2419)
This commit is contained in:
1
console-webapp/.gitignore
vendored
1
console-webapp/.gitignore
vendored
@@ -36,6 +36,7 @@ yarn-error.log
|
|||||||
/libpeerconnection.log
|
/libpeerconnection.log
|
||||||
testem.log
|
testem.log
|
||||||
/typings
|
/typings
|
||||||
|
.nx/
|
||||||
|
|
||||||
# System files
|
# System files
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|||||||
@@ -33,6 +33,11 @@ export class BackendService {
|
|||||||
error: HttpErrorResponse,
|
error: HttpErrorResponse,
|
||||||
mockData?: Type
|
mockData?: Type
|
||||||
): Observable<Type> {
|
): Observable<Type> {
|
||||||
|
// This is a temporary redirect to the old console untill the new console
|
||||||
|
// is fully released and enabled
|
||||||
|
if (error.url && window.location.href.indexOf(error.url) < 0) {
|
||||||
|
window.location.href = error.url;
|
||||||
|
}
|
||||||
if (error.error instanceof Error) {
|
if (error.error instanceof Error) {
|
||||||
// A client-side or network error occurred. Handle it accordingly.
|
// A client-side or network error occurred. Handle it accordingly.
|
||||||
console.error('An error occurred:', error.error.message);
|
console.error('An error occurred:', error.error.message);
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ import org.joda.time.DateTime;
|
|||||||
*/
|
*/
|
||||||
public interface Response {
|
public interface Response {
|
||||||
|
|
||||||
|
void sendRedirect(String url) throws IOException;
|
||||||
|
|
||||||
/** Sets the HTTP status code. */
|
/** Sets the HTTP status code. */
|
||||||
void setStatus(int status);
|
void setStatus(int status);
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,11 @@ public final class ResponseImpl implements Response {
|
|||||||
this.rsp = rsp;
|
this.rsp = rsp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendRedirect(String url) throws IOException {
|
||||||
|
rsp.sendRedirect(url);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setStatus(int status) {
|
public void setStatus(int status) {
|
||||||
rsp.setStatus(status);
|
rsp.setStatus(status);
|
||||||
|
|||||||
@@ -17,10 +17,15 @@ package google.registry.ui.server.console;
|
|||||||
import static google.registry.request.Action.Method.GET;
|
import static google.registry.request.Action.Method.GET;
|
||||||
|
|
||||||
import com.google.api.client.http.HttpStatusCodes;
|
import com.google.api.client.http.HttpStatusCodes;
|
||||||
|
import google.registry.model.console.GlobalRole;
|
||||||
import google.registry.model.console.User;
|
import google.registry.model.console.User;
|
||||||
|
import google.registry.request.auth.AuthResult;
|
||||||
import google.registry.security.XsrfTokenManager;
|
import google.registry.security.XsrfTokenManager;
|
||||||
import google.registry.ui.server.registrar.ConsoleApiParams;
|
import google.registry.ui.server.registrar.ConsoleApiParams;
|
||||||
|
import google.registry.ui.server.registrar.ConsoleUiAction;
|
||||||
|
import google.registry.util.RegistryEnvironment;
|
||||||
import jakarta.servlet.http.Cookie;
|
import jakarta.servlet.http.Cookie;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@@ -35,11 +40,26 @@ public abstract class ConsoleApiAction implements Runnable {
|
|||||||
@Override
|
@Override
|
||||||
public final void run() {
|
public final void run() {
|
||||||
// Shouldn't be even possible because of Auth annotations on the various implementing classes
|
// Shouldn't be even possible because of Auth annotations on the various implementing classes
|
||||||
if (consoleApiParams.authResult().userAuthInfo().get().consoleUser().isEmpty()) {
|
AuthResult authResult = consoleApiParams.authResult();
|
||||||
|
if (authResult.userAuthInfo().isEmpty()
|
||||||
|
|| authResult.userAuthInfo().get().consoleUser().isEmpty()) {
|
||||||
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
|
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
User user = consoleApiParams.authResult().userAuthInfo().get().consoleUser().get();
|
User user = consoleApiParams.authResult().userAuthInfo().get().consoleUser().get();
|
||||||
|
|
||||||
|
// This allows us to enable console to a selected cohort of users with release
|
||||||
|
// We can ignore it in tests
|
||||||
|
if (RegistryEnvironment.get() != RegistryEnvironment.UNITTEST
|
||||||
|
&& !GlobalRole.FTE.equals(user.getUserRoles().getGlobalRole())) {
|
||||||
|
try {
|
||||||
|
consoleApiParams.response().sendRedirect(ConsoleUiAction.PATH);
|
||||||
|
return;
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (consoleApiParams.request().getMethod().equals(GET.toString())) {
|
if (consoleApiParams.request().getMethod().equals(GET.toString())) {
|
||||||
getHandler(user);
|
getHandler(user);
|
||||||
} else {
|
} else {
|
||||||
@@ -75,4 +95,5 @@ public abstract class ConsoleApiAction implements Runnable {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,11 +24,8 @@ import google.registry.model.console.User;
|
|||||||
import google.registry.model.domain.Domain;
|
import google.registry.model.domain.Domain;
|
||||||
import google.registry.request.Action;
|
import google.registry.request.Action;
|
||||||
import google.registry.request.Parameter;
|
import google.registry.request.Parameter;
|
||||||
import google.registry.request.Response;
|
|
||||||
import google.registry.request.auth.Auth;
|
import google.registry.request.auth.Auth;
|
||||||
import google.registry.request.auth.AuthResult;
|
import google.registry.ui.server.registrar.ConsoleApiParams;
|
||||||
import google.registry.request.auth.UserAuthInfo;
|
|
||||||
import google.registry.ui.server.registrar.JsonGetAction;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
@@ -37,55 +34,41 @@ import javax.inject.Inject;
|
|||||||
service = Action.Service.DEFAULT,
|
service = Action.Service.DEFAULT,
|
||||||
path = ConsoleDomainGetAction.PATH,
|
path = ConsoleDomainGetAction.PATH,
|
||||||
auth = Auth.AUTH_PUBLIC_LOGGED_IN)
|
auth = Auth.AUTH_PUBLIC_LOGGED_IN)
|
||||||
public class ConsoleDomainGetAction implements JsonGetAction {
|
public class ConsoleDomainGetAction extends ConsoleApiAction {
|
||||||
|
|
||||||
public static final String PATH = "/console-api/domain";
|
public static final String PATH = "/console-api/domain";
|
||||||
|
|
||||||
private final AuthResult authResult;
|
|
||||||
private final Response response;
|
|
||||||
private final Gson gson;
|
private final Gson gson;
|
||||||
private final String paramDomain;
|
private final String paramDomain;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ConsoleDomainGetAction(
|
public ConsoleDomainGetAction(
|
||||||
AuthResult authResult,
|
ConsoleApiParams consoleApiParams,
|
||||||
Response response,
|
|
||||||
Gson gson,
|
Gson gson,
|
||||||
@Parameter("consoleDomain") String paramDomain) {
|
@Parameter("consoleDomain") String paramDomain) {
|
||||||
this.authResult = authResult;
|
super(consoleApiParams);
|
||||||
this.response = response;
|
|
||||||
this.gson = gson;
|
|
||||||
this.paramDomain = paramDomain;
|
this.paramDomain = paramDomain;
|
||||||
|
this.gson = gson;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
protected void getHandler(User user) {
|
||||||
if (!authResult.isAuthenticated() || authResult.userAuthInfo().isEmpty()) {
|
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
UserAuthInfo authInfo = authResult.userAuthInfo().get();
|
|
||||||
if (authInfo.consoleUser().isEmpty()) {
|
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
User user = authInfo.consoleUser().get();
|
|
||||||
Optional<Domain> possibleDomain =
|
Optional<Domain> possibleDomain =
|
||||||
tm().transact(
|
tm().transact(
|
||||||
() ->
|
() ->
|
||||||
EppResourceUtils.loadByForeignKeyCached(
|
EppResourceUtils.loadByForeignKeyCached(
|
||||||
Domain.class, paramDomain, tm().getTransactionTime()));
|
Domain.class, paramDomain, tm().getTransactionTime()));
|
||||||
if (possibleDomain.isEmpty()) {
|
if (possibleDomain.isEmpty()) {
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
|
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Domain domain = possibleDomain.get();
|
Domain domain = possibleDomain.get();
|
||||||
if (!user.getUserRoles()
|
if (!user.getUserRoles()
|
||||||
.hasPermission(domain.getCurrentSponsorRegistrarId(), ConsolePermission.DOWNLOAD_DOMAINS)) {
|
.hasPermission(domain.getCurrentSponsorRegistrarId(), ConsolePermission.DOWNLOAD_DOMAINS)) {
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
|
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_OK);
|
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
response.setPayload(gson.toJson(domain));
|
consoleApiParams.response().setPayload(gson.toJson(domain));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,10 +27,8 @@ import google.registry.model.console.User;
|
|||||||
import google.registry.model.domain.Domain;
|
import google.registry.model.domain.Domain;
|
||||||
import google.registry.request.Action;
|
import google.registry.request.Action;
|
||||||
import google.registry.request.Parameter;
|
import google.registry.request.Parameter;
|
||||||
import google.registry.request.Response;
|
|
||||||
import google.registry.request.auth.Auth;
|
import google.registry.request.auth.Auth;
|
||||||
import google.registry.request.auth.AuthResult;
|
import google.registry.ui.server.registrar.ConsoleApiParams;
|
||||||
import google.registry.ui.server.registrar.JsonGetAction;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@@ -43,7 +41,7 @@ import org.joda.time.DateTime;
|
|||||||
path = ConsoleDomainListAction.PATH,
|
path = ConsoleDomainListAction.PATH,
|
||||||
method = Action.Method.GET,
|
method = Action.Method.GET,
|
||||||
auth = Auth.AUTH_PUBLIC_LOGGED_IN)
|
auth = Auth.AUTH_PUBLIC_LOGGED_IN)
|
||||||
public class ConsoleDomainListAction implements JsonGetAction {
|
public class ConsoleDomainListAction extends ConsoleApiAction {
|
||||||
|
|
||||||
public static final String PATH = "/console-api/domain-list";
|
public static final String PATH = "/console-api/domain-list";
|
||||||
|
|
||||||
@@ -54,8 +52,6 @@ public class ConsoleDomainListAction implements JsonGetAction {
|
|||||||
private static final String SEARCH_TERM_QUERY = " AND LOWER(domainName) LIKE :searchTerm";
|
private static final String SEARCH_TERM_QUERY = " AND LOWER(domainName) LIKE :searchTerm";
|
||||||
private static final String ORDER_BY_STATEMENT = " ORDER BY creationTime DESC";
|
private static final String ORDER_BY_STATEMENT = " ORDER BY creationTime DESC";
|
||||||
|
|
||||||
private final AuthResult authResult;
|
|
||||||
private final Response response;
|
|
||||||
private final Gson gson;
|
private final Gson gson;
|
||||||
private final String registrarId;
|
private final String registrarId;
|
||||||
private final Optional<DateTime> checkpointTime;
|
private final Optional<DateTime> checkpointTime;
|
||||||
@@ -66,8 +62,7 @@ public class ConsoleDomainListAction implements JsonGetAction {
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ConsoleDomainListAction(
|
public ConsoleDomainListAction(
|
||||||
AuthResult authResult,
|
ConsoleApiParams consoleApiParams,
|
||||||
Response response,
|
|
||||||
Gson gson,
|
Gson gson,
|
||||||
@Parameter("registrarId") String registrarId,
|
@Parameter("registrarId") String registrarId,
|
||||||
@Parameter("checkpointTime") Optional<DateTime> checkpointTime,
|
@Parameter("checkpointTime") Optional<DateTime> checkpointTime,
|
||||||
@@ -75,8 +70,7 @@ public class ConsoleDomainListAction implements JsonGetAction {
|
|||||||
@Parameter("resultsPerPage") Optional<Integer> resultsPerPage,
|
@Parameter("resultsPerPage") Optional<Integer> resultsPerPage,
|
||||||
@Parameter("totalResults") Optional<Long> totalResults,
|
@Parameter("totalResults") Optional<Long> totalResults,
|
||||||
@Parameter("searchTerm") Optional<String> searchTerm) {
|
@Parameter("searchTerm") Optional<String> searchTerm) {
|
||||||
this.authResult = authResult;
|
super(consoleApiParams);
|
||||||
this.response = response;
|
|
||||||
this.gson = gson;
|
this.gson = gson;
|
||||||
this.registrarId = registrarId;
|
this.registrarId = registrarId;
|
||||||
this.checkpointTime = checkpointTime;
|
this.checkpointTime = checkpointTime;
|
||||||
@@ -87,19 +81,20 @@ public class ConsoleDomainListAction implements JsonGetAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
protected void getHandler(User user) {
|
||||||
User user = authResult.userAuthInfo().get().consoleUser().get();
|
|
||||||
if (!user.getUserRoles().hasPermission(registrarId, DOWNLOAD_DOMAINS)) {
|
if (!user.getUserRoles().hasPermission(registrarId, DOWNLOAD_DOMAINS)) {
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resultsPerPage < 1 || resultsPerPage > 500) {
|
if (resultsPerPage < 1 || resultsPerPage > 500) {
|
||||||
writeBadRequest("Results per page must be between 1 and 500 inclusive");
|
setFailedResponse(
|
||||||
|
"Results per page must be between 1 and 500 inclusive",
|
||||||
|
HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (pageNumber < 0) {
|
if (pageNumber < 0) {
|
||||||
writeBadRequest("Page number must be non-negative");
|
setFailedResponse(
|
||||||
|
"Page number must be non-negative", HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,8 +125,10 @@ public class ConsoleDomainListAction implements JsonGetAction {
|
|||||||
.setFirstResult(numResultsToSkip)
|
.setFirstResult(numResultsToSkip)
|
||||||
.setMaxResults(resultsPerPage)
|
.setMaxResults(resultsPerPage)
|
||||||
.getResultList();
|
.getResultList();
|
||||||
response.setPayload(gson.toJson(new DomainListResult(domains, checkpoint, actualTotalResults)));
|
consoleApiParams
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_OK);
|
.response()
|
||||||
|
.setPayload(gson.toJson(new DomainListResult(domains, checkpoint, actualTotalResults)));
|
||||||
|
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates the query to get the total number of matching domains, interpolating as necessary. */
|
/** Creates the query to get the total number of matching domains, interpolating as necessary. */
|
||||||
@@ -154,11 +151,6 @@ public class ConsoleDomainListAction implements JsonGetAction {
|
|||||||
return tm().query(DOMAIN_QUERY_TEMPLATE + ORDER_BY_STATEMENT, Domain.class);
|
return tm().query(DOMAIN_QUERY_TEMPLATE + ORDER_BY_STATEMENT, Domain.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeBadRequest(String message) {
|
|
||||||
response.setPayload(message);
|
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Container result class that allows for pagination. */
|
/** Container result class that allows for pagination. */
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final class DomainListResult {
|
static final class DomainListResult {
|
||||||
|
|||||||
@@ -31,12 +31,9 @@ import google.registry.model.registrar.RegistrarBase.State;
|
|||||||
import google.registry.model.registrar.RegistrarPoc;
|
import google.registry.model.registrar.RegistrarPoc;
|
||||||
import google.registry.request.Action;
|
import google.registry.request.Action;
|
||||||
import google.registry.request.Parameter;
|
import google.registry.request.Parameter;
|
||||||
import google.registry.request.Response;
|
|
||||||
import google.registry.request.auth.Auth;
|
import google.registry.request.auth.Auth;
|
||||||
import google.registry.request.auth.AuthResult;
|
import google.registry.ui.server.registrar.ConsoleApiParams;
|
||||||
import google.registry.ui.server.registrar.JsonGetAction;
|
|
||||||
import google.registry.util.StringGenerator;
|
import google.registry.util.StringGenerator;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
@@ -46,50 +43,33 @@ import javax.inject.Named;
|
|||||||
path = RegistrarsAction.PATH,
|
path = RegistrarsAction.PATH,
|
||||||
method = {GET, POST},
|
method = {GET, POST},
|
||||||
auth = Auth.AUTH_PUBLIC_LOGGED_IN)
|
auth = Auth.AUTH_PUBLIC_LOGGED_IN)
|
||||||
public class RegistrarsAction implements JsonGetAction {
|
public class RegistrarsAction extends ConsoleApiAction {
|
||||||
private static final int PASSWORD_LENGTH = 16;
|
private static final int PASSWORD_LENGTH = 16;
|
||||||
private static final int PASSCODE_LENGTH = 5;
|
private static final int PASSCODE_LENGTH = 5;
|
||||||
static final String PATH = "/console-api/registrars";
|
static final String PATH = "/console-api/registrars";
|
||||||
private final AuthResult authResult;
|
|
||||||
private final Response response;
|
|
||||||
private final Gson gson;
|
private final Gson gson;
|
||||||
private final HttpServletRequest req;
|
|
||||||
private Optional<Registrar> registrar;
|
private Optional<Registrar> registrar;
|
||||||
private StringGenerator passwordGenerator;
|
private StringGenerator passwordGenerator;
|
||||||
private StringGenerator passcodeGenerator;
|
private StringGenerator passcodeGenerator;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public RegistrarsAction(
|
public RegistrarsAction(
|
||||||
HttpServletRequest req,
|
ConsoleApiParams consoleApiParams,
|
||||||
AuthResult authResult,
|
|
||||||
Response response,
|
|
||||||
Gson gson,
|
Gson gson,
|
||||||
@Parameter("registrar") Optional<Registrar> registrar,
|
@Parameter("registrar") Optional<Registrar> registrar,
|
||||||
@Named("base58StringGenerator") StringGenerator passwordGenerator,
|
@Named("base58StringGenerator") StringGenerator passwordGenerator,
|
||||||
@Named("digitOnlyStringGenerator") StringGenerator passcodeGenerator) {
|
@Named("digitOnlyStringGenerator") StringGenerator passcodeGenerator) {
|
||||||
this.authResult = authResult;
|
super(consoleApiParams);
|
||||||
this.response = response;
|
|
||||||
this.gson = gson;
|
this.gson = gson;
|
||||||
this.registrar = registrar;
|
this.registrar = registrar;
|
||||||
this.req = req;
|
|
||||||
this.passcodeGenerator = passcodeGenerator;
|
this.passcodeGenerator = passcodeGenerator;
|
||||||
this.passwordGenerator = passwordGenerator;
|
this.passwordGenerator = passwordGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
protected void getHandler(User user) {
|
||||||
User user = authResult.userAuthInfo().get().consoleUser().get();
|
|
||||||
if (req.getMethod().equals(GET.toString())) {
|
|
||||||
getHandler(user);
|
|
||||||
} else {
|
|
||||||
postHandler(user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getHandler(User user) {
|
|
||||||
if (!user.getUserRoles().hasGlobalPermission(ConsolePermission.VIEW_REGISTRARS)) {
|
if (!user.getUserRoles().hasGlobalPermission(ConsolePermission.VIEW_REGISTRARS)) {
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ImmutableList<Registrar> registrars =
|
ImmutableList<Registrar> registrars =
|
||||||
@@ -97,19 +77,20 @@ public class RegistrarsAction implements JsonGetAction {
|
|||||||
.filter(r -> r.getType() == Registrar.Type.REAL)
|
.filter(r -> r.getType() == Registrar.Type.REAL)
|
||||||
.collect(ImmutableList.toImmutableList());
|
.collect(ImmutableList.toImmutableList());
|
||||||
|
|
||||||
response.setPayload(gson.toJson(registrars));
|
consoleApiParams.response().setPayload(gson.toJson(registrars));
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_OK);
|
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void postHandler(User user) {
|
@Override
|
||||||
|
protected void postHandler(User user) {
|
||||||
if (!user.getUserRoles().isAdmin()) {
|
if (!user.getUserRoles().isAdmin()) {
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (registrar.isEmpty()) {
|
if (registrar.isEmpty()) {
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
||||||
response.setPayload(gson.toJson("'registrar' parameter is not present"));
|
consoleApiParams.response().setPayload(gson.toJson("'registrar' parameter is not present"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,11 +152,9 @@ public class RegistrarsAction implements JsonGetAction {
|
|||||||
});
|
});
|
||||||
|
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
setFailedResponse(e.getMessage(), HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
||||||
response.setPayload(gson.toJson(e.getMessage()));
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_SERVER_ERROR);
|
setFailedResponse(e.getMessage(), HttpStatusCodes.STATUS_CODE_SERVER_ERROR);
|
||||||
response.setPayload(gson.toJson(e.getMessage()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,13 +31,11 @@ import google.registry.model.registrar.RegistrarPoc;
|
|||||||
import google.registry.persistence.transaction.QueryComposer.Comparator;
|
import google.registry.persistence.transaction.QueryComposer.Comparator;
|
||||||
import google.registry.request.Action;
|
import google.registry.request.Action;
|
||||||
import google.registry.request.Parameter;
|
import google.registry.request.Parameter;
|
||||||
import google.registry.request.Response;
|
|
||||||
import google.registry.request.auth.Auth;
|
import google.registry.request.auth.Auth;
|
||||||
import google.registry.request.auth.AuthResult;
|
|
||||||
import google.registry.ui.forms.FormException;
|
import google.registry.ui.forms.FormException;
|
||||||
import google.registry.ui.server.registrar.JsonGetAction;
|
import google.registry.ui.server.console.ConsoleApiAction;
|
||||||
|
import google.registry.ui.server.registrar.ConsoleApiParams;
|
||||||
import google.registry.ui.server.registrar.RegistrarSettingsAction;
|
import google.registry.ui.server.registrar.RegistrarSettingsAction;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@@ -47,45 +45,29 @@ import javax.inject.Inject;
|
|||||||
path = ContactAction.PATH,
|
path = ContactAction.PATH,
|
||||||
method = {GET, POST},
|
method = {GET, POST},
|
||||||
auth = Auth.AUTH_PUBLIC_LOGGED_IN)
|
auth = Auth.AUTH_PUBLIC_LOGGED_IN)
|
||||||
public class ContactAction implements JsonGetAction {
|
public class ContactAction extends ConsoleApiAction {
|
||||||
static final String PATH = "/console-api/settings/contacts";
|
static final String PATH = "/console-api/settings/contacts";
|
||||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||||
private final HttpServletRequest req;
|
|
||||||
private final AuthResult authResult;
|
|
||||||
private final Response response;
|
|
||||||
private final Gson gson;
|
private final Gson gson;
|
||||||
private final Optional<ImmutableSet<RegistrarPoc>> contacts;
|
private final Optional<ImmutableSet<RegistrarPoc>> contacts;
|
||||||
private final String registrarId;
|
private final String registrarId;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ContactAction(
|
public ContactAction(
|
||||||
HttpServletRequest req,
|
ConsoleApiParams consoleApiParams,
|
||||||
AuthResult authResult,
|
|
||||||
Response response,
|
|
||||||
Gson gson,
|
Gson gson,
|
||||||
@Parameter("registrarId") String registrarId,
|
@Parameter("registrarId") String registrarId,
|
||||||
@Parameter("contacts") Optional<ImmutableSet<RegistrarPoc>> contacts) {
|
@Parameter("contacts") Optional<ImmutableSet<RegistrarPoc>> contacts) {
|
||||||
this.authResult = authResult;
|
super(consoleApiParams);
|
||||||
this.response = response;
|
|
||||||
this.gson = gson;
|
this.gson = gson;
|
||||||
this.registrarId = registrarId;
|
this.registrarId = registrarId;
|
||||||
this.contacts = contacts;
|
this.contacts = contacts;
|
||||||
this.req = req;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
protected void getHandler(User user) {
|
||||||
User user = authResult.userAuthInfo().get().consoleUser().get();
|
|
||||||
if (req.getMethod().equals(GET.toString())) {
|
|
||||||
getHandler(user);
|
|
||||||
} else {
|
|
||||||
postHandler(user);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getHandler(User user) {
|
|
||||||
if (!user.getUserRoles().hasPermission(registrarId, ConsolePermission.VIEW_REGISTRAR_DETAILS)) {
|
if (!user.getUserRoles().hasPermission(registrarId, ConsolePermission.VIEW_REGISTRAR_DETAILS)) {
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,19 +81,20 @@ public class ContactAction implements JsonGetAction {
|
|||||||
.filter(r -> !r.getTypes().isEmpty())
|
.filter(r -> !r.getTypes().isEmpty())
|
||||||
.collect(toImmutableList()));
|
.collect(toImmutableList()));
|
||||||
|
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_OK);
|
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
response.setPayload(gson.toJson(am));
|
consoleApiParams.response().setPayload(gson.toJson(am));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void postHandler(User user) {
|
@Override
|
||||||
|
protected void postHandler(User user) {
|
||||||
if (!user.getUserRoles().hasPermission(registrarId, ConsolePermission.EDIT_REGISTRAR_DETAILS)) {
|
if (!user.getUserRoles().hasPermission(registrarId, ConsolePermission.EDIT_REGISTRAR_DETAILS)) {
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contacts.isEmpty()) {
|
if (contacts.isEmpty()) {
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
||||||
response.setPayload(gson.toJson("Contacts parameter is not present"));
|
consoleApiParams.response().setPayload(gson.toJson("Contacts parameter is not present"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,12 +120,12 @@ public class ContactAction implements JsonGetAction {
|
|||||||
} catch (FormException e) {
|
} catch (FormException e) {
|
||||||
logger.atWarning().withCause(e).log(
|
logger.atWarning().withCause(e).log(
|
||||||
"Error processing contacts post request for registrar: %s", registrarId);
|
"Error processing contacts post request for registrar: %s", registrarId);
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
||||||
response.setPayload(e.getMessage());
|
consoleApiParams.response().setPayload(e.getMessage());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegistrarPoc.updateContacts(registrar, updatedContacts);
|
RegistrarPoc.updateContacts(registrar, updatedContacts);
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_OK);
|
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import static google.registry.persistence.transaction.TransactionManagerFactory.
|
|||||||
import static google.registry.request.Action.Method.POST;
|
import static google.registry.request.Action.Method.POST;
|
||||||
|
|
||||||
import com.google.api.client.http.HttpStatusCodes;
|
import com.google.api.client.http.HttpStatusCodes;
|
||||||
import com.google.gson.Gson;
|
|
||||||
import google.registry.flows.certs.CertificateChecker;
|
import google.registry.flows.certs.CertificateChecker;
|
||||||
import google.registry.flows.certs.CertificateChecker.InsecureCertificateException;
|
import google.registry.flows.certs.CertificateChecker.InsecureCertificateException;
|
||||||
import google.registry.model.console.ConsolePermission;
|
import google.registry.model.console.ConsolePermission;
|
||||||
@@ -26,12 +25,11 @@ import google.registry.model.console.User;
|
|||||||
import google.registry.model.registrar.Registrar;
|
import google.registry.model.registrar.Registrar;
|
||||||
import google.registry.request.Action;
|
import google.registry.request.Action;
|
||||||
import google.registry.request.Parameter;
|
import google.registry.request.Parameter;
|
||||||
import google.registry.request.Response;
|
|
||||||
import google.registry.request.auth.Auth;
|
import google.registry.request.auth.Auth;
|
||||||
import google.registry.request.auth.AuthResult;
|
|
||||||
import google.registry.request.auth.AuthenticatedRegistrarAccessor;
|
import google.registry.request.auth.AuthenticatedRegistrarAccessor;
|
||||||
import google.registry.request.auth.AuthenticatedRegistrarAccessor.RegistrarAccessDeniedException;
|
import google.registry.request.auth.AuthenticatedRegistrarAccessor.RegistrarAccessDeniedException;
|
||||||
import google.registry.ui.server.registrar.JsonGetAction;
|
import google.registry.ui.server.console.ConsoleApiAction;
|
||||||
|
import google.registry.ui.server.registrar.ConsoleApiParams;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
@@ -40,12 +38,9 @@ import javax.inject.Inject;
|
|||||||
path = SecurityAction.PATH,
|
path = SecurityAction.PATH,
|
||||||
method = {POST},
|
method = {POST},
|
||||||
auth = Auth.AUTH_PUBLIC_LOGGED_IN)
|
auth = Auth.AUTH_PUBLIC_LOGGED_IN)
|
||||||
public class SecurityAction implements JsonGetAction {
|
public class SecurityAction extends ConsoleApiAction {
|
||||||
|
|
||||||
static final String PATH = "/console-api/settings/security";
|
static final String PATH = "/console-api/settings/security";
|
||||||
private final AuthResult authResult;
|
|
||||||
private final Response response;
|
|
||||||
private final Gson gson;
|
|
||||||
private final String registrarId;
|
private final String registrarId;
|
||||||
private final AuthenticatedRegistrarAccessor registrarAccessor;
|
private final AuthenticatedRegistrarAccessor registrarAccessor;
|
||||||
private final Optional<Registrar> registrar;
|
private final Optional<Registrar> registrar;
|
||||||
@@ -53,16 +48,12 @@ public class SecurityAction implements JsonGetAction {
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public SecurityAction(
|
public SecurityAction(
|
||||||
AuthResult authResult,
|
ConsoleApiParams consoleApiParams,
|
||||||
Response response,
|
|
||||||
Gson gson,
|
|
||||||
CertificateChecker certificateChecker,
|
CertificateChecker certificateChecker,
|
||||||
AuthenticatedRegistrarAccessor registrarAccessor,
|
AuthenticatedRegistrarAccessor registrarAccessor,
|
||||||
@Parameter("registrarId") String registrarId,
|
@Parameter("registrarId") String registrarId,
|
||||||
@Parameter("registrar") Optional<Registrar> registrar) {
|
@Parameter("registrar") Optional<Registrar> registrar) {
|
||||||
this.authResult = authResult;
|
super(consoleApiParams);
|
||||||
this.response = response;
|
|
||||||
this.gson = gson;
|
|
||||||
this.registrarId = registrarId;
|
this.registrarId = registrarId;
|
||||||
this.registrarAccessor = registrarAccessor;
|
this.registrarAccessor = registrarAccessor;
|
||||||
this.registrar = registrar;
|
this.registrar = registrar;
|
||||||
@@ -70,16 +61,15 @@ public class SecurityAction implements JsonGetAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
protected void postHandler(User user) {
|
||||||
User user = authResult.userAuthInfo().get().consoleUser().get();
|
|
||||||
if (!user.getUserRoles().hasPermission(registrarId, ConsolePermission.EDIT_REGISTRAR_DETAILS)) {
|
if (!user.getUserRoles().hasPermission(registrarId, ConsolePermission.EDIT_REGISTRAR_DETAILS)) {
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (registrar.isEmpty()) {
|
if (registrar.isEmpty()) {
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
setFailedResponse(
|
||||||
response.setPayload(gson.toJson("'registrar' parameter is not present"));
|
"'registrar' parameter is not present", HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,8 +77,7 @@ public class SecurityAction implements JsonGetAction {
|
|||||||
try {
|
try {
|
||||||
savedRegistrar = registrarAccessor.getRegistrar(registrarId);
|
savedRegistrar = registrarAccessor.getRegistrar(registrarId);
|
||||||
} catch (RegistrarAccessDeniedException e) {
|
} catch (RegistrarAccessDeniedException e) {
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
setFailedResponse(e.getMessage(), HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
||||||
response.setPayload(e.getMessage());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,12 +111,12 @@ public class SecurityAction implements JsonGetAction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (InsecureCertificateException e) {
|
} catch (InsecureCertificateException e) {
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
setFailedResponse(
|
||||||
response.setPayload("Invalid certificate in parameter");
|
"Invalid certificate in parameter", HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tm().put(updatedRegistrar.build());
|
tm().put(updatedRegistrar.build());
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_OK);
|
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,18 +18,16 @@ import static google.registry.persistence.transaction.TransactionManagerFactory.
|
|||||||
import static google.registry.request.Action.Method.POST;
|
import static google.registry.request.Action.Method.POST;
|
||||||
|
|
||||||
import com.google.api.client.http.HttpStatusCodes;
|
import com.google.api.client.http.HttpStatusCodes;
|
||||||
import com.google.gson.Gson;
|
|
||||||
import google.registry.model.console.ConsolePermission;
|
import google.registry.model.console.ConsolePermission;
|
||||||
import google.registry.model.console.User;
|
import google.registry.model.console.User;
|
||||||
import google.registry.model.registrar.Registrar;
|
import google.registry.model.registrar.Registrar;
|
||||||
import google.registry.request.Action;
|
import google.registry.request.Action;
|
||||||
import google.registry.request.Parameter;
|
import google.registry.request.Parameter;
|
||||||
import google.registry.request.Response;
|
|
||||||
import google.registry.request.auth.Auth;
|
import google.registry.request.auth.Auth;
|
||||||
import google.registry.request.auth.AuthResult;
|
|
||||||
import google.registry.request.auth.AuthenticatedRegistrarAccessor;
|
import google.registry.request.auth.AuthenticatedRegistrarAccessor;
|
||||||
import google.registry.request.auth.AuthenticatedRegistrarAccessor.RegistrarAccessDeniedException;
|
import google.registry.request.auth.AuthenticatedRegistrarAccessor.RegistrarAccessDeniedException;
|
||||||
import google.registry.ui.server.registrar.JsonGetAction;
|
import google.registry.ui.server.console.ConsoleApiAction;
|
||||||
|
import google.registry.ui.server.registrar.ConsoleApiParams;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
@@ -44,42 +42,34 @@ import javax.inject.Inject;
|
|||||||
path = WhoisRegistrarFieldsAction.PATH,
|
path = WhoisRegistrarFieldsAction.PATH,
|
||||||
method = {POST},
|
method = {POST},
|
||||||
auth = Auth.AUTH_PUBLIC_LOGGED_IN)
|
auth = Auth.AUTH_PUBLIC_LOGGED_IN)
|
||||||
public class WhoisRegistrarFieldsAction implements JsonGetAction {
|
public class WhoisRegistrarFieldsAction extends ConsoleApiAction {
|
||||||
|
|
||||||
static final String PATH = "/console-api/settings/whois-fields";
|
static final String PATH = "/console-api/settings/whois-fields";
|
||||||
private final AuthResult authResult;
|
|
||||||
private final Response response;
|
|
||||||
private final Gson gson;
|
|
||||||
private AuthenticatedRegistrarAccessor registrarAccessor;
|
private AuthenticatedRegistrarAccessor registrarAccessor;
|
||||||
private Optional<Registrar> registrar;
|
private Optional<Registrar> registrar;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public WhoisRegistrarFieldsAction(
|
public WhoisRegistrarFieldsAction(
|
||||||
AuthResult authResult,
|
ConsoleApiParams consoleApiParams,
|
||||||
Response response,
|
|
||||||
Gson gson,
|
|
||||||
AuthenticatedRegistrarAccessor registrarAccessor,
|
AuthenticatedRegistrarAccessor registrarAccessor,
|
||||||
@Parameter("registrar") Optional<Registrar> registrar) {
|
@Parameter("registrar") Optional<Registrar> registrar) {
|
||||||
this.authResult = authResult;
|
super(consoleApiParams);
|
||||||
this.response = response;
|
|
||||||
this.gson = gson;
|
|
||||||
this.registrarAccessor = registrarAccessor;
|
this.registrarAccessor = registrarAccessor;
|
||||||
this.registrar = registrar;
|
this.registrar = registrar;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
protected void postHandler(User user) {
|
||||||
if (registrar.isEmpty()) {
|
if (registrar.isEmpty()) {
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
setFailedResponse(
|
||||||
response.setPayload(gson.toJson("'registrar' parameter is not present"));
|
"'registrar' parameter is not present", HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
User user = authResult.userAuthInfo().get().consoleUser().get();
|
|
||||||
if (!user.getUserRoles()
|
if (!user.getUserRoles()
|
||||||
.hasPermission(
|
.hasPermission(
|
||||||
registrar.get().getRegistrarId(), ConsolePermission.EDIT_REGISTRAR_DETAILS)) {
|
registrar.get().getRegistrarId(), ConsolePermission.EDIT_REGISTRAR_DETAILS)) {
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,8 +82,8 @@ public class WhoisRegistrarFieldsAction implements JsonGetAction {
|
|||||||
// reload to make sure the object has all the correct fields
|
// reload to make sure the object has all the correct fields
|
||||||
savedRegistrar = registrarAccessor.getRegistrar(providedRegistrar.getRegistrarId());
|
savedRegistrar = registrarAccessor.getRegistrar(providedRegistrar.getRegistrarId());
|
||||||
} catch (RegistrarAccessDeniedException e) {
|
} catch (RegistrarAccessDeniedException e) {
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
||||||
response.setPayload(e.getMessage());
|
consoleApiParams.response().setPayload(e.getMessage());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,6 +92,6 @@ public class WhoisRegistrarFieldsAction implements JsonGetAction {
|
|||||||
newRegistrar.setUrl(providedRegistrar.getUrl());
|
newRegistrar.setUrl(providedRegistrar.getUrl());
|
||||||
newRegistrar.setLocalizedAddress(providedRegistrar.getLocalizedAddress());
|
newRegistrar.setLocalizedAddress(providedRegistrar.getLocalizedAddress());
|
||||||
tm().put(newRegistrar.build());
|
tm().put(newRegistrar.build());
|
||||||
response.setStatus(HttpStatusCodes.STATUS_CODE_OK);
|
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,12 @@ public final class FakeResponse implements Response {
|
|||||||
return writer;
|
return writer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendRedirect(String url) throws IOException {
|
||||||
|
status = 302;
|
||||||
|
this.payload = String.format("Redirected to %s", url);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setStatus(int status) {
|
public void setStatus(int status) {
|
||||||
checkArgument(status >= 100);
|
checkArgument(status >= 100);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ package google.registry.ui.server.console;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static google.registry.testing.DatabaseHelper.createTld;
|
import static google.registry.testing.DatabaseHelper.createTld;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.google.api.client.http.HttpStatusCodes;
|
import com.google.api.client.http.HttpStatusCodes;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
@@ -25,11 +26,15 @@ import google.registry.model.console.RegistrarRole;
|
|||||||
import google.registry.model.console.User;
|
import google.registry.model.console.User;
|
||||||
import google.registry.model.console.UserRoles;
|
import google.registry.model.console.UserRoles;
|
||||||
import google.registry.persistence.transaction.JpaTestExtensions;
|
import google.registry.persistence.transaction.JpaTestExtensions;
|
||||||
|
import google.registry.request.Action;
|
||||||
import google.registry.request.RequestModule;
|
import google.registry.request.RequestModule;
|
||||||
import google.registry.request.auth.AuthResult;
|
import google.registry.request.auth.AuthResult;
|
||||||
import google.registry.request.auth.UserAuthInfo;
|
import google.registry.request.auth.UserAuthInfo;
|
||||||
import google.registry.testing.DatabaseHelper;
|
import google.registry.testing.DatabaseHelper;
|
||||||
|
import google.registry.testing.FakeConsoleApiParams;
|
||||||
import google.registry.testing.FakeResponse;
|
import google.registry.testing.FakeResponse;
|
||||||
|
import google.registry.ui.server.registrar.ConsoleApiParams;
|
||||||
|
import java.util.Optional;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
@@ -38,7 +43,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
|
|||||||
public class ConsoleDomainGetActionTest {
|
public class ConsoleDomainGetActionTest {
|
||||||
|
|
||||||
private static final Gson GSON = RequestModule.provideGson();
|
private static final Gson GSON = RequestModule.provideGson();
|
||||||
private static final FakeResponse RESPONSE = new FakeResponse();
|
private ConsoleApiParams consoleApiParams;
|
||||||
|
|
||||||
@RegisterExtension
|
@RegisterExtension
|
||||||
final JpaTestExtensions.JpaIntegrationTestExtension jpa =
|
final JpaTestExtensions.JpaIntegrationTestExtension jpa =
|
||||||
@@ -63,8 +68,9 @@ public class ConsoleDomainGetActionTest {
|
|||||||
.build()))),
|
.build()))),
|
||||||
"exists.tld");
|
"exists.tld");
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(RESPONSE.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
assertThat(RESPONSE.getPayload())
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
|
assertThat(((FakeResponse) consoleApiParams.response()).getPayload())
|
||||||
.isEqualTo(
|
.isEqualTo(
|
||||||
"{\"domainName\":\"exists.tld\",\"adminContact\":{\"key\":\"3-ROID\",\"kind\":"
|
"{\"domainName\":\"exists.tld\",\"adminContact\":{\"key\":\"3-ROID\",\"kind\":"
|
||||||
+ "\"google.registry.model.contact.Contact\"},\"techContact\":{\"key\":\"3-ROID\","
|
+ "\"google.registry.model.contact.Contact\"},\"techContact\":{\"key\":\"3-ROID\","
|
||||||
@@ -82,7 +88,8 @@ public class ConsoleDomainGetActionTest {
|
|||||||
void testFailure_emptyAuth() {
|
void testFailure_emptyAuth() {
|
||||||
ConsoleDomainGetAction action = createAction(AuthResult.NOT_AUTHENTICATED, "exists.tld");
|
ConsoleDomainGetAction action = createAction(AuthResult.NOT_AUTHENTICATED, "exists.tld");
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(RESPONSE.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -90,7 +97,8 @@ public class ConsoleDomainGetActionTest {
|
|||||||
ConsoleDomainGetAction action =
|
ConsoleDomainGetAction action =
|
||||||
createAction(AuthResult.createApp("service@registry.example"), "exists.tld");
|
createAction(AuthResult.createApp("service@registry.example"), "exists.tld");
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(RESPONSE.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -101,7 +109,8 @@ public class ConsoleDomainGetActionTest {
|
|||||||
UserAuthInfo.create(mock(com.google.appengine.api.users.User.class), false)),
|
UserAuthInfo.create(mock(com.google.appengine.api.users.User.class), false)),
|
||||||
"exists.tld");
|
"exists.tld");
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(RESPONSE.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -111,7 +120,8 @@ public class ConsoleDomainGetActionTest {
|
|||||||
AuthResult.createUser(UserAuthInfo.create(createUser(new UserRoles.Builder().build()))),
|
AuthResult.createUser(UserAuthInfo.create(createUser(new UserRoles.Builder().build()))),
|
||||||
"exists.tld");
|
"exists.tld");
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(RESPONSE.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -122,7 +132,8 @@ public class ConsoleDomainGetActionTest {
|
|||||||
UserAuthInfo.create(createUser(new UserRoles.Builder().setIsAdmin(true).build()))),
|
UserAuthInfo.create(createUser(new UserRoles.Builder().setIsAdmin(true).build()))),
|
||||||
"nonexistent.tld");
|
"nonexistent.tld");
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(RESPONSE.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
private User createUser(UserRoles userRoles) {
|
private User createUser(UserRoles userRoles) {
|
||||||
@@ -133,6 +144,8 @@ public class ConsoleDomainGetActionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ConsoleDomainGetAction createAction(AuthResult authResult, String domain) {
|
private ConsoleDomainGetAction createAction(AuthResult authResult, String domain) {
|
||||||
return new ConsoleDomainGetAction(authResult, RESPONSE, GSON, domain);
|
consoleApiParams = FakeConsoleApiParams.get(Optional.of(authResult));
|
||||||
|
when(consoleApiParams.request().getMethod()).thenReturn(Action.Method.GET.toString());
|
||||||
|
return new ConsoleDomainGetAction(consoleApiParams, GSON, domain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import static google.registry.testing.DatabaseHelper.createAdminUser;
|
|||||||
import static google.registry.testing.DatabaseHelper.createTld;
|
import static google.registry.testing.DatabaseHelper.createTld;
|
||||||
import static google.registry.testing.DatabaseHelper.persistActiveDomain;
|
import static google.registry.testing.DatabaseHelper.persistActiveDomain;
|
||||||
import static google.registry.testing.DatabaseHelper.persistDomainAsDeleted;
|
import static google.registry.testing.DatabaseHelper.persistDomainAsDeleted;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.google.api.client.http.HttpStatusCodes;
|
import com.google.api.client.http.HttpStatusCodes;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
@@ -27,13 +28,16 @@ import com.google.gson.Gson;
|
|||||||
import google.registry.model.EppResourceUtils;
|
import google.registry.model.EppResourceUtils;
|
||||||
import google.registry.model.domain.Domain;
|
import google.registry.model.domain.Domain;
|
||||||
import google.registry.persistence.transaction.JpaTestExtensions;
|
import google.registry.persistence.transaction.JpaTestExtensions;
|
||||||
|
import google.registry.request.Action;
|
||||||
import google.registry.request.auth.AuthResult;
|
import google.registry.request.auth.AuthResult;
|
||||||
import google.registry.request.auth.UserAuthInfo;
|
import google.registry.request.auth.UserAuthInfo;
|
||||||
import google.registry.testing.DatabaseHelper;
|
import google.registry.testing.DatabaseHelper;
|
||||||
import google.registry.testing.FakeClock;
|
import google.registry.testing.FakeClock;
|
||||||
|
import google.registry.testing.FakeConsoleApiParams;
|
||||||
import google.registry.testing.FakeResponse;
|
import google.registry.testing.FakeResponse;
|
||||||
import google.registry.tools.GsonUtils;
|
import google.registry.tools.GsonUtils;
|
||||||
import google.registry.ui.server.console.ConsoleDomainListAction.DomainListResult;
|
import google.registry.ui.server.console.ConsoleDomainListAction.DomainListResult;
|
||||||
|
import google.registry.ui.server.registrar.ConsoleApiParams;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
@@ -48,7 +52,7 @@ public class ConsoleDomainListActionTest {
|
|||||||
|
|
||||||
private final FakeClock clock = new FakeClock(DateTime.parse("2023-10-20T00:00:00.000Z"));
|
private final FakeClock clock = new FakeClock(DateTime.parse("2023-10-20T00:00:00.000Z"));
|
||||||
|
|
||||||
private FakeResponse response;
|
private ConsoleApiParams consoleApiParams;
|
||||||
|
|
||||||
@RegisterExtension
|
@RegisterExtension
|
||||||
final JpaTestExtensions.JpaIntegrationTestExtension jpa =
|
final JpaTestExtensions.JpaIntegrationTestExtension jpa =
|
||||||
@@ -68,7 +72,9 @@ public class ConsoleDomainListActionTest {
|
|||||||
void testSuccess_allDomains() {
|
void testSuccess_allDomains() {
|
||||||
ConsoleDomainListAction action = createAction("TheRegistrar");
|
ConsoleDomainListAction action = createAction("TheRegistrar");
|
||||||
action.run();
|
action.run();
|
||||||
DomainListResult result = GSON.fromJson(response.getPayload(), DomainListResult.class);
|
DomainListResult result =
|
||||||
|
GSON.fromJson(
|
||||||
|
((FakeResponse) consoleApiParams.response()).getPayload(), DomainListResult.class);
|
||||||
assertThat(result.domains).hasSize(10);
|
assertThat(result.domains).hasSize(10);
|
||||||
assertThat(result.totalResults).isEqualTo(10);
|
assertThat(result.totalResults).isEqualTo(10);
|
||||||
assertThat(result.checkpointTime).isEqualTo(clock.nowUtc());
|
assertThat(result.checkpointTime).isEqualTo(clock.nowUtc());
|
||||||
@@ -80,7 +86,9 @@ public class ConsoleDomainListActionTest {
|
|||||||
void testSuccess_noDomains() {
|
void testSuccess_noDomains() {
|
||||||
ConsoleDomainListAction action = createAction("NewRegistrar");
|
ConsoleDomainListAction action = createAction("NewRegistrar");
|
||||||
action.run();
|
action.run();
|
||||||
DomainListResult result = GSON.fromJson(response.getPayload(), DomainListResult.class);
|
DomainListResult result =
|
||||||
|
GSON.fromJson(
|
||||||
|
((FakeResponse) consoleApiParams.response()).getPayload(), DomainListResult.class);
|
||||||
assertThat(result.domains).hasSize(0);
|
assertThat(result.domains).hasSize(0);
|
||||||
assertThat(result.totalResults).isEqualTo(0);
|
assertThat(result.totalResults).isEqualTo(0);
|
||||||
assertThat(result.checkpointTime).isEqualTo(clock.nowUtc());
|
assertThat(result.checkpointTime).isEqualTo(clock.nowUtc());
|
||||||
@@ -91,7 +99,9 @@ public class ConsoleDomainListActionTest {
|
|||||||
// Two pages of results should go in reverse chronological order
|
// Two pages of results should go in reverse chronological order
|
||||||
ConsoleDomainListAction action = createAction("TheRegistrar", null, 0, 5, null, null);
|
ConsoleDomainListAction action = createAction("TheRegistrar", null, 0, 5, null, null);
|
||||||
action.run();
|
action.run();
|
||||||
DomainListResult result = GSON.fromJson(response.getPayload(), DomainListResult.class);
|
DomainListResult result =
|
||||||
|
GSON.fromJson(
|
||||||
|
((FakeResponse) consoleApiParams.response()).getPayload(), DomainListResult.class);
|
||||||
assertThat(result.domains.stream().map(Domain::getDomainName).collect(toImmutableList()))
|
assertThat(result.domains.stream().map(Domain::getDomainName).collect(toImmutableList()))
|
||||||
.containsExactly("9exists.tld", "8exists.tld", "7exists.tld", "6exists.tld", "5exists.tld");
|
.containsExactly("9exists.tld", "8exists.tld", "7exists.tld", "6exists.tld", "5exists.tld");
|
||||||
assertThat(result.totalResults).isEqualTo(10);
|
assertThat(result.totalResults).isEqualTo(10);
|
||||||
@@ -99,7 +109,9 @@ public class ConsoleDomainListActionTest {
|
|||||||
// Now do the second page
|
// Now do the second page
|
||||||
action = createAction("TheRegistrar", result.checkpointTime, 1, 5, 10L, null);
|
action = createAction("TheRegistrar", result.checkpointTime, 1, 5, 10L, null);
|
||||||
action.run();
|
action.run();
|
||||||
result = GSON.fromJson(response.getPayload(), DomainListResult.class);
|
result =
|
||||||
|
GSON.fromJson(
|
||||||
|
((FakeResponse) consoleApiParams.response()).getPayload(), DomainListResult.class);
|
||||||
assertThat(result.domains.stream().map(Domain::getDomainName).collect(toImmutableList()))
|
assertThat(result.domains.stream().map(Domain::getDomainName).collect(toImmutableList()))
|
||||||
.containsExactly("4exists.tld", "3exists.tld", "2exists.tld", "1exists.tld", "0exists.tld");
|
.containsExactly("4exists.tld", "3exists.tld", "2exists.tld", "1exists.tld", "0exists.tld");
|
||||||
}
|
}
|
||||||
@@ -108,7 +120,9 @@ public class ConsoleDomainListActionTest {
|
|||||||
void testSuccess_partialPage() {
|
void testSuccess_partialPage() {
|
||||||
ConsoleDomainListAction action = createAction("TheRegistrar", null, 1, 8, null, null);
|
ConsoleDomainListAction action = createAction("TheRegistrar", null, 1, 8, null, null);
|
||||||
action.run();
|
action.run();
|
||||||
DomainListResult result = GSON.fromJson(response.getPayload(), DomainListResult.class);
|
DomainListResult result =
|
||||||
|
GSON.fromJson(
|
||||||
|
((FakeResponse) consoleApiParams.response()).getPayload(), DomainListResult.class);
|
||||||
assertThat(result.domains.stream().map(Domain::getDomainName).collect(toImmutableList()))
|
assertThat(result.domains.stream().map(Domain::getDomainName).collect(toImmutableList()))
|
||||||
.containsExactly("1exists.tld", "0exists.tld");
|
.containsExactly("1exists.tld", "0exists.tld");
|
||||||
}
|
}
|
||||||
@@ -118,7 +132,9 @@ public class ConsoleDomainListActionTest {
|
|||||||
ConsoleDomainListAction action = createAction("TheRegistrar", null, 0, 10, null, null);
|
ConsoleDomainListAction action = createAction("TheRegistrar", null, 0, 10, null, null);
|
||||||
action.run();
|
action.run();
|
||||||
|
|
||||||
DomainListResult result = GSON.fromJson(response.getPayload(), DomainListResult.class);
|
DomainListResult result =
|
||||||
|
GSON.fromJson(
|
||||||
|
((FakeResponse) consoleApiParams.response()).getPayload(), DomainListResult.class);
|
||||||
assertThat(result.domains).hasSize(10);
|
assertThat(result.domains).hasSize(10);
|
||||||
assertThat(result.totalResults).isEqualTo(10);
|
assertThat(result.totalResults).isEqualTo(10);
|
||||||
|
|
||||||
@@ -128,7 +144,9 @@ public class ConsoleDomainListActionTest {
|
|||||||
// Even though we persisted a new domain, the old checkpoint should return no more results
|
// Even though we persisted a new domain, the old checkpoint should return no more results
|
||||||
action = createAction("TheRegistrar", result.checkpointTime, 1, 10, null, null);
|
action = createAction("TheRegistrar", result.checkpointTime, 1, 10, null, null);
|
||||||
action.run();
|
action.run();
|
||||||
result = GSON.fromJson(response.getPayload(), DomainListResult.class);
|
result =
|
||||||
|
GSON.fromJson(
|
||||||
|
((FakeResponse) consoleApiParams.response()).getPayload(), DomainListResult.class);
|
||||||
assertThat(result.domains).isEmpty();
|
assertThat(result.domains).isEmpty();
|
||||||
assertThat(result.totalResults).isEqualTo(10);
|
assertThat(result.totalResults).isEqualTo(10);
|
||||||
}
|
}
|
||||||
@@ -137,7 +155,9 @@ public class ConsoleDomainListActionTest {
|
|||||||
void testSuccess_checkpointTime_deletion() {
|
void testSuccess_checkpointTime_deletion() {
|
||||||
ConsoleDomainListAction action = createAction("TheRegistrar", null, 0, 5, null, null);
|
ConsoleDomainListAction action = createAction("TheRegistrar", null, 0, 5, null, null);
|
||||||
action.run();
|
action.run();
|
||||||
DomainListResult result = GSON.fromJson(response.getPayload(), DomainListResult.class);
|
DomainListResult result =
|
||||||
|
GSON.fromJson(
|
||||||
|
((FakeResponse) consoleApiParams.response()).getPayload(), DomainListResult.class);
|
||||||
|
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
Domain toDelete =
|
Domain toDelete =
|
||||||
@@ -147,7 +167,9 @@ public class ConsoleDomainListActionTest {
|
|||||||
// Second page should include the domain that is now deleted due to the checkpoint time
|
// Second page should include the domain that is now deleted due to the checkpoint time
|
||||||
action = createAction("TheRegistrar", result.checkpointTime, 1, 5, null, null);
|
action = createAction("TheRegistrar", result.checkpointTime, 1, 5, null, null);
|
||||||
action.run();
|
action.run();
|
||||||
result = GSON.fromJson(response.getPayload(), DomainListResult.class);
|
result =
|
||||||
|
GSON.fromJson(
|
||||||
|
((FakeResponse) consoleApiParams.response()).getPayload(), DomainListResult.class);
|
||||||
assertThat(result.domains.stream().map(Domain::getDomainName).collect(toImmutableList()))
|
assertThat(result.domains.stream().map(Domain::getDomainName).collect(toImmutableList()))
|
||||||
.containsExactly("4exists.tld", "3exists.tld", "2exists.tld", "1exists.tld", "0exists.tld");
|
.containsExactly("4exists.tld", "3exists.tld", "2exists.tld", "1exists.tld", "0exists.tld");
|
||||||
}
|
}
|
||||||
@@ -156,7 +178,9 @@ public class ConsoleDomainListActionTest {
|
|||||||
void testSuccess_searchTerm_oneMatch() {
|
void testSuccess_searchTerm_oneMatch() {
|
||||||
ConsoleDomainListAction action = createAction("TheRegistrar", null, 0, 5, null, "0");
|
ConsoleDomainListAction action = createAction("TheRegistrar", null, 0, 5, null, "0");
|
||||||
action.run();
|
action.run();
|
||||||
DomainListResult result = GSON.fromJson(response.getPayload(), DomainListResult.class);
|
DomainListResult result =
|
||||||
|
GSON.fromJson(
|
||||||
|
((FakeResponse) consoleApiParams.response()).getPayload(), DomainListResult.class);
|
||||||
assertThat(Iterables.getOnlyElement(result.domains).getDomainName()).isEqualTo("0exists.tld");
|
assertThat(Iterables.getOnlyElement(result.domains).getDomainName()).isEqualTo("0exists.tld");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,7 +188,9 @@ public class ConsoleDomainListActionTest {
|
|||||||
void testSuccess_searchTerm_returnsNone() {
|
void testSuccess_searchTerm_returnsNone() {
|
||||||
ConsoleDomainListAction action = createAction("TheRegistrar", null, 0, 5, null, "deleted");
|
ConsoleDomainListAction action = createAction("TheRegistrar", null, 0, 5, null, "deleted");
|
||||||
action.run();
|
action.run();
|
||||||
DomainListResult result = GSON.fromJson(response.getPayload(), DomainListResult.class);
|
DomainListResult result =
|
||||||
|
GSON.fromJson(
|
||||||
|
((FakeResponse) consoleApiParams.response()).getPayload(), DomainListResult.class);
|
||||||
assertThat(result.domains).isEmpty();
|
assertThat(result.domains).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +198,9 @@ public class ConsoleDomainListActionTest {
|
|||||||
void testSuccess_searchTerm_caseInsensitive() {
|
void testSuccess_searchTerm_caseInsensitive() {
|
||||||
ConsoleDomainListAction action = createAction("TheRegistrar", null, 0, 5, null, "eXiStS");
|
ConsoleDomainListAction action = createAction("TheRegistrar", null, 0, 5, null, "eXiStS");
|
||||||
action.run();
|
action.run();
|
||||||
DomainListResult result = GSON.fromJson(response.getPayload(), DomainListResult.class);
|
DomainListResult result =
|
||||||
|
GSON.fromJson(
|
||||||
|
((FakeResponse) consoleApiParams.response()).getPayload(), DomainListResult.class);
|
||||||
assertThat(result.domains).hasSize(5);
|
assertThat(result.domains).hasSize(5);
|
||||||
assertThat(result.totalResults).isEqualTo(10);
|
assertThat(result.totalResults).isEqualTo(10);
|
||||||
}
|
}
|
||||||
@@ -181,7 +209,9 @@ public class ConsoleDomainListActionTest {
|
|||||||
void testSuccess_searchTerm_tld() {
|
void testSuccess_searchTerm_tld() {
|
||||||
ConsoleDomainListAction action = createAction("TheRegistrar", null, 0, 5, null, "tld");
|
ConsoleDomainListAction action = createAction("TheRegistrar", null, 0, 5, null, "tld");
|
||||||
action.run();
|
action.run();
|
||||||
DomainListResult result = GSON.fromJson(response.getPayload(), DomainListResult.class);
|
DomainListResult result =
|
||||||
|
GSON.fromJson(
|
||||||
|
((FakeResponse) consoleApiParams.response()).getPayload(), DomainListResult.class);
|
||||||
assertThat(result.domains).hasSize(5);
|
assertThat(result.domains).hasSize(5);
|
||||||
assertThat(result.totalResults).isEqualTo(10);
|
assertThat(result.totalResults).isEqualTo(10);
|
||||||
}
|
}
|
||||||
@@ -190,7 +220,9 @@ public class ConsoleDomainListActionTest {
|
|||||||
void testPartialSuccess_pastEnd() {
|
void testPartialSuccess_pastEnd() {
|
||||||
ConsoleDomainListAction action = createAction("TheRegistrar", null, 5, 5, null, null);
|
ConsoleDomainListAction action = createAction("TheRegistrar", null, 5, 5, null, null);
|
||||||
action.run();
|
action.run();
|
||||||
DomainListResult result = GSON.fromJson(response.getPayload(), DomainListResult.class);
|
DomainListResult result =
|
||||||
|
GSON.fromJson(
|
||||||
|
((FakeResponse) consoleApiParams.response()).getPayload(), DomainListResult.class);
|
||||||
assertThat(result.domains).isEmpty();
|
assertThat(result.domains).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,14 +230,16 @@ public class ConsoleDomainListActionTest {
|
|||||||
void testFailure_invalidResultsPerPage() {
|
void testFailure_invalidResultsPerPage() {
|
||||||
ConsoleDomainListAction action = createAction("TheRegistrar", null, 0, 0, null, null);
|
ConsoleDomainListAction action = createAction("TheRegistrar", null, 0, 0, null, null);
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
assertThat(response.getPayload())
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
||||||
|
assertThat(((FakeResponse) consoleApiParams.response()).getPayload())
|
||||||
.isEqualTo("Results per page must be between 1 and 500 inclusive");
|
.isEqualTo("Results per page must be between 1 and 500 inclusive");
|
||||||
|
|
||||||
action = createAction("TheRegistrar", null, 0, 501, null, null);
|
action = createAction("TheRegistrar", null, 0, 501, null, null);
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
assertThat(response.getPayload())
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
||||||
|
assertThat(((FakeResponse) consoleApiParams.response()).getPayload())
|
||||||
.isEqualTo("Results per page must be between 1 and 500 inclusive");
|
.isEqualTo("Results per page must be between 1 and 500 inclusive");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,8 +247,10 @@ public class ConsoleDomainListActionTest {
|
|||||||
void testFailure_invalidPageNumber() {
|
void testFailure_invalidPageNumber() {
|
||||||
ConsoleDomainListAction action = createAction("TheRegistrar", null, -1, 10, null, null);
|
ConsoleDomainListAction action = createAction("TheRegistrar", null, -1, 10, null, null);
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
assertThat(response.getPayload()).isEqualTo("Page number must be non-negative");
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
||||||
|
assertThat(((FakeResponse) consoleApiParams.response()).getPayload())
|
||||||
|
.isEqualTo("Page number must be non-negative");
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConsoleDomainListAction createAction(String registrarId) {
|
private ConsoleDomainListAction createAction(String registrarId) {
|
||||||
@@ -228,12 +264,12 @@ public class ConsoleDomainListActionTest {
|
|||||||
@Nullable Integer resultsPerPage,
|
@Nullable Integer resultsPerPage,
|
||||||
@Nullable Long totalResults,
|
@Nullable Long totalResults,
|
||||||
@Nullable String searchTerm) {
|
@Nullable String searchTerm) {
|
||||||
response = new FakeResponse();
|
|
||||||
AuthResult authResult =
|
AuthResult authResult =
|
||||||
AuthResult.createUser(UserAuthInfo.create(createAdminUser("email@email.example")));
|
AuthResult.createUser(UserAuthInfo.create(createAdminUser("email@email.example")));
|
||||||
|
consoleApiParams = FakeConsoleApiParams.get(Optional.of(authResult));
|
||||||
|
when(consoleApiParams.request().getMethod()).thenReturn(Action.Method.GET.toString());
|
||||||
return new ConsoleDomainListAction(
|
return new ConsoleDomainListAction(
|
||||||
authResult,
|
consoleApiParams,
|
||||||
response,
|
|
||||||
GSON,
|
GSON,
|
||||||
registrarId,
|
registrarId,
|
||||||
Optional.ofNullable(checkpointTime),
|
Optional.ofNullable(checkpointTime),
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ import google.registry.testing.FakeResponse;
|
|||||||
import google.registry.tools.GsonUtils;
|
import google.registry.tools.GsonUtils;
|
||||||
import google.registry.ui.server.registrar.ConsoleApiParams;
|
import google.registry.ui.server.registrar.ConsoleApiParams;
|
||||||
import google.registry.util.EmailMessage;
|
import google.registry.util.EmailMessage;
|
||||||
import jakarta.servlet.http.Cookie;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import javax.mail.internet.AddressException;
|
import javax.mail.internet.AddressException;
|
||||||
import javax.mail.internet.InternetAddress;
|
import javax.mail.internet.InternetAddress;
|
||||||
@@ -197,12 +196,7 @@ class ConsoleEppPasswordActionTest {
|
|||||||
AuthenticatedRegistrarAccessor authenticatedRegistrarAccessor =
|
AuthenticatedRegistrarAccessor authenticatedRegistrarAccessor =
|
||||||
AuthenticatedRegistrarAccessor.createForTesting(
|
AuthenticatedRegistrarAccessor.createForTesting(
|
||||||
ImmutableSetMultimap.of("registrarId", OWNER));
|
ImmutableSetMultimap.of("registrarId", OWNER));
|
||||||
Cookie cookie =
|
|
||||||
new Cookie(
|
|
||||||
consoleApiParams.xsrfTokenManager().X_CSRF_TOKEN,
|
|
||||||
consoleApiParams.xsrfTokenManager().generateToken(""));
|
|
||||||
when(consoleApiParams.request().getMethod()).thenReturn(Action.Method.POST.toString());
|
when(consoleApiParams.request().getMethod()).thenReturn(Action.Method.POST.toString());
|
||||||
when(consoleApiParams.request().getCookies()).thenReturn(new Cookie[] {cookie});
|
|
||||||
|
|
||||||
return new ConsoleEppPasswordAction(
|
return new ConsoleEppPasswordAction(
|
||||||
consoleApiParams, authenticatedRegistrarAccessor, gmailClient);
|
consoleApiParams, authenticatedRegistrarAccessor, gmailClient);
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import static google.registry.testing.DatabaseHelper.persistNewRegistrar;
|
|||||||
import static google.registry.testing.DatabaseHelper.persistResource;
|
import static google.registry.testing.DatabaseHelper.persistResource;
|
||||||
import static google.registry.testing.SqlHelper.saveRegistrar;
|
import static google.registry.testing.SqlHelper.saveRegistrar;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.google.api.client.http.HttpStatusCodes;
|
import com.google.api.client.http.HttpStatusCodes;
|
||||||
@@ -40,10 +39,11 @@ import google.registry.request.RequestModule;
|
|||||||
import google.registry.request.auth.AuthResult;
|
import google.registry.request.auth.AuthResult;
|
||||||
import google.registry.request.auth.UserAuthInfo;
|
import google.registry.request.auth.UserAuthInfo;
|
||||||
import google.registry.testing.DeterministicStringGenerator;
|
import google.registry.testing.DeterministicStringGenerator;
|
||||||
|
import google.registry.testing.FakeConsoleApiParams;
|
||||||
import google.registry.testing.FakeResponse;
|
import google.registry.testing.FakeResponse;
|
||||||
|
import google.registry.ui.server.registrar.ConsoleApiParams;
|
||||||
import google.registry.ui.server.registrar.RegistrarConsoleModule;
|
import google.registry.ui.server.registrar.RegistrarConsoleModule;
|
||||||
import google.registry.util.StringGenerator;
|
import google.registry.util.StringGenerator;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
@@ -56,9 +56,8 @@ import org.junit.jupiter.api.extension.RegisterExtension;
|
|||||||
/** Tests for {@link google.registry.ui.server.console.RegistrarsAction}. */
|
/** Tests for {@link google.registry.ui.server.console.RegistrarsAction}. */
|
||||||
class RegistrarsActionTest {
|
class RegistrarsActionTest {
|
||||||
|
|
||||||
private final HttpServletRequest request = mock(HttpServletRequest.class);
|
|
||||||
private static final Gson GSON = RequestModule.provideGson();
|
private static final Gson GSON = RequestModule.provideGson();
|
||||||
private FakeResponse response;
|
private ConsoleApiParams consoleApiParams;
|
||||||
|
|
||||||
private StringGenerator passwordGenerator =
|
private StringGenerator passwordGenerator =
|
||||||
new DeterministicStringGenerator("abcdefghijklmnopqrstuvwxyz");
|
new DeterministicStringGenerator("abcdefghijklmnopqrstuvwxyz");
|
||||||
@@ -112,8 +111,9 @@ class RegistrarsActionTest {
|
|||||||
createUser(
|
createUser(
|
||||||
new UserRoles.Builder().setGlobalRole(GlobalRole.SUPPORT_LEAD).build()))));
|
new UserRoles.Builder().setGlobalRole(GlobalRole.SUPPORT_LEAD).build()))));
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
String payload = response.getPayload();
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
|
String payload = ((FakeResponse) consoleApiParams.response()).getPayload();
|
||||||
assertThat(
|
assertThat(
|
||||||
ImmutableList.of("\"registrarId\":\"NewRegistrar\"", "\"registrarId\":\"TheRegistrar\"")
|
ImmutableList.of("\"registrarId\":\"NewRegistrar\"", "\"registrarId\":\"TheRegistrar\"")
|
||||||
.stream()
|
.stream()
|
||||||
@@ -131,8 +131,9 @@ class RegistrarsActionTest {
|
|||||||
UserAuthInfo.create(
|
UserAuthInfo.create(
|
||||||
createUser(new UserRoles.Builder().setGlobalRole(GlobalRole.FTE).build()))));
|
createUser(new UserRoles.Builder().setGlobalRole(GlobalRole.FTE).build()))));
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
String payload = response.getPayload();
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
|
String payload = ((FakeResponse) consoleApiParams.response()).getPayload();
|
||||||
assertThat(
|
assertThat(
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
"\"registrarId\":\"NewRegistrar\"",
|
"\"registrarId\":\"NewRegistrar\"",
|
||||||
@@ -151,7 +152,8 @@ class RegistrarsActionTest {
|
|||||||
AuthResult.createUser(
|
AuthResult.createUser(
|
||||||
UserAuthInfo.create(createUser(new UserRoles.Builder().setIsAdmin(true).build()))));
|
UserAuthInfo.create(createUser(new UserRoles.Builder().setIsAdmin(true).build()))));
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
Registrar r = loadRegistrar("regIdTest");
|
Registrar r = loadRegistrar("regIdTest");
|
||||||
assertThat(r).isNotNull();
|
assertThat(r).isNotNull();
|
||||||
assertThat(
|
assertThat(
|
||||||
@@ -180,12 +182,12 @@ class RegistrarsActionTest {
|
|||||||
UserAuthInfo.create(
|
UserAuthInfo.create(
|
||||||
createUser(new UserRoles.Builder().setIsAdmin(true).build()))));
|
createUser(new UserRoles.Builder().setIsAdmin(true).build()))));
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
assertThat(response.getPayload())
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
||||||
|
assertThat(((FakeResponse) consoleApiParams.response()).getPayload())
|
||||||
.isEqualTo(
|
.isEqualTo(
|
||||||
GSON.toJson(
|
String.format(
|
||||||
String.format(
|
"Missing value for %s", userFriendlyKeysToRegistrarKeys.get(key)));
|
||||||
"Missing value for %s", userFriendlyKeysToRegistrarKeys.get(key))));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,9 +200,10 @@ class RegistrarsActionTest {
|
|||||||
AuthResult.createUser(
|
AuthResult.createUser(
|
||||||
UserAuthInfo.create(createUser(new UserRoles.Builder().setIsAdmin(true).build()))));
|
UserAuthInfo.create(createUser(new UserRoles.Builder().setIsAdmin(true).build()))));
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
assertThat(response.getPayload())
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_BAD_REQUEST);
|
||||||
.isEqualTo(GSON.toJson("Registrar with registrarId regIdTest already exists"));
|
assertThat(((FakeResponse) consoleApiParams.response()).getPayload())
|
||||||
|
.isEqualTo("Registrar with registrarId regIdTest already exists");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -219,7 +222,8 @@ class RegistrarsActionTest {
|
|||||||
RegistrarRole.ACCOUNT_MANAGER_WITH_REGISTRY_LOCK))
|
RegistrarRole.ACCOUNT_MANAGER_WITH_REGISTRY_LOCK))
|
||||||
.build()))));
|
.build()))));
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
private User createUser(UserRoles userRoles) {
|
private User createUser(UserRoles userRoles) {
|
||||||
@@ -230,27 +234,19 @@ class RegistrarsActionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private RegistrarsAction createAction(Action.Method method, AuthResult authResult) {
|
private RegistrarsAction createAction(Action.Method method, AuthResult authResult) {
|
||||||
response = new FakeResponse();
|
consoleApiParams = FakeConsoleApiParams.get(Optional.of(authResult));
|
||||||
when(request.getMethod()).thenReturn(method.toString());
|
when(consoleApiParams.request().getMethod()).thenReturn(method.toString());
|
||||||
if (method.equals(Action.Method.GET)) {
|
if (method.equals(Action.Method.GET)) {
|
||||||
return new RegistrarsAction(
|
return new RegistrarsAction(
|
||||||
request,
|
consoleApiParams, GSON, Optional.ofNullable(null), passwordGenerator, passcodeGenerator);
|
||||||
authResult,
|
|
||||||
response,
|
|
||||||
GSON,
|
|
||||||
Optional.ofNullable(null),
|
|
||||||
passwordGenerator,
|
|
||||||
passcodeGenerator);
|
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
doReturn(new BufferedReader(new StringReader(registrarParamMap.toString())))
|
doReturn(new BufferedReader(new StringReader(registrarParamMap.toString())))
|
||||||
.when(request)
|
.when(consoleApiParams.request())
|
||||||
.getReader();
|
.getReader();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return new RegistrarsAction(
|
return new RegistrarsAction(
|
||||||
request,
|
consoleApiParams,
|
||||||
authResult,
|
|
||||||
response,
|
|
||||||
GSON,
|
GSON,
|
||||||
Optional.ofNullable(null),
|
Optional.ofNullable(null),
|
||||||
passwordGenerator,
|
passwordGenerator,
|
||||||
@@ -258,15 +254,9 @@ class RegistrarsActionTest {
|
|||||||
}
|
}
|
||||||
Optional<Registrar> maybeRegistrar =
|
Optional<Registrar> maybeRegistrar =
|
||||||
RegistrarConsoleModule.provideRegistrar(
|
RegistrarConsoleModule.provideRegistrar(
|
||||||
GSON, RequestModule.provideJsonBody(request, GSON));
|
GSON, RequestModule.provideJsonBody(consoleApiParams.request(), GSON));
|
||||||
return new RegistrarsAction(
|
return new RegistrarsAction(
|
||||||
request,
|
consoleApiParams, GSON, maybeRegistrar, passwordGenerator, passcodeGenerator);
|
||||||
authResult,
|
|
||||||
response,
|
|
||||||
GSON,
|
|
||||||
maybeRegistrar,
|
|
||||||
passwordGenerator,
|
|
||||||
passcodeGenerator);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import static google.registry.testing.DatabaseHelper.createAdminUser;
|
|||||||
import static google.registry.testing.DatabaseHelper.insertInDb;
|
import static google.registry.testing.DatabaseHelper.insertInDb;
|
||||||
import static google.registry.testing.DatabaseHelper.loadAllOf;
|
import static google.registry.testing.DatabaseHelper.loadAllOf;
|
||||||
import static google.registry.testing.SqlHelper.saveRegistrar;
|
import static google.registry.testing.SqlHelper.saveRegistrar;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.google.api.client.http.HttpStatusCodes;
|
import com.google.api.client.http.HttpStatusCodes;
|
||||||
@@ -38,9 +38,10 @@ import google.registry.request.Action;
|
|||||||
import google.registry.request.RequestModule;
|
import google.registry.request.RequestModule;
|
||||||
import google.registry.request.auth.AuthResult;
|
import google.registry.request.auth.AuthResult;
|
||||||
import google.registry.request.auth.UserAuthInfo;
|
import google.registry.request.auth.UserAuthInfo;
|
||||||
|
import google.registry.testing.FakeConsoleApiParams;
|
||||||
import google.registry.testing.FakeResponse;
|
import google.registry.testing.FakeResponse;
|
||||||
|
import google.registry.ui.server.registrar.ConsoleApiParams;
|
||||||
import google.registry.ui.server.registrar.RegistrarConsoleModule;
|
import google.registry.ui.server.registrar.RegistrarConsoleModule;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
@@ -69,10 +70,9 @@ class ContactActionTest {
|
|||||||
+ "\"visibleInWhoisAsTech\":false,\"visibleInDomainWhoisAsAbuse\":false}";
|
+ "\"visibleInWhoisAsTech\":false,\"visibleInDomainWhoisAsAbuse\":false}";
|
||||||
|
|
||||||
private Registrar testRegistrar;
|
private Registrar testRegistrar;
|
||||||
private final HttpServletRequest request = mock(HttpServletRequest.class);
|
private ConsoleApiParams consoleApiParams;
|
||||||
private RegistrarPoc testRegistrarPoc;
|
private RegistrarPoc testRegistrarPoc;
|
||||||
private static final Gson GSON = RequestModule.provideGson();
|
private static final Gson GSON = RequestModule.provideGson();
|
||||||
private FakeResponse response;
|
|
||||||
|
|
||||||
@RegisterExtension
|
@RegisterExtension
|
||||||
final JpaTestExtensions.JpaIntegrationTestExtension jpa =
|
final JpaTestExtensions.JpaIntegrationTestExtension jpa =
|
||||||
@@ -80,7 +80,6 @@ class ContactActionTest {
|
|||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void beforeEach() {
|
void beforeEach() {
|
||||||
response = new FakeResponse();
|
|
||||||
testRegistrar = saveRegistrar("registrarId");
|
testRegistrar = saveRegistrar("registrarId");
|
||||||
testRegistrarPoc =
|
testRegistrarPoc =
|
||||||
new RegistrarPoc.Builder()
|
new RegistrarPoc.Builder()
|
||||||
@@ -106,8 +105,10 @@ class ContactActionTest {
|
|||||||
testRegistrar.getRegistrarId(),
|
testRegistrar.getRegistrarId(),
|
||||||
null);
|
null);
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
assertThat(response.getPayload()).isEqualTo("[" + jsonRegistrar1 + "]");
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
|
assertThat(((FakeResponse) consoleApiParams.response()).getPayload())
|
||||||
|
.isEqualTo("[" + jsonRegistrar1 + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -121,8 +122,9 @@ class ContactActionTest {
|
|||||||
testRegistrar.getRegistrarId(),
|
testRegistrar.getRegistrarId(),
|
||||||
null);
|
null);
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
assertThat(response.getPayload()).isEqualTo("[]");
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
|
assertThat(((FakeResponse) consoleApiParams.response()).getPayload()).isEqualTo("[]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -134,7 +136,8 @@ class ContactActionTest {
|
|||||||
testRegistrar.getRegistrarId(),
|
testRegistrar.getRegistrarId(),
|
||||||
"[" + jsonRegistrar1 + "," + jsonRegistrar2 + "]");
|
"[" + jsonRegistrar1 + "," + jsonRegistrar2 + "]");
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
assertThat(
|
assertThat(
|
||||||
loadAllOf(RegistrarPoc.class).stream()
|
loadAllOf(RegistrarPoc.class).stream()
|
||||||
.filter(r -> r.registrarId.equals(testRegistrar.getRegistrarId()))
|
.filter(r -> r.registrarId.equals(testRegistrar.getRegistrarId()))
|
||||||
@@ -154,7 +157,8 @@ class ContactActionTest {
|
|||||||
testRegistrar.getRegistrarId(),
|
testRegistrar.getRegistrarId(),
|
||||||
"[" + jsonRegistrar1 + "," + jsonRegistrar2 + "]");
|
"[" + jsonRegistrar1 + "," + jsonRegistrar2 + "]");
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
HashMap<String, String> testResult = new HashMap<>();
|
HashMap<String, String> testResult = new HashMap<>();
|
||||||
loadAllOf(RegistrarPoc.class).stream()
|
loadAllOf(RegistrarPoc.class).stream()
|
||||||
.filter(r -> r.registrarId.equals(testRegistrar.getRegistrarId()))
|
.filter(r -> r.registrarId.equals(testRegistrar.getRegistrarId()))
|
||||||
@@ -177,7 +181,8 @@ class ContactActionTest {
|
|||||||
testRegistrar.getRegistrarId(),
|
testRegistrar.getRegistrarId(),
|
||||||
"[" + jsonRegistrar2 + "]");
|
"[" + jsonRegistrar2 + "]");
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
assertThat(
|
assertThat(
|
||||||
loadAllOf(RegistrarPoc.class).stream()
|
loadAllOf(RegistrarPoc.class).stream()
|
||||||
.filter(r -> r.registrarId.equals(testRegistrar.getRegistrarId()))
|
.filter(r -> r.registrarId.equals(testRegistrar.getRegistrarId()))
|
||||||
@@ -207,21 +212,25 @@ class ContactActionTest {
|
|||||||
testRegistrar.getRegistrarId(),
|
testRegistrar.getRegistrarId(),
|
||||||
"[" + jsonRegistrar2 + "]");
|
"[" + jsonRegistrar2 + "]");
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ContactAction createAction(
|
private ContactAction createAction(
|
||||||
Action.Method method, AuthResult authResult, String registrarId, String contacts)
|
Action.Method method, AuthResult authResult, String registrarId, String contacts)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
when(request.getMethod()).thenReturn(method.toString());
|
consoleApiParams = FakeConsoleApiParams.get(Optional.of(authResult));
|
||||||
|
when(consoleApiParams.request().getMethod()).thenReturn(method.toString());
|
||||||
if (method.equals(Action.Method.GET)) {
|
if (method.equals(Action.Method.GET)) {
|
||||||
return new ContactAction(request, authResult, response, GSON, registrarId, Optional.empty());
|
return new ContactAction(consoleApiParams, GSON, registrarId, Optional.empty());
|
||||||
} else {
|
} else {
|
||||||
when(request.getReader()).thenReturn(new BufferedReader(new StringReader(contacts)));
|
doReturn(new BufferedReader(new StringReader(contacts)))
|
||||||
|
.when(consoleApiParams.request())
|
||||||
|
.getReader();
|
||||||
Optional<ImmutableSet<RegistrarPoc>> maybeContacts =
|
Optional<ImmutableSet<RegistrarPoc>> maybeContacts =
|
||||||
RegistrarConsoleModule.provideContacts(
|
RegistrarConsoleModule.provideContacts(
|
||||||
GSON, RequestModule.provideJsonBody(request, GSON));
|
GSON, RequestModule.provideJsonBody(consoleApiParams.request(), GSON));
|
||||||
return new ContactAction(request, authResult, response, GSON, registrarId, maybeContacts);
|
return new ContactAction(consoleApiParams, GSON, registrarId, maybeContacts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import static google.registry.testing.DatabaseHelper.loadRegistrar;
|
|||||||
import static google.registry.testing.SqlHelper.saveRegistrar;
|
import static google.registry.testing.SqlHelper.saveRegistrar;
|
||||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.google.api.client.http.HttpStatusCodes;
|
import com.google.api.client.http.HttpStatusCodes;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
@@ -30,15 +30,17 @@ import com.google.gson.Gson;
|
|||||||
import google.registry.flows.certs.CertificateChecker;
|
import google.registry.flows.certs.CertificateChecker;
|
||||||
import google.registry.model.registrar.Registrar;
|
import google.registry.model.registrar.Registrar;
|
||||||
import google.registry.persistence.transaction.JpaTestExtensions;
|
import google.registry.persistence.transaction.JpaTestExtensions;
|
||||||
|
import google.registry.request.Action;
|
||||||
import google.registry.request.RequestModule;
|
import google.registry.request.RequestModule;
|
||||||
import google.registry.request.auth.AuthResult;
|
import google.registry.request.auth.AuthResult;
|
||||||
import google.registry.request.auth.AuthenticatedRegistrarAccessor;
|
import google.registry.request.auth.AuthenticatedRegistrarAccessor;
|
||||||
import google.registry.request.auth.UserAuthInfo;
|
import google.registry.request.auth.UserAuthInfo;
|
||||||
import google.registry.testing.DatabaseHelper;
|
import google.registry.testing.DatabaseHelper;
|
||||||
import google.registry.testing.FakeClock;
|
import google.registry.testing.FakeClock;
|
||||||
|
import google.registry.testing.FakeConsoleApiParams;
|
||||||
import google.registry.testing.FakeResponse;
|
import google.registry.testing.FakeResponse;
|
||||||
|
import google.registry.ui.server.registrar.ConsoleApiParams;
|
||||||
import google.registry.ui.server.registrar.RegistrarConsoleModule;
|
import google.registry.ui.server.registrar.RegistrarConsoleModule;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
@@ -57,10 +59,9 @@ class SecurityActionTest {
|
|||||||
+ " \"ipAddressAllowList\": [\"192.168.1.1/32\"]}",
|
+ " \"ipAddressAllowList\": [\"192.168.1.1/32\"]}",
|
||||||
SAMPLE_CERT2);
|
SAMPLE_CERT2);
|
||||||
private static final Gson GSON = RequestModule.provideGson();
|
private static final Gson GSON = RequestModule.provideGson();
|
||||||
private final HttpServletRequest request = mock(HttpServletRequest.class);
|
private ConsoleApiParams consoleApiParams;
|
||||||
private final FakeClock clock = new FakeClock();
|
private final FakeClock clock = new FakeClock();
|
||||||
private Registrar testRegistrar;
|
private Registrar testRegistrar;
|
||||||
private FakeResponse response = new FakeResponse();
|
|
||||||
|
|
||||||
private AuthenticatedRegistrarAccessor registrarAccessor =
|
private AuthenticatedRegistrarAccessor registrarAccessor =
|
||||||
AuthenticatedRegistrarAccessor.createForTesting(
|
AuthenticatedRegistrarAccessor.createForTesting(
|
||||||
@@ -93,7 +94,8 @@ class SecurityActionTest {
|
|||||||
UserAuthInfo.create(DatabaseHelper.createAdminUser("email@email.com"))),
|
UserAuthInfo.create(DatabaseHelper.createAdminUser("email@email.com"))),
|
||||||
testRegistrar.getRegistrarId());
|
testRegistrar.getRegistrarId());
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
Registrar r = loadRegistrar(testRegistrar.getRegistrarId());
|
Registrar r = loadRegistrar(testRegistrar.getRegistrarId());
|
||||||
assertThat(r.getClientCertificateHash().get())
|
assertThat(r.getClientCertificateHash().get())
|
||||||
.isEqualTo("GNd6ZP8/n91t9UTnpxR8aH7aAW4+CpvufYx9ViGbcMY");
|
.isEqualTo("GNd6ZP8/n91t9UTnpxR8aH7aAW4+CpvufYx9ViGbcMY");
|
||||||
@@ -103,16 +105,15 @@ class SecurityActionTest {
|
|||||||
|
|
||||||
private SecurityAction createAction(AuthResult authResult, String registrarId)
|
private SecurityAction createAction(AuthResult authResult, String registrarId)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
doReturn(new BufferedReader(new StringReader(jsonRegistrar1))).when(request).getReader();
|
consoleApiParams = FakeConsoleApiParams.get(Optional.of(authResult));
|
||||||
|
when(consoleApiParams.request().getMethod()).thenReturn(Action.Method.POST.toString());
|
||||||
|
doReturn(new BufferedReader(new StringReader(jsonRegistrar1)))
|
||||||
|
.when(consoleApiParams.request())
|
||||||
|
.getReader();
|
||||||
Optional<Registrar> maybeRegistrar =
|
Optional<Registrar> maybeRegistrar =
|
||||||
RegistrarConsoleModule.provideRegistrar(GSON, RequestModule.provideJsonBody(request, GSON));
|
RegistrarConsoleModule.provideRegistrar(
|
||||||
return new SecurityAction(
|
GSON, RequestModule.provideJsonBody(consoleApiParams.request(), GSON));
|
||||||
authResult,
|
return new SecurityAction(
|
||||||
response,
|
consoleApiParams, certificateChecker, registrarAccessor, registrarId, maybeRegistrar);
|
||||||
GSON,
|
|
||||||
certificateChecker,
|
|
||||||
registrarAccessor,
|
|
||||||
registrarId,
|
|
||||||
maybeRegistrar);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ package google.registry.ui.server.console.settings;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
|
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import com.google.api.client.http.HttpStatusCodes;
|
import com.google.api.client.http.HttpStatusCodes;
|
||||||
@@ -30,6 +30,7 @@ import google.registry.model.console.User;
|
|||||||
import google.registry.model.console.UserRoles;
|
import google.registry.model.console.UserRoles;
|
||||||
import google.registry.model.registrar.Registrar;
|
import google.registry.model.registrar.Registrar;
|
||||||
import google.registry.persistence.transaction.JpaTestExtensions;
|
import google.registry.persistence.transaction.JpaTestExtensions;
|
||||||
|
import google.registry.request.Action;
|
||||||
import google.registry.request.RequestModule;
|
import google.registry.request.RequestModule;
|
||||||
import google.registry.request.auth.AuthResult;
|
import google.registry.request.auth.AuthResult;
|
||||||
import google.registry.request.auth.AuthenticatedRegistrarAccessor;
|
import google.registry.request.auth.AuthenticatedRegistrarAccessor;
|
||||||
@@ -37,13 +38,15 @@ import google.registry.request.auth.AuthenticatedRegistrarAccessor.Role;
|
|||||||
import google.registry.request.auth.UserAuthInfo;
|
import google.registry.request.auth.UserAuthInfo;
|
||||||
import google.registry.testing.DatabaseHelper;
|
import google.registry.testing.DatabaseHelper;
|
||||||
import google.registry.testing.FakeClock;
|
import google.registry.testing.FakeClock;
|
||||||
|
import google.registry.testing.FakeConsoleApiParams;
|
||||||
import google.registry.testing.FakeResponse;
|
import google.registry.testing.FakeResponse;
|
||||||
|
import google.registry.ui.server.registrar.ConsoleApiParams;
|
||||||
import google.registry.ui.server.registrar.RegistrarConsoleModule;
|
import google.registry.ui.server.registrar.RegistrarConsoleModule;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Optional;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
@@ -51,10 +54,9 @@ import org.junit.jupiter.api.extension.RegisterExtension;
|
|||||||
/** Tests for {@link WhoisRegistrarFieldsAction}. */
|
/** Tests for {@link WhoisRegistrarFieldsAction}. */
|
||||||
public class WhoisRegistrarFieldsActionTest {
|
public class WhoisRegistrarFieldsActionTest {
|
||||||
|
|
||||||
|
private ConsoleApiParams consoleApiParams;
|
||||||
private static final Gson GSON = RequestModule.provideGson();
|
private static final Gson GSON = RequestModule.provideGson();
|
||||||
private final FakeClock clock = new FakeClock(DateTime.parse("2023-08-01T00:00:00.000Z"));
|
private final FakeClock clock = new FakeClock(DateTime.parse("2023-08-01T00:00:00.000Z"));
|
||||||
private final FakeResponse fakeResponse = new FakeResponse();
|
|
||||||
private final HttpServletRequest request = mock(HttpServletRequest.class);
|
|
||||||
private final AuthenticatedRegistrarAccessor registrarAccessor =
|
private final AuthenticatedRegistrarAccessor registrarAccessor =
|
||||||
AuthenticatedRegistrarAccessor.createForTesting(
|
AuthenticatedRegistrarAccessor.createForTesting(
|
||||||
ImmutableSetMultimap.of("TheRegistrar", Role.OWNER, "NewRegistrar", Role.OWNER));
|
ImmutableSetMultimap.of("TheRegistrar", Role.OWNER, "NewRegistrar", Role.OWNER));
|
||||||
@@ -110,7 +112,8 @@ public class WhoisRegistrarFieldsActionTest {
|
|||||||
+ " \"NL\", \"zip\": \"10011\", \"countryCode\": \"CA\"}"));
|
+ " \"NL\", \"zip\": \"10011\", \"countryCode\": \"CA\"}"));
|
||||||
WhoisRegistrarFieldsAction action = createAction();
|
WhoisRegistrarFieldsAction action = createAction();
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(fakeResponse.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
Registrar newRegistrar = Registrar.loadByRegistrarId("TheRegistrar").get(); // skip cache
|
Registrar newRegistrar = Registrar.loadByRegistrarId("TheRegistrar").get(); // skip cache
|
||||||
assertThat(newRegistrar.getWhoisServer()).isEqualTo("whois.nic.google");
|
assertThat(newRegistrar.getWhoisServer()).isEqualTo("whois.nic.google");
|
||||||
assertThat(newRegistrar.getUrl()).isEqualTo("https://newurl.example");
|
assertThat(newRegistrar.getUrl()).isEqualTo("https://newurl.example");
|
||||||
@@ -138,7 +141,8 @@ public class WhoisRegistrarFieldsActionTest {
|
|||||||
uiRegistrarMap.put("registrarId", "NewRegistrar");
|
uiRegistrarMap.put("registrarId", "NewRegistrar");
|
||||||
WhoisRegistrarFieldsAction action = createAction(onlyTheRegistrar);
|
WhoisRegistrarFieldsAction action = createAction(onlyTheRegistrar);
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(fakeResponse.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
||||||
// should be no change
|
// should be no change
|
||||||
assertThat(DatabaseHelper.loadByEntity(newRegistrar)).isEqualTo(newRegistrar);
|
assertThat(DatabaseHelper.loadByEntity(newRegistrar)).isEqualTo(newRegistrar);
|
||||||
}
|
}
|
||||||
@@ -153,14 +157,15 @@ public class WhoisRegistrarFieldsActionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private WhoisRegistrarFieldsAction createAction(AuthResult authResult) throws IOException {
|
private WhoisRegistrarFieldsAction createAction(AuthResult authResult) throws IOException {
|
||||||
when(request.getReader())
|
consoleApiParams = FakeConsoleApiParams.get(Optional.of(authResult));
|
||||||
.thenReturn(new BufferedReader(new StringReader(uiRegistrarMap.toString())));
|
when(consoleApiParams.request().getMethod()).thenReturn(Action.Method.POST.toString());
|
||||||
|
doReturn(new BufferedReader(new StringReader(uiRegistrarMap.toString())))
|
||||||
|
.when(consoleApiParams.request())
|
||||||
|
.getReader();
|
||||||
return new WhoisRegistrarFieldsAction(
|
return new WhoisRegistrarFieldsAction(
|
||||||
authResult,
|
consoleApiParams,
|
||||||
fakeResponse,
|
|
||||||
GSON,
|
|
||||||
registrarAccessor,
|
registrarAccessor,
|
||||||
RegistrarConsoleModule.provideRegistrar(
|
RegistrarConsoleModule.provideRegistrar(
|
||||||
GSON, RequestModule.provideJsonBody(request, GSON)));
|
GSON, RequestModule.provideJsonBody(consoleApiParams.request(), GSON)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user