Adding remaining cases to the test
package io.vertx.ext.web.handler.sockjs;
import io.vertx.core.buffer.Buffer;
+import io.vertx.core.http.WebSocketConnectOptions;
import io.vertx.test.core.TestUtils;
import org.junit.Test;
@@ -34,6 +35,60 @@ public class SockJSRawTransportTest extends SockJSTestBase {
testWrite(false);
}
+ @Test
+ public void disableHost() throws Exception {
+ String expected = TestUtils.randomAlphaString(64);
+ socketHandler = () -> socket -> {
+ socket.write(expected);
+ socket.endHandler(v -> {
+ testComplete();
+ });
+ };
+ startServers(new SockJSHandlerOptions());
+ client.webSocket(
+ new WebSocketConnectOptions()
+ .setHost("localhost")
+ .setPort(8080)
+ .setURI("/test/websocket")
+ .setAllowOriginHeader(false),
+ onSuccess(ws -> {
+ ws.frameHandler(frame -> {
+ if (frame.isClose()) {
+ //
+ } else {
+ assertTrue(frame.isText());
+ assertEquals(expected, frame.textData());
+ ws.end();
+ }
+ });
+ }));
+ await();
+ }
+
+ @Test
+ public void disableHostFailWhenOriginIsRequired() throws Exception {
+ String expected = TestUtils.randomAlphaString(64);
+ socketHandler = () -> socket -> {
+ socket.write(expected);
+ socket.endHandler(v -> {
+ testComplete();
+ });
+ };
+ startServers(new SockJSHandlerOptions().setOrigin("http://localhost:8080"));
+ client.webSocket(
+ new WebSocketConnectOptions()
+ .setHost("localhost")
+ .setPort(8080)
+ .setURI("/test/websocket")
+ .setAllowOriginHeader(false),
+ onFailure(err -> {
+ assertNotNull(err);
+ assertEquals("WebSocket upgrade failure: 403 (Forbidden)", err.getMessage());
+ testComplete();
+ }));
+ await();
+ }
+
@Test
public void goodOrigin() throws Exception {
String expected = TestUtils.randomAlphaString(64);
