mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-12-01 09:36:47 +00:00
Avoid attribute modification errors on numberless accounts
This commit is contained in:
1 parent
23932b1087
commit
74bd9754a0
4 files changed
+35
-2
No files matched your search
+4
@@ -239,6 +239,10 @@ public class AccountController {
|
||||
}
|
||||
});
|
||||
|
||||
if (StringUtils.isNotEmpty(attributes.getRegistrationLock()) && a.getNumber().isEmpty()) {
|
||||
throw new BadRequestException("account does not have a phone number");
|
||||
}
|
||||
|
||||
a.setRegistrationLockFromAttributes(attributes);
|
||||
a.setUnidentifiedAccessKey(attributes.getUnidentifiedAccessKey());
|
||||
a.setUnrestrictedUnidentifiedAccess(attributes.isUnrestrictedUnidentifiedAccess());
|
||||
|
||||
@@ -475,10 +475,11 @@ public class Account {
|
||||
}
|
||||
}
|
||||
|
||||
public void setRegistrationLock(final String registrationLock, final String registrationLockSalt) {
|
||||
public void setRegistrationLock(@Nullable final String registrationLock, @Nullable final String registrationLockSalt) {
|
||||
requireNotStale();
|
||||
|
||||
if (number == null) {
|
||||
// Accounts without a phone number can't set a registration lock
|
||||
if (number == null && (registrationLock != null || registrationLockSalt != null)) {
|
||||
throw new IllegalArgumentException("Cannot set registration lock on account with no phone number");
|
||||
}
|
||||
|
||||
|
||||
+13
@@ -869,6 +869,19 @@ class AccountControllerTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSetAccountAttributesRegistrationLockWithNoNumber() {
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
.target("/v1/accounts/attributes/")
|
||||
.request()
|
||||
.header(HttpHeaders.AUTHORIZATION, AuthHelper.getAuthHeader(AuthHelper.NUMBERLESS_UUID, AuthHelper.NUMBERLESS_PASSWORD))
|
||||
.put(Entity.json(new AccountAttributes(false, 2222, 3333, null, "1234", false, null, null)
|
||||
.setUnidentifiedAccessKey(new byte[16])))) {
|
||||
|
||||
assertThat(response.getStatus()).isEqualTo(422);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSetAccountAttributesEnableDiscovery() {
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.whispersystems.textsecuregcm.auth.StoredRegistrationLock;
|
||||
import org.whispersystems.textsecuregcm.tests.util.AccountsHelper;
|
||||
import org.whispersystems.textsecuregcm.util.SystemMapper;
|
||||
import org.whispersystems.textsecuregcm.util.TestClock;
|
||||
@@ -108,6 +109,20 @@ class AccountTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSetRegistrationLockWithNoPhoneNumber() {
|
||||
final Account numberlessAccount =
|
||||
AccountsHelper.generateTestAccount(null, UUID.randomUUID(), null, List.of(recentPrimaryDevice), null);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> numberlessAccount.setRegistrationLock("hash", "salt"),
|
||||
"Accounts without phone numbers should never have a registration lock");
|
||||
|
||||
assertDoesNotThrow(() -> numberlessAccount.setRegistrationLock(null, null),
|
||||
"Clearing a registration lock an account never had should be a no-op");
|
||||
|
||||
assertEquals(StoredRegistrationLock.Status.ABSENT, numberlessAccount.getRegistrationLock().getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDiscoverableByPhoneNumber() {
|
||||
final Account account = AccountsHelper.generateTestAccount("+14152222222", UUID.randomUUID(), UUID.randomUUID(), List.of(recentPrimaryDevice),
|
||||
|
||||
Reference in new issue
Block a user