This commit is contained in:
2026-09-23 08:58:56 +08:00
parent 2555eda797
commit 5c01b34503
23 changed files with 790 additions and 54 deletions
@@ -0,0 +1,40 @@
package com.baiyue.firstleg.lingxing;
import static org.assertj.core.api.Assertions.assertThat;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import java.net.URI;
import org.junit.jupiter.api.Test;
class LingxingBrowserSessionReaderTest {
private final ObjectMapper mapper = new ObjectMapper();
@Test
void rewritesDiscoverySocketToConfiguredEndpointAndKeepsTargetPath() {
URI result = LingxingBrowserSessionReader.rewriteWebSocketEndpoint(
URI.create("ws://127.0.0.1:9223/devtools/page/abc"),
URI.create("http://127.0.0.1:19222"));
assertThat(result.toString()).isEqualTo("ws://127.0.0.1:19222/devtools/page/abc");
assertThat(LingxingBrowserSessionReader.rewriteWebSocketEndpoint(
URI.create("ws://127.0.0.1:9223/devtools/page/abc"), URI.create("https://cdp.example.test")))
.hasScheme("wss");
}
@Test
void selectsOnlyOmsPageWithExactOriginAndPrefersLoggedInPage() throws Exception {
ArrayNode pages = (ArrayNode) mapper.readTree("""
[
{"type":"other","url":"https://oms.xlwms.com/app","webSocketDebuggerUrl":"ws://x/other"},
{"type":"page","url":"https://oms.xlwms.com.evil.test/app","webSocketDebuggerUrl":"ws://x/evil"},
{"type":"page","url":"https://oms.xlwms.com/login","webSocketDebuggerUrl":"ws://x/login"},
{"type":"page","url":"https://oms.xlwms.com/app","webSocketDebuggerUrl":"ws://x/app"}
]
""");
assertThat(LingxingBrowserSessionReader.selectPage(pages, "https://oms.xlwms.com").path("url").asText())
.isEqualTo("https://oms.xlwms.com/app");
}
}
@@ -6,6 +6,13 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
class LingxingTrackKeyVectorTest {
@Test
void acceptsAStandard32ByteKeyAfterOneBase64Decode() {
assertThat(LingxingDirectClient.buildTrackKey(
"POST", "{}", "MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDE="))
.isEqualTo("v2:0cA9d60u8HVKLHZRgbSCZJDOvec7bNGfg1tvJIFRIh4=");
}
@Test
void matchesNodeTrackKeyV2VectorWhenSecretIsProvided() {
String secret = System.getenv("LINGXING_TRACK_KEY_V2_SECRET_BASE64");