[embjopr-commits] EMBJOPR SVN: r376 - in trunk/jsfunit: src/test/java/org/jboss/jopr/jsfunit/as4 and 4 other directories.

embjopr-commits at lists.jboss.org embjopr-commits at lists.jboss.org
Mon May 4 15:29:06 EDT 2009


Author: fjuma
Date: 2009-05-04 15:29:05 -0400 (Mon, 04 May 2009)
New Revision: 376

Added:
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jmsDestinations/JMSSecurityTest.java
   trunk/jsfunit/testdata/destinations/ExistingQueueWithSecurityRoleInvalidUserSpecified-service.xml
   trunk/jsfunit/testdata/destinations/ExistingQueueWithSecurityRoleNoUserSpecified-service.xml
   trunk/jsfunit/testdata/destinations/ExistingQueueWithSecurityRoleUserSpecified-service.xml
   trunk/jsfunit/testdata/destinations/ExistingTopicWithSecurityRoleInvalidUserSpecified-service.xml
   trunk/jsfunit/testdata/destinations/ExistingTopicWithSecurityRoleNoUserSpecified-service.xml
   trunk/jsfunit/testdata/destinations/ExistingTopicWithSecurityRoleUserSpecified-service.xml
Modified:
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as4/DatasourceTest.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ResourceTestBase.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/datasources/DatasourceConfigurationTest.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/datasources/DatasourceTest.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jmsDestinations/JMSMetricsTest.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jmsDestinations/JMSTest.java
Log:
Adding tests for secure JMS destinations.


Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java	2009-05-04 17:43:37 UTC (rev 375)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java	2009-05-04 19:29:05 UTC (rev 376)
@@ -80,6 +80,8 @@
     public static final String CONFIGURATION_TAB = "configurationTab";
     public static final String CONTROL_TAB = "controlTab";
     public static final String CONTENT_TAB = "contentTab";
+    
+    public static final String RESOURCE_CONFIGURATION_FORM = "resourceConfigurationForm";
 
     public JSFClientSession getClient() { return client; }
     public JSFServerSession getServer() { return server; }
@@ -290,7 +292,7 @@
      * @param properties maps property names (eg. "jndi-name", 
      * "min-pool-size", etc.) to property values 
      */
-    public void fillOutForm(Map<String, String> properties) {
+    public void fillOutForm(Map<String, String> properties, String formName) {
         Iterator itr = properties.keySet().iterator();
         
         // Set each property
@@ -299,7 +301,8 @@
 
             // Make sure the input is enabled
             HtmlInput input = enableOrDisableFormInput(propertyName, 
-                                                       Boolean.TRUE);
+                                                       Boolean.TRUE,
+                                                       formName);
             
             assertFalse("Could not enable: " + propertyName, input.isDisabled());
             
@@ -313,7 +316,7 @@
 			for( String propName : EmbJoprTestToolkit.stringPropertyNames(props) ) {
 				map.put(propName, props.getProperty(propName));
 			}
-			fillOutForm(map);
+			fillOutForm(map, RESOURCE_CONFIGURATION_FORM);
     }
 
 		/** Check if the form is filled according to given Properties. */
@@ -372,14 +375,15 @@
      * If the input box/radio button does not have an enable/disable checkbox, 
      * return the input element as is. 
      */
