This is an automated email from the ASF dual-hosted git repository.
solomax pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openmeetings.git
The following commit(s) were added to refs/heads/master by this push:
new 8b0024e [OPENMEETINGS-2511] wssUrl should contain port
8b0024e is described below
commit 8b0024e9efc9e4b189ebc841e54287f4a38edba8
Author: Maxim Solodovnik <[email protected]>
AuthorDate: Mon Nov 16 09:21:44 2020 +0700
[OPENMEETINGS-2511] wssUrl should contain port
---
.../apache/openmeetings/web/app/Application.java | 19 +++++++----
.../web/app/TestApplicationMocked.java | 39 ++++++++++++++++++++++
2 files changed, 52 insertions(+), 6 deletions(-)
diff --git
a/openmeetings-web/src/main/java/org/apache/openmeetings/web/app/Application.java
b/openmeetings-web/src/main/java/org/apache/openmeetings/web/app/Application.java
index 5a1f10f..1b7baaf 100644
---
a/openmeetings-web/src/main/java/org/apache/openmeetings/web/app/Application.java
+++
b/openmeetings-web/src/main/java/org/apache/openmeetings/web/app/Application.java
@@ -114,6 +114,7 @@ import
org.apache.wicket.protocol.ws.WebSocketAwareCsrfPreventionRequestCycleLis
import org.apache.wicket.request.IRequestHandler;
import org.apache.wicket.request.Response;
import org.apache.wicket.request.Url;
+import org.apache.wicket.request.Url.StringMode;
import org.apache.wicket.request.component.IRequestablePage;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.http.WebResponse;
@@ -644,19 +645,25 @@ public class Application extends
AuthenticatedWebApplication implements IApplica
return wsUrl;
}
- private static String getWsUrl(Url reqUrl) {
+ // package private for testing
+ static String getWsUrl(Url reqUrl) {
if (!reqUrl.isFull()) {
return null;
}
final boolean insecure =
"http".equalsIgnoreCase(reqUrl.getProtocol());
String delim = ":";
- String port = reqUrl.getPort() == null || reqUrl.getPort() < 0
? "" : String.valueOf(reqUrl.getPort());
- if (!port.isEmpty() && ((insecure && 80 == reqUrl.getPort()) ||
(!insecure && 443 == reqUrl.getPort()))) {
+ String port;
+ if (reqUrl.getPort() == null || reqUrl.getPort() < 0
+ || (insecure && 80 == reqUrl.getPort())
+ || (!insecure && 443 == reqUrl.getPort()))
+ {
port = "";
- }
- if (port.isEmpty()) {
delim = "";
+ } else {
+ port = String.valueOf(reqUrl.getPort());
}
- return String.format("%s://%s%s%s", insecure ? "ws" : "wss",
reqUrl.getHost(), delim, port);
+ String url = (insecure ? "ws" : "wss") + "://" +
reqUrl.getHost() + delim + port;
+ log.debug("Getting WS url from '{}', result: '{}'",
reqUrl.toString(StringMode.FULL), url);
+ return url;
}
}
diff --git
a/openmeetings-web/src/test/java/org/apache/openmeetings/web/app/TestApplicationMocked.java
b/openmeetings-web/src/test/java/org/apache/openmeetings/web/app/TestApplicationMocked.java
new file mode 100644
index 0000000..7d5fa53
--- /dev/null
+++
b/openmeetings-web/src/test/java/org/apache/openmeetings/web/app/TestApplicationMocked.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") + you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openmeetings.web.app;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.apache.wicket.request.Url;
+import org.junit.jupiter.api.Test;
+
+class TestApplicationMocked {
+ @Test
+ void testWsUrlIncomplete() {
+ assertNull(Application.getWsUrl(Url.parse("./test")));
+ }
+
+ @Test
+ void testWsUrlNoPort() {
+ assertEquals("ws://www.com",
Application.getWsUrl(Url.parse("http://www.com/test?param#hash")));
+ assertEquals("wss://www.com",
Application.getWsUrl(Url.parse("https://www.com/test?param#hash")));
+ assertEquals("wss://www.com:8443",
Application.getWsUrl(Url.parse("https://www.com:8443/test")));
+ }
+}