io.vertx.ext.bridge.PermittedOptions Java Examples

The following examples show how to use io.vertx.ext.bridge.PermittedOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EventbusBridgeTest.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
@Test
public void testPermittedOptionsJson() {
  String address = TestUtils.randomAlphaString(10);
  String addressRegex = TestUtils.randomAlphaString(10);
  String requiredAuthority = TestUtils.randomAlphaString(10);
  JsonObject match = new JsonObject().put(TestUtils.randomAlphaString(10), TestUtils.randomAlphaString(10));
  JsonObject json = new JsonObject().
    put("address", address).
    put("addressRegex", addressRegex).
    put("requiredAuthority", requiredAuthority).
    put("match", match);
  PermittedOptions options = new PermittedOptions(json);
  assertEquals(address, options.getAddress());
  assertEquals(addressRegex, options.getAddressRegex());
  assertEquals(requiredAuthority, options.getRequiredAuthority());
  assertEquals(match, options.getMatch());
}
 
Example #2
Source File: WebExamples.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
public void handleSocketIdle(Vertx vertx, PermittedOptions inboundPermitted) {
  Router router = Router.router(vertx);

  // Initialize SockJS handler
  SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
  SockJSBridgeOptions options = new SockJSBridgeOptions()
    .addInboundPermitted(inboundPermitted)
    .setPingTimeout(5000);

  // mount the bridge on the router
  router
    .mountSubRouter("/eventbus", sockJSHandler.bridge(options, be -> {
      if (be.type() == BridgeEventType.SOCKET_IDLE) {
        // Do some custom handling...
      }

      be.complete(true);
    }));
}
 
Example #3
Source File: EventBusBridgeVisitor.java    From nubes with Apache License 2.0 6 votes vote down vote up
private static BridgeOptions createBridgeOptions(Class<?> controller) {
  BridgeOptions options = new BridgeOptions();
  InboundPermitted[] inbounds = controller.getAnnotationsByType(InboundPermitted.class);
  if (inbounds.length > 0) {
    List<PermittedOptions> inboundPermitteds = new ArrayList<>(inbounds.length);
    for (InboundPermitted inbound : inbounds) {
      inboundPermitteds.add(createInboundPermitted(inbound));
    }
    options.setInboundPermitted(inboundPermitteds);

  } else {
    options.addInboundPermitted(new PermittedOptions());
  }
  OutboundPermitted[] outbounds = controller.getAnnotationsByType(OutboundPermitted.class);
  if (outbounds.length > 0) {
    List<PermittedOptions> outboundPermitteds = new ArrayList<>(outbounds.length);
    for (OutboundPermitted outbound : outbounds) {
      outboundPermitteds.add(createOutboundPermitted(outbound));
    }
    options.setOutboundPermitted(outboundPermitteds);
  } else {
    options.addOutboundPermitted(new PermittedOptions());
  }
  return options;
}
 
Example #4
Source File: WebSocketBridgeTest.java    From vertx-stomp with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
  vertx = Vertx.vertx();
  AsyncLock<HttpServer> httpLock = new AsyncLock<>();
  AsyncLock<StompServer> stompLock = new AsyncLock<>();

  vertx = Vertx.vertx();

  server = StompServer.create(vertx, new StompServerOptions().setWebsocketBridge(true))
      .handler(StompServerHandler.create(vertx)
       .bridge(new BridgeOptions()
        .addInboundPermitted(new PermittedOptions().setAddressRegex(".*"))
        .addOutboundPermitted(new PermittedOptions().setAddressRegex(".*")))
      )
      .listen(stompLock.handler());
  stompLock.waitForSuccess();

  HttpServerOptions httpOptions = new HttpServerOptions()
    .setMaxWebSocketFrameSize(MAX_WEBSOCKET_FRAME_SIZE)
    .setMaxWebSocketMessageSize(2048);

  http = vertx.createHttpServer(httpOptions).webSocketHandler(server.webSocketHandler()).listen(8080, httpLock.handler());
  httpLock.waitForSuccess();
}
 