-    public HtmlInput enableOrDisableFormInput(String propertyName, Boolean enableInput) {
+    public HtmlInput enableOrDisableFormInput(String propertyName, Boolean enableInput, String formName) {
 			
-        HtmlForm form = (HtmlForm)client.getElement("resourceConfigurationForm");
-				if( null == form ){
-					// Wrapped. Don't want to add "throws Html..." all over the project.
-					throw new RuntimeException(new HtmlElementNotFoundException(
-									"Element #resourceConfigurationForm not found. Page dumped.", this));
-				}
+        HtmlForm form = (HtmlForm)client.getElement(formName);
+        
+        if( null == form ){
+            // Wrapped. Don't want to add "throws Html..." all over the project.
+            throw new RuntimeException(new HtmlElementNotFoundException(
+                                       "Element " + formName + " not found. Page dumped.", this));
+        }
 
         HtmlInput input = (HtmlInput)form.getFirstByXPath(".//input[@ondblclick='//" 
                           + propertyName + "']");

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as4/DatasourceTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as4/DatasourceTest.java	2009-05-04 17:43:37 UTC (rev 375)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as4/DatasourceTest.java	2009-05-04 19:29:05 UTC (rev 376)
@@ -85,7 +85,7 @@
 
         // Configure the properties associated with this datasource
 				propertiesMap.put("type", DatasourceType.LOCAL_TX_DATASOURCE.getHtmlRadioValue() );
-        fillOutForm(propertiesMap);  
+        fillOutForm(propertiesMap, RESOURCE_CONFIGURATION_FORM);  
 				// Remove the type property not to be treated later as regular properties.
 				propertiesMap.remove("type");
     }

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ResourceTestBase.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ResourceTestBase.java	2009-05-04 17:43:37 UTC (rev 375)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/ResourceTestBase.java	2009-05-04 19:29:05 UTC (rev 376)
@@ -68,6 +68,8 @@
     public static final String PARAMETERS_FORM_OK_BUTTON = "parametersForm:okButton";
     public static final String ADD_NEW_RESOURCE_BUTTON = "actionHeaderForm:addNewNotContent";
     public static final String CONTINUE_AFTER_TEMPLATE_SELECTION_BUTTON = "resourceCreateForm:addButton";
+    public static final String EDIT_RESOURCE_CONFIGURATION_FORM_OK_BUTTON = "editResourceConfigurationForm:okButton";
+    public static final String ADD_NEW_CONFIG_BUTTON = "Add New";
     
     // Template selection
     public static final String SELECT_TEMPLATE = "selectedTemplate";
@@ -92,6 +94,7 @@
     public static final String OPERATION_RESULTS = "operationResults";
     public static final String REFRESH_OPERATIONS_TABLE = "refreshLink";
     public static final String RESOURCE_SUMMARY_FORM = "resourceSummaryForm";
+    public static final String EDIT_RESOURCE_CONFIGURATION_FORM = "editResourceConfigurationForm";
 
     // Pagination constants
     public static final String MAX_ITEMS_PER_PAGE="50";
@@ -137,7 +140,7 @@
      */
     protected void setResourceProperties(Map<String, MetaValue> propertiesMap) {
         Map<String, String> formattedPropertiesMap = formatPropertiesMap(propertiesMap);
-        fillOutForm(formattedPropertiesMap);  
+        fillOutForm(formattedPropertiesMap, RESOURCE_CONFIGURATION_FORM);  
     }
     
     /**
@@ -188,7 +191,7 @@
         // Unset the given properties
         for(int i = 0; i < propertiesToUnset.length; i++) {
             String propertyName = propertiesToUnset[i];
-            enableOrDisableFormInput(propertyName, Boolean.FALSE);
+            enableOrDisableFormInput(propertyName, Boolean.FALSE, RESOURCE_CONFIGURATION_FORM);
         }
         
         client.click(SAVE_BUTTON);

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/datasources/DatasourceConfigurationTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/datasources/DatasourceConfigurationTest.java	2009-05-04 17:43:37 UTC (rev 375)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/datasources/DatasourceConfigurationTest.java	2009-05-04 19:29:05 UTC (rev 376)
@@ -63,7 +63,7 @@
                     client.getPageAsText().contains("There was an error retrieving the configuration for this resource"));
 
         Map<String, String> propertiesMapChanges = formatPropertiesMap(propertiesMapChangesAsMetaValues);
-        fillOutForm(propertiesMapChanges);
+        fillOutForm(propertiesMapChanges, RESOURCE_CONFIGURATION_FORM);
         client.click(SAVE_BUTTON);
 
         // Check for the appropriate success messages
@@ -105,7 +105,7 @@
                     client.getPageAsText().contains("There was an error retrieving the configuration for this resource"));
 
         Map<String, String> propertiesMapChanges = formatPropertiesMap(propertiesMapChangesAsMetaValues);
-        fillOutForm(propertiesMapChanges);
+        fillOutForm(propertiesMapChanges, RESOURCE_CONFIGURATION_FORM);
         client.click(SAVE_BUTTON);
 
         // Check for the appropriate success messages
@@ -137,11 +137,11 @@
         assertFalse("The configuration page could not be displayed",
                     client.getPageAsText().contains("There was an error retrieving the configuration for this resource"));
 
-        enableOrDisableFormInput("user-name", Boolean.FALSE);
-        enableOrDisableFormInput("idle-timeout-minutes", Boolean.FALSE);
-        enableOrDisableFormInput("track-connection-by-tx", Boolean.FALSE);
-        enableOrDisableFormInput("domain", Boolean.FALSE);
-        enableOrDisableFormInput("no-tx-separate-pools", Boolean.FALSE);
+        enableOrDisableFormInput("user-name", Boolean.FALSE, RESOURCE_CONFIGURATION_FORM);
+        enableOrDisableFormInput("idle-timeout-minutes", Boolean.FALSE, RESOURCE_CONFIGURATION_FORM);
+        enableOrDisableFormInput("track-connection-by-tx", Boolean.FALSE, RESOURCE_CONFIGURATION_FORM);
+        enableOrDisableFormInput("domain", Boolean.FALSE, RESOURCE_CONFIGURATION_FORM);
+        enableOrDisableFormInput("no-tx-separate-pools", Boolean.FALSE, RESOURCE_CONFIGURATION_FORM);
         client.click(SAVE_BUTTON);
 
         // Check for the appropriate success messages

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/datasources/DatasourceTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/datasources/DatasourceTest.java	2009-05-04 17:43:37 UTC (rev 375)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/datasources/DatasourceTest.java	2009-05-04 19:29:05 UTC (rev 376)
@@ -83,7 +83,7 @@
         client.click(CONTINUE_AFTER_TEMPLATE_SELECTION_BUTTON);
         
         // Configure the properties associated with this datasource
-        fillOutForm(propertiesMap);  
+        fillOutForm(propertiesMap, RESOURCE_CONFIGURATION_FORM);  
     }
 
     /**

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jmsDestinations/JMSMetricsTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jmsDestinations/JMSMetricsTest.java	2009-05-04 17:43:37 UTC (rev 375)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jmsDestinations/JMSMetricsTest.java	2009-05-04 19:29:05 UTC (rev 376)
@@ -647,19 +647,4 @@
         disconnect();
         deleteDestination(DestinationType.QUEUE, jndiName);    
     }
-    
-    /**
-     * Common code for the metrics tests.
-     */
-    private void checkDestinationMetrics(String jndiName,
-                                         Map<String, String> expectedMetrics,
-                                         ArrayList<String> summaryMetrics,
-                                         DestinationType destinationType) throws Exception {
-        checkResourceMetrics(JMS_NAV_LABEL, destinationType.getNavLabel(), 
-                             jndiName, expectedMetrics, summaryMetrics);
-
-        // Clean up
-        disconnect();
-        deleteDestination(destinationType, jndiName);  
-    }
 }

Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jmsDestinations/JMSSecurityTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jmsDestinations/JMSSecurityTest.java	                        (rev 0)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jmsDestinations/JMSSecurityTest.java	2009-05-04 19:29:05 UTC (rev 376)
@@ -0,0 +1,349 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jopr.jsfunit.as5.jmsDestinations;
+
+import com.gargoylesoftware.htmlunit.html.*;
+import junit.framework.Test;
+import org.jboss.jopr.jsfunit.*;
+import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
+import javax.jms.Topic;
+import javax.jms.TopicSession;
+import javax.jms.Queue;
+import javax.jms.QueueSession;
+import javax.jms.JMSSecurityException;
+import java.util.Map;
+import java.util.LinkedHashMap;
+
+/**
+ * This class tests topics and queues that have security roles configured.
+ * This class should be run against JBAS 5.x.
+ * 
+ * @author Farah Juma
+ */
+public class JMSSecurityTest extends JMSTest {
+    
+    // A pre-defined JMS user from messaging/hsqldb-persistence-service.xml 
+    private static final String JMS_USER = "dynsub";
+    
+    // A pre-defined security role name from messaging/hsqldb-persistence-service.xml 
+    private static final String ROLE_NAME = "publisher";
+    
+    /**
+     * Test Name: testSendMessageToSecureTopicAndSpecifyUser
+     * Assertion: Verify the ability to send a message to a topic that has
+     * a security role configured. 
+     */
+    public void testSendMessageToSecureTopicAndSpecifyUser() throws Exception {
+        String jndiName = "TopicWithSecurityRoleSpecifyUser";
+        String expectedMessage = ADD_MESSAGE + DestinationType.TOPIC.getName();
+
+        createDestinationWithSecurityRole(DestinationType.TOPIC, TOPIC_DEFAULT_TEMPLATE, 
+                                          jndiName, expectedMessage, TOPIC_COMPONENT_TYPE,
+                                          ROLE_NAME, Boolean.TRUE, Boolean.TRUE, Boolean.TRUE);
+        sendMessageToSecureTopicAndSpecifyUser(jndiName, JMS_USER, JMS_USER);   
+    }
+
+    /**
+     * Test Name: testSendMessageToSecureTopicAndSpecifyUserUsingExistingServiceFile
+     * Assertion: Verify the ability to send a message to a topic that has
+     * a security role defined. Use a topic that already exists.
+     */
+    public void testSendMessageToSecureTopicAndSpecifyUserUsingExistingServiceFile() throws Exception {
+        String jndiName = "ExistingTopicWithSecurityRoleUserSpecified";
+        
+        expandNavTreeArrow(JMS_NAV_LABEL);
+        sendMessageToSecureTopicAndSpecifyUser(jndiName, JMS_USER, JMS_USER);
+    }
+    
+    /**
+     * Test Name: testSendMessageToSecureTopicAndSpecifyInvalidUser
+     * Assertion: Attempt to send a message to a secure topic, specifying an
+     * invalid username. Make sure a JMSSecurityException occurs.
+     */
+    public void testSendMessageToSecureTopicAndSpecifyInvalidUser() throws Exception {
+        String jndiName = "TopicWithSecurityRoleSpecifyInvalidUser";
+        String expectedMessage = ADD_MESSAGE + DestinationType.TOPIC.getName();
+        Exception jmsSecurityException = null;
+
+        createDestinationWithSecurityRole(DestinationType.TOPIC, TOPIC_DEFAULT_TEMPLATE, 
+                                          jndiName, expectedMessage, TOPIC_COMPONENT_TYPE,
+                                          ROLE_NAME, Boolean.TRUE, Boolean.TRUE, Boolean.TRUE);
+        
+        // Specify an invalid user when creating the topic connection
+        try {
+            sendMessageToSecureTopicAndSpecifyUser(jndiName, "fakeUser", "fakePassword");
+        } catch (JMSSecurityException e) {
+            jmsSecurityException = e;
+        } finally {
+            assertNotNull("Expected a JMSSecurityException to be thrown", jmsSecurityException);
+            deleteDestination(DestinationType.TOPIC, jndiName);  
+        }
+    }
+
+    /**
+     * Test Name: testSendMessageToSecureTopicAndSpecifyInvalidUserUsingExistingServiceFile
+     * Assertion: Attempt to send a message to a secure topic, specifying an
+     * invalid username. Make sure a JMSSecurityException occurs. Use a topic
+     * that already exists.
+     */
+    public void testSendMessageToSecureTopicAndSpecifyInvalidUserUsingExistingServiceFile() throws Exception {
+        String jndiName = "ExistingTopicWithSecurityRoleInvalidUserSpecified";
+        Exception jmsSecurityException = null;
+        
+        expandNavTreeArrow(JMS_NAV_LABEL);
+        
+        // Specify an invalid user when creating the topic connection
+        try {
+            sendMessageToSecureTopicAndSpecifyUser(jndiName, "fakeUser", "fakePassword");
+        } catch (JMSSecurityException e) {
+            jmsSecurityException = e;
+        } finally {
+            assertNotNull("Expected a JMSSecurityException to be thrown", jmsSecurityException);
+            deleteDestination(DestinationType.TOPIC, jndiName);  
+        }
+    }
+
+    /**
+     * Attempt to send a message to the topic given by jndiName,
+     * specifying the given username and password when creating the
+     * topic connection. If the username and password are not valid,
+     * a JMSSecurityException will be thrown.
+     */
+    private void sendMessageToSecureTopicAndSpecifyUser(String jndiName, 
+                                                        String username, 
+                                                        String password) throws Exception {
+
+        TopicSession session = createTopicSessionAndSpecifyUser(username, password);
+        Topic topic = getTopic(jndiName);
+
+        createDurableTopicSubscriber(session, topic, jndiName + "Subscriber");
+        publishMessages(session, topic, 1);
+        
+        Map<String, String> expectedMetrics = new LinkedHashMap<String, String>();
+        expectedMetrics.put(ALL_MSG_COUNT, "1.0");
+          
+        checkDestinationMetrics(jndiName, expectedMetrics, getTopicSummaryMetrics(),
+                                DestinationType.TOPIC);
+    }
+
+    /**
+     * Test Name: testSendMessageToSecureTopicWithoutSpecifyingUser
+     * Assertion: Make sure an error occurs when trying to send a message, without
+     * specifying a user, to a topic that has a security role configured.  
+     * 
+     * This test should pass if a JMSSecurityException is thrown.
+     */
+    public void testSendMessageToSecureTopicWithoutSpecifyingUser() throws Exception {
+        String jndiName = "TopicWithSecurityRoleNoUserSpecified";
+        String expectedMessage = ADD_MESSAGE + DestinationType.TOPIC.getName();
+        
+        createDestinationWithSecurityRole(DestinationType.TOPIC, TOPIC_DEFAULT_TEMPLATE, 
+                                          jndiName, expectedMessage, TOPIC_COMPONENT_TYPE,
+                                          ROLE_NAME, Boolean.TRUE, Boolean.TRUE, Boolean.TRUE);
+
+        sendMessageToSecureTopicWithoutSpecifyingUser(jndiName);
+    }
+    
+    /**
+     * Test Name: testSendMessageToSecureTopicWithoutSpecifyingUserUsingExistingServiceFile
+     * Assertion: Make sure an error occurs when trying to send a message, without
+     * specifying a user, to a topic that has a security role configured. 
+     * Use a topic that already exists.
+     * 
+     * This test should pass if a JMSSecurityException is thrown.
+     */
+    public void testSendMessageToSecureTopicWithoutSpecifyingUserUsingExistingServiceFile() throws Exception {
+        String jndiName = "ExistingTopicWithSecurityRoleNoUserSpecified";
+        
+        expandNavTreeArrow(JMS_NAV_LABEL);
+        sendMessageToSecureTopicWithoutSpecifyingUser(jndiName);
+    }
+    
+    /**
+     * Common code for the testSendMessageToSecureTopicWithoutSpecifyingUser* tests.
+     */
+    private void sendMessageToSecureTopicWithoutSpecifyingUser(String jndiName) throws Exception {
+        
+        Exception jmsSecurityException = null;
+        
+        // We should not be able to send a message since no user was specified when
+        // creating the topic connection
+        try {
+            createTopicSessionAndSendMessages(1, jndiName);
+        } catch (JMSSecurityException e) {
+            jmsSecurityException = e;
+        } finally {
+            assertNotNull("Expected a JMSSecurityException to be thrown", jmsSecurityException);
+            deleteDestination(DestinationType.TOPIC, jndiName);    
+        }
+    }
+    
+    /**
+     * Test Name: testSendMessageToSecureQueueAndSpecifyUser
+     * Assertion: Verify the ability to send a message to a queue that has
+     * a security role configured. 
+     */
+    public void testSendMessageToSecureQueueAndSpecifyUser() throws Exception {
+        String jndiName = "QueueWithSecurityRoleSpecifyUser";
+        String expectedMessage = ADD_MESSAGE + DestinationType.QUEUE.getName();
+
+        createDestinationWithSecurityRole(DestinationType.QUEUE, QUEUE_DEFAULT_TEMPLATE, 
+                                          jndiName, expectedMessage, QUEUE_COMPONENT_TYPE,
+                                          ROLE_NAME, Boolean.TRUE, Boolean.TRUE, Boolean.TRUE);
+        sendMessageToSecureQueueAndSpecifyUser(jndiName, JMS_USER, JMS_USER);
+    }
+    
+    /**
+     * Test Name: testSendMessageToSecureQueueAndSpecifyUserUsingExistingServiceFile
+     * Assertion: Verify the ability to send a message to a queue that has
+     * a security role defined. Use a queue that already exists.
+     */
+    public void testSendMessageToSecureQueueAndSpecifyUserUsingExistingServiceFile() throws Exception {
+        String jndiName = "ExistingQueueWithSecurityRoleUserSpecified";
+        
+        expandNavTreeArrow(JMS_NAV_LABEL);
+        sendMessageToSecureQueueAndSpecifyUser(jndiName, JMS_USER, JMS_USER);
+    }
+    
+    /**
+     * Test Name: testSendMessageToSecureQueueAndSpecifyInvalidUser
+     * Assertion: Attempt to send a message to a secure queue, specifying an
+     * invalid username. Make sure a JMSSecurityException occurs. 
+     */
+    public void testSendMessageToSecureQueueAndSpecifyInvalidUser() throws Exception {
+        String jndiName = "QueueWithSecurityRoleSpecifyInvalidUser";
+        String expectedMessage = ADD_MESSAGE + DestinationType.QUEUE.getName();
+        Exception jmsSecurityException = null;
+
+        createDestinationWithSecurityRole(DestinationType.QUEUE, QUEUE_DEFAULT_TEMPLATE, 
+                                          jndiName, expectedMessage, QUEUE_COMPONENT_TYPE,
+                                          ROLE_NAME, Boolean.TRUE, Boolean.TRUE, Boolean.TRUE);
+        
+        // Specify an invalid username when creating the queue connection
+        try {
+            sendMessageToSecureQueueAndSpecifyUser(jndiName, "fakeUser", "fakePassword");
+        } catch (JMSSecurityException e) {
+            jmsSecurityException = e;
+        } finally {
+            assertNotNull("Expected a JMSSecurityException to be thrown", jmsSecurityException);
+            deleteDestination(DestinationType.QUEUE, jndiName);    
+        }
+    }
+    
+    /**
+     * Test Name: testSendMessageToSecureQueueAndSpecifyInvalidUserUsingExistingServiceFile
+     * Assertion: Attempt to send a message to a secure queue, specifying an
+     * invalid username. Make sure a JMSSecurityException occurs. Use a queue
+     * that already exists. 
+     */
+    public void testSendMessageToSecureQueueAndSpecifyInvalidUserUsingExistingServiceFile() throws Exception {
+        String jndiName = "ExistingQueueWithSecurityRoleInvalidUserSpecified";
+        Exception jmsSecurityException = null;
+        
+        expandNavTreeArrow(JMS_NAV_LABEL);
+        
+        // Specify an invalid username when creating the queue connection
+        try {
+            sendMessageToSecureQueueAndSpecifyUser(jndiName, "fakeUser", "fakePassword");
+        } catch (JMSSecurityException e) {
+            jmsSecurityException = e;
+        } finally {
+            assertNotNull("Expected a JMSSecurityException to be thrown", jmsSecurityException);
+            deleteDestination(DestinationType.QUEUE, jndiName);    
+        }
+    }
+
+    /**
+     * Attempt to send a message to the queue given by jndiName,
+     * specifying the given username and password when creating the
+     * queue connection. If the username and password are not valid,
+     * a JMSSecurityException will be thrown.
+     */
+    private void sendMessageToSecureQueueAndSpecifyUser(String jndiName, 
+                                                        String username, 
+                                                        String password) throws Exception {
+
+        QueueSession session = createQueueSessionAndSpecifyUser(username, password);
+        Queue queue = getQueue(jndiName);
+
+        sendMessages(session, queue, 1);
+        
+        Map<String, String> expectedMetrics = new LinkedHashMap<String, String>();
+        expectedMetrics.put(MSG_COUNT, "1.0");
+           
+        checkDestinationMetrics(jndiName, expectedMetrics, getQueueSummaryMetrics(),
+                                DestinationType.QUEUE);
+    }
+    
+    /**
+     * Test Name: testSendMessageToSecureQueueWithoutSpecifyingUser
+     * Assertion: Make sure an error occurs when trying to send a message, without
+     * specifying a user, to a queue that has a security role configured.
+     * 
+     * This test should pass if a JMSSecurityException is thrown.
+     */
+    public void testSendMessageToSecureQueueWithoutSpecifyingUser() throws Exception {
+        String jndiName = "QueueWithSecurityRoleNoUserSpecified";
+        String expectedMessage = ADD_MESSAGE + DestinationType.QUEUE.getName();
+        
+        createDestinationWithSecurityRole(DestinationType.QUEUE, QUEUE_DEFAULT_TEMPLATE, 
+                                          jndiName, expectedMessage, QUEUE_COMPONENT_TYPE,
+                                          ROLE_NAME, Boolean.TRUE, Boolean.TRUE, Boolean.TRUE);
+
+        sendMessageToSecureQueueWithoutSpecifyingUser(jndiName);
+    }
+    
+    /**
+     * Test Name: testSendMessageToSecureQueueWithoutSpecifyingUserUsingExistingServiceFile
+     * Assertion: Make sure an error occurs when trying to send a message, without
+     * specifying a user, to a queue that has a security role configured.
+     * Use a queue that already exists.
+     * 
+     * This test should pass if a JMSSecurityException is thrown.
+     */
+    public void testSendMessageToSecureQueueWithoutSpecifyingUserUsingExistingServiceFile() throws Exception {
+        String jndiName = "ExistingQueueWithSecurityRoleNoUserSpecified";
+        
+        expandNavTreeArrow(JMS_NAV_LABEL);
+        sendMessageToSecureQueueWithoutSpecifyingUser(jndiName);
+    }
+    
+    /**
+     * Common code for the testSendMessageToSecureQueueWithoutSpecifyingUser* tests.
+     */
+    private void sendMessageToSecureQueueWithoutSpecifyingUser(String jndiName) throws Exception {
+        
+        Exception jmsSecurityException = null;
+        
+        // We should not be able to send a message since no user is specified when
+        // creating the queue connection
+        try {
+            createQueueSessionAndSendMessages(1, jndiName);
+        } catch (JMSSecurityException e) {
+            jmsSecurityException = e;
+        } finally {
+            assertNotNull("Expected a JMSSecurityException to be thrown", jmsSecurityException);
+            deleteDestination(DestinationType.QUEUE, jndiName);    
+        }
+    }
+}

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jmsDestinations/JMSTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jmsDestinations/JMSTest.java	2009-05-04 17:43:37 UTC (rev 375)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/jmsDestinations/JMSTest.java	2009-05-04 19:29:05 UTC (rev 376)
@@ -53,6 +53,12 @@
 import javax.jms.TextMessage;
 import javax.jms.JMSException;
 import javax.naming.NamingException;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.CompositeValueSupport;
