From 0a8db1776848ed19f70f0a6cf9875ee2e5555f1b Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Wed, 29 Nov 2023 12:45:14 +0530 Subject: [PATCH 1/3] [java] WebSocket connection for vnc session is not using the --sub-path argument Signed-off-by: Viet Nguyen Duc --- .../selenium/grid/node/local/LocalNode.java | 3 ++ .../grid/node/config/NodeOptionsTest.java | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/java/src/org/openqa/selenium/grid/node/local/LocalNode.java b/java/src/org/openqa/selenium/grid/node/local/LocalNode.java index 4c11c15209ca3..9f9e2a3ab6ad9 100644 --- a/java/src/org/openqa/selenium/grid/node/local/LocalNode.java +++ b/java/src/org/openqa/selenium/grid/node/local/LocalNode.java @@ -838,6 +838,9 @@ private Session createExternalSession( private URI rewrite(String path) { try { String scheme = "https".equals(gridUri.getScheme()) ? "wss" : "ws"; + if (gridUri.getPath() != null && !gridUri.getPath().isEmpty()) { + path = gridUri.getPath() + path; + } return new URI( scheme, gridUri.getUserInfo(), gridUri.getHost(), gridUri.getPort(), path, null, null); } catch (URISyntaxException e) { diff --git a/java/test/org/openqa/selenium/grid/node/config/NodeOptionsTest.java b/java/test/org/openqa/selenium/grid/node/config/NodeOptionsTest.java index 6eff850a9db54..cdec80a3c41d5 100644 --- a/java/test/org/openqa/selenium/grid/node/config/NodeOptionsTest.java +++ b/java/test/org/openqa/selenium/grid/node/config/NodeOptionsTest.java @@ -235,6 +235,36 @@ void platformNameIsAddedByDefault() { .hasSize(reported.size()); } + @Test + void seVncUrlSeCdpUrlCapabilityWhenGridUrlWithSubPath() { + String gridUrl = "http://localhost:4444/subPath"; + Config config = new MapConfig(singletonMap("node", singletonMap("grid-url", gridUrl))); + + List reported = new ArrayList<>(); + NodeOptions nodeOptions = new NodeOptions(config); + NodeOptions nodeOptionsSpy = Mockito.spy(nodeOptions); + Mockito.doReturn(true).when(nodeOptionsSpy).isVncEnabled(); + nodeOptionsSpy.getSessionFactories( + caps -> { + reported.add(caps); + return Collections.singleton(HelperFactory.create(config, caps)); + }); + + assertThat(reported) + .filteredOn( + capabilities -> + capabilities.getCapability("se:vnc") != null + && String.valueOf(capabilities.getCapability("se:vnc")).contains(gridUrl)) + .hasSize(reported.size()); + + assertThat(reported) + .filteredOn( + capabilities -> + capabilities.getCapability("se:cdp") != null + && String.valueOf(capabilities.getCapability("se:cdp")).contains(gridUrl)) + .hasSize(reported.size()); + } + @Test void vncEnabledCapabilityIsAddedWhenEnvVarIsTrue() { Config config = new MapConfig(singletonMap("node", singletonMap("detect-drivers", "false"))); From cd953da610275a4d249aacb08eb98581366244da Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Wed, 29 Nov 2023 23:14:43 +0530 Subject: [PATCH 2/3] [java] Update unit test Signed-off-by: Viet Nguyen Duc --- .../grid/node/config/NodeOptionsTest.java | 30 ---------------- .../grid/node/local/LocalNodeTest.java | 34 +++++++++++++++++++ 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/java/test/org/openqa/selenium/grid/node/config/NodeOptionsTest.java b/java/test/org/openqa/selenium/grid/node/config/NodeOptionsTest.java index cdec80a3c41d5..6eff850a9db54 100644 --- a/java/test/org/openqa/selenium/grid/node/config/NodeOptionsTest.java +++ b/java/test/org/openqa/selenium/grid/node/config/NodeOptionsTest.java @@ -235,36 +235,6 @@ void platformNameIsAddedByDefault() { .hasSize(reported.size()); } - @Test - void seVncUrlSeCdpUrlCapabilityWhenGridUrlWithSubPath() { - String gridUrl = "http://localhost:4444/subPath"; - Config config = new MapConfig(singletonMap("node", singletonMap("grid-url", gridUrl))); - - List reported = new ArrayList<>(); - NodeOptions nodeOptions = new NodeOptions(config); - NodeOptions nodeOptionsSpy = Mockito.spy(nodeOptions); - Mockito.doReturn(true).when(nodeOptionsSpy).isVncEnabled(); - nodeOptionsSpy.getSessionFactories( - caps -> { - reported.add(caps); - return Collections.singleton(HelperFactory.create(config, caps)); - }); - - assertThat(reported) - .filteredOn( - capabilities -> - capabilities.getCapability("se:vnc") != null - && String.valueOf(capabilities.getCapability("se:vnc")).contains(gridUrl)) - .hasSize(reported.size()); - - assertThat(reported) - .filteredOn( - capabilities -> - capabilities.getCapability("se:cdp") != null - && String.valueOf(capabilities.getCapability("se:cdp")).contains(gridUrl)) - .hasSize(reported.size()); - } - @Test void vncEnabledCapabilityIsAddedWhenEnvVarIsTrue() { Config config = new MapConfig(singletonMap("node", singletonMap("detect-drivers", "false"))); diff --git a/java/test/org/openqa/selenium/grid/node/local/LocalNodeTest.java b/java/test/org/openqa/selenium/grid/node/local/LocalNodeTest.java index 9ee8b8dca7f54..6c36e67863d7d 100644 --- a/java/test/org/openqa/selenium/grid/node/local/LocalNodeTest.java +++ b/java/test/org/openqa/selenium/grid/node/local/LocalNodeTest.java @@ -279,6 +279,40 @@ void nodeDrainsAfterSessionCountIsReached() throws URISyntaxException { assertThat(localNode.isDraining()).isTrue(); } + @Test + void seVncCdpUrlCapabilityWhenGridUrlWithSubPath() throws URISyntaxException { + Tracer tracer = DefaultTestTracer.createTracer(); + EventBus bus = new GuavaEventBus(); + String gridUrl = "http://localhost:7890/subPath"; + URI uri = new URI(gridUrl); + Capabilities stereotype = new ImmutableCapabilities("se:vncLocalAddress", "ws://localhost:7900", + "se:cdp", "ws://localhost:9222/devtools/browser/1a2b3c4d5e6f"); + + LocalNode.Builder builder = + LocalNode.builder(tracer, bus, uri, uri, registrationSecret) + .enableCdp(true) + .add( + stereotype, + new TestSessionFactory( + (id, caps) -> new Session(id, uri, stereotype, caps, Instant.now()))); + LocalNode localNode = builder.build(); + + Either response = + localNode.newSession( + new CreateSessionRequest(ImmutableSet.of(W3C), stereotype, ImmutableMap.of())); + assertThat(response.isRight()).isTrue(); + + CreateSessionResponse sessionResponse = response.right(); + Capabilities capabilities = sessionResponse.getSession().getCapabilities(); + Object seVnc = capabilities.getCapability("se:vnc"); + assertThat(seVnc).isNotNull(); + assertThat(seVnc.toString().contains(gridUrl.replace("http", "ws"))).isTrue(); + + Object seCdp = capabilities.getCapability("se:cdp"); + assertThat(seCdp).isNotNull(); + assertThat(seCdp.toString().contains(gridUrl.replace("http", "ws"))).isTrue(); + } + @Test void cdpIsDisabledAndResponseCapsShowThat() throws URISyntaxException { Tracer tracer = DefaultTestTracer.createTracer(); From 1ae3f8d6f9ec52cb720a639600c70855134db662 Mon Sep 17 00:00:00 2001 From: snyk-bot Date: Fri, 1 Dec 2023 17:14:09 +0000 Subject: [PATCH 3/3] fix: upgrade @types/react from 18.2.31 to 18.2.37 Snyk has created this PR to upgrade @types/react from 18.2.31 to 18.2.37. See this package in npm: https://www.npmjs.com/package/@types/react See this project in Snyk: https://app.snyk.io/org/vietnd96/project/6c157220-6f2f-4f63-8ea2-77be21d916b9?utm_source=github&utm_medium=referral&page=upgrade-pr --- package-lock.json | 16 ++++++++-------- package.json | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 882abf2270a53..4b1dbc10b8b29 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "selenium", + "name": "npm-proj-1701450826169-0.59403090301774695exteh", "lockfileVersion": 2, "requires": true, "packages": { @@ -11,7 +11,7 @@ "@mui/icons-material": "^5.14.14", "@mui/material": "^5.14.14", "@novnc/novnc": "^1.4.0", - "@types/react": "^18.2.31", + "@types/react": "^18.2.37", "@types/react-dom": "^18.2.7", "@types/react-modal": "^3.16.0", "@types/react-router-dom": "^5.3.3", @@ -4867,9 +4867,9 @@ "dev": true }, "node_modules/@types/react": { - "version": "18.2.31", - "resolved": "https://registry.npmjs.org/@types/react/-/react-18.2.31.tgz", - "integrity": "sha512-c2UnPv548q+5DFh03y8lEDeMfDwBn9G3dRwfkrxQMo/dOtRHUUO57k6pHvBIfH/VF4Nh+98mZ5aaSe+2echD5g==", + "version": "18.2.37", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.2.37.tgz", + "integrity": "sha512-RGAYMi2bhRgEXT3f4B92WTohopH6bIXw05FuGlmJEnv/omEn190+QYEIYxIAuIBdKgboYYdVved2p1AxZVQnaw==", "dependencies": { "@types/prop-types": "*", "@types/scheduler": "*", @@ -26690,9 +26690,9 @@ "dev": true }, "@types/react": { - "version": "18.2.31", - "resolved": "https://registry.npmjs.org/@types/react/-/react-18.2.31.tgz", - "integrity": "sha512-c2UnPv548q+5DFh03y8lEDeMfDwBn9G3dRwfkrxQMo/dOtRHUUO57k6pHvBIfH/VF4Nh+98mZ5aaSe+2echD5g==", + "version": "18.2.37", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.2.37.tgz", + "integrity": "sha512-RGAYMi2bhRgEXT3f4B92WTohopH6bIXw05FuGlmJEnv/omEn190+QYEIYxIAuIBdKgboYYdVved2p1AxZVQnaw==", "requires": { "@types/prop-types": "*", "@types/scheduler": "*", diff --git a/package.json b/package.json index f27d961493679..d13f9ff5a9ee1 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "@mui/icons-material": "^5.14.14", "@mui/material": "^5.14.14", "@novnc/novnc": "^1.4.0", - "@types/react": "^18.2.31", + "@types/react": "^18.2.37", "@types/react-dom": "^18.2.7", "@types/react-modal": "^3.16.0", "@types/react-router-dom": "^5.3.3",