Browse Source

-tests for old and new signjar features written; working

-signjar test patched for offline testing
-fixed SignJar to pass the tests
-doc updates to match tested code


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278049 13f79535-47bb-0310-9956-ffa450edef68
master
Steve Loughran 20 years ago
parent
commit
abf8e1ecce
6 changed files with 265 additions and 52 deletions
  1. +10
    -0
      WHATSNEW
  2. +0
    -1
      build.xml
  3. +1
    -8
      docs/manual/CoreTasks/signjar.html
  4. +142
    -31
      src/etc/testcases/taskdefs/signjar.xml
  5. +34
    -10
      src/main/org/apache/tools/ant/taskdefs/SignJar.java
  6. +78
    -2
      src/testcases/org/apache/tools/ant/taskdefs/SignJarTest.java

+ 10
- 0
WHATSNEW View File

@@ -40,6 +40,10 @@ Changes that could break older environments:
actually crashes the JVM on our (Java1.5) systems, we don't think any actually crashes the JVM on our (Java1.5) systems, we don't think any
build files which actually worked will be affected by the change. build files which actually worked will be affected by the change.


* <signjar> used to ignore a nested fileset when a jar was also provided
as an attribute, printing a warning message; now it signs files in the
fileset.



Fixed bugs: Fixed bugs:
----------- -----------
@@ -141,6 +145,12 @@ Other changes:
* <sync> has a new nested element <preserveInTarget> that can be used * <sync> has a new nested element <preserveInTarget> that can be used
to protect extra-content in the target directory. Bugzilla Report to protect extra-content in the target directory. Bugzilla Report
21832. 21832.
* <signjar> now supports:
-nested filesets at the same time as the jar attribute
-a destDir attribute with the appropriate dependency logic, which
can be used with the jar attribute or nested filesets
-a mapper to permit filename remapping on signing


Changes from Ant 1.6.2 to current Ant 1.6 CVS version Changes from Ant 1.6.2 to current Ant 1.6 CVS version
===================================================== =====================================================


+ 0
- 1
build.xml View File

@@ -334,7 +334,6 @@


<patternset id="onlinetests"> <patternset id="onlinetests">
<exclude name="**/GetTest.java" if="offline"/> <exclude name="**/GetTest.java" if="offline"/>
<exclude name="**/SignJarTest.java" if="offline"/>
</patternset> </patternset>


<patternset id="teststhatfail"> <patternset id="teststhatfail">


+ 1
- 8
docs/manual/CoreTasks/signjar.html View File

@@ -24,16 +24,11 @@ Dependency rules
<li>Out of date destination JARs are created/signed</li> <li>Out of date destination JARs are created/signed</li>
<li>If a destination file and a source file are the same, <li>If a destination file and a source file are the same,
and <tt>lazy</tt> is true, the JAR is only signed if it does not and <tt>lazy</tt> is true, the JAR is only signed if it does not
contain any signature.</li>
contain a signature by this alias.</li>
<li>If a destination file and a source file are the same, <li>If a destination file and a source file are the same,
and <tt>lazy</tt> is false, the JAR is signed.</li> and <tt>lazy</tt> is false, the JAR is signed.</li>
</ul> </ul>


<p>
When checking signatures, the actual signatory itself is not verified. This
means that "lazy" checks do not work if a JAR is signed by multiple authors.
</p>

<h3>Parameters</h3> <h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0"> <table border="1" cellpadding="2" cellspacing="0">
<tr> <tr>
@@ -131,13 +126,11 @@ block</td>
<td valign="top">fileset of JAR files to sign. </td> <td valign="top">fileset of JAR files to sign. </td>
<td valign="top" align="center">No</td> <td valign="top" align="center">No</td>
</tr> </tr>
<!--
<tr> <tr>
<td valign="top">mapper</td> <td valign="top">mapper</td>
<td valign="top">A mapper to rename jar files during signing</td> <td valign="top">A mapper to rename jar files during signing</td>
<td valign="top" align="center">No, and only one can be supplied</td> <td valign="top" align="center">No, and only one can be supplied</td>
</tr> </tr>
-->
</table> </table>
<h3>Examples</h3> <h3>Examples</h3>
<blockquote><pre> <blockquote><pre>


+ 142
- 31
src/etc/testcases/taskdefs/signjar.xml View File

@@ -1,48 +1,86 @@
<project name="signjartest" default="help" basedir=".."> <project name="signjartest" default="help" basedir="..">