Example #5
Source File: EventBusBridgeTest.java    From vertx-stomp with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatEventBusConsumerCanReplyToStompMessages() {
  server.stompHandler().bridge(new BridgeOptions()
          .addOutboundPermitted(new PermittedOptions().setAddress("/replyTo"))
          .addInboundPermitted(new PermittedOptions().setAddress("/request"))
          .setPointToPoint(true)
  );

  AtomicReference<Frame> response = new AtomicReference<>();

  consumers.add(vertx.eventBus().consumer("/request", msg -> {
    msg.reply("pong");
  }));

  clients.add(StompClient.create(vertx).connect(ar -> {
    final StompClientConnection connection = ar.result();
    connection.subscribe("/replyTo", response::set, r1 -> {
      connection.send("/request", Headers.create("reply-address", "/replyTo"), Buffer.buffer("ping"));
    });
  }));

  Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> response.get() != null);
}
 
Example #6
Source File: EventBusBridgeTest.java    From vertx-stomp with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatEventBusMessagesAreOnlyTransferredToOneStompClientsInP2P() throws InterruptedException {
  List<Frame> frames = new CopyOnWriteArrayList<>();
  server.stompHandler().bridge(new BridgeOptions()
          .addOutboundPermitted(new PermittedOptions().setAddress("/toStomp"))
          .setPointToPoint(true)
  );

  clients.add(StompClient.create(vertx).connect(ar -> {
    final StompClientConnection connection = ar.result();
    connection.subscribe("/toStomp", frames::add,
        f -> {
          clients.add(StompClient.create(vertx).connect(ar2 -> {
            final StompClientConnection connection2 = ar2.result();
            connection2.subscribe("/toStomp", frames::add, receipt -> {
              vertx.eventBus().publish("/toStomp", "Hello from Vert.x", new DeliveryOptions().addHeader("foo", "bar"));
            });
          }));
        });
  }));

  Thread.sleep(500);
  assertThat(frames).hasSize(1);
}
 
Example #7
Source File: EventBusBridgeTest.java    From vertx-stomp with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatOnlyOnEventBusConsumersReceiveAStompMessageInP2P() throws InterruptedException {
  server.stompHandler().bridge(new BridgeOptions()
          .addInboundPermitted(new PermittedOptions().setAddress("/toBus"))
          .setPointToPoint(true)
  );
  List<Message> messages = new CopyOnWriteArrayList<>();
  consumers.add(vertx.eventBus().consumer("/toBus", messages::add));
  consumers.add(vertx.eventBus().consumer("/toBus", messages::add));

  clients.add(StompClient.create(vertx).connect(ar -> {
    final StompClientConnection connection = ar.result();
    connection.send("/toBus", Headers.create("foo", "bar"), Buffer.buffer("Hello from STOMP"));
  }));

  Thread.sleep(500);
  assertThat(messages).hasSize(1);
}
 
Example #8
Source File: TcpEventBusBridgeInteropTest.java    From vertx-tcp-eventbus-bridge with Apache License 2.0 6 votes vote down vote up
@Before
public void before(TestContext context) {
  vertx = Vertx.vertx();
  final Async async = context.async();

  vertx.eventBus().consumer("hello", (Message<JsonObject> msg) -> msg.reply(new JsonObject().put("value", "Hello " + msg.body().getString("value"))));

  TcpEventBusBridge bridge = TcpEventBusBridge.create(
          vertx,
          new BridgeOptions()
                  .addInboundPermitted(new PermittedOptions())
                  .addOutboundPermitted(new PermittedOptions()));

  bridge.listen(7000, res -> {
    context.assertTrue(res.succeeded());
    async.complete();
  });
}
 
Example #9
Source File: TCPBridgeExamples.java    From vertx-tcp-eventbus-bridge with Apache License 2.0 6 votes vote down vote up
public void example1(Vertx vertx) {

    TcpEventBusBridge bridge = TcpEventBusBridge.create(
        vertx,
        new BridgeOptions()
            .addInboundPermitted(new PermittedOptions().setAddress("in"))
            .addOutboundPermitted(new PermittedOptions().setAddress("out")));

    bridge.listen(7000, res -> {
      if (res.succeeded()) {
        // succeed...
      } else {
        // fail...
      }
    });

  }
 
