added crypto file system tests

This commit is contained in:
Sebastian Stenzel
2016-01-28 19:49:20 +01:00
parent 3696fea3ee
commit 0dc30c27d9

View File

@@ -0,0 +1,62 @@
package org.cryptomator.filesystem.crypto;
import java.nio.ByteBuffer;
import org.cryptomator.crypto.engine.InvalidPassphraseException;
import org.cryptomator.crypto.engine.impl.TestCryptorImplFactory;
import org.cryptomator.filesystem.FileSystem;
import org.cryptomator.filesystem.WritableFile;
import org.cryptomator.filesystem.inmem.InMemoryFileSystem;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class MasterkeysTest {
private FileSystem fs;
private Masterkeys m;
@Before
public void setup() {
fs = new InMemoryFileSystem();
m = new Masterkeys(TestCryptorImplFactory::insecureCryptorImpl);
}
@Test
public void testInitialize() {
m.initialize(fs, "asd");
Assert.assertTrue(fs.file("masterkey.cryptomator").exists());
}
@Test
public void testBackup() {
try (WritableFile w = fs.file("masterkey.cryptomator").openWritable()) {
w.write(ByteBuffer.wrap("asd".getBytes()));
}
m.backup(fs);
Assert.assertTrue(fs.file("masterkey.cryptomator.bkup").exists());
}
@Test
public void testRestoreBackup() {
try (WritableFile w = fs.file("masterkey.cryptomator.bkup").openWritable()) {
w.write(ByteBuffer.wrap("asd".getBytes()));
}
m.restoreBackup(fs);
Assert.assertTrue(fs.file("masterkey.cryptomator").exists());
}
@Test
public void testChangePassphraseWithCorrectPassword() {
m.initialize(fs, "foo");
m.changePassphrase(fs, "foo", "bar");
Assert.assertNotNull(m.decrypt(fs, "bar"));
}
@Test(expected = InvalidPassphraseException.class)
public void testChangePassphraseWithIncorrectPassword() {
m.initialize(fs, "foo");
m.changePassphrase(fs, "wrong", "bar");
}
}