git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GitHub] activemq-artemis pull request #1722: (WIP DO NOT MERGE) ARTEMIS-1545 Support...


Github user michaelandrepearce commented on a diff in the pull request:

    https://github.com/apache/activemq-artemis/pull/1722#discussion_r157336666
  
    --- Diff: tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/SecurityTest.java ---
    @@ -169,6 +180,71 @@ public void testLoginInvalidUserInvalidPassword() throws Exception {
           }
        }
     
    +   /**
    +    * Login with valid user and password
    +    * But try send to address not authorised - Persistent
    +    * Should not allow and should throw exception
    +    */
    +   @Test
    +   public void testLoginValidUserAndPasswordButNotAuthorisedToSend() throws Exception {
    +      ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
    +      Connection connection = connectionFactory.createConnection("guest", "guest");
    +      Session session = connection.createSession();
    +      Destination destination = session.createQueue("guest.cannot.send");
    +      MessageProducer messageProducer = session.createProducer(destination);
    +      try {
    +         messageProducer.send(session.createTextMessage("hello"));
    +         fail("JMSSecurityException expected as guest is not allowed to send");
    +      } catch (JMSSecurityException activeMQSecurityException) {
    +         //pass
    +      }
    +      connection.close();
    +   }
    +
    +   /**
    +    * Login with valid user and password
    +    * But try send to address not authorised - Non Persistent.
    +    * Should have same behaviour as Persistent with exception on send.
    +    */
    +   @Test
    +   public void testLoginValidUserAndPasswordButNotAuthorisedToSendNonPersistent() throws Exception {
    +      ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
    +      connectionFactory.setConfirmationWindowSize(100);
    +      connectionFactory.setBlockOnDurableSend(false);
    +      connectionFactory.setBlockOnNonDurableSend(false);
    +      Connection connection = connectionFactory.createConnection("guest", "guest");
    +      Session session = connection.createSession();
    +      Destination destination = session.createQueue("guest.cannot.send");
    +      MessageProducer messageProducer = session.createProducer(destination);
    +      messageProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
    +      try {
    +         AtomicReference<Exception> e = new AtomicReference<>();
    +         //        messageProducer.send(session.createTextMessage("hello"));
    +
    +         CountDownLatch countDownLatch = new CountDownLatch(1);
    +         messageProducer.send(session.createTextMessage("hello"), new CompletionListener() {
    +            @Override
    +            public void onCompletion(Message message) {
    +               countDownLatch.countDown();
    +            }
    +
    +            @Override
    +            public void onException(Message message, Exception exception) {
    +               countDownLatch.countDown();
    +               e.set(exception);
    --- End diff --
    
    good spot, thanks.


---