<property name="classes.dir" value="../../../build/classes"/> <property name="classes.dir" value="../../../build/classes"/>
<property name="sign.dir" location="signedjars" />
<property name="subdir" location="${sign.dir}/subdir" />
<property name="test.jar" location="${sign.dir}/signtest.jar" />
<property name="subdirtest.jar" location="${subdir}/signtest.jar" />
<mkdir dir="${sign.dir}" />
<mkdir dir="${subdir}" />
<macrodef name="assertSigned">
<attribute name="jar" default="${test.jar}" />
<sequential>
<fail message="not signed: @{jar}" >
<condition>
<not><issigned file="@{jar}" /></not>
</condition>
</fail>
</sequential>
</macrodef>

<presetdef name="sign-base">
<signjar alias="testonly" keystore="testkeystore"
storepass="apacheant"/>
</presetdef>
<presetdef name="sign">
<sign-base jar="${test.jar}" />
</presetdef>
<target name="jar" >
<jar jarfile="${test.jar}" basedir="${classes.dir}" includes="**/Task.class"/>
</target>


<target name="basic">
<jar jarfile="signtest.jar" basedir="${classes.dir}" includes="**/Task.class"/>
<signjar jar="signtest.jar" alias="testonly" keystore="testkeystore"
storepass="apacheant"/>
<target name="clean">
<delete dir="${sign.dir}"/>
</target>

<target name="help">
<echo>This build is for use with Ant's test cases</echo>
</target>
<target name="basic" depends="jar">
<sign />
<assertSigned/>
</target> </target>


<target name="sigfile">
<jar jarfile="signtest.jar" basedir="${classes.dir}" includes="**/Task.class"/>
<signjar jar="signtest.jar" alias="testonly" keystore="testkeystore"
storepass="apacheant" sigfile="TEST"/>
<target name="sigfile" depends="jar">
<sign sigfile="TEST"/>
<assertSigned/>
</target> </target>


<target name="maxmemory">
<jar jarfile="signtest.jar" basedir="${classes.dir}" includes="**/Task.class"/>
<signjar jar="signtest.jar" alias="testonly" keystore="testkeystore"
storepass="apacheant" maxmemory="128m"/>
<target name="maxmemory" depends="jar">
<sign maxmemory="128m"/>
<assertSigned/>
</target> </target>


<target name="urlKeystoreFile">
<jar jarfile="signtest.jar" basedir="${classes.dir}" includes="**/Task.class"/>
<signjar jar="signtest.jar" alias="testonly" keystore="file://../testkeystore"
storepass="apacheant" maxmemory="128m"/>
<target name="urlKeystoreFile" depends="jar">
<sign keystore="file://../testkeystore"
maxmemory="128m"/>
<assertSigned/>
</target> </target>


<!--TODO: change this when we move to SUBVERSION--> <!--TODO: change this when we move to SUBVERSION-->
<target name="urlKeystoreHTTP">
<jar jarfile="signtest.jar" basedir="${classes.dir}" includes="**/Task.class"/>
<signjar jar="signtest.jar" alias="testonly"
keystore="http://cvs.apache.org/viewcvs.cgi/*checkout*/ant/src/etc/testcases/testkeystore?rev=HEAD"
storepass="apacheant" maxmemory="128m"/>
<target name="urlKeystoreHTTP" depends="jar">
<sign
keystore="http://cvs.apache.org/viewcvs.cgi/*checkout*/ant/src/etc/testcases/testkeystore?rev=HEAD"
/>
<assertSigned/>
</target> </target>


<target name="preserveLastModified">
<jar jarfile="signtest.jar" basedir="${classes.dir}" includes="**/Task.class"/>
<touch file="signtest.jar" datetime="06/28/2000 2:02 pm"/>
<signjar jar="signtest.jar" alias="testonly" keystore="testkeystore" storepass="apacheant"
<target name="preserveLastModified" depends="jar">
<touch file="${test.jar}" datetime="06/28/2000 2:02 pm"/>
<sign
preservelastmodified="true"/> preservelastmodified="true"/>
<assertSigned />
<fail message="preserveLastModified did not preserve the last modified time"> <fail message="preserveLastModified did not preserve the last modified time">
<condition> <condition>
<not> <not>
<isfileselected file="signtest.jar">
<isfileselected file="${test.jar}" >
<date datetime="06/28/2000 2:02 pm" when="equal"/> <date datetime="06/28/2000 2:02 pm" when="equal"/>
</isfileselected> </isfileselected>
</not> </not>
@@ -50,13 +88,86 @@
</fail> </fail>
</target> </target>


