Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public OteAccountBuilder setReplaceExisting(boolean replaceExisting) {
}

/**
* Adds a {@link User} with Web Console access.
* Adds a {@link User} with {@link RegistrarRole#TECH_CONTACT} Web Console access.
*
* <p>NOTE: can be called more than once, adding multiple users. Each user will have access to all
* OT&amp;E Registrars.
Expand All @@ -197,7 +197,7 @@ public OteAccountBuilder addUser(String email) {
registrars.stream()
.collect(
toImmutableMap(
Registrar::getRegistrarId, _ -> RegistrarRole.ACCOUNT_MANAGER)))
Registrar::getRegistrarId, _ -> RegistrarRole.TECH_CONTACT)))
.build())
.build());
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,8 @@ protected void postHandler(User user) {
@Override
protected void getHandler(User user) {
checkArgument(!Strings.isNullOrEmpty(registrarId), "Missing registrarId parameter");
checkPermission(user, registrarId, ConsolePermission.CHECK_ONBOARDING_STATUS);

if (!user.getUserRoles().hasGlobalPermission(ConsolePermission.EDIT_REGISTRAR_DETAILS)) {
setFailedResponse("User doesn't have a permission to check OT&E status", SC_BAD_REQUEST);
return;
}

String baseRegistrarId = OteAccountBuilder.getBaseRegistrarId(registrarId);
tm().transact(
() -> {
Optional<Registrar> registrar = Registrar.loadByRegistrarId(registrarId);
Expand All @@ -147,6 +142,7 @@ protected void getHandler(User user) {
SC_BAD_REQUEST);
return;
}
String baseRegistrarId = OteAccountBuilder.getBaseRegistrarId(registrarId);
OteStats oteStats = OteStats.getFromRegistrar(baseRegistrarId);
var stats =
StatType.REQUIRED_STAT_TYPES.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package google.registry.model;

import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.console.ConsolePermission.CHECK_ONBOARDING_STATUS;
import static google.registry.model.console.ConsolePermission.EDIT_REGISTRAR_DETAILS;
import static google.registry.model.console.User.IAP_SECURED_WEB_APP_USER_ROLE;
import static google.registry.model.tld.Tld.TldState.GENERAL_AVAILABILITY;
import static google.registry.model.tld.Tld.TldState.START_DATE_SUNRISE;
Expand Down Expand Up @@ -109,8 +111,11 @@ private static void assertRegistrarExists(String registrarId, String tld) {
public static void verifyUser(String registrarId, String email) {
Optional<User> maybeUser = loadByKeyIfPresent(VKey.create(User.class, email));
assertThat(maybeUser).isPresent();
assertThat(maybeUser.get().getUserRoles().getRegistrarRoles().get(registrarId))
.isEqualTo(RegistrarRole.ACCOUNT_MANAGER);
User user = maybeUser.get();
assertThat(user.getUserRoles().getRegistrarRoles().get(registrarId))
.isEqualTo(RegistrarRole.TECH_CONTACT);
assertThat(user.getUserRoles().hasPermission(registrarId, EDIT_REGISTRAR_DETAILS)).isTrue();
assertThat(user.getUserRoles().hasPermission(registrarId, CHECK_ONBOARDING_STATUS)).isTrue();
}

public static void verifyIapPermission(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@

import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.OteAccountBuilderTest.verifyIapPermission;
import static google.registry.model.OteAccountBuilderTest.verifyUser;
import static google.registry.testing.CertificateSamples.SAMPLE_CERT2;
import static google.registry.testing.CertificateSamples.SAMPLE_CERT2_HASH;
import static google.registry.testing.DatabaseHelper.loadExistingUser;
import static google.registry.testing.DatabaseHelper.loadRegistrar;
import static google.registry.testing.DatabaseHelper.persistPremiumList;
import static google.registry.util.DateTimeUtils.START_INSTANT;
import static jakarta.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
import static jakarta.servlet.http.HttpServletResponse.SC_FORBIDDEN;
import static jakarta.servlet.http.HttpServletResponse.SC_OK;
Expand All @@ -27,20 +33,29 @@

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
import com.google.gson.reflect.TypeToken;
import google.registry.flows.certs.CertificateChecker;
import google.registry.model.OteStatsTestHelper;
import google.registry.model.console.GlobalRole;
import google.registry.model.console.RegistrarRole;
import google.registry.model.console.User;
import google.registry.model.console.UserRoles;
import google.registry.model.registrar.Registrar;
import google.registry.request.Action;
import google.registry.request.auth.AuthResult;
import google.registry.request.auth.AuthenticatedRegistrarAccessor;
import google.registry.testing.CloudTasksHelper;
import google.registry.testing.ConsoleApiParamsUtils;
import google.registry.testing.DeterministicStringGenerator;
import google.registry.testing.FakeResponse;
import google.registry.tools.IamClient;
import google.registry.ui.server.console.ConsoleOteAction.OteCreateData;
import google.registry.ui.server.console.settings.SecurityAction;
import google.registry.util.CidrAddressBlock;
import google.registry.util.StringGenerator;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -141,6 +156,10 @@ void testSuccess_oteCreated() {
"password", "abcdefghijklmnop"))
.containsExactlyEntriesIn(obsResponse);
assertThat(response.getStatus()).isEqualTo(SC_OK);
verifyUser("theregistrar-1", "contact@registry.example");
verifyUser("theregistrar-3", "contact@registry.example");
verifyUser("theregistrar-4", "contact@registry.example");
verifyUser("theregistrar-5", "contact@registry.example");
verifyIapPermission(
"contact@registry.example",
Optional.of("someRandomString@email.test"),
Expand All @@ -149,6 +168,132 @@ void testSuccess_oteCreated() {
iamClient);
}

@Test
void testSuccess_oteCreated_userCanConfigureSecurityAndCheckStatus() {
AuthResult fteAuthResult = AuthResult.createUser(fteUser);
ConsoleOteAction createOteAction =
createAction(
Action.Method.POST,
fteAuthResult,
"theregistrar",
Optional.of("someRandomString@email.test"),
Optional.of(new OteCreateData("theregistrar", "contact@registry.example")));
createOteAction.cloudTasksUtils = cloudTasksHelper.getTestCloudTasksUtils();
createOteAction.run();
assertThat(response.getStatus()).isEqualTo(SC_OK);

User createdOteUser = loadExistingUser("contact@registry.example");
AuthResult oteUserAuth = AuthResult.createUser(createdOteUser);

// Newly provisioned OT&E TECH_CONTACT user can check their own OT&E status
ConsoleOteAction statusAction =
createAction(
Action.Method.GET, oteUserAuth, "theregistrar-1", Optional.empty(), Optional.empty());
statusAction.run();
assertThat(response.getStatus()).isEqualTo(SC_OK);

// Newly provisioned OT&E TECH_CONTACT user cannot mint new OT&E accounts
ConsoleOteAction forbiddenCreateAction =
createAction(
Action.Method.POST,
oteUserAuth,
"anotherreg",
Optional.empty(),
Optional.of(new OteCreateData("anotherreg", "other@registry.example")));
forbiddenCreateAction.run();
assertThat(response.getStatus()).isEqualTo(SC_FORBIDDEN);

// Newly provisioned OT&E TECH_CONTACT user can self-service upload mTLS cert & IP allowlist
ConsoleApiParams securityParams = ConsoleApiParamsUtils.createFake(oteUserAuth);
when(securityParams.request().getMethod()).thenReturn(Action.Method.POST.toString());
FakeResponse securityResponse = (FakeResponse) securityParams.response();
CertificateChecker certificateChecker =
new CertificateChecker(
ImmutableSortedMap.of(START_INSTANT, 20825, Instant.parse("2020-09-01T00:00:00Z"), 398),
30,
15,
2048,
ImmutableSet.of("secp256r1", "secp384r1"),
clock);
AuthenticatedRegistrarAccessor registrarAccessor =
new AuthenticatedRegistrarAccessor(
oteUserAuth, "adminRegistrarId", Optional.empty(), () -> null);
Registrar updatedRegistrarParam =
loadRegistrar("theregistrar-1")
.asBuilder()
.setClientCertificate(SAMPLE_CERT2, Instant.parse("2024-04-15T00:00:00Z"))
.setIpAddressAllowList(ImmutableList.of(CidrAddressBlock.create("192.168.1.1/32")))
.build();
SecurityAction securityAction =
new SecurityAction(
securityParams,
certificateChecker,
registrarAccessor,
"theregistrar-1",
Optional.of(updatedRegistrarParam));
securityAction.run();
assertThat(securityResponse.getStatus()).isEqualTo(SC_OK);
Registrar persistedRegistrar = loadRegistrar("theregistrar-1");
assertThat(persistedRegistrar.getClientCertificateHash()).hasValue(SAMPLE_CERT2_HASH);
assertThat(persistedRegistrar.getIpAddressAllowList())
.containsExactly(CidrAddressBlock.create("192.168.1.1/32"));
}

@Test
void testFailure_getStatusMissingPermission() throws Exception {
OteStatsTestHelper.setupIncompleteOte("theregistrar");
User viewerUser =
user.asBuilder()
.setUserRoles(
new UserRoles.Builder()
.setRegistrarRoles(
ImmutableMap.of("theregistrar-1", RegistrarRole.ACCOUNT_MANAGER))
.build())
.build();
ConsoleOteAction viewerAction =
createAction(
Action.Method.GET,
AuthResult.createUser(viewerUser),
"theregistrar-1",
Optional.empty(),
Optional.empty());
viewerAction.run();
assertThat(response.getStatus()).isEqualTo(SC_FORBIDDEN);

User otherRegistrarUser =
user.asBuilder()
.setUserRoles(
new UserRoles.Builder()
.setRegistrarRoles(
ImmutableMap.of("otherregistrar-1", RegistrarRole.TECH_CONTACT))
.build())
.build();
ConsoleOteAction crossRegistrarAction =
createAction(
Action.Method.GET,
AuthResult.createUser(otherRegistrarUser),
"theregistrar-1",
Optional.empty(),
Optional.empty());
crossRegistrarAction.run();
assertThat(response.getStatus()).isEqualTo(SC_FORBIDDEN);
}

@Test
void testFailure_getStatusNonOteRegistrar() {
ConsoleOteAction action =
createAction(
Action.Method.GET,
AuthResult.createUser(fteUser),
"TheRegistrar",
Optional.empty(),
Optional.empty());
action.run();
assertThat(response.getStatus()).isEqualTo(SC_BAD_REQUEST);
assertThat(response.getPayload())
.isEqualTo("Registrar with ID TheRegistrar is not an OT&E registrar");
}

@Test
void testFail_statusMissingParam() {
AuthResult authResult = AuthResult.createUser(user);
Expand Down
Loading