Normalize the account parameter of the SSE endpoint (#2171)

The account of JSON-RPC requests is normalized with
AccountIdentifier.normalize, so an ACI without dashes or in upper case
works there. The account query parameter of /api/v1/events was not, so
the same account identifier was rejected for the events.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ryan SandClaude Opus 5.5 authored and GitHub committed 2026-11-13 20:51:28 +01:00
1 parent 67449bba9a
commit 6c69d3d238
2 files changed
+69 -1

No files matched your search

@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpServer;
import org.asamk.signal.AccountIdentifier;
import org.asamk.signal.commands.Commands;
import org.asamk.signal.jsonrpc.JsonRpcReader;
import org.asamk.signal.jsonrpc.JsonRpcResponse;
@@ -279,7 +280,7 @@ public class HttpServerHandler implements AutoCloseable {
if (account == null || account.isEmpty()) {
return c.getManagers();
} else {
final var manager = c.getManager(account);
final var manager = c.getManager(AccountIdentifier.normalize(account));
if (manager == null) {
// Account not found by the given identifier (number or ACI/UUID)
// Log the available accounts to help debug
@@ -0,0 +1,67 @@
package org.asamk.signal.http;
import org.asamk.signal.manager.internal.MultiAccountManagerImpl;
import org.asamk.signal.testutil.ManagerMock;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.URI;
import java.time.Duration;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* The account query parameter of GET /api/v1/events accepts the same account identifiers as the JSON-RPC
* account parameter.
*/
class SseAccountParameterTest {
private HttpServerHandler handler;
private int port;
@AfterEach
void tearDown() {
if (handler != null) {
handler.close();
}
}
@Test
void acceptsAciWithoutDashes() throws Exception {
start();
// ManagerMock's ACI is 00000000-0000-0000-0000-000000000000
assertEquals(200, connect("00000000000000000000000000000000"));
}
@Test
void acceptsAciWithDashes() throws Exception {
start();
assertEquals(200, connect("00000000-0000-0000-0000-000000000000"));
}
private void start() throws Exception {
try (var ss = new ServerSocket(0)) {
port = ss.getLocalPort();
}
handler = new HttpServerHandler(new InetSocketAddress("127.0.0.1", port),
Duration.ofSeconds(15),
new MultiAccountManagerImpl(List.of(ManagerMock.create("+10000000000")), null));
handler.init();
}
private int connect(final String account) throws Exception {
final var url = URI.create("http://127.0.0.1:" + port + "/api/v1/events?account=" + account).toURL();
final var connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(2_000);
connection.setReadTimeout(5_000);
try {
return connection.getResponseCode();
} finally {
connection.disconnect();
}
}
}