mirror of
https://github.com/google/nomulus
synced 2026-01-07 14:05:44 +00:00
Add OTE registrars to console /registrars response (#2440)
This commit is contained in:
@@ -27,6 +27,7 @@ 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.model.registrar.RegistrarBase;
|
||||||
import google.registry.model.registrar.RegistrarBase.State;
|
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;
|
||||||
@@ -46,12 +47,15 @@ import javax.inject.Named;
|
|||||||
public class RegistrarsAction extends ConsoleApiAction {
|
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;
|
||||||
|
private static final ImmutableList<RegistrarBase.Type> allowedRegistrarTypes =
|
||||||
|
ImmutableList.of(Registrar.Type.REAL, RegistrarBase.Type.OTE);
|
||||||
static final String PATH = "/console-api/registrars";
|
static final String PATH = "/console-api/registrars";
|
||||||
private final Gson gson;
|
private final Gson gson;
|
||||||
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(
|
||||||
ConsoleApiParams consoleApiParams,
|
ConsoleApiParams consoleApiParams,
|
||||||
@@ -72,9 +76,10 @@ public class RegistrarsAction extends ConsoleApiAction {
|
|||||||
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_FORBIDDEN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImmutableList<Registrar> registrars =
|
ImmutableList<Registrar> registrars =
|
||||||
Streams.stream(Registrar.loadAll())
|
Streams.stream(Registrar.loadAll())
|
||||||
.filter(r -> r.getType() == Registrar.Type.REAL)
|
.filter(r -> allowedRegistrarTypes.contains(r.getType()))
|
||||||
.collect(ImmutableList.toImmutableList());
|
.collect(ImmutableList.toImmutableList());
|
||||||
|
|
||||||
consoleApiParams.response().setPayload(gson.toJson(registrars));
|
consoleApiParams.response().setPayload(gson.toJson(registrars));
|
||||||
|
|||||||
@@ -99,10 +99,15 @@ class RegistrarsActionTest {
|
|||||||
new JpaTestExtensions.Builder().buildIntegrationTestExtension();
|
new JpaTestExtensions.Builder().buildIntegrationTestExtension();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testSuccess_onlyRealRegistrars() {
|
void testSuccess_onlyRealAndOteRegistrars() {
|
||||||
Registrar registrar = persistNewRegistrar("registrarId");
|
Registrar registrar = persistNewRegistrar("registrarId");
|
||||||
registrar = registrar.asBuilder().setType(Registrar.Type.TEST).setIanaIdentifier(null).build();
|
registrar = registrar.asBuilder().setType(Registrar.Type.TEST).setIanaIdentifier(null).build();
|
||||||
persistResource(registrar);
|
persistResource(registrar);
|
||||||
|
|
||||||
|
registrar = persistNewRegistrar("registrarId2");
|
||||||
|
registrar = registrar.asBuilder().setType(Registrar.Type.OTE).setIanaIdentifier(null).build();
|
||||||
|
persistResource(registrar);
|
||||||
|
|
||||||
RegistrarsAction action =
|
RegistrarsAction action =
|
||||||
createAction(
|
createAction(
|
||||||
Action.Method.GET,
|
Action.Method.GET,
|
||||||
@@ -114,11 +119,13 @@ class RegistrarsActionTest {
|
|||||||
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
assertThat(((FakeResponse) consoleApiParams.response()).getStatus())
|
||||||
.isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
.isEqualTo(HttpStatusCodes.STATUS_CODE_OK);
|
||||||
String payload = ((FakeResponse) consoleApiParams.response()).getPayload();
|
String payload = ((FakeResponse) consoleApiParams.response()).getPayload();
|
||||||
assertThat(
|
|
||||||
ImmutableList.of("\"registrarId\":\"NewRegistrar\"", "\"registrarId\":\"TheRegistrar\"")
|
var actualRegistrarIds =
|
||||||
.stream()
|
ImmutableList.copyOf(GSON.fromJson(payload, Registrar[].class)).stream()
|
||||||
.allMatch(s -> payload.contains(s)))
|
.map(r -> r.getRegistrarId())
|
||||||
.isTrue();
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
assertThat(actualRegistrarIds).containsExactly("NewRegistrar", "TheRegistrar", "registrarId2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user