mirror of
https://github.com/google/nomulus
synced 2026-04-21 08:40:44 +00:00
Add console DUM download (#2402)
* Add console DUM download * Add console DUM download
This commit is contained in:
@@ -23,6 +23,9 @@ import com.google.common.base.Throwables;
|
||||
import com.google.common.net.MediaType;
|
||||
import google.registry.request.Response;
|
||||
import jakarta.servlet.http.Cookie;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -39,6 +42,9 @@ public final class FakeResponse implements Response {
|
||||
private boolean wasMutuallyExclusiveResponseSet;
|
||||
private String lastResponseStackTrace;
|
||||
|
||||
private final StringWriter writer = new StringWriter();
|
||||
private PrintWriter printWriter = new PrintWriter(writer);
|
||||
|
||||
private ArrayList<Cookie> cookies = new ArrayList<>();
|
||||
|
||||
public int getStatus() {
|
||||
@@ -57,6 +63,10 @@ public final class FakeResponse implements Response {
|
||||
return unmodifiableMap(headers);
|
||||
}
|
||||
|
||||
public StringWriter getStringWriter() {
|
||||
return writer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStatus(int status) {
|
||||
checkArgument(status >= 100);
|
||||
@@ -93,6 +103,11 @@ public final class FakeResponse implements Response {
|
||||
cookies.add(cookie);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrintWriter getWriter() throws IOException {
|
||||
return printWriter;
|
||||
}
|
||||
|
||||
public List<Cookie> getCookies() {
|
||||
return cookies;
|
||||
}
|
||||
@@ -113,4 +128,5 @@ public final class FakeResponse implements Response {
|
||||
return Throwables.getStackTraceAsString(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
// Copyright 2024 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.ui.server.console;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.google.api.client.http.HttpStatusCodes;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gson.Gson;
|
||||
import google.registry.model.console.GlobalRole;
|
||||
import google.registry.model.console.User;
|
||||
import google.registry.model.console.UserRoles;
|
||||
import google.registry.persistence.transaction.JpaTestExtensions;
|
||||
import google.registry.request.Action;
|
||||
import google.registry.request.auth.AuthResult;
|
||||
import google.registry.request.auth.UserAuthInfo;
|
||||
import google.registry.testing.DatabaseHelper;
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.testing.FakeConsoleApiParams;
|
||||
import google.registry.testing.FakeResponse;
|
||||
import google.registry.tools.GsonUtils;
|
||||
import google.registry.ui.server.registrar.ConsoleApiParams;
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
class ConsoleDumDownloadActionTest {
|
||||
|
||||
private static final Gson GSON = GsonUtils.provideGson();
|
||||
|
||||
private final FakeClock clock = new FakeClock(DateTime.parse("2024-04-15T00:00:00.000Z"));
|
||||
|
||||
private ConsoleApiParams consoleApiParams;
|
||||
|
||||
@RegisterExtension
|
||||
final JpaTestExtensions.JpaIntegrationTestExtension jpa =
|
||||
new JpaTestExtensions.Builder().withClock(clock).buildIntegrationTestExtension();
|
||||
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
createTld("tld");
|
||||
for (int i = 0; i < 3; i++) {
|
||||
DatabaseHelper.persistActiveDomain(
|
||||
i + "exists.tld", clock.nowUtc(), clock.nowUtc().plusDays(300));
|
||||
clock.advanceOneMilli();
|
||||
}
|
||||
DatabaseHelper.persistDeletedDomain("deleted.tld", clock.nowUtc().minusDays(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_returnsCorrectDomains() throws IOException {
|
||||
User user =
|
||||
new User.Builder()
|
||||
.setEmailAddress("email@email.com")
|
||||
.setUserRoles(new UserRoles.Builder().setGlobalRole(GlobalRole.FTE).build())
|
||||
.build();
|
||||
|
||||
AuthResult authResult = AuthResult.createUser(UserAuthInfo.create(user));
|
||||
ConsoleDumDownloadAction action = createAction(Optional.of(authResult));
|
||||
action.run();
|
||||
ImmutableList<String> expected =
|
||||
ImmutableList.of(
|
||||
"Domain Name,Creation Time,Expiration Time,Domain Statuses",
|
||||
"2exists.tld,2024-04-15 00:00:00.002+00,2025-02-09 00:00:00.002+00,{INACTIVE}",
|
||||
"1exists.tld,2024-04-15 00:00:00.001+00,2025-02-09 00:00:00.001+00,{INACTIVE}",
|
||||
"0exists.tld,2024-04-15 00:00:00+00,2025-02-09 00:00:00+00,{INACTIVE}");
|
||||
FakeResponse response = (FakeResponse) consoleApiParams.response();
|
||||
assertThat(response.getStatus()).isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
||||
ImmutableList<String> actual =
|
||||
ImmutableList.copyOf(response.getStringWriter().toString().split("\r\n"));
|
||||
assertThat(actual).containsExactlyElementsIn(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFailure_forbidden() {
|
||||
UserRoles userRoles =
|
||||
new UserRoles.Builder().setGlobalRole(GlobalRole.NONE).setIsAdmin(false).build();
|
||||
|
||||
User user =
|
||||
new User.Builder().setEmailAddress("email@email.com").setUserRoles(userRoles).build();
|
||||
|
||||
AuthResult authResult = AuthResult.createUser(UserAuthInfo.create(user));
|
||||
ConsoleDumDownloadAction action = createAction(Optional.of(authResult));
|
||||
action.run();
|
||||
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||
.isEqualTo(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
||||
}
|
||||
|
||||
private ConsoleDumDownloadAction createAction(Optional<AuthResult> maybeAuthResult) {
|
||||
consoleApiParams = FakeConsoleApiParams.get(maybeAuthResult);
|
||||
when(consoleApiParams.request().getMethod()).thenReturn(Action.Method.GET.toString());
|
||||
return new ConsoleDumDownloadAction(clock, consoleApiParams, "TheRegistrar", "test_name");
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ PATH CLASS METHODS OK AUT
|
||||
/_dr/epp EppTlsAction POST n API APP ADMIN
|
||||
/console-api/domain ConsoleDomainGetAction GET n API,LEGACY USER PUBLIC
|
||||
/console-api/domain-list ConsoleDomainListAction GET n API,LEGACY USER PUBLIC
|
||||
/console-api/dum-download ConsoleDumDownloadAction GET n API,LEGACY USER PUBLIC
|
||||
/console-api/eppPassword ConsoleEppPasswordAction POST n API,LEGACY USER PUBLIC
|
||||
/console-api/registrars RegistrarsAction GET,POST n API,LEGACY USER PUBLIC
|
||||
/console-api/settings/contacts ContactAction GET,POST n API,LEGACY USER PUBLIC
|
||||
@@ -15,4 +16,4 @@ PATH CLASS METHODS OK AUT
|
||||
/registrar-settings RegistrarSettingsAction POST n API,LEGACY USER PUBLIC
|
||||
/registry-lock-get RegistryLockGetAction GET n API,LEGACY USER PUBLIC
|
||||
/registry-lock-post RegistryLockPostAction POST n API,LEGACY USER PUBLIC
|
||||
/registry-lock-verify RegistryLockVerifyAction GET n API,LEGACY NONE PUBLIC
|
||||
/registry-lock-verify RegistryLockVerifyAction GET n API,LEGACY NONE PUBLIC
|
||||
|
||||
@@ -57,6 +57,7 @@ PATH CLASS
|
||||
/check CheckApiAction GET n API NONE PUBLIC
|
||||
/console-api/domain ConsoleDomainGetAction GET n API,LEGACY USER PUBLIC
|
||||
/console-api/domain-list ConsoleDomainListAction GET n API,LEGACY USER PUBLIC
|
||||
/console-api/dum-download ConsoleDumDownloadAction GET n API,LEGACY USER PUBLIC
|
||||
/console-api/eppPassword ConsoleEppPasswordAction POST n API,LEGACY USER PUBLIC
|
||||
/console-api/registrars RegistrarsAction GET,POST n API,LEGACY USER PUBLIC
|
||||
/console-api/settings/contacts ContactAction GET,POST n API,LEGACY USER PUBLIC
|
||||
@@ -80,4 +81,4 @@ PATH CLASS
|
||||
/registry-lock-get RegistryLockGetAction GET n API,LEGACY USER PUBLIC
|
||||
/registry-lock-post RegistryLockPostAction POST n API,LEGACY USER PUBLIC
|
||||
/registry-lock-verify RegistryLockVerifyAction GET n API,LEGACY NONE PUBLIC
|
||||
/whois/(*) WhoisHttpAction GET n API NONE PUBLIC
|
||||
/whois/(*) WhoisHttpAction GET n API NONE PUBLIC
|
||||
|
||||
Reference in New Issue
Block a user