mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-12-02 11:46:53 +00:00
Update metrics for spam reports from numberless accounts
This commit is contained in:
1 parent
0117ed1a0b
commit
a3d01a94d4
6 files changed
+59
-49
No files matched your search
+23
-21
@@ -719,12 +719,12 @@ class MessageControllerTest {
|
||||
final UUID senderAci = UUID.randomUUID();
|
||||
final UUID senderPni = UUID.randomUUID();
|
||||
final String userAgent = "user-agent";
|
||||
UUID messageGuid = UUID.randomUUID();
|
||||
final UUID messageGuid = UUID.randomUUID();
|
||||
|
||||
final Account account = mock(Account.class);
|
||||
when(account.getAccountIdentifier()).thenReturn(senderAci);
|
||||
when(account.getNumber()).thenReturn(senderNumber);
|
||||
when(account.getPhoneNumberIdentifier()).thenReturn(senderPni);
|
||||
when(account.getNumberOptional()).thenReturn(Optional.of(senderNumber));
|
||||
when(account.getPhoneNumberIdentifierOptional()).thenReturn(Optional.of(senderPni));
|
||||
|
||||
when(accountsManager.getByE164(senderNumber)).thenReturn(Optional.of(account));
|
||||
|
||||
@@ -739,24 +739,24 @@ class MessageControllerTest {
|
||||
assertThat(response.getStatus(), is(equalTo(202)));
|
||||
|
||||
verify(reportMessageManager).report(Optional.of(senderNumber), Optional.of(senderAci), Optional.of(senderPni),
|
||||
messageGuid, AuthHelper.VALID_UUID, Optional.empty(), userAgent);
|
||||
messageGuid, AuthHelper.VALID_UUID, Optional.empty(), userAgent, false);
|
||||
verify(accountsManager, never()).findRecentlyDeletedPhoneNumberIdentifier(any(UUID.class));
|
||||
verify(phoneNumberIdentifiers, never()).getPhoneNumber(any());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testReportMesageByE164DeletedAccount() {
|
||||
void testReportMessageByE164DeletedAccount() {
|
||||
final String senderNumber = "+12125550001";
|
||||
final UUID senderAci = UUID.randomUUID();
|
||||
final UUID senderPni = UUID.randomUUID();
|
||||
final String userAgent = "user-agent";
|
||||
UUID messageGuid = UUID.randomUUID();
|
||||
final UUID messageGuid = UUID.randomUUID();
|
||||
|
||||
final Account account = mock(Account.class);
|
||||
when(account.getAccountIdentifier()).thenReturn(senderAci);
|
||||
when(account.getNumber()).thenReturn(senderNumber);
|
||||
when(account.getPhoneNumberIdentifier()).thenReturn(senderPni);
|
||||
when(account.getNumberOptional()).thenReturn(Optional.of(senderNumber));
|
||||
when(account.getPhoneNumberIdentifierOptional()).thenReturn(Optional.of(senderPni));
|
||||
|
||||
when(accountsManager.getByE164(senderNumber)).thenReturn(Optional.empty());
|
||||
when(phoneNumberIdentifiers.getPhoneNumberIdentifier(senderNumber)).thenReturn(CompletableFuture.completedFuture(senderPni));
|
||||
@@ -773,7 +773,7 @@ class MessageControllerTest {
|
||||
assertThat(response.getStatus(), is(equalTo(202)));
|
||||
|
||||
verify(reportMessageManager).report(Optional.of(senderNumber), Optional.of(senderAci), Optional.of(senderPni),
|
||||
messageGuid, AuthHelper.VALID_UUID, Optional.empty(), userAgent);
|
||||
messageGuid, AuthHelper.VALID_UUID, Optional.empty(), userAgent, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -787,8 +787,8 @@ class MessageControllerTest {
|
||||
|
||||
final Account account = mock(Account.class);
|
||||
when(account.getAccountIdentifier()).thenReturn(senderAci);
|
||||
when(account.getNumber()).thenReturn(senderNumber);
|
||||
when(account.getPhoneNumberIdentifier()).thenReturn(senderPni);
|
||||
when(account.getNumberOptional()).thenReturn(Optional.of(senderNumber));
|
||||
when(account.getPhoneNumberIdentifierOptional()).thenReturn(Optional.of(senderPni));
|
||||
|
||||
when(accountsManager.getByAccountIdentifier(senderAci)).thenReturn(Optional.of(account));
|
||||
when(phoneNumberIdentifiers.getPhoneNumber(senderPni)).thenReturn(CompletableFuture.completedFuture(List.of(senderNumber)));
|
||||
@@ -804,7 +804,7 @@ class MessageControllerTest {
|
||||
assertThat(response.getStatus(), is(equalTo(202)));
|
||||
|
||||
verify(reportMessageManager).report(Optional.of(senderNumber), Optional.of(senderAci), Optional.of(senderPni),
|
||||
messageGuid, AuthHelper.VALID_UUID, Optional.empty(), userAgent);
|
||||
messageGuid, AuthHelper.VALID_UUID, Optional.empty(), userAgent, false);
|
||||
verify(accountsManager, never()).findRecentlyDeletedPhoneNumberIdentifier(any(UUID.class));
|
||||
verify(phoneNumberIdentifiers, never()).getPhoneNumber(any());
|
||||
}
|
||||
@@ -820,8 +820,8 @@ class MessageControllerTest {
|
||||
|
||||
final Account account = mock(Account.class);
|
||||
when(account.getAccountIdentifier()).thenReturn(senderAci);
|
||||
when(account.getNumber()).thenReturn(senderNumber);
|
||||
when(account.getPhoneNumberIdentifier()).thenReturn(senderPni);
|
||||
when(account.getNumberOptional()).thenReturn(Optional.of(senderNumber));
|
||||
when(account.getPhoneNumberIdentifierOptional()).thenReturn(Optional.of(senderPni));
|
||||
|
||||
when(accountsManager.getByAccountIdentifier(senderAci)).thenReturn(Optional.empty());
|
||||
when(accountsManager.findRecentlyDeletedPhoneNumberIdentifier(senderAci)).thenReturn(Optional.of(senderPni));
|
||||
@@ -838,7 +838,7 @@ class MessageControllerTest {
|
||||
assertThat(response.getStatus(), is(equalTo(202)));
|
||||
|
||||
verify(reportMessageManager).report(Optional.of(senderNumber), Optional.of(senderAci), Optional.of(senderPni),
|
||||
messageGuid, AuthHelper.VALID_UUID, Optional.empty(), userAgent);
|
||||
messageGuid, AuthHelper.VALID_UUID, Optional.empty(), userAgent, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -852,8 +852,8 @@ class MessageControllerTest {
|
||||
|
||||
final Account account = mock(Account.class);
|
||||
when(account.getAccountIdentifier()).thenReturn(senderAci);
|
||||
when(account.getNumber()).thenReturn(senderNumber);
|
||||
when(account.getPhoneNumberIdentifier()).thenReturn(senderPni);
|
||||
when(account.getNumberOptional()).thenReturn(Optional.of(senderNumber));
|
||||
when(account.getPhoneNumberIdentifierOptional()).thenReturn(Optional.of(senderPni));
|
||||
|
||||
when(accountsManager.getByAccountIdentifier(senderAci)).thenReturn(Optional.of(account));
|
||||
when(accountsManager.findRecentlyDeletedPhoneNumberIdentifier(senderAci)).thenReturn(Optional.of(senderPni));
|
||||
@@ -875,7 +875,8 @@ class MessageControllerTest {
|
||||
eq(messageGuid),
|
||||
eq(AuthHelper.VALID_UUID),
|
||||
argThat(maybeBytes -> maybeBytes.map(bytes -> Arrays.equals(bytes, new byte[3])).orElse(false)),
|
||||
any());
|
||||
any(),
|
||||
eq(false));
|
||||
verify(accountsManager, never()).findRecentlyDeletedPhoneNumberIdentifier(any(UUID.class));
|
||||
verify(phoneNumberIdentifiers, never()).getPhoneNumber(any());
|
||||
}
|
||||
@@ -900,7 +901,8 @@ class MessageControllerTest {
|
||||
eq(messageGuid),
|
||||
eq(AuthHelper.VALID_UUID),
|
||||
argThat(maybeBytes -> maybeBytes.map(bytes -> Arrays.equals(bytes, new byte[5])).orElse(false)),
|
||||
any());
|
||||
any(),
|
||||
eq(true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -915,8 +917,8 @@ class MessageControllerTest {
|
||||
|
||||
final Account account = mock(Account.class);
|
||||
when(account.getAccountIdentifier()).thenReturn(senderAci);
|
||||
when(account.getNumber()).thenReturn(senderNumber);
|
||||
when(account.getPhoneNumberIdentifier()).thenReturn(senderPni);
|
||||
when(account.getNumberOptional()).thenReturn(Optional.of(senderNumber));
|
||||
when(account.getPhoneNumberIdentifierOptional()).thenReturn(Optional.of(senderPni));
|
||||
|
||||
when(accountsManager.getByAccountIdentifier(senderAci)).thenReturn(Optional.of(account));
|
||||
when(accountsManager.findRecentlyDeletedPhoneNumberIdentifier(senderAci)).thenReturn(Optional.of(senderPni));
|
||||
|
||||
+8
-9
@@ -55,8 +55,7 @@ class ReportMessageManagerTest {
|
||||
|
||||
sourceAccount = mock(Account.class);
|
||||
when(sourceAccount.getAccountIdentifier()).thenReturn(sourceAci);
|
||||
when(sourceAccount.getNumber()).thenReturn(sourceNumber);
|
||||
when(sourceAccount.getPhoneNumberIdentifier()).thenReturn(sourcePni);
|
||||
when(sourceAccount.getPhoneNumberIdentifierOptional()).thenReturn(Optional.of(sourcePni));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,16 +81,16 @@ class ReportMessageManagerTest {
|
||||
|
||||
when(reportMessageDynamoDb.remove(any())).thenReturn(false);
|
||||
reportMessageManager.report(Optional.of(sourceNumber), Optional.of(sourceAci), Optional.of(sourcePni), messageGuid,
|
||||
reporterUuid, Optional.empty(), "user-agent");
|
||||
reporterUuid, Optional.empty(), "user-agent", false);
|
||||
|
||||
assertEquals(0, reportMessageManager.getRecentReportCount(sourceAccount));
|
||||
|
||||
when(reportMessageDynamoDb.remove(any())).thenReturn(true);
|
||||
reportMessageManager.report(Optional.of(sourceNumber), Optional.of(sourceAci), Optional.of(sourcePni), messageGuid,
|
||||
reporterUuid, Optional.empty(), "user-agent");
|
||||
reporterUuid, Optional.empty(), "user-agent", false);
|
||||
|
||||
assertEquals(1, reportMessageManager.getRecentReportCount(sourceAccount));
|
||||
verify(listener).handleMessageReported(sourceNumber, messageGuid, reporterUuid, Optional.empty());
|
||||
verify(listener).handleMessageReported(Optional.of(sourceNumber), messageGuid, reporterUuid, Optional.empty(), false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,7 +100,7 @@ class ReportMessageManagerTest {
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
reportMessageManager.report(Optional.of(sourceNumber), Optional.of(sourceAci), Optional.of(sourcePni),
|
||||
messageGuid, UUID.randomUUID(), Optional.empty(), "user-agent");
|
||||
messageGuid, UUID.randomUUID(), Optional.empty(), "user-agent", false);
|
||||
}
|
||||
|
||||
assertTrue(reportMessageManager.getRecentReportCount(sourceAccount) > 10);
|
||||
@@ -115,7 +114,7 @@ class ReportMessageManagerTest {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
reportMessageManager.report(Optional.of(sourceNumber), Optional.of(sourceAci), Optional.of(sourcePni),
|
||||
messageGuid,
|
||||
reporterUuid, Optional.empty(), "user-agent");
|
||||
reporterUuid, Optional.empty(), "user-agent", false);
|
||||
}
|
||||
|
||||
assertEquals(1, reportMessageManager.getRecentReportCount(sourceAccount));
|
||||
@@ -128,11 +127,11 @@ class ReportMessageManagerTest {
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
reportMessageManager.report(Optional.empty(), Optional.of(sourceAci), Optional.of(sourcePni),
|
||||
messageGuid, UUID.randomUUID(), Optional.empty(), "user-agent");
|
||||
messageGuid, UUID.randomUUID(), Optional.empty(), "user-agent", false);
|
||||
}
|
||||
|
||||
reportMessageManager.report(Optional.empty(), Optional.of(sourceAci), Optional.empty(),
|
||||
messageGuid, UUID.randomUUID(), Optional.empty(), "user-agent");
|
||||
messageGuid, UUID.randomUUID(), Optional.empty(), "user-agent", false);
|
||||
|
||||
final int recentReportCount = reportMessageManager.getRecentReportCount(sourceAccount);
|
||||
assertTrue(recentReportCount > 10);
|
||||
|
||||
Reference in new issue
Block a user