+import org.jboss.metatype.api.values.MapCompositeValueSupport;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.types.MapCompositeMetaType;
+import org.jboss.metatype.plugins.types.MutableCompositeMetaType;
 
 /**
  * This is the base test class for JMS tests. This class
@@ -162,6 +168,25 @@
     public TopicConnection topicConnection = null;
     public QueueConnection queueConnection = null;
     
+    /** The following variables are needed for tests that use secure topics/queues. **/
+    
+    // The meta type
+    protected static final MapCompositeMetaType securityConfType;
+
+    // The composite meta type.
+    public static MutableCompositeMetaType composite;
+
+    static
+    {
+        // Create the meta type
+        composite = new MutableCompositeMetaType("SecurityConfig", "The security config");
+        composite.addItem("read", "read permission", SimpleMetaType.BOOLEAN);
+        composite.addItem("write", "write permission", SimpleMetaType.BOOLEAN);
+        composite.addItem("create", "create permission", SimpleMetaType.BOOLEAN);
+        composite.freeze();
+        securityConfType = new MapCompositeMetaType(composite);
+    }
+    
     /**
      * Create a new topic or queue using the given destination type and properties.
      */
@@ -232,6 +257,101 @@
     }
     
     /**
+     * Create a new topic or queue with a security role configured.
+     */
+    protected void createDestinationWithSecurityRole(DestinationType destinationType, 
+                                                     String destinationTemplate, 
+                                                     String jndiName, 
+                                                     String expectedMessage,
+                                                     ComponentType componentType,
+                                                     String roleName,
+                                                     boolean canRead,
+                                                     boolean canWrite,
+                                                     boolean canCreate) throws Exception {
+
+        Map<String, MetaValue> propertiesMap = new LinkedHashMap<String, MetaValue>();
+        propertiesMap.put("name", SimpleValueSupport.wrap(jndiName));
+        propertiesMap.put("JNDIName", SimpleValueSupport.wrap(jndiName));
+
+        // Fill in the property values
+        createDestination(destinationType, destinationTemplate, propertiesMap);
+
+        // Add a security role
+        createSecurityRole(roleName, canRead, canWrite, canCreate);
+
+        checkClientAndServerMessages(expectedMessage, expectedMessage, false);
+
+        // Make sure the destination is deployed and that the securityConfig property
+        // was set correctly
+        assertTrue("The destination is not deployed ",
+                   isDeployed(jndiName + "-service.xml"));
+
+        Map<String, MetaValue> actualProperties = getComponentProperties(jndiName, componentType);
+
+        Map<String, MetaValue> values = new HashMap<String, MetaValue>();
+        values.put(roleName, createCompositeValue(true, true, true));
+        CompositeValue expectedSecurityConfigProp = new MapCompositeValueSupport(values, securityConfType);
+
+        assertEquals("The 'securityConfig' property was not set correctly: ", 
+                     expectedSecurityConfigProp, 
+                     actualProperties.get("securityConfig"));
+    }
+
+    /**
+     * Create a security role.
+     */
+    protected void createSecurityRole(String roleName, boolean canRead, 
+                                      boolean canWrite, boolean canCreate) throws IOException {
+
+        HtmlForm form = (HtmlForm)client.getElement(RESOURCE_CONFIGURATION_FORM);
+        String xpath = ".//a[@title=\"" + ADD_NEW_CONFIG_BUTTON + "\"]";
+
+        HtmlAnchor addSecurityRoleButton = (HtmlAnchor)form.getFirstByXPath(xpath);
+        addSecurityRoleButton.click();
+
+        // Create the new role
+        Map<String, MetaValue> securityRoleMap = new LinkedHashMap<String, MetaValue>();
+        securityRoleMap.put("name", SimpleValueSupport.wrap(roleName));
+        securityRoleMap.put("read", SimpleValueSupport.wrap(canRead));
+        securityRoleMap.put("write", SimpleValueSupport.wrap(canWrite));
+        securityRoleMap.put("create", SimpleValueSupport.wrap(canCreate));
+
+        Map<String, String> formattedPropertiesMap = formatPropertiesMap(securityRoleMap);
+        fillOutForm(formattedPropertiesMap, EDIT_RESOURCE_CONFIGURATION_FORM);  
+
+        client.click(EDIT_RESOURCE_CONFIGURATION_FORM_OK_BUTTON);
+        client.click(SAVE_BUTTON);
+    }
+
+    /**
+     * Set up a security role.
+     */
+    protected CompositeValue createCompositeValue(Boolean read, Boolean write, Boolean create) {
+        Map<String, MetaValue> map = new HashMap<String, MetaValue>();
+
+        map.put("read", new SimpleValueSupport(SimpleMetaType.BOOLEAN, read));
+        map.put("write", new SimpleValueSupport(SimpleMetaType.BOOLEAN, write));
+        map.put("create", new SimpleValueSupport(SimpleMetaType.BOOLEAN, create));
+
+        return new CompositeValueSupport(composite, map);
+    }
+
+    /**
+     * Check that the metrics for the given destination are correct.
+     */
+    protected void checkDestinationMetrics(String jndiName,
+                                           Map<String, String> expectedMetrics,
+                                           ArrayList<String> summaryMetrics,
+                                           DestinationType destinationType) throws Exception {
+        checkResourceMetrics(JMS_NAV_LABEL, destinationType.getNavLabel(), 
+                             jndiName, expectedMetrics, summaryMetrics);
+
+        // Clean up
+        disconnect();
+        deleteDestination(destinationType, jndiName);  
+    }
+    
+    /**
      * Create a map of property names to property values for a particular
      * destination. The desired property names are given by specificProperties.
      * (This is useful when we need to check the values of some specific properties
@@ -511,4 +631,43 @@
             createDurableTopicSubscriber(session, topic, jndiName + "Subscriber" + i);
         }
     }
+    
+    /**
+     * Create a topic session and specify the given username and password
+     * when creating the TopicConnection.
+     */
+    protected TopicSession createTopicSessionAndSpecifyUser(String username, 
+                                                            String password) throws Exception {
+        InitialContext context = new InitialContext();
+        Object tmp = context.lookup(TOPIC_FACTORY);
+
+        TopicConnectionFactory tcf = (TopicConnectionFactory)tmp;
+        topicConnection = tcf.createTopicConnection(username, password);
+        topicConnection.setClientID(CLIENT_ID);
+
+        TopicSession topicSession = topicConnection.createTopicSession(Boolean.FALSE, 
+                                                                       TopicSession.AUTO_ACKNOWLEDGE);
+        topicConnection.start();
+
+        return topicSession;
+    }
+
+    /**
+     * Create a queue session and specify the given username and password
+     * when creating the QueueConnection.
+     */
+    protected QueueSession createQueueSessionAndSpecifyUser(String username,
+                                                            String password) throws Exception {
+        InitialContext context = new InitialContext();
+        Object tmp = context.lookup(QUEUE_FACTORY);
+
+        QueueConnectionFactory qcf = (QueueConnectionFactory)tmp;
+        queueConnection = qcf.createQueueConnection(username, password);
+
+        QueueSession queueSession = queueConnection.createQueueSession(Boolean.FALSE, 
+                                                                       QueueSession.AUTO_ACKNOWLEDGE);
+        queueConnection.start();
+
+        return queueSession;
+    }
 }