<target name="clean">
<delete file="signtest.jar"/>
<target name="testFileset" depends="jar">
<sign-base>
<fileset file="${test.jar}" />
</sign-base>
<assertSigned/>
</target> </target>


<target name="help">
<echo>This build is for use with Ant's test cases</echo>
<target name="testFilesetAndJar" depends="jar">
<sign-base jar="${test.jar}" lazy="true">
<fileset file="${test.jar}" />
</sign-base>
<assertSigned/>
</target>
<target name="testFilesetAndSignedJar" depends="jar">
<sign-base signedjar="${sign.dir}/newfile.jar">
<fileset file="${test.jar}" />
</sign-base>
</target>
<target name="testSignedJar" depends="jar">
<property name="new.jar" location="${sign.dir}/newfile.jar" />
<sign signedjar="${new.jar}"/>
<assertSigned jar="${new.jar}"/>
</target> </target>


<target name="testDestDirAndSignedJar" depends="jar">
<sign destDir="${subdir}" signedjar="${sign.dir}/newfile.jar"/>
</target>

<target name="testDestDir" depends="jar">
<sign destDir="${subdir}" />
<assertSigned jar="${subdirtest.jar}"/>
</target>
<target name="testDestDirFileset" depends="jar">
<sign-base destDir="${subdir}">
<fileset file="${test.jar}" />
</sign-base>
<assertSigned jar="${subdirtest.jar}"/>
</target>
<target name="testMapperNoDest" depends="jar">
<sign-base >
<flattenmapper />
<fileset file="${test.jar}" />
</sign-base>
</target>
<target name="testMapperFileset" depends="jar">
<sign-base destDir="${subdir}">
<fileset file="${test.jar}" />
<flattenmapper />
</sign-base>
<assertSigned jar="${subdirtest.jar}"/>
</target>

<target name="testTwoMappers" depends="jar">
<sign-base destDir="${subdir}">
<fileset file="${test.jar}" />
<flattenmapper />
<flattenmapper />
</sign-base>
</target>

<target name="testNoAlias" depends="jar">
<signjar keystore="testkeystore"
jar="${test.jar}"
storepass="apacheant"/>
</target>

<target name="testNoFiles" >
<sign-base />
</target>

<target name="testNoStorePass" depends="jar">
<signjar keystore="testkeystore"
alias="testonly"
jar="${test.jar}"/>
</target>
</project> </project>



+ 34
- 10
src/main/org/apache/tools/ant/taskdefs/SignJar.java View File