Example #10
Source File: EventbusBridgeTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendPermittedStructureMatchWithAddress() throws Exception {
  JsonObject match = new JsonObject().put("fib", "wib").put("oop", 12);
  sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setMatch(match).setAddress(addr)));
  testSend(addr, match);
  JsonObject json1 = match.copy();
  json1.put("blah", "foob");
  testSend(addr, json1);
  json1.remove("fib");
  testError(new JsonObject().put("type", "send").put("address", addr).put("body", json1),
    "access_denied");
  testError(new JsonObject().put("type", "send").put("address", "otheraddress").put("body", json1),
    "access_denied");
}
 
Example #11
Source File: WebExamples.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
public void example49(Vertx vertx) {

    Router router = Router.router(vertx);

    // Let through any messages sent to 'demo.orderMgr' from the client
    PermittedOptions inboundPermitted = new PermittedOptions()
      .setAddress("demo.someService");

    SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
    SockJSBridgeOptions options = new SockJSBridgeOptions()
      .addInboundPermitted(inboundPermitted);

    // mount the bridge on the router
    router
      .mountSubRouter("/eventbus", sockJSHandler
        .bridge(options, be -> {
          if (be.type() == BridgeEventType.PUBLISH ||
            be.type() == BridgeEventType.RECEIVE) {

            if (be.getRawMessage().getString("body").equals("armadillos")) {
              // Reject it
              be.complete(false);
              return;
            }
          }
          be.complete(true);
        }));
  }
 
Example #12
Source File: DashboardWebAppVerticle.java    From vertx-in-action with MIT License 5 votes vote down vote up
@Override
public Completable rxStart() {
  Router router = Router.router(vertx);

  KafkaConsumer.<String, JsonObject>create(vertx, KafkaConfig.consumerConfig("dashboard-webapp-throughput"))
    .subscribe("event-stats.throughput")
    .toFlowable()
    .subscribe(record -> forwardKafkaRecord(record, "client.updates.throughput"));

  KafkaConsumer.<String, JsonObject>create(vertx, KafkaConfig.consumerConfig("dashboard-webapp-city-trend"))
    .subscribe("event-stats.city-trend.updates")
    .toFlowable()
    .subscribe(record -> forwardKafkaRecord(record, "client.updates.city-trend"));

  KafkaConsumer.<String, JsonObject>create(vertx, KafkaConfig.consumerConfig("dashboard-webapp-ranking"))
    .subscribe("event-stats.user-activity.updates")
    .toFlowable()
    .filter(record -> record.value().getBoolean("makePublic"))
    .buffer(5, TimeUnit.SECONDS, RxHelper.scheduler(vertx))
    .subscribe(this::updatePublicRanking);

  hydrate();

  SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
  SockJSBridgeOptions bridgeOptions = new SockJSBridgeOptions()
    .addInboundPermitted(new PermittedOptions().setAddressRegex("client.updates.*"))
    .addOutboundPermitted(new PermittedOptions().setAddressRegex("client.updates.*"));
  sockJSHandler.bridge(bridgeOptions);
  router.route("/eventbus/*").handler(sockJSHandler);

  router.get("/").handler(ctx -> ctx.reroute("/index.html"));
  router.route().handler(StaticHandler.create("webroot/assets"));

  return vertx.createHttpServer()
    .requestHandler(router)
    .rxListen(HTTP_PORT)
    .ignoreElement();
}
 
Example #13
Source File: EventBusBridgeImpl.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
private Match checkMatches(boolean inbound, String address, Object body) {

    List<PermittedOptions> matches = inbound ? inboundPermitted : outboundPermitted;

    for (PermittedOptions matchHolder : matches) {
      String matchAddress = matchHolder.getAddress();
      String matchRegex;
      if (matchAddress == null) {
        matchRegex = matchHolder.getAddressRegex();
      } else {
        matchRegex = null;
      }

      boolean addressOK;
      if (matchAddress == null) {
        addressOK = matchRegex == null || regexMatches(matchRegex, address);
      } else {
        addressOK = matchAddress.equals(address);
      }

      if (addressOK) {
        boolean matched = structureMatches(matchHolder.getMatch(), body);
        if (matched) {
          String requiredAuthority = matchHolder.getRequiredAuthority();
          return new Match(true, requiredAuthority);
        }
      }
    }
    return new Match(false);
  }
 
