    1   package groovy.security;
    2
    3   import junit.framework.Test;
    4   import junit.framework.TestSuite;
    5   import junit.textui.TestRunner;
    6
    7
    8   /***
    9    * Read a .groovy file from a signed jar and verify that a policy file grant with a signedBy field
    10   * works.  The following steps were used to create and manage the keys used to sign and read the jar:
    11   * <ol>
    12   * <li>keytool -genkey -alias groovy -keypass keypass -keystore groovystore -storepass storepass -validity 7000
    13   * <li>keytool -export -keystore groovystore -alias groovy -file GroovyDev.cer
    14   * <li>keytool -import -alias groovy -file GroovyDev.cer -keystore groovykeys
    15   * </ol>
    16   * Once the keys are constructed, creat the jar and sign:
    17   * <ol>
    18   * <li>jar -cvf Groovy.jar groovy
    19   * <li>jarsigner -keystore groovystore -signedjar GroovyJarTest.jar Groovy.jar groovy
    20   * </ol>
    21   * Add the keystore to the policy file and write the grant:
    22   * <ol>
    23   * <li>keystore "file:${user.dir}/src/test/groovy/security/groovykeys";
    24   * </ol>
    25   */
    26  public class SignedJarTest extends SecurityTestSupport {
    27
    28  	public static void main(String[] args) {
    29          TestRunner.run( suite() );
    30      }
    31
    32      public static Test suite() {
    33      	return new TestSuite(SignedJarTest.class);
    34      }
    35
    36      public void testReadSignedJar() throws Exception {
    37      	if (!isSecurityAvailable() || (notYetImplemented())) return;
    38
    39      	//spg 2006-02-09 The GroovyClassLoader code that checked jar files
    40      	//for source files was removed last July.  This test will not function
    41      	//without that capability.
    42          Class c = loader.loadClass("groovy.security.JarTest");  // ClassNotFoundException !
    43      	executeTest(c, null);
    44
    45      }
    46  }