mirror of
https://github.com/signalapp/libsignal.git
synced 2026-04-25 17:25:18 +02:00
Use syntactically correct usernames to test server behavior
This commit is contained in:
@@ -23,6 +23,9 @@ import org.signal.libsignal.util.TestLogger;
|
||||
|
||||
public class ChatServiceConnectTests {
|
||||
private static final String USER_AGENT = "test";
|
||||
// A syntactically valid but non-existent ACI username for testing server rejection.
|
||||
private static final String FAKE_USERNAME = "90c979fd-eab4-4a08-b6da-69dedeab9b29.1";
|
||||
private static final String FAKE_PASSWORD = "password";
|
||||
|
||||
private static class Listener implements ChatConnectionListener {
|
||||
CompletableFuture<ChatServiceException> disconnectReason = new CompletableFuture<>();
|
||||
@@ -116,7 +119,8 @@ public class ChatServiceConnectTests {
|
||||
|
||||
final var e =
|
||||
assertThrows(
|
||||
ExecutionException.class, () -> net.connectAuthChat("", "", false, listener).get());
|
||||
ExecutionException.class,
|
||||
() -> net.connectAuthChat(FAKE_USERNAME, FAKE_PASSWORD, false, listener).get());
|
||||
assertTrue(e.getCause() instanceof DeviceDeregisteredException);
|
||||
}
|
||||
|
||||
@@ -137,7 +141,8 @@ public class ChatServiceConnectTests {
|
||||
// use preconnects.
|
||||
final var e =
|
||||
assertThrows(
|
||||
ExecutionException.class, () -> net.connectAuthChat("", "", false, listener).get());
|
||||
ExecutionException.class,
|
||||
() -> net.connectAuthChat(FAKE_USERNAME, FAKE_PASSWORD, false, listener).get());
|
||||
assertTrue(e.getCause() instanceof DeviceDeregisteredException);
|
||||
}
|
||||
|
||||
|
||||
@@ -371,11 +371,17 @@ describe('chat service api', () => {
|
||||
// you can check the log lines for: "[authenticated] using preconnection".
|
||||
// We have to use an authenticated connection because that's the only one that's allowed to
|
||||
// use preconnects.
|
||||
await net.connectAuthenticatedChat('', '', true, {
|
||||
onIncomingMessage: sinon.stub(),
|
||||
onConnectionInterrupted: sinon.stub(),
|
||||
onQueueEmpty: sinon.stub(),
|
||||
});
|
||||
// Use a syntactically valid but non-existent ACI so the server rejects the credentials.
|
||||
await net.connectAuthenticatedChat(
|
||||
'90c979fd-eab4-4a08-b6da-69dedeab9b29.1',
|
||||
'password',
|
||||
true,
|
||||
{
|
||||
onIncomingMessage: sinon.stub(),
|
||||
onConnectionInterrupted: sinon.stub(),
|
||||
onQueueEmpty: sinon.stub(),
|
||||
}
|
||||
);
|
||||
assert.fail('should not have managed to authenticate');
|
||||
} catch (e) {
|
||||
assert.instanceOf(e, LibSignalErrorBase);
|
||||
|
||||
@@ -603,7 +603,12 @@ final class ChatConnectionTests: TestCaseBase {
|
||||
// you can check the log lines for: "[authenticated] using preconnection".
|
||||
// We have to use an authenticated connection because that's the only one that's allowed to
|
||||
// use preconnects.
|
||||
_ = try await net.connectAuthenticatedChat(username: "", password: "", receiveStories: false)
|
||||
// Use a syntactically valid but non-existent ACI so the server rejects the credentials.
|
||||
_ = try await net.connectAuthenticatedChat(
|
||||
username: "90c979fd-eab4-4a08-b6da-69dedeab9b29.1",
|
||||
password: "password",
|
||||
receiveStories: false
|
||||
)
|
||||
XCTFail("should not have managed to authenticate")
|
||||
} catch SignalError.deviceDeregistered(_:) {
|
||||
// expected error, okay
|
||||
|
||||
Reference in New Issue
Block a user