Example #14
Source File: EventbusBridgeTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendPermittedAllowAddress() throws Exception {
  String addr = "allow1";
  sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setAddress(addr)));
  testSend(addr, "foobar");
  testError(new JsonObject().put("type", "send").put("address", "allow2").put("body", "blah"),
    "access_denied");
}
 
Example #15
Source File: EventbusBridgeTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendPermittedAllowAddressRe() throws Exception {
  String addr = "allo.+";
  sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setAddressRegex(addr)));
  testSend("allow1", "foobar");
  testSend("allow2", "foobar");
  testError(new JsonObject().put("type", "send").put("address", "hello").put("body", "blah"),
    "access_denied");
}
 
Example #16
Source File: EventbusBridgeTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendPermittedMultipleAddresses() throws Exception {
  String addr1 = "allow1";
  String addr2 = "allow2";
  sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setAddress(addr1)).
    addInboundPermitted(new PermittedOptions().setAddress(addr2)));
  testSend("allow1", "foobar");
  testSend("allow2", "foobar");
  testError(new JsonObject().put("type", "send").put("address", "allow3").put("body", "blah"),
    "access_denied");
}
 
Example #17
Source File: EventbusBridgeTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendPermittedMultipleAddressRe() throws Exception {
  String addr1 = "allo.+";
  String addr2 = "ballo.+";
  sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setAddressRegex(addr1)).
    addInboundPermitted(new PermittedOptions().setAddressRegex(addr2)));
  testSend("allow1", "foobar");
  testSend("allow2", "foobar");
  testSend("ballow1", "foobar");
  testSend("ballow2", "foobar");
  testError(new JsonObject().put("type", "send").put("address", "hello").put("body", "blah"),
    "access_denied");
}
 
Example #18
Source File: EventbusBridgeTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testPermittedOptions() {
  PermittedOptions options = new PermittedOptions();
  assertEquals(PermittedOptions.DEFAULT_ADDRESS, options.getAddress());
  assertEquals(PermittedOptions.DEFAULT_ADDRESS_REGEX, options.getAddressRegex());
  assertEquals(PermittedOptions.DEFAULT_REQUIRED_AUTHORITY, options.getRequiredAuthority());
  assertEquals(PermittedOptions.DEFAULT_MATCH, options.getMatch());
  String address = TestUtils.randomAlphaString(10);
  String addressRegex = TestUtils.randomAlphaString(10);
  String requiredAuthority = TestUtils.randomAlphaString(10);
  JsonObject match = new JsonObject().put(TestUtils.randomAlphaString(10), TestUtils.randomAlphaString(10));
  assertSame(options, options.setAddress(address));
  assertSame(options, options.setAddressRegex(addressRegex));
  assertSame(options, options.setRequiredAuthority(requiredAuthority));
  assertSame(options, options.setMatch(match));
  assertEquals(address, options.getAddress());
  assertEquals(addressRegex, options.getAddressRegex());
  assertEquals(requiredAuthority, options.getRequiredAuthority());
  assertEquals(match, options.getMatch());
  PermittedOptions copy = new PermittedOptions(options);
  assertEquals(address, copy.getAddress());
  assertEquals(addressRegex, copy.getAddressRegex());
  assertEquals(requiredAuthority, copy.getRequiredAuthority());
  assertEquals(match, copy.getMatch());
  assertSame(copy, copy.setAddress(TestUtils.randomAlphaString(10)));
  assertSame(copy, copy.setAddressRegex(TestUtils.randomAlphaString(10)));
  assertSame(copy, copy.setRequiredAuthority(TestUtils.randomAlphaString(10)));
  assertSame(copy, copy.setMatch(new JsonObject().put(TestUtils.randomAlphaString(10), TestUtils.randomAlphaString(10))));
  assertSame(options, options.setAddress(address));
  assertSame(options, options.setAddressRegex(addressRegex));
  assertSame(options, options.setRequiredAuthority(requiredAuthority));
  assertSame(options, options.setMatch(match));
}
 