Added: trunk/jsfunit/testdata/destinations/ExistingQueueWithSecurityRoleInvalidUserSpecified-service.xml
===================================================================
--- trunk/jsfunit/testdata/destinations/ExistingQueueWithSecurityRoleInvalidUserSpecified-service.xml	                        (rev 0)
+++ trunk/jsfunit/testdata/destinations/ExistingQueueWithSecurityRoleInvalidUserSpecified-service.xml	2009-05-04 19:29:05 UTC (rev 376)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<server>
+    <mbean xmbean-dd="xmdesc/Queue-xmbean.xml" name="jboss.messaging.destination:service=Queue,name=ExistingQueueWithSecurityRoleInvalidUserSpecified" code="org.jboss.jms.server.destination.QueueService">
+        <annotation>@org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.QueueServiceMO)</annotation>
+        <attribute name="JNDIName">ExistingQueueWithSecurityRoleInvalidUserSpecified</attribute>
+        <attribute name="SecurityConfig">
+            <security>
+                <role create="true" name="publisher" read="true" write="true"/>
+            </security>
+        </attribute>
+        <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+        <depends>jboss.messaging:service=PostOffice</depends>
+    </mbean>
+</server>

Added: trunk/jsfunit/testdata/destinations/ExistingQueueWithSecurityRoleNoUserSpecified-service.xml
===================================================================
--- trunk/jsfunit/testdata/destinations/ExistingQueueWithSecurityRoleNoUserSpecified-service.xml	                        (rev 0)
+++ trunk/jsfunit/testdata/destinations/ExistingQueueWithSecurityRoleNoUserSpecified-service.xml	2009-05-04 19:29:05 UTC (rev 376)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<server>
+    <mbean xmbean-dd="xmdesc/Queue-xmbean.xml" name="jboss.messaging.destination:service=Queue,name=ExistingQueueWithSecurityRoleNoUserSpecified" code="org.jboss.jms.server.destination.QueueService">
+        <annotation>@org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.QueueServiceMO)</annotation>
+        <attribute name="JNDIName">ExistingQueueWithSecurityRoleNoUserSpecified</attribute>
+        <attribute name="SecurityConfig">
+            <security>
+                <role create="true" name="publisher" read="true" write="true"/>
+            </security>
+        </attribute>
+        <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+        <depends>jboss.messaging:service=PostOffice</depends>
+    </mbean>
+</server>