@@ -59,16 +59,43 @@ public class SignJar extends Task {
protected String alias; protected String alias;


/** /**
* The name of keystore file.
* The url or path of keystore file.
*/ */
private String keystore; private String keystore;


/**
* password for the store
*/
protected String storepass; protected String storepass;

/**
* type of store,-storetype param
*/
protected String storetype; protected String storetype;

/**
* password for the key in the store
*/
protected String keypass; protected String keypass;

/**
* name to a signature file
*/
protected String sigfile; protected String sigfile;

/**
* name of a single jar
*/
protected File signedjar; protected File signedjar;

/**
* verbose output
*/
protected boolean verbose; protected boolean verbose;

/**
* flag for
*/
protected boolean internalsf; protected boolean internalsf;
protected boolean sectionsonly; protected boolean sectionsonly;
private boolean preserveLastModified; private boolean preserveLastModified;
@@ -98,11 +125,8 @@ public class SignJar extends Task {
/** /**
* mapper for todir work * mapper for todir work
*/ */
private Mapper mapper;
private FileNameMapper mapper;


/** error string for unit test verification: {@value} */
public static final String ERROR_SIGNEDJAR_AND_FILESET =
"The signedjar attribute is not supported with filesets";
/** /**
* error string for unit test verification: {@value} * error string for unit test verification: {@value}
*/ */
@@ -113,7 +137,7 @@ public class SignJar extends Task {
*/ */
public static final String ERROR_TOO_MANY_MAPPERS = "Too many mappers"; public static final String ERROR_TOO_MANY_MAPPERS = "Too many mappers";
/** /**
* error string for unit test verification: {@value}
* error string for unit test verification {@value}
*/ */
public static final String ERROR_SIGNEDJAR_AND_FILESETS = "You cannot specify the signed JAR when using filesets"; public static final String ERROR_SIGNEDJAR_AND_FILESETS = "You cannot specify the signed JAR when using filesets";
/** /**
@@ -296,14 +320,14 @@ public class SignJar extends Task {
* @param newMapper * @param newMapper
* @since Ant 1.7 * @since Ant 1.7
*/ */
public void addMapper(Mapper newMapper) {
public void add(FileNameMapper newMapper) {
if (mapper != null) { if (mapper != null) {
throw new BuildException(ERROR_TOO_MANY_MAPPERS); throw new BuildException(ERROR_TOO_MANY_MAPPERS);
} }
mapper = newMapper; mapper = newMapper;
} }


public Mapper getMapper() {
public FileNameMapper getMapper() {
return mapper; return mapper;
} }


@@ -373,7 +397,7 @@ public class SignJar extends Task {
//set up our mapping policy //set up our mapping policy
FileNameMapper destMapper; FileNameMapper destMapper;
if (hasMapper) { if (hasMapper) {
destMapper = mapper.getImplementation();
destMapper = mapper;
} else { } else {
//no mapper? use the identity policy //no mapper? use the identity policy
destMapper = new IdentityMapper(); destMapper = new IdentityMapper();
@@ -563,7 +587,7 @@ public class SignJar extends Task {


/** /**
* test for a file being signed, by looking for a signature in the META-INF * test for a file being signed, by looking for a signature in the META-INF
* directory
* directory with our alias.
* *
* @param file the file to be checked * @param file the file to be checked
* @return true if the file is signed * @return true if the file is signed


+ 78
- 2
src/testcases/org/apache/tools/ant/taskdefs/SignJarTest.java View File

@@ -35,6 +35,7 @@ public class SignJarTest extends BuildFileTest {
public static final String EXPANDED_MANIFEST public static final String EXPANDED_MANIFEST
= "src/etc/testcases/taskdefs/manifests/META-INF/MANIFEST.MF"; = "src/etc/testcases/taskdefs/manifests/META-INF/MANIFEST.MF";



public SignJarTest(String name) { public SignJarTest(String name) {
super(name); super(name);
} }
@@ -47,6 +48,13 @@ public class SignJarTest extends BuildFileTest {
executeTarget("clean"); executeTarget("clean");
} }


/**
* check for being offline
* @return true iff the system property "offline" is "true"
*/
private boolean isOffline() {
return Boolean.getBoolean("offline");
}
public void testBasicSigning() { public void testBasicSigning() {
executeTarget("basic"); executeTarget("basic");
} }
@@ -64,10 +72,78 @@ public class SignJarTest extends BuildFileTest {
} }


public void testURLKeystoreHTTP() { public void testURLKeystoreHTTP() {
executeTarget("urlKeystoreHTTP");
if(!isOffline()) {
executeTarget("urlKeystoreHTTP");
}
} }


public void testPreserveLastModified() { public void testPreserveLastModified() {
executeTarget("preserveLastModified"); executeTarget("preserveLastModified");
} }
}

public void testFileset() {
executeTarget("testFileset");
}

public void testFilesetAndJar() {
executeTarget("testFilesetAndJar");
}

public void testFilesetAndSignedJar() {
expectBuildExceptionContaining("testFilesetAndSignedJar",
"incompatible attributes",
SignJar.ERROR_SIGNEDJAR_AND_FILESETS);
}

public void testSignedJar() {
executeTarget("testSignedJar");
}

public void testDestDir() {
executeTarget("testDestDir");
}

public void testDestDirAndSignedJar() {
expectBuildExceptionContaining("testFilesetAndSignedJar",
"incompatible attributes",
SignJar.ERROR_SIGNEDJAR_AND_FILESETS);
}

public void testDestDirFileset() {
executeTarget("testDestDirFileset");
}

public void testMapperFileset() {
executeTarget("testMapperFileset");
}

public void testMapperNoDest() {
expectBuildExceptionContaining("testMapperNoDest",
"two mappers",
SignJar.ERROR_MAPPER_WITHOUT_DEST);
}

public void testTwoMappers() {
expectBuildExceptionContaining("testTwoMappers",
"two mappers",
SignJar.ERROR_TOO_MANY_MAPPERS);
}

public void testNoAlias() {
expectBuildExceptionContaining("testNoAlias",
"no alias",
SignJar.ERROR_NO_ALIAS);
}

public void testNoFiles() {
expectBuildExceptionContaining("testNoFiles",
"no files",
SignJar.ERROR_NO_SOURCE);
}

public void testNoStorePass() {
expectBuildExceptionContaining("testNoStorePass",
"no files",
SignJar.ERROR_NO_STOREPASS);
}
}

Loading…
Cancel
Save