Fix for PubSub channel.

1) Create channels based on numbers rather than DB row ids.

2) Ensure that stored messages are cleared at reregistration
   time.
This commit is contained in:
Moxie Marlinspike
2014-07-26 20:41:25 -07:00
parent 4eb88a3e02
commit c9a1386a55
12 changed files with 77 additions and 91 deletions

View File

@@ -13,6 +13,7 @@ import org.whispersystems.textsecuregcm.sms.SmsSender;
import org.whispersystems.textsecuregcm.storage.Account;
import org.whispersystems.textsecuregcm.storage.AccountsManager;
import org.whispersystems.textsecuregcm.storage.PendingAccountsManager;
import org.whispersystems.textsecuregcm.storage.StoredMessages;
import org.whispersystems.textsecuregcm.tests.util.AuthHelper;
import javax.ws.rs.core.MediaType;
@@ -31,6 +32,7 @@ public class AccountControllerTest {
private RateLimiters rateLimiters = mock(RateLimiters.class );
private RateLimiter rateLimiter = mock(RateLimiter.class );
private SmsSender smsSender = mock(SmsSender.class );
private StoredMessages storedMessages = mock(StoredMessages.class );
@Rule
public final ResourceTestRule resources = ResourceTestRule.builder()
@@ -38,7 +40,8 @@ public class AccountControllerTest {
.addResource(new AccountController(pendingAccountsManager,
accountsManager,
rateLimiters,
smsSender))
smsSender,
storedMessages))
.build();

View File

@@ -94,7 +94,6 @@ public class WebsocketControllerTest {
}};
when(device.getId()).thenReturn(2L);
when(account.getId()).thenReturn(31337L);
when(account.getAuthenticatedDevice()).thenReturn(Optional.of(device));
when(account.getNumber()).thenReturn("+14152222222");
when(session.getRemote()).thenReturn(remote);
@@ -120,7 +119,7 @@ public class WebsocketControllerTest {
when(accountAuthenticator.authenticate(eq(new BasicCredentials(VALID_USER, VALID_PASSWORD))))
.thenReturn(Optional.of(account));
when(storedMessages.getMessagesForDevice(account.getId(), device.getId()))
when(storedMessages.getMessagesForDevice(new WebsocketAddress(account.getNumber(), device.getId())))
.thenReturn(outgoingMessages);
WebsocketControllerFactory factory = new WebsocketControllerFactory(accountAuthenticator, accountsManager, pushSender, storedMessages, pubSubManager);
@@ -128,7 +127,7 @@ public class WebsocketControllerTest {
controller.onWebSocketConnect(session);
verify(pubSubManager).subscribe(eq(new WebsocketAddress(31337L, 2L)), eq((controller)));
verify(pubSubManager).subscribe(eq(new WebsocketAddress("+14152222222", 2L)), eq((controller)));
verify(remote, times(3)).sendStringByFuture(anyString());
controller.onWebSocketText(mapper.writeValueAsString(new AcknowledgeWebsocketMessage(1)));