Ensure multi-recipient messages are addressed to ACI service IDs
This commit is contained in:
parent
e4ffc932a9
commit
6fa6c3c81c
|
@ -717,6 +717,13 @@ public class MessageController {
|
||||||
final @NotNull CombinedUnidentifiedSenderAccessKeys accessKeys,
|
final @NotNull CombinedUnidentifiedSenderAccessKeys accessKeys,
|
||||||
final Collection<MultiRecipientDeliveryData> destinations) {
|
final Collection<MultiRecipientDeliveryData> destinations) {
|
||||||
final int keyLength = UnidentifiedAccessUtil.UNIDENTIFIED_ACCESS_KEY_LENGTH;
|
final int keyLength = UnidentifiedAccessUtil.UNIDENTIFIED_ACCESS_KEY_LENGTH;
|
||||||
|
|
||||||
|
if (destinations.stream()
|
||||||
|
.anyMatch(destination -> IdentityType.PNI.equals(destination.serviceIdentifier.identityType()))) {
|
||||||
|
throw new WebApplicationException("Multi-recipient messages must be addressed to ACI service IDs",
|
||||||
|
Status.UNAUTHORIZED);
|
||||||
|
}
|
||||||
|
|
||||||
final byte[] combinedUnidentifiedAccessKeys = destinations.stream()
|
final byte[] combinedUnidentifiedAccessKeys = destinations.stream()
|
||||||
.map(MultiRecipientDeliveryData::account)
|
.map(MultiRecipientDeliveryData::account)
|
||||||
.filter(Predicate.not(Account::isUnrestrictedUnidentifiedAccess))
|
.filter(Predicate.not(Account::isUnrestrictedUnidentifiedAccess))
|
||||||
|
|
|
@ -1343,10 +1343,10 @@ class MessageControllerTest {
|
||||||
new MultiRecipientMessageTestCase(bothAccountsMixed, auth, story, 200, 4),
|
new MultiRecipientMessageTestCase(bothAccountsMixed, auth, story, 200, 4),
|
||||||
new MultiRecipientMessageTestCase(realAndFakeMixed, auth, story, 200, 4),
|
new MultiRecipientMessageTestCase(realAndFakeMixed, auth, story, 200, 4),
|
||||||
|
|
||||||
new MultiRecipientMessageTestCase(singleDevicePni, auth, notStory, 200, 1),
|
new MultiRecipientMessageTestCase(singleDevicePni, auth, notStory, 401, 0),
|
||||||
new MultiRecipientMessageTestCase(singleDeviceAciAndPni, unauth, story, 200, 2),
|
new MultiRecipientMessageTestCase(singleDeviceAciAndPni, auth, notStory, 401, 0),
|
||||||
new MultiRecipientMessageTestCase(multiDevicePni, auth, notStory, 200, 3),
|
new MultiRecipientMessageTestCase(multiDevicePni, auth, notStory, 401, 0),
|
||||||
new MultiRecipientMessageTestCase(bothAccountsMixed, auth, notStory, 200, 4),
|
new MultiRecipientMessageTestCase(bothAccountsMixed, auth, notStory, 401, 0),
|
||||||
new MultiRecipientMessageTestCase(realAndFakeMixed, auth, notStory, 404, 0))
|
new MultiRecipientMessageTestCase(realAndFakeMixed, auth, notStory, 404, 0))
|
||||||
.argumentsForNextParameter(false, true); // urgent
|
.argumentsForNextParameter(false, true); // urgent
|
||||||
}
|
}
|
||||||
|
@ -1580,10 +1580,10 @@ class MessageControllerTest {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@Test
|
||||||
@MethodSource
|
void sendMultiRecipientMessageMismatchedDevices() throws JsonProcessingException {
|
||||||
void sendMultiRecipientMessageMismatchedDevices(final ServiceIdentifier serviceIdentifier)
|
|
||||||
throws JsonProcessingException {
|
final ServiceIdentifier serviceIdentifier = MULTI_DEVICE_ACI_ID;
|
||||||
|
|
||||||
final byte extraDeviceId = MULTI_DEVICE_ID3 + 1;
|
final byte extraDeviceId = MULTI_DEVICE_ID3 + 1;
|
||||||
|
|
||||||
|
@ -1627,15 +1627,9 @@ class MessageControllerTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Stream<Arguments> sendMultiRecipientMessageMismatchedDevices() {
|
@Test
|
||||||
return Stream.of(
|
void sendMultiRecipientMessageStaleDevices() throws JsonProcessingException {
|
||||||
Arguments.of(MULTI_DEVICE_ACI_ID),
|
final ServiceIdentifier serviceIdentifier = MULTI_DEVICE_ACI_ID;
|
||||||
Arguments.of(MULTI_DEVICE_PNI_ID));
|
|
||||||
}
|
|
||||||
|
|
||||||
@ParameterizedTest
|
|
||||||
@MethodSource
|
|
||||||
void sendMultiRecipientMessageStaleDevices(final ServiceIdentifier serviceIdentifier) throws JsonProcessingException {
|
|
||||||
final List<Recipient> recipients = List.of(
|
final List<Recipient> recipients = List.of(
|
||||||
new Recipient(serviceIdentifier, MULTI_DEVICE_ID1, MULTI_DEVICE_REG_ID1 + 1, new byte[48]),
|
new Recipient(serviceIdentifier, MULTI_DEVICE_ID1, MULTI_DEVICE_REG_ID1 + 1, new byte[48]),
|
||||||
new Recipient(serviceIdentifier, MULTI_DEVICE_ID2, MULTI_DEVICE_REG_ID2 + 1, new byte[48]),
|
new Recipient(serviceIdentifier, MULTI_DEVICE_ID2, MULTI_DEVICE_REG_ID2 + 1, new byte[48]),
|
||||||
|
@ -1677,12 +1671,6 @@ class MessageControllerTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Stream<Arguments> sendMultiRecipientMessageStaleDevices() {
|
|
||||||
return Stream.of(
|
|
||||||
Arguments.of(MULTI_DEVICE_ACI_ID),
|
|
||||||
Arguments.of(MULTI_DEVICE_PNI_ID));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void sendMultiRecipientMessageStoryRateLimited() {
|
void sendMultiRecipientMessageStoryRateLimited() {
|
||||||
final List<Recipient> recipients = List.of(new Recipient(SINGLE_DEVICE_ACI_ID, SINGLE_DEVICE_ID1, SINGLE_DEVICE_REG_ID1, new byte[48]));
|
final List<Recipient> recipients = List.of(new Recipient(SINGLE_DEVICE_ACI_ID, SINGLE_DEVICE_ID1, SINGLE_DEVICE_REG_ID1, new byte[48]));
|
||||||
|
|
Loading…
Reference in New Issue