Example #19
Source File: EventbusBridgeTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendRequiresAuthorityHasnotAuthority() throws Exception {
  sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setAddress(addr).setRequiredAuthority("pick_nose")));
  router.clear();
  SessionStore store = LocalSessionStore.create(vertx);
  router.route().handler(SessionHandler.create(store));
  AuthenticationProvider authProvider = PropertyFileAuthentication.create(vertx, "login/loginusers.properties");
  addLoginHandler(router, authProvider);
  router.route("/eventbus/*").handler(sockJSHandler);
  testError(new JsonObject().put("type", "send").put("address", addr).put("body", "foo"), "access_denied");
}
 
Example #20
Source File: EventbusBridgeTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendPermittedMixedAddressRe() throws Exception {
  String addr1 = "allow1";
  String addr2 = "ballo.+";
  sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setAddress(addr1)).
    addInboundPermitted(new PermittedOptions().setAddressRegex(addr2)));
  testSend("allow1", "foobar");
  testSend("ballow1", "foobar");
  testSend("ballow2", "foobar");
  testError(new JsonObject().put("type", "send").put("address", "hello").put("body", "blah"),
    "access_denied");
  testError(new JsonObject().put("type", "send").put("address", "allow2").put("body", "blah"),
    "access_denied");
}
 
Example #21
Source File: EventbusBridgeTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendPermittedStructureMatch() throws Exception {
  JsonObject match = new JsonObject().put("fib", "wib").put("oop", 12);
  sockJSHandler.bridge(defaultOptions.addInboundPermitted(new PermittedOptions().setMatch(match)));
  testSend(addr, match);
  JsonObject json1 = match.copy();
  json1.put("blah", "foob");
  testSend(addr, json1);
  json1.remove("fib");
  testError(new JsonObject().put("type", "send").put("address", addr).put("body", json1),
    "access_denied");
}
 
Example #22
Source File: EventbusBridgeTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testReplyMessagesOutbound() throws Exception {

  // Only allow outbound address, reply message should still get through though
  sockJSHandler.bridge(defaultOptions.addOutboundPermitted(new PermittedOptions().setAddress(addr)));

  CountDownLatch latch = new CountDownLatch(1);

  client.webSocket(websocketURI, onSuccess(ws -> {

    JsonObject reg = new JsonObject().put("type", "register").put("address", addr);
    ws.writeFrame(io.vertx.core.http.WebSocketFrame.textFrame(reg.encode(), true));

    ws.handler(buff -> {
      String str = buff.toString();
      JsonObject received = new JsonObject(str);
      Object rec = received.getValue("body");
      assertEquals("foobar", rec);

      // Now send back reply
      JsonObject reply = new JsonObject().put("type", "send").put("address", received.getString("replyAddress")).put("body", "barfoo");
      ws.writeFrame(io.vertx.core.http.WebSocketFrame.textFrame(reply.encode(), true));
    });

    vertx.setTimer(500, tid -> vertx.eventBus().request(addr, "foobar", res -> {
      if (res.succeeded()) {
        assertEquals("barfoo", res.result().body());
        ws.closeHandler(v2 -> latch.countDown());
        ws.close();
      }
    }));

  }));

  awaitLatch(latch);
}
 
Example #23
Source File: EventbusBridgeTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testRegisterPermittedAllowAddress() throws Exception {
  String addr = "allow1";
  sockJSHandler.bridge(defaultOptions.addOutboundPermitted(new PermittedOptions().setAddress(addr)));
  testReceive(addr, "foobar");
  testError(new JsonObject().put("type", "register").put("address", "allow2").put("body", "blah"),
    "access_denied");
}
 
