1 6 21 22 package de.schlichtherle.io; 23 24 import de.schlichtherle.crypto.io.raes.*; 25 import de.schlichtherle.io.archive.*; 26 import de.schlichtherle.io.archive.zip.raes.*; 27 28 import java.io.IOException ; 29 30 import junit.framework.*; 31 32 37 public class RandomDataZip32RaesTest extends FileTestBase { 38 39 private static final DefaultArchiveDetector defaultArchiveDetector 40 = new StandardArchiveDetector(); 41 42 public static Test suite() throws Exception { 43 TestSuite suite = new TestSuite(RandomDataZip32RaesTest.class); 44 46 47 return suite; 48 } 49 50 53 public RandomDataZip32RaesTest(String testName) { 54 super(testName); 55 } 56 57 protected void setUp() throws Exception { 58 suffix = ".zip.rae"; 59 File.setDefaultArchiveDetector(defaultArchiveDetector); 60 61 super.setUp(); 62 } 63 64 public void testCancelling() 65 throws IOException { 66 final ArchiveDetector passwdCancellingDetector 67 = new PasswdCancellingDetector(); 68 File.setDefaultArchiveDetector(passwdCancellingDetector); 69 70 archive = new File(archive.getPath()); final File entry1 = new File(archive, "entry1"); 72 73 assertFalse(new java.io.File (archive.getPath()).exists()); 74 75 assertFalse(entry1.mkdirs()); 76 assertFalse(new java.io.File (entry1.getPath()).exists()); 77 assertFalse(new java.io.File (archive.getPath()).exists()); 78 79 try { 80 assertFalse(entry1.createNewFile()); 81 fail("An IOException should have been thrown because password prompting has been disabled!"); 82 } catch (IOException expected) { 83 } 84 assertFalse(new java.io.File (entry1.getPath()).exists()); 85 assertFalse(new java.io.File (archive.getPath()).exists()); 86 87 final File entry2 = new File(entry1, "entry2"); 88 assertFalse(entry2.mkdirs()); 89 assertFalse(new java.io.File (entry2.getPath()).exists()); 90 assertFalse(new java.io.File (entry1.getPath()).exists()); 91 assertFalse(new java.io.File (archive.getPath()).exists()); 92 93 try { 94 assertFalse(entry2.createNewFile()); 95 fail("An IOException should have been thrown because password prompting has been disabled!"); 96 } catch (IOException expected) { 97 } 98 assertFalse(new java.io.File (entry2.getPath()).exists()); 99 assertFalse(new java.io.File (entry1.getPath()).exists()); 100 assertFalse(new java.io.File (archive.getPath()).exists()); 101 } 102 103 public static class StandardArchiveDetector extends DefaultArchiveDetector { 104 private StandardArchiveDetector() { 105 super(ArchiveDetector.NULL, 106 "zip.rae", 107 new SafeZip32RaesDriver() { 108 public RaesParameters getRaesParameters(Archive archive) { 109 return new Type0RaesParameters() { 110 public char[] getOpenPasswd() { 111 return "test".toCharArray(); 112 } 113 114 public void invalidOpenPasswd() { 115 } 116 117 public char[] getCreatePasswd() { 118 return "test".toCharArray(); 119 } 120 121 public int getKeyStrength() { 122 return KEY_STRENGTH_256; 123 } 124 125 public void setKeyStrength(int keyStrength) { 126 } 127 }; 128 } 129 } 130 ); 131 } 132 } 133 134 public static class PasswdCancellingDetector extends DefaultArchiveDetector { 135 private PasswdCancellingDetector() { 136 super(ArchiveDetector.NULL, 137 "zip.rae", 138 new SafeZip32RaesDriver() { 139 public RaesParameters getRaesParameters(Archive archive) { 140 return new Type0RaesParameters() { 141 public char[] getOpenPasswd() throws RaesKeyException { 142 throw new RaesKeyException(); 143 } 144 145 public void invalidOpenPasswd() { 146 throw new AssertionError ("Password prompting has been cancelled. Hence, this callback is illegal!"); 147 } 148 149 public char[] getCreatePasswd() throws RaesKeyException { 150 throw new RaesKeyException(); 151 } 152 153 public int getKeyStrength() { 154 return KEY_STRENGTH_256; 155 } 156 157 public void setKeyStrength(int keyStrength) { 158 } 159 }; 160 } 161 } 162 ); 163 } 164 } 165 } 166 | Popular Tags |