1
0
mirror of https://github.com/google/nomulus synced 2025-12-23 06:15:42 +00:00

Add OTE registrars to console /registrars response (#2440)

This commit is contained in:
Pavlo Tkach
2024-05-16 10:49:32 -04:00
committed by GitHub
parent 36a660a8ad
commit a66b9ea749
2 changed files with 19 additions and 7 deletions

View File

@@ -27,6 +27,7 @@ import com.google.gson.Gson;
import google.registry.model.console.ConsolePermission;
import google.registry.model.console.User;
import google.registry.model.registrar.Registrar;
import google.registry.model.registrar.RegistrarBase;
import google.registry.model.registrar.RegistrarBase.State;
import google.registry.model.registrar.RegistrarPoc;
import google.registry.request.Action;
@@ -46,12 +47,15 @@ import javax.inject.Named;
public class RegistrarsAction extends ConsoleApiAction {
private static final int PASSWORD_LENGTH = 16;
private static final int PASSCODE_LENGTH = 5;
private static final ImmutableList<RegistrarBase.Type> allowedRegistrarTypes =
ImmutableList.of(Registrar.Type.REAL, RegistrarBase.Type.OTE);
static final String PATH = "/console-api/registrars";
private final Gson gson;
private Optional<Registrar> registrar;
private StringGenerator passwordGenerator;
private StringGenerator passcodeGenerator;
@Inject
public RegistrarsAction(
ConsoleApiParams consoleApiParams,
@@ -72,9 +76,10 @@ public class RegistrarsAction extends ConsoleApiAction {
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
return;
}
ImmutableList<Registrar> registrars =
Streams.stream(Registrar.loadAll())
.filter(r -> r.getType() == Registrar.Type.REAL)
.filter(r -> allowedRegistrarTypes.contains(r.getType()))
.collect(ImmutableList.toImmutableList());
consoleApiParams.response().setPayload(gson.toJson(registrars));

View File

@@ -99,10 +99,15 @@ class RegistrarsActionTest {
new JpaTestExtensions.Builder().buildIntegrationTestExtension();
@Test
void testSuccess_onlyRealRegistrars() {
void testSuccess_onlyRealAndOteRegistrars() {
Registrar registrar = persistNewRegistrar("registrarId");
registrar = registrar.asBuilder().setType(Registrar.Type.TEST).setIanaIdentifier(null).build();
persistResource(registrar);
registrar = persistNewRegistrar("registrarId2");
registrar = registrar.asBuilder().setType(Registrar.Type.OTE).setIanaIdentifier(null).build();
persistResource(registrar);
RegistrarsAction action =
createAction(
Action.Method.GET,
@@ -114,11 +119,13 @@ class RegistrarsActionTest {
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
.isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
String payload = ((FakeResponse) consoleApiParams.response()).getPayload();
assertThat(
ImmutableList.of("\"registrarId\":\"NewRegistrar\"", "\"registrarId\":\"TheRegistrar\"")
.stream()
.allMatch(s -> payload.contains(s)))
.isTrue();
var actualRegistrarIds =
ImmutableList.copyOf(GSON.fromJson(payload, Registrar[].class)).stream()
.map(r -> r.getRegistrarId())
.collect(Collectors.toList());
assertThat(actualRegistrarIds).containsExactly("NewRegistrar", "TheRegistrar", "registrarId2");
}
@Test