Example #24
Source File: EventbusBridgeTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendRequiresAuthorityHasAuthority() throws Exception {
  sockJSHandler.bridge(PropertyFileAuthorization.create(vertx, "login/loginusers.properties"), defaultOptions.addInboundPermitted(new PermittedOptions().setAddress(addr).setRequiredAuthority("bang_sticks")), null);
  router.clear();
  SessionStore store = LocalSessionStore.create(vertx);
  router.route().handler(SessionHandler.create(store));
  AuthenticationProvider authProvider = PropertyFileAuthentication.create(vertx, "login/loginusers.properties");
  addLoginHandler(router, authProvider);
  router.route("/eventbus/*").handler(sockJSHandler);
  testSend("foo");
}
 
Example #25
Source File: EventbusBridgeTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testRegisterPermittedAllowAddressRe() throws Exception {
  String addr = "allo.+";
  sockJSHandler.bridge(defaultOptions.addOutboundPermitted(new PermittedOptions().setAddressRegex(addr)));
  testReceive("allow1", "foobar");
  testReceive("allow2", "foobar");
  testError(new JsonObject().put("type", "register").put("address", "hello").put("body", "blah"),
    "access_denied");
}
 
Example #26
Source File: EventbusBridgeTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testRegisterPermittedMultipleAddresses() throws Exception {
  String addr1 = "allow1";
  String addr2 = "allow2";
  sockJSHandler.bridge(defaultOptions.addOutboundPermitted(new PermittedOptions().setAddress(addr1)).
    addOutboundPermitted(new PermittedOptions().setAddress(addr2)));
  testReceive("allow1", "foobar");
  testReceive("allow2", "foobar");
  testError(new JsonObject().put("type", "register").put("address", "allow3").put("body", "blah"),
    "access_denied");
}
 
Example #27
Source File: EventbusBridgeTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testRegisterPermittedMultipleAddressRe() throws Exception {
  String addr1 = "allo.+";
  String addr2 = "ballo.+";
  sockJSHandler.bridge(defaultOptions.addOutboundPermitted(new PermittedOptions().setAddressRegex(addr1)).
    addOutboundPermitted(new PermittedOptions().setAddressRegex(addr2)));
  testReceive("allow1", "foobar");
  testReceive("allow2", "foobar");
  testReceive("ballow1", "foobar");
  testReceive("ballow2", "foobar");
  testError(new JsonObject().put("type", "register").put("address", "hello").put("body", "blah"),
    "access_denied");
}
 
Example #28
Source File: EventbusBridgeTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testRegisterPermittedMixedAddressRe() throws Exception {
  String addr1 = "allow1";
  String addr2 = "ballo.+";
  sockJSHandler.bridge(defaultOptions.addOutboundPermitted(new PermittedOptions().setAddress(addr1)).
    addOutboundPermitted(new PermittedOptions().setAddressRegex(addr2)));
  testReceive("allow1", "foobar");
  testReceive("ballow1", "foobar");
  testReceive("ballow2", "foobar");
  testError(new JsonObject().put("type", "register").put("address", "hello").put("body", "blah"),
    "access_denied");
  testError(new JsonObject().put("type", "register").put("address", "allow2").put("body", "blah"),
    "access_denied");
}
 
Example #29
Source File: EventbusBridgeTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testRegisterPermittedStructureMatch() throws Exception {
  JsonObject match = new JsonObject().put("fib", "wib").put("oop", 12);
  sockJSHandler.bridge(defaultOptions.addOutboundPermitted(new PermittedOptions().setMatch(match)));
  testReceive(addr, match);
  JsonObject json1 = match.copy();
  json1.put("blah", "foob");
  testReceive(addr, json1);
  JsonObject json2 = json1.copy();
  json2.remove("fib");
  testReceiveFail(addr, json2);
}
 
Example #30
Source File: EventbusBridgeTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testRegisterPermittedStructureMatchWithAddress() throws Exception {
  JsonObject match = new JsonObject().put("fib", "wib").put("oop", 12);
  sockJSHandler.bridge(defaultOptions.addOutboundPermitted(new PermittedOptions().setMatch(match).setAddress(addr)));
  testReceive(addr, match);
  JsonObject json1 = match.copy();
  json1.put("blah", "foob");
  testReceive(addr, json1);
  JsonObject json2 = json1.copy();
  json2.remove("fib");
  testReceiveFail(addr, json2);
}