View Javadoc

1   /*
2    * $Id: GWESSecurityTest.java 1529 2011-06-22 16:37:19Z hoheisel $
3    *
4    * Copyright (c) 2007
5    * Fraunhofer Institute for Computer Architecture and Software Technology
6    * See http://www.first.fraunhofer.de for more details.
7    */
8   
9   package net.kwfgrid.gwes;
10  
11  import net.kwfgrid.gwes.exception.LoggingException;
12  import net.kwfgrid.gwes.util.StringUtils;
13  import org.apache.log4j.Logger;
14  import junit.framework.Test;
15  import junit.framework.TestSuite;
16  import junit.framework.Assert;
17  
18  /**
19   * <code>
20   * maven -Dtestcase=net.kwfgrid.gwes.GWESSecurityTest test:single
21   * </code>
22   *
23   * @author Andreas Hoheisel
24   *         (<a href="http://www.andreas-hoheisel.de">www.andreas-hoheisel.de</a>)
25   * @version $Id: GWESSecurityTest.java 1529 2011-06-22 16:37:19Z hoheisel $
26   */
27  public final class GWESSecurityTest extends LocalGWESAbstractTestCase {
28  
29      static Logger logger = Logger.getLogger(GWESSecurityTest.class);
30  
31      /**
32       * Create the test case.
33       *
34       * @param testName name of the test case
35       */
36      public GWESSecurityTest(String testName) throws LoggingException {
37          super(testName);
38      }
39  
40      /**
41       * @return the suite of tests being tested
42       */
43      public static Test suite() {
44          return new TestSuite(GWESSecurityTest.class);
45      }
46  
47      public void testJSEE() {
48          boolean test = false;
49          try {
50              Class.forName("com.sun.net.ssl.internal.ssl.Provider");
51              test = true;
52          } catch(Exception e) {
53              logger.info("JSSE is NOT installed correctly!");
54          }
55          logger.info("JSSE is installed correctly!");
56          Assert.assertTrue("JSSE",test);
57      }
58  
59      public void testTrustStore() {
60          String trustStore = System.getProperty("javax.net.ssl.trustStore");
61          if(trustStore == null) logger.info("javax.net.ssl.trustStore is not defined");
62          else logger.info("javax.net.ssl.trustStore = " + trustStore);
63      }
64  
65      public void testExtractFilteredCNFromDN() {
66          // test GSSCredential
67          String dn = "/C=DE/O=GridGermany/OU=Firma A/OU=Abteilung/CN=Prof. Dr. Name";
68          String cn = StringUtils.extractFilteredCNFromDN(dn);
69          logger.info("CN="+cn);
70          Assert.assertEquals("CN","Prof--Dr--Name",cn);
71  
72          //test tomcat TLS
73          dn = "CN=Prof. Dr. Name, OU=Abteilung, OU=Firma A, O=GridGermany, C=DE";
74          cn = StringUtils.extractFilteredCNFromDN(dn);
75          logger.info("CN="+cn);
76          Assert.assertEquals("CN","Prof--Dr--Name",cn);
77  
78          //test userID without DN
79          dn = "Prof. Dr. Name";
80          cn = StringUtils.extractFilteredCNFromDN(dn);
81          logger.info("CN="+cn);
82          Assert.assertEquals("CN","Prof--Dr--Name",cn);
83      }
84  
85      /**
86       * *******************************************************************************************
87       * End of public test classes.
88       * ********************************************************************************************
89       */
90  
91  }