Added: trunk/jsfunit/testdata/destinations/ExistingQueueWithSecurityRoleUserSpecified-service.xml
===================================================================
--- trunk/jsfunit/testdata/destinations/ExistingQueueWithSecurityRoleUserSpecified-service.xml	                        (rev 0)
+++ trunk/jsfunit/testdata/destinations/ExistingQueueWithSecurityRoleUserSpecified-service.xml	2009-05-04 19:29:05 UTC (rev 376)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<server>
+    <mbean xmbean-dd="xmdesc/Queue-xmbean.xml" name="jboss.messaging.destination:service=Queue,name=ExistingQueueWithSecurityRoleUserSpecified" code="org.jboss.jms.server.destination.QueueService">
+        <annotation>@org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.QueueServiceMO)</annotation>
+        <attribute name="JNDIName">ExistingQueueWithSecurityRoleUserSpecified</attribute>
+        <attribute name="SecurityConfig">
+            <security>
+                <role create="true" name="publisher" read="true" write="true"/>
+            </security>
+        </attribute>
+        <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+        <depends>jboss.messaging:service=PostOffice</depends>
+    </mbean>
+</server>

Added: trunk/jsfunit/testdata/destinations/ExistingTopicWithSecurityRoleInvalidUserSpecified-service.xml
===================================================================
--- trunk/jsfunit/testdata/destinations/ExistingTopicWithSecurityRoleInvalidUserSpecified-service.xml	                        (rev 0)
+++ trunk/jsfunit/testdata/destinations/ExistingTopicWithSecurityRoleInvalidUserSpecified-service.xml	2009-05-04 19:29:05 UTC (rev 376)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<server>
+    <mbean xmbean-dd="xmdesc/Topic-xmbean.xml" name="jboss.messaging.destination:service=Topic,name=ExistingTopicWithSecurityRoleInvalidUserSpecified" code="org.jboss.jms.server.destination.TopicService">
+        <annotation>@org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.TopicServiceMO)</annotation>
+        <attribute name="JNDIName">ExistingTopicWithSecurityRoleInvalidUserSpecified</attribute>
+        <attribute name="SecurityConfig">
+            <security>
+                <role create="true" name="publisher" read="true" write="true"/>
+            </security>
+        </attribute>
+        <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+        <depends>jboss.messaging:service=PostOffice</depends>
+    </mbean>
+</server>

