use of java.util.jar.JarFile in project robovm by robovm.
the class JarFileTest method test_JarFile_Modified_Class.
/*
* The content of Test.class is modified, jarFile.getInputStream will not
* throw security Exception, but it will anytime before the inputStream got
* from getInputStream method has been read to end.
*/
public void test_JarFile_Modified_Class() throws IOException {
String modifiedJarName = "Modified_Class.jar";
Support_Resources.copyFile(resources, null, modifiedJarName);
JarFile jarFile = new JarFile(new File(resources, modifiedJarName), true);
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
ZipEntry zipEntry = entries.nextElement();
jarFile.getInputStream(zipEntry);
}
/* The content of Test.class has been tampered. */
ZipEntry zipEntry = jarFile.getEntry("Test.class");
InputStream in = jarFile.getInputStream(zipEntry);
byte[] buffer = new byte[1024];
try {
while (in.available() > 0) {
in.read(buffer);
}
fail("SecurityException expected");
} catch (SecurityException e) {
// desired
}
}
use of java.util.jar.JarFile in project robovm by robovm.
the class JarFileTest method testJarVerificationModifiedEntry.
/**
* The jar is intact, but the entry object is modified.
*/
public void testJarVerificationModifiedEntry() throws IOException {
Support_Resources.copyFile(resources, null, integrateJar);
File f = new File(resources, integrateJar);
JarFile jarFile = new JarFile(f);
ZipEntry zipEntry = jarFile.getJarEntry(integrateJarEntry);
zipEntry.setSize(zipEntry.getSize() + 1);
jarFile.getInputStream(zipEntry).skip(Long.MAX_VALUE);
jarFile = new JarFile(f);
zipEntry = jarFile.getJarEntry(integrateJarEntry);
zipEntry.setSize(zipEntry.getSize() - 1);
try {
//jarFile.getInputStream(zipEntry).skip(Long.MAX_VALUE);
jarFile.getInputStream(zipEntry).read(new byte[5000], 0, 5000);
fail("SecurityException expected");
} catch (SecurityException e) {
// desired
}
}
use of java.util.jar.JarFile in project robovm by robovm.
the class JarFileTest method test_ConstructorLjava_lang_String.
/**
* java.util.jar.JarFile#JarFile(java.lang.String)
*/
public void test_ConstructorLjava_lang_String() {
try {
JarFile jarFile = new JarFile("Wrong.file");
fail("Should throw IOException");
} catch (IOException e) {
// expected
}
try {
Support_Resources.copyFile(resources, null, jarName);
String fileName = (new File(resources, jarName)).getCanonicalPath();
JarFile jarFile = new JarFile(fileName);
} catch (IOException e) {
fail("Should not throw IOException");
}
}
use of java.util.jar.JarFile in project robovm by robovm.
the class JarFileTest method test_JarFile_Modified_Manifest_MainAttributes.
/*
* In the Modified.jar, the main attributes of META-INF/MANIFEST.MF is
* tampered manually. Hence the RI 5.0 JarFile.getInputStream of any
* JarEntry will throw security exception.
*/
public void test_JarFile_Modified_Manifest_MainAttributes() throws IOException {
String modifiedJarName = "Modified_Manifest_MainAttributes.jar";
Support_Resources.copyFile(resources, null, modifiedJarName);
JarFile jarFile = new JarFile(new File(resources, modifiedJarName), true);
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
ZipEntry zipEntry = entries.nextElement();
try {
jarFile.getInputStream(zipEntry);
fail("SecurityException expected");
} catch (SecurityException e) {
// desired
}
}
}
use of java.util.jar.JarFile in project robovm by robovm.
the class JarFileTest method test_close.
public void test_close() throws IOException {
String modifiedJarName = "Modified_SF_EntryAttributes.jar";
Support_Resources.copyFile(resources, null, modifiedJarName);
JarFile jarFile = new JarFile(new File(resources, modifiedJarName), true);
Enumeration<JarEntry> entries = jarFile.entries();
jarFile.close();
jarFile.close();
// Can not check IOException
}
Aggregations