18149 - Add tests for connection assertions (connectLocalAFUNIX & connectLocalAFUNIXunauth) osol_166
authorDan Labrecque <dan.labrecque@oracle.com>
Tue, 17 May 2011 10:07:43 -0400
changeset 705 ea1ecdb64a75
parent 704 172b0cfc1fd1
child 706 9a1e4e1fa997
18149 - Add tests for connection assertions (connectLocalAFUNIX & connectLocalAFUNIXunauth)
usr/src/test/java/src/client/ConnectTest.java
--- a/usr/src/test/java/src/client/ConnectTest.java	Sat May 14 23:35:31 2011 -0400
+++ b/usr/src/test/java/src/client/ConnectTest.java	Tue May 17 10:07:43 2011 -0400
@@ -1,3 +1,4 @@
+
 
 /*
  * CDDL HEADER START
@@ -57,7 +58,8 @@
 
     private static final String CERT_FILENAME = "cert.pem";
     private static final String KEY_FILENAME = "key.pem";
-    private static final String TEST_DIRNAME = "/tmp/rad_connect_test";
+    private static final String UDS_FILENAME = "uds";
+    private static final String TEMP_DIRNAME = "/tmp/rad_connect_test";
     private static final String TRUSTSTORE_FILENAME = "truststore";
     private static final String TRUSTSTORE_PASSWORD = "trustpass";
 
@@ -68,43 +70,45 @@
     @Test
     @Desc("Connect to a local rad daemon using IPv4 loopback.")
     public void testConnectLocalTCP4() throws Exception {
-        connectLocalTCP("127.0.0.1", getFreePort());
+	connectLocalTCP("127.0.0.1", getFreePort());
     }
 
     @Test
     @Desc("Connect to a local rad daemon using IPv6 loopback.")
     public void testConnectLocalTCP6() throws Exception {
-        connectLocalTCP("[::1]", getFreePort());
+	connectLocalTCP("[::1]", getFreePort());
     }
 
     @Test
     @Desc("Connect to a local rad daemon using TLS over IPv4 loopback")
     public void testConnectLocalTLS4() throws Exception {
-        connectLocalTLS("127.0.0.1", getFreePort());
+	connectLocalTLS("127.0.0.1", getFreePort());
     }
 
     @Test
     @Desc("Connect to a local rad daemon using TLS over IPv6 loopback")
     public void testConnectLocalTLS6() throws Exception {
-        connectLocalTLS("[::1]", getFreePort());
+	connectLocalTLS("[::1]", getFreePort());
     }
 
+    @Test
     @Desc("Connect to a local rad daemon using an AF_UNIX socket.")
     public void testConnectLocalAFUNIX() throws Exception {
-
+	connectLocalUDS(true);
     }
 
+    @Test
     @Desc("Connect to a local rad daemon using an AF_UNIX socket with " +
 	  "peercred=false.")
     public void testConnectLocalAFUNIXunauth() throws Exception {
-
+	connectLocalUDS(false);
     }
 
     @After
     @Override
     public void tearDown() throws IOException {
 	super.tearDown();
-	deleteTestDir();
+	deleteTempDir();
     }
 
     //
@@ -148,7 +152,7 @@
 	};
 
 	// Set up server.
-	setUpTestDir();
+	setUpTempDir();
 	setUpCommon(auxargs, "/usr/lib/rad/transport/mod_xport_tls.so");
 	testConnection(getMBSC());
 
@@ -169,6 +173,30 @@
     }
 
     /**
+     * Connect to a local rad daemon using UDS.
+     *
+     * @param auth The value for the peercred option.
+     */
+    protected void connectLocalUDS(boolean auth) throws Exception {
+	File uds = getUDSFile();
+	String[] auxargs = new String[] { "-t",
+	    "uds:path=" + uds.getAbsolutePath() +
+	    ",peercred=" + auth
+	};
+
+	// Set up server.
+	setUpTempDir();
+	setUpCommon(auxargs, "/usr/lib/rad/transport/mod_xport_uds.so");
+	testConnection(getMBSC());
+
+	// Perform test.
+	JMXConnector conn = JMXConnectorFactory.connect(new JMXServiceURL(
+	    "service:jmx:raduds://" + uds.getAbsolutePath()), null);
+	testConnection(conn.getMBeanServerConnection());
+	conn.close();
+    }
+
+    /**
      * Get the next free port.
      *
      * Note: There is no guarantee that the port chosen by
@@ -185,28 +213,35 @@
      * Get certificate file.
      */
     protected File getCertificateFile() {
-	return new File(TEST_DIRNAME, CERT_FILENAME);
+	return new File(TEMP_DIRNAME, CERT_FILENAME);
     }
 
     /**
      * Get private key file.
      */
     protected File getPrivateKeyFile() {
-	return new File(TEST_DIRNAME, KEY_FILENAME);
+	return new File(TEMP_DIRNAME, KEY_FILENAME);
     }
 
     /**
-     * Get test directory.
+     * Get temp directory.
      */
-    protected File getTestDir() {
-	return new File(TEST_DIRNAME);
+    protected File getTempDir() {
+	return new File(TEMP_DIRNAME);
     }
 
     /**
      * Get trust store file.
      */
     protected File getTrustStoreFile() {
-	return new File(TEST_DIRNAME, TRUSTSTORE_FILENAME);
+	return new File(TEMP_DIRNAME, TRUSTSTORE_FILENAME);
+    }
+
+    /**
+     * Get Unix domain socket file.
+     */
+    protected File getUDSFile() {
+	return new File(TEMP_DIRNAME, UDS_FILENAME);
     }
 
     /**
@@ -227,15 +262,15 @@
     // Private methods
     //
 
-    // Delete test directory.
-    private void deleteTestDir() {
-	File testDir = getTestDir();
-	if (testDir.exists()) {
-	    File[] files = testDir.listFiles();
+    // Delete temp directory.
+    private void deleteTempDir() {
+	File tempDir = getTempDir();
+	if (tempDir.exists()) {
+	    File[] files = tempDir.listFiles();
 	    for (File file : files) {
 		file.delete();
 	    }
-	    testDir.delete();
+	    tempDir.delete();
 	}
     }
 
@@ -267,13 +302,13 @@
 	fos.close();
     }
 
-    // Set up test directory.
-    private void setUpTestDir() throws IOException {
-	File testDir = getTestDir();
-	if (!testDir.exists()) {
-	    if (!testDir.mkdirs()) {
+    // Set up temp directory.
+    private void setUpTempDir() throws IOException {
+	File tempDir = getTempDir();
+	if (!tempDir.exists()) {
+	    if (!tempDir.mkdirs()) {
 		throw new IOException("Cannot create directory: " +
-		    testDir.getAbsolutePath());
+		    tempDir.getAbsolutePath());
 	    }
 	}
     }