Added: trunk/jsfunit/testdata/destinations/ExistingTopicWithSecurityRoleNoUserSpecified-service.xml
===================================================================
--- trunk/jsfunit/testdata/destinations/ExistingTopicWithSecurityRoleNoUserSpecified-service.xml	                        (rev 0)
+++ trunk/jsfunit/testdata/destinations/ExistingTopicWithSecurityRoleNoUserSpecified-service.xml	2009-05-04 19:29:05 UTC (rev 376)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<server>
+    <mbean xmbean-dd="xmdesc/Topic-xmbean.xml" name="jboss.messaging.destination:service=Topic,name=ExistingTopicWithSecurityRoleNoUserSpecified" code="org.jboss.jms.server.destination.TopicService">
+        <annotation>@org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.TopicServiceMO)</annotation>
+        <attribute name="JNDIName">ExistingTopicWithSecurityRoleNoUserSpecified</attribute>
+        <attribute name="SecurityConfig">
+            <security>
+                <role create="true" name="publisher" read="true" write="true"/>
+            </security>
+        </attribute>
+        <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+        <depends>jboss.messaging:service=PostOffice</depends>
+    </mbean>
+</server>

Added: trunk/jsfunit/testdata/destinations/ExistingTopicWithSecurityRoleUserSpecified-service.xml
===================================================================
--- trunk/jsfunit/testdata/destinations/ExistingTopicWithSecurityRoleUserSpecified-service.xml	                        (rev 0)
+++ trunk/jsfunit/testdata/destinations/ExistingTopicWithSecurityRoleUserSpecified-service.xml	2009-05-04 19:29:05 UTC (rev 376)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<server>
+    <mbean xmbean-dd="xmdesc/Topic-xmbean.xml" name="jboss.messaging.destination:service=Topic,name=ExistingTopicWithSecurityRoleUserSpecified" code="org.jboss.jms.server.destination.TopicService">
+        <annotation>@org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.TopicServiceMO)</annotation>
+        <attribute name="JNDIName">ExistingTopicWithSecurityRoleUserSpecified</attribute>
+        <attribute name="SecurityConfig">
+            <security>
+                <role create="true" name="publisher" read="true" write="true"/>
+            </security>
+        </attribute>
+        <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+        <depends>jboss.messaging:service=PostOffice</depends>
+    </mbean>
+</server>




More information about the embjopr-commits mailing list