Handle null GAE user IDs gracefully (for non-admins) (#531)

Unfortunately in our testing environments, we're all admins so it's easy
to miss things like this.
This commit is contained in:
gbrodman 2020-03-26 14:29:05 -04:00 committed by GitHub
parent f1c46b8030
commit 2ff1026cfd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 3 deletions

View file

@ -224,7 +224,6 @@ public final class AppEngineRule extends ExternalResource {
.setEmailAddress("janedoe@theregistrar.com")
.setPhoneNumber("+1.1234567890")
.setTypes(ImmutableSet.of(RegistrarContact.Type.ADMIN))
.setGaeUserId(NEW_REGISTRAR_GAE_USER_ID)
.build();
}

View file

@ -127,7 +127,11 @@ public class RegistrarContactCommandTest extends CommandTestCase<RegistrarContac
"--email=jane.doe@example.com",
"--allow_console_access=true",
"NewRegistrar");
RegistrarContact registrarContact = loadRegistrar("NewRegistrar").getContacts().asList().get(1);
RegistrarContact registrarContact =
loadRegistrar("NewRegistrar").getContacts().stream()
.filter(rc -> rc.getEmailAddress().equals("jane.doe@example.com"))
.findFirst()
.get();
assertThat(registrarContact.getGaeUserId()).matches("-?[0-9]+");
}

View file

@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.request.auth.AuthenticatedRegistrarAccessor.Role.ADMIN;
import static google.registry.request.auth.AuthenticatedRegistrarAccessor.Role.OWNER;
import static google.registry.testing.AppEngineRule.makeRegistrar2;
import static google.registry.testing.AppEngineRule.makeRegistrarContact2;
import static google.registry.testing.AppEngineRule.makeRegistrarContact3;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.SqlHelper.saveRegistryLock;
@ -287,6 +288,8 @@ public final class RegistryLockGetActionTest {
public void testSuccess_lockAllowedForAdmin() {
// Locks are allowed for admins even when they're not enabled for the registrar
persistResource(makeRegistrar2().asBuilder().setRegistryLockAllowed(false).build());
// disallow the other user
persistResource(makeRegistrarContact2().asBuilder().setGaeUserId(null).build());
authResult = AuthResult.create(AuthLevel.USER, UserAuthInfo.create(user, true));
accessor =
AuthenticatedRegistrarAccessor.createForTesting(