Beispiel #1
0
 private File createTempFile() throws Exception {
   String filePath = System.getProperty("java.io.tmpdir") + System.nanoTime() + ".text";
   File file = new File(filePath);
   file.createNewFile();
   FileWriter fileWriter = new FileWriter(file);
   for (int i = 0; i < 1000; i++) {
     fileWriter.write("Sample text " + i + System.getProperty("line.separator"));
   }
   fileWriter.close();
   return file;
 }
Beispiel #2
0
 public void testDisableEncryption() throws Exception {
   File dir = new File(System.getProperty("java.io.tmpdir") + File.separator + System.nanoTime());
   dir.mkdir();
   assertEquals(FILE_ENCRYPTABLE, Advapi32Util.fileEncryptionStatus(dir));
   Advapi32Util.disableEncryption(dir, true);
   assertEquals(FILE_DIR_DISALOWED, Advapi32Util.fileEncryptionStatus(dir));
   Advapi32Util.disableEncryption(dir, false);
   assertEquals(FILE_ENCRYPTABLE, Advapi32Util.fileEncryptionStatus(dir));
   for (File file : dir.listFiles()) {
     file.delete();
   }
   dir.delete();
 }
Beispiel #3
0
 public void testExecuteAccess() {
   final boolean access =
       Advapi32Util.accessCheck(
           new File(System.getProperty("java.io.tmpdir")),
           Advapi32Util.AccessCheckPermission.EXECUTE);
   assertTrue(access);
 }
Beispiel #4
0
  public void testBackupEncryptedFile() throws Exception {
    // backup an encrypted file
    File srcFile = createTempFile();
    Advapi32Util.encryptFile(srcFile);
    File dest =
        new File(
            System.getProperty("java.io.tmpdir") + File.separator + "backup" + System.nanoTime());
    dest.mkdir();

    Advapi32Util.backupEncryptedFile(srcFile, dest);

    // simple check to see if a backup file exist
    File backupFile = new File(dest.getAbsolutePath() + File.separator + srcFile.getName());
    assertTrue(backupFile.exists());
    assertEquals(srcFile.length(), backupFile.length());

    // backup an encrypted directory
    File srcDir =
        new File(System.getProperty("java.io.tmpdir") + File.separator + System.nanoTime());
    srcDir.mkdir();
    Advapi32Util.encryptFile(srcDir);

    Advapi32Util.backupEncryptedFile(srcDir, dest);

    // Check to see if a backup directory exist
    File backupDir = new File(dest.getAbsolutePath() + File.separator + srcDir.getName());
    assertTrue(backupDir.exists());

    // clean up
    srcFile.delete();
    for (File file : srcDir.listFiles()) {
      file.delete();
    }
    srcDir.delete();
    for (File file : dest.listFiles()) {
      file.delete();
    }
    dest.delete();
  }