reiern70 commented on code in PR #1674:
URL: https://github.com/apache/wicket/pull/1674#discussion_r4300825826


##########
wicket-native-websocket/wicket-native-websocket-tester/src/test/java/org/apache/wicket/protocol/ws/tester/WebSocketProcessorPageIdTest.java:
##########
@@ -0,0 +1,78 @@
+/*
+* 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.wicket.protocol.ws.tester;
+
+import org.apache.wicket.mock.MockApplication;
+import org.apache.wicket.protocol.http.WebApplication;
+import org.apache.wicket.protocol.http.mock.MockHttpServletRequest;
+import org.apache.wicket.request.http.WebRequest;
+import org.apache.wicket.util.tester.WicketTester;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import jakarta.servlet.http.HttpServletRequest;
+
+/**
+* Tests that a handshake with a pageId that is not a number does not fail with 
an exception.
+*/
+public class WebSocketProcessorPageIdTest
+{
+       WicketTester tester;
+       WebApplication application = new MockApplication();
+
+       private static class TestProcessor extends TestWebSocketProcessor
+       {
+               private TestProcessor(HttpServletRequest request, 
WebApplication application)
+               {
+                       super(request, application);
+               }
+
+               @Override
+               protected void onOutMessage(String message)
+               {
+               }
+
+               @Override
+               protected void onOutMessage(byte[] message, int offset, int 
length)
+               {
+               }
+       }
+
+       @BeforeEach
+       public void before()
+       {
+               tester = new WicketTester(application);
+               application.getWicketFilter().setFilterPath("");
+       }
+
+       @AfterEach
+       public void after()
+       {
+               tester.destroy();
+       }
+
+       @Test
+       public void malformedPageIdDoesNotFailTheHandshake()
+       {
+               MockHttpServletRequest request = tester.getRequest();
+               request.addParameter("pageId", "NaN");
+               request.addParameter(WebRequest.PARAM_AJAX_BASE_URL, ".");
+
+               new TestProcessor(request, tester.getApplication());

Review Comment:
   This only checks that the constructor returns; what the connection does 
shows once `onOpen()` and `onMessage()` are called.



##########
wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/AbstractWebSocketProcessor.java:
##########
@@ -120,14 +120,19 @@ public AbstractWebSocketProcessor(final 
HttpServletRequest request, final WebApp
                {
                        throw new IllegalArgumentException("The request should 
have either 'pageId' or 'resourceName' parameter!");
                }
+               int parsedPageId = NO_PAGE_ID;
                if (Strings.isEmpty(pageId) == false)
                {
-                       this.pageId = Integer.parseInt(pageId, 10);
-               }
-               else
-               {
-                       this.pageId = NO_PAGE_ID;
+                       try
+                       {
+                               parsedPageId = Integer.parseInt(pageId, 10);
+                       }
+                       catch (NumberFormatException e)
+                       {
+                               // no page will be found with this id anyway

Review Comment:
   A page is found: for `NO_PAGE_ID` `getPage()` returns a 
`WebSocketResourcePage`, and the connection is registered under `PageIdKey(-1)`.



##########
wicket-native-websocket/wicket-native-websocket-tester/src/test/java/org/apache/wicket/protocol/ws/tester/WebSocketProcessorPageIdTest.java:
##########
@@ -0,0 +1,78 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more

Review Comment:
   The license header lost the leading space on each line (` * Licensed to 
...`); please copy it from a neighbouring file.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to