From f5e9748fd02e8b8e979bd5c12989a2638cb68571 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Thu, 22 Apr 2021 22:11:01 +0200 Subject: [PATCH] support only one single key loader that must be provided by the user --- pom.xml | 2 +- .../cryptofs/CryptoFileSystemProperties.java | 57 ++++--------------- .../cryptofs/CryptoFileSystemProvider.java | 2 +- .../cryptofs/CryptoFileSystems.java | 2 +- ...toFileChannelWriteReadIntegrationTest.java | 6 +- .../CryptoFileSystemPropertiesTest.java | 29 +++++----- ...yptoFileSystemProviderIntegrationTest.java | 23 +++----- .../CryptoFileSystemProviderTest.java | 7 +-- .../cryptofs/CryptoFileSystemUriTest.java | 3 +- .../cryptofs/CryptoFileSystemsTest.java | 2 +- ...ptyCiphertextDirectoryIntegrationTest.java | 3 +- .../cryptofs/ReadmeCodeSamplesTest.java | 6 +- .../RealFileSystemIntegrationTest.java | 4 +- ...iteFileWhileReadonlyChannelIsOpenTest.java | 4 +- .../attr/FileAttributeIntegrationTest.java | 3 +- 15 files changed, 53 insertions(+), 100 deletions(-) diff --git a/pom.xml b/pom.xml index 6f9b3e62..e72520e9 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ UTF-8 - 2.0.0-beta6 + 2.0.0-beta7 3.12.0 2.31 30.1-jre diff --git a/src/main/java/org/cryptomator/cryptofs/CryptoFileSystemProperties.java b/src/main/java/org/cryptomator/cryptofs/CryptoFileSystemProperties.java index b917a60f..39d3c04d 100644 --- a/src/main/java/org/cryptomator/cryptofs/CryptoFileSystemProperties.java +++ b/src/main/java/org/cryptomator/cryptofs/CryptoFileSystemProperties.java @@ -9,9 +9,7 @@ package org.cryptomator.cryptofs; import com.google.common.base.Strings; -import org.cryptomator.cryptofs.common.Constants; import org.cryptomator.cryptolib.api.MasterkeyLoader; -import org.cryptomator.cryptolib.api.MasterkeyLoadingFailedException; import java.net.URI; import java.nio.file.FileSystems; @@ -19,7 +17,6 @@ import java.util.AbstractMap; import java.util.Collection; import java.util.EnumSet; -import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.function.Consumer; @@ -51,9 +48,7 @@ public class CryptoFileSystemProperties extends AbstractMap { * * @since 2.0.0 */ - public static final String PROPERTY_KEYLOADERS = "keyLoaders"; - - static final Collection DEFAULT_KEYLOADERS = Set.of(); + public static final String PROPERTY_KEYLOADER = "keyLoader"; /** * Key identifying the name of the vault config file located inside the vault directory. @@ -102,7 +97,7 @@ public enum FileSystemFlags { private CryptoFileSystemProperties(Builder builder) { this.entries = Set.of( // - Map.entry(PROPERTY_KEYLOADERS, builder.keyLoaders), // + Map.entry(PROPERTY_KEYLOADER, builder.keyLoader), // Map.entry(PROPERTY_FILESYSTEM_FLAGS, builder.flags), // Map.entry(PROPERTY_VAULTCONFIG_FILENAME, builder.vaultConfigFilename), // Map.entry(PROPERTY_MASTERKEY_FILENAME, builder.masterkeyFilename), // @@ -111,24 +106,8 @@ private CryptoFileSystemProperties(Builder builder) { ); } - Collection keyLoaders() { - return (Collection) get(PROPERTY_KEYLOADERS); - } - - /** - * Selects the first applicable MasterkeyLoader that supports the given scheme. - * - * @param scheme An URI scheme used in key IDs - * @return A key loader - * @throws MasterkeyLoadingFailedException If the scheme is not supported by any key loader - */ - MasterkeyLoader keyLoader(String scheme) throws MasterkeyLoadingFailedException { - for (MasterkeyLoader loader : keyLoaders()) { - if (loader.supportsScheme(scheme)) { - return loader; - } - } - throw new MasterkeyLoadingFailedException("No key loader for key type: " + scheme); + MasterkeyLoader keyLoader() { + return (MasterkeyLoader) get(PROPERTY_KEYLOADER); } public VaultCipherCombo cipherCombo() { @@ -205,7 +184,7 @@ public static CryptoFileSystemProperties wrap(Map properties) { public static class Builder { public VaultCipherCombo cipherCombo = DEFAULT_CIPHER_COMBO; - private Collection keyLoaders = new HashSet<>(DEFAULT_KEYLOADERS); + private MasterkeyLoader keyLoader = null; private final Set flags = EnumSet.copyOf(DEFAULT_FILESYSTEM_FLAGS); private String vaultConfigFilename = DEFAULT_VAULTCONFIG_FILENAME; private String masterkeyFilename = DEFAULT_MASTERKEY_FILENAME; @@ -215,7 +194,7 @@ private Builder() { } private Builder(Map properties) { - checkedSet(Collection.class, PROPERTY_KEYLOADERS, properties, this::withKeyLoaders); + checkedSet(MasterkeyLoader.class, PROPERTY_KEYLOADER, properties, this::withKeyLoader); checkedSet(String.class, PROPERTY_VAULTCONFIG_FILENAME, properties, this::withVaultConfigFilename); checkedSet(String.class, PROPERTY_MASTERKEY_FILENAME, properties, this::withMasterkeyFilename); checkedSet(Set.class, PROPERTY_FILESYSTEM_FLAGS, properties, this::withFlags); @@ -262,26 +241,14 @@ public Builder withCipherCombo(VaultCipherCombo cipherCombo) { } /** - * Sets the keyLoaders for a CryptoFileSystem. - * - * @param keyLoaders A set of keyLoaders to load the key configured in the vault configuration - * @return this - * @since 2.0.0 - */ - public Builder withKeyLoaders(MasterkeyLoader... keyLoaders) { - return withKeyLoaders(asList(keyLoaders)); - } - - /** - * Sets the keyLoaders for a CryptoFileSystem. + * Sets the keyloader for a CryptoFileSystem. * - * @param keyLoaders A set of keyLoaders to load the key configured in the vault configuration + * @param keyLoader A factory creating a {@link MasterkeyLoader} capable of handling the given {@code scheme}. * @return this * @since 2.0.0 */ - public Builder withKeyLoaders(Collection keyLoaders) { - this.keyLoaders.clear(); - this.keyLoaders.addAll(keyLoaders); + public Builder withKeyLoader(MasterkeyLoader keyLoader) { + this.keyLoader = keyLoader; return this; } @@ -345,8 +312,8 @@ public CryptoFileSystemProperties build() { } private void validate() { - if (keyLoaders.isEmpty()) { - throw new IllegalStateException("at least one keyloader is required"); + if (keyLoader == null) { + throw new IllegalStateException("keyLoader is required"); } if (Strings.nullToEmpty(masterkeyFilename).trim().isEmpty()) { throw new IllegalStateException("masterkeyFilename is required"); diff --git a/src/main/java/org/cryptomator/cryptofs/CryptoFileSystemProvider.java b/src/main/java/org/cryptomator/cryptofs/CryptoFileSystemProvider.java index 0a1330f5..4a401c84 100644 --- a/src/main/java/org/cryptomator/cryptofs/CryptoFileSystemProvider.java +++ b/src/main/java/org/cryptomator/cryptofs/CryptoFileSystemProvider.java @@ -142,7 +142,7 @@ public static void initialize(Path pathToVault, CryptoFileSystemProperties prope } byte[] rawKey = new byte[0]; var config = VaultConfig.createNew().cipherCombo(properties.cipherCombo()).shorteningThreshold(Constants.DEFAULT_SHORTENING_THRESHOLD).build(); - try (Masterkey key = properties.keyLoader(keyId.getScheme()).loadKey(keyId); + try (Masterkey key = properties.keyLoader().loadKey(keyId); Cryptor cryptor = config.getCipherCombo().getCryptorProvider(strongSecureRandom()).withKey(key)) { rawKey = key.getEncoded(); // save vault config: diff --git a/src/main/java/org/cryptomator/cryptofs/CryptoFileSystems.java b/src/main/java/org/cryptomator/cryptofs/CryptoFileSystems.java index 438b9577..16c5e2ca 100644 --- a/src/main/java/org/cryptomator/cryptofs/CryptoFileSystems.java +++ b/src/main/java/org/cryptomator/cryptofs/CryptoFileSystems.java @@ -49,7 +49,7 @@ public CryptoFileSystemImpl create(CryptoFileSystemProvider provider, Path pathT var configLoader = VaultConfig.decode(token); var keyId = configLoader.getKeyId(); - try (Masterkey key = properties.keyLoader(keyId.getScheme()).loadKey(keyId)) { + try (Masterkey key = properties.keyLoader().loadKey(keyId)) { var config = configLoader.verify(key.getEncoded(), Constants.VAULT_VERSION); var adjustedProperties = adjustForCapabilities(pathToVault, properties); var cryptor = config.getCipherCombo().getCryptorProvider(csprng).withKey(key.clone()); diff --git a/src/test/java/org/cryptomator/cryptofs/CryptoFileChannelWriteReadIntegrationTest.java b/src/test/java/org/cryptomator/cryptofs/CryptoFileChannelWriteReadIntegrationTest.java index 7bca22ee..3b12c4c0 100644 --- a/src/test/java/org/cryptomator/cryptofs/CryptoFileChannelWriteReadIntegrationTest.java +++ b/src/test/java/org/cryptomator/cryptofs/CryptoFileChannelWriteReadIntegrationTest.java @@ -66,9 +66,8 @@ public class Windows { @BeforeAll public void setupClass(@TempDir Path tmpDir) throws IOException, MasterkeyLoadingFailedException { MasterkeyLoader keyLoader = Mockito.mock(MasterkeyLoader.class); - Mockito.when(keyLoader.supportsScheme(Mockito.any())).thenReturn(true); Mockito.when(keyLoader.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(new byte[64])); - CryptoFileSystemProperties properties = cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); + CryptoFileSystemProperties properties = cryptoFileSystemProperties().withKeyLoader(keyLoader).build(); CryptoFileSystemProvider.initialize(tmpDir, properties, URI.create("test:key")); fileSystem = CryptoFileSystemProvider.newFileSystem(tmpDir, properties); } @@ -142,9 +141,8 @@ public void beforeAll() throws IOException, MasterkeyLoadingFailedException { Path vaultPath = inMemoryFs.getPath("vault"); Files.createDirectories(vaultPath); MasterkeyLoader keyLoader = Mockito.mock(MasterkeyLoader.class); - Mockito.when(keyLoader.supportsScheme("test")).thenReturn(true); Mockito.when(keyLoader.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(new byte[64])); - var properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); + var properties = cryptoFileSystemProperties().withKeyLoader(keyLoader).build(); CryptoFileSystemProvider.initialize(vaultPath, properties, URI.create("test:key")); fileSystem = new CryptoFileSystemProvider().newFileSystem(vaultPath, properties); file = fileSystem.getPath("/test.txt"); diff --git a/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemPropertiesTest.java b/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemPropertiesTest.java index 78fc7cac..185dbc08 100644 --- a/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemPropertiesTest.java +++ b/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemPropertiesTest.java @@ -15,7 +15,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Objects; -import java.util.Set; import static org.cryptomator.cryptofs.CryptoFileSystemProperties.*; import static org.hamcrest.CoreMatchers.sameInstance; @@ -37,7 +36,7 @@ public void testSetNoPassphrase() { public void testSetMasterkeyFilenameAndReadonlyFlag() { String masterkeyFilename = "aMasterkeyFilename"; CryptoFileSystemProperties inTest = cryptoFileSystemProperties() // - .withKeyLoaders(keyLoader) // + .withKeyLoader(keyLoader) // .withMasterkeyFilename(masterkeyFilename) // .withFlags(FileSystemFlags.READONLY) .build(); @@ -46,7 +45,7 @@ public void testSetMasterkeyFilenameAndReadonlyFlag() { MatcherAssert.assertThat(inTest.readonly(), is(true)); MatcherAssert.assertThat(inTest.entrySet(), containsInAnyOrder( // - anEntry(PROPERTY_KEYLOADERS, Set.of(keyLoader)), // + anEntry(PROPERTY_KEYLOADER, keyLoader), // anEntry(PROPERTY_VAULTCONFIG_FILENAME, DEFAULT_VAULTCONFIG_FILENAME), // anEntry(PROPERTY_MASTERKEY_FILENAME, masterkeyFilename), // anEntry(PROPERTY_MAX_CLEARTEXT_NAME_LENGTH, DEFAULT_MAX_CLEARTEXT_NAME_LENGTH), // @@ -58,7 +57,7 @@ public void testSetMasterkeyFilenameAndReadonlyFlag() { public void testFromMap() { Map map = new HashMap<>(); String masterkeyFilename = "aMasterkeyFilename"; - map.put(PROPERTY_KEYLOADERS, Set.of(keyLoader)); + map.put(PROPERTY_KEYLOADER, keyLoader); map.put(PROPERTY_MASTERKEY_FILENAME, masterkeyFilename); map.put(PROPERTY_MAX_CLEARTEXT_NAME_LENGTH, 255); map.put(PROPERTY_FILESYSTEM_FLAGS, EnumSet.of(FileSystemFlags.READONLY)); @@ -69,7 +68,7 @@ public void testFromMap() { MatcherAssert.assertThat(inTest.maxCleartextNameLength(), is(255)); MatcherAssert.assertThat(inTest.entrySet(), containsInAnyOrder( // - anEntry(PROPERTY_KEYLOADERS, Set.of(keyLoader)), // + anEntry(PROPERTY_KEYLOADER, keyLoader), // anEntry(PROPERTY_VAULTCONFIG_FILENAME, DEFAULT_VAULTCONFIG_FILENAME), // anEntry(PROPERTY_MASTERKEY_FILENAME, masterkeyFilename), // anEntry(PROPERTY_MAX_CLEARTEXT_NAME_LENGTH, 255), // @@ -81,7 +80,7 @@ public void testFromMap() { public void testWrapMapWithTrueReadonly() { Map map = new HashMap<>(); String masterkeyFilename = "aMasterkeyFilename"; - map.put(PROPERTY_KEYLOADERS, Set.of(keyLoader)); + map.put(PROPERTY_KEYLOADER, keyLoader); map.put(PROPERTY_MASTERKEY_FILENAME, masterkeyFilename); map.put(PROPERTY_FILESYSTEM_FLAGS, EnumSet.of(FileSystemFlags.READONLY)); CryptoFileSystemProperties inTest = CryptoFileSystemProperties.wrap(map); @@ -90,7 +89,7 @@ public void testWrapMapWithTrueReadonly() { MatcherAssert.assertThat(inTest.readonly(), is(true)); MatcherAssert.assertThat(inTest.entrySet(), containsInAnyOrder( // - anEntry(PROPERTY_KEYLOADERS, Set.of(keyLoader)), // + anEntry(PROPERTY_KEYLOADER, keyLoader), // anEntry(PROPERTY_VAULTCONFIG_FILENAME, DEFAULT_VAULTCONFIG_FILENAME), // anEntry(PROPERTY_MASTERKEY_FILENAME, masterkeyFilename), // anEntry(PROPERTY_MAX_CLEARTEXT_NAME_LENGTH, DEFAULT_MAX_CLEARTEXT_NAME_LENGTH), // @@ -102,7 +101,7 @@ public void testWrapMapWithTrueReadonly() { public void testWrapMapWithFalseReadonly() { Map map = new HashMap<>(); String masterkeyFilename = "aMasterkeyFilename"; - map.put(PROPERTY_KEYLOADERS, Set.of(keyLoader)); + map.put(PROPERTY_KEYLOADER, keyLoader); map.put(PROPERTY_MASTERKEY_FILENAME, masterkeyFilename); map.put(PROPERTY_FILESYSTEM_FLAGS, EnumSet.noneOf(FileSystemFlags.class)); CryptoFileSystemProperties inTest = CryptoFileSystemProperties.wrap(map); @@ -111,7 +110,7 @@ public void testWrapMapWithFalseReadonly() { MatcherAssert.assertThat(inTest.readonly(), is(false)); MatcherAssert.assertThat(inTest.entrySet(), containsInAnyOrder( // - anEntry(PROPERTY_KEYLOADERS, Set.of(keyLoader)), // + anEntry(PROPERTY_KEYLOADER, keyLoader), // anEntry(PROPERTY_VAULTCONFIG_FILENAME, DEFAULT_VAULTCONFIG_FILENAME), // anEntry(PROPERTY_MASTERKEY_FILENAME, masterkeyFilename), // anEntry(PROPERTY_MAX_CLEARTEXT_NAME_LENGTH, DEFAULT_MAX_CLEARTEXT_NAME_LENGTH), // @@ -155,14 +154,14 @@ public void testWrapMapWithInvalidPassphrase() { @Test public void testWrapMapWithoutReadonly() { Map map = new HashMap<>(); - map.put(PROPERTY_KEYLOADERS, Set.of(keyLoader)); + map.put(PROPERTY_KEYLOADER, keyLoader); CryptoFileSystemProperties inTest = CryptoFileSystemProperties.wrap(map); MatcherAssert.assertThat(inTest.masterkeyFilename(), is(DEFAULT_MASTERKEY_FILENAME)); MatcherAssert.assertThat(inTest.readonly(), is(false)); MatcherAssert.assertThat(inTest.entrySet(), containsInAnyOrder( // - anEntry(PROPERTY_KEYLOADERS, Set.of(keyLoader)), // + anEntry(PROPERTY_KEYLOADER, keyLoader), // anEntry(PROPERTY_VAULTCONFIG_FILENAME, DEFAULT_VAULTCONFIG_FILENAME), // anEntry(PROPERTY_MASTERKEY_FILENAME, DEFAULT_MASTERKEY_FILENAME), // anEntry(PROPERTY_MAX_CLEARTEXT_NAME_LENGTH, DEFAULT_MAX_CLEARTEXT_NAME_LENGTH), // @@ -181,7 +180,7 @@ public void testWrapMapWithoutPassphrase() { @Test public void testWrapCryptoFileSystemProperties() { - CryptoFileSystemProperties inTest = cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); + CryptoFileSystemProperties inTest = cryptoFileSystemProperties().withKeyLoader(keyLoader).build(); MatcherAssert.assertThat(CryptoFileSystemProperties.wrap(inTest), is(sameInstance(inTest))); } @@ -190,7 +189,7 @@ public void testWrapCryptoFileSystemProperties() { public void testMapIsImmutable() { Assertions.assertThrows(UnsupportedOperationException.class, () -> { cryptoFileSystemProperties() // - .withKeyLoaders(keyLoader) // + .withKeyLoader(keyLoader) // .build() // .put("test", "test"); }); @@ -200,7 +199,7 @@ public void testMapIsImmutable() { public void testEntrySetIsImmutable() { Assertions.assertThrows(UnsupportedOperationException.class, () -> { cryptoFileSystemProperties() // - .withKeyLoaders(keyLoader) // + .withKeyLoader(keyLoader) // .build() // .entrySet() // .add(null); @@ -211,7 +210,7 @@ public void testEntrySetIsImmutable() { public void testEntryIsImmutable() { Assertions.assertThrows(UnsupportedOperationException.class, () -> { cryptoFileSystemProperties() // - .withKeyLoaders(keyLoader) // + .withKeyLoader(keyLoader) // .build() // .entrySet() // .iterator().next() // diff --git a/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemProviderIntegrationTest.java b/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemProviderIntegrationTest.java index 65b1b845..5ae7a36a 100644 --- a/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemProviderIntegrationTest.java +++ b/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemProviderIntegrationTest.java @@ -84,12 +84,11 @@ class WithLimitedPaths { @BeforeAll public void setup(@TempDir Path tmpDir) throws IOException, MasterkeyLoadingFailedException { - Mockito.when(keyLoader.supportsScheme("test")).thenReturn(true); Mockito.when(keyLoader.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(new byte[64])); CryptoFileSystemProperties properties = cryptoFileSystemProperties() // .withFlags() // .withMasterkeyFilename("masterkey.cryptomator") // - .withKeyLoaders(keyLoader) // + .withKeyLoader(keyLoader) // .withMaxCleartextNameLength(50) .build(); CryptoFileSystemProvider.initialize(tmpDir, properties, URI.create("test:key")); @@ -192,8 +191,6 @@ public void setup() throws IOException, MasterkeyLoadingFailedException { Arrays.fill(key2, (byte) 0x77); keyLoader1 = Mockito.mock(MasterkeyLoader.class); keyLoader2 = Mockito.mock(MasterkeyLoader.class); - Mockito.when(keyLoader1.supportsScheme("test")).thenReturn(true); - Mockito.when(keyLoader2.supportsScheme("test")).thenReturn(true); Mockito.when(keyLoader1.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(key1)); Mockito.when(keyLoader2.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(key2)); pathToVault1 = tmpFs.getPath("/vaultDir1"); @@ -215,12 +212,12 @@ public void teardown() throws IOException { public void initializeVaults() { Assertions.assertAll( () -> { - var properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoaders(keyLoader1).build(); + var properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoader(keyLoader1).build(); CryptoFileSystemProvider.initialize(pathToVault1, properties, URI.create("test:key")); Assertions.assertTrue(Files.isDirectory(pathToVault1.resolve("d"))); Assertions.assertTrue(Files.isRegularFile(vaultConfigFile1)); }, () -> { - var properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoaders(keyLoader2).build(); + var properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoader(keyLoader2).build(); CryptoFileSystemProvider.initialize(pathToVault2, properties, URI.create("test:key")); Assertions.assertTrue(Files.isDirectory(pathToVault2.resolve("d"))); Assertions.assertTrue(Files.isRegularFile(vaultConfigFile2)); @@ -239,7 +236,7 @@ public void testGetFsWithWrongCredentials() { CryptoFileSystemProperties properties = cryptoFileSystemProperties() // .withFlags() // .withMasterkeyFilename("masterkey.cryptomator") // - .withKeyLoaders(keyLoader2) // + .withKeyLoader(keyLoader2) // .build(); Assertions.assertThrows(VaultKeyInvalidException.class, () -> { FileSystems.newFileSystem(fsUri, properties); @@ -250,7 +247,7 @@ public void testGetFsWithWrongCredentials() { CryptoFileSystemProperties properties = cryptoFileSystemProperties() // .withFlags() // .withMasterkeyFilename("masterkey.cryptomator") // - .withKeyLoaders(keyLoader1) // + .withKeyLoader(keyLoader1) // .build(); Assertions.assertThrows(VaultKeyInvalidException.class, () -> { FileSystems.newFileSystem(fsUri, properties); @@ -267,7 +264,7 @@ public void testGetFsViaNioApi() { Assertions.assertAll( () -> { URI fsUri = CryptoFileSystemUri.create(pathToVault1); - fs1 = FileSystems.newFileSystem(fsUri, cryptoFileSystemProperties().withKeyLoaders(keyLoader1).build()); + fs1 = FileSystems.newFileSystem(fsUri, cryptoFileSystemProperties().withKeyLoader(keyLoader1).build()); Assertions.assertTrue(fs1 instanceof CryptoFileSystemImpl); FileSystem sameFs = FileSystems.getFileSystem(fsUri); @@ -275,7 +272,7 @@ public void testGetFsViaNioApi() { }, () -> { URI fsUri = CryptoFileSystemUri.create(pathToVault2); - fs2 = FileSystems.newFileSystem(fsUri, cryptoFileSystemProperties().withKeyLoaders(keyLoader2).build()); + fs2 = FileSystems.newFileSystem(fsUri, cryptoFileSystemProperties().withKeyLoader(keyLoader2).build()); Assertions.assertTrue(fs2 instanceof CryptoFileSystemImpl); FileSystem sameFs = FileSystems.getFileSystem(fsUri); @@ -535,9 +532,8 @@ public void setup(@TempDir Path tmpDir) throws IOException, MasterkeyLoadingFail Path pathToVault = tmpDir.resolve("vaultDir1"); Files.createDirectories(pathToVault); MasterkeyLoader keyLoader = Mockito.mock(MasterkeyLoader.class); - Mockito.when(keyLoader.supportsScheme("test")).thenReturn(true); Mockito.when(keyLoader.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(new byte[64])); - var properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); + var properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoader(keyLoader).build(); CryptoFileSystemProvider.initialize(pathToVault, properties, URI.create("test:key")); fs = CryptoFileSystemProvider.newFileSystem(pathToVault, properties); } @@ -628,9 +624,8 @@ public void setup(@TempDir Path tmpDir) throws IOException, MasterkeyLoadingFail Path pathToVault = tmpDir.resolve("vaultDir1"); Files.createDirectories(pathToVault); MasterkeyLoader keyLoader = Mockito.mock(MasterkeyLoader.class); - Mockito.when(keyLoader.supportsScheme("test")).thenReturn(true); Mockito.when(keyLoader.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(new byte[64])); - var properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); + var properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoader(keyLoader).build(); CryptoFileSystemProvider.initialize(pathToVault, properties, URI.create("test:key")); fs = CryptoFileSystemProvider.newFileSystem(pathToVault, properties); } diff --git a/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemProviderTest.java b/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemProviderTest.java index ed488d7b..d786d9d0 100644 --- a/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemProviderTest.java +++ b/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemProviderTest.java @@ -114,7 +114,6 @@ private static final Stream shouldFailWithRelativePat @BeforeEach @SuppressWarnings("deprecation") public void setup() throws MasterkeyLoadingFailedException { - Mockito.when(keyLoader.supportsScheme("test")).thenReturn(true); when(keyLoader.loadKey(Mockito.any())).thenReturn(new Masterkey(new byte[64])); CryptoFileSystemProviderComponent component = mock(CryptoFileSystemProviderComponent.class); @@ -168,7 +167,7 @@ public void testGetSchemeReturnsCryptomatorScheme() { public void testInitializeFailWithNotDirectoryException() { FileSystem fs = Jimfs.newFileSystem(Configuration.unix()); Path pathToVault = fs.getPath("/vaultDir"); - var properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); + var properties = cryptoFileSystemProperties().withKeyLoader(keyLoader).build(); Assertions.assertThrows(NotDirectoryException.class, () -> { CryptoFileSystemProvider.initialize(pathToVault, properties, URI.create("test:key")); @@ -181,7 +180,7 @@ public void testInitialize() throws IOException, MasterkeyLoadingFailedException Path pathToVault = fs.getPath("/vaultDir"); Path vaultConfigFile = pathToVault.resolve("vault.cryptomator"); Path dataDir = pathToVault.resolve("d"); - var properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); + var properties = cryptoFileSystemProperties().withKeyLoader(keyLoader).build(); Files.createDirectory(pathToVault); CryptoFileSystemProvider.initialize(pathToVault, properties, URI.create("test:key")); @@ -204,7 +203,7 @@ public void testNewFileSystem() throws IOException, MasterkeyLoadingFailedExcept URI uri = CryptoFileSystemUri.create(pathToVault); CryptoFileSystemProperties properties = cryptoFileSystemProperties() // .withFlags() // - .withKeyLoaders(keyLoader) // + .withKeyLoader(keyLoader) // .build(); inTest.newFileSystem(uri, properties); diff --git a/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemUriTest.java b/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemUriTest.java index fe60e12d..d6d186b5 100644 --- a/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemUriTest.java +++ b/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemUriTest.java @@ -75,9 +75,8 @@ public void testCreateWithPathToVaultFromNonDefaultProvider() throws IOException Path tempDir = createTempDirectory("CryptoFileSystemUrisTest").toAbsolutePath(); try { MasterkeyLoader keyLoader = Mockito.mock(MasterkeyLoader.class); - Mockito.when(keyLoader.supportsScheme("test")).thenReturn(true); Mockito.when(keyLoader.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(new byte[64])); - CryptoFileSystemProperties properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); + CryptoFileSystemProperties properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoader(keyLoader).build(); CryptoFileSystemProvider.initialize(tempDir, properties, URI.create("test:key")); FileSystem fileSystem = CryptoFileSystemProvider.newFileSystem(tempDir, properties); Path absolutePathToVault = fileSystem.getPath("a").toAbsolutePath(); diff --git a/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemsTest.java b/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemsTest.java index 43456ad2..fd2e6bca 100644 --- a/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemsTest.java +++ b/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemsTest.java @@ -71,7 +71,7 @@ public void setup() throws IOException, MasterkeyLoadingFailedException { when(pathToVault.normalize()).thenReturn(normalizedPathToVault); when(normalizedPathToVault.resolve("vault.cryptomator")).thenReturn(configFilePath); when(properties.vaultConfigFilename()).thenReturn("vault.cryptomator"); - when(properties.keyLoader(Mockito.any())).thenReturn(keyLoader); + when(properties.keyLoader()).thenReturn(keyLoader); filesClass.when(() -> Files.readString(configFilePath, StandardCharsets.US_ASCII)).thenReturn("jwt-vault-config"); vaultConficClass.when(() -> VaultConfig.decode("jwt-vault-config")).thenReturn(configLoader); when(VaultConfig.decode("jwt-vault-config")).thenReturn(configLoader); diff --git a/src/test/java/org/cryptomator/cryptofs/DeleteNonEmptyCiphertextDirectoryIntegrationTest.java b/src/test/java/org/cryptomator/cryptofs/DeleteNonEmptyCiphertextDirectoryIntegrationTest.java index fe566bac..21754ca2 100644 --- a/src/test/java/org/cryptomator/cryptofs/DeleteNonEmptyCiphertextDirectoryIntegrationTest.java +++ b/src/test/java/org/cryptomator/cryptofs/DeleteNonEmptyCiphertextDirectoryIntegrationTest.java @@ -46,9 +46,8 @@ public static void setupClass(@TempDir Path tmpDir) throws IOException, Masterke pathToVault = tmpDir.resolve("vault"); Files.createDirectory(pathToVault); MasterkeyLoader keyLoader = Mockito.mock(MasterkeyLoader.class); - Mockito.when(keyLoader.supportsScheme("test")).thenReturn(true); Mockito.when(keyLoader.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(new byte[64])); - CryptoFileSystemProperties properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); + CryptoFileSystemProperties properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoader(keyLoader).build(); CryptoFileSystemProvider.initialize(pathToVault, properties, URI.create("test:key")); fileSystem = new CryptoFileSystemProvider().newFileSystem(create(pathToVault), properties); } diff --git a/src/test/java/org/cryptomator/cryptofs/ReadmeCodeSamplesTest.java b/src/test/java/org/cryptomator/cryptofs/ReadmeCodeSamplesTest.java index 30c1a857..fc0037e5 100644 --- a/src/test/java/org/cryptomator/cryptofs/ReadmeCodeSamplesTest.java +++ b/src/test/java/org/cryptomator/cryptofs/ReadmeCodeSamplesTest.java @@ -31,9 +31,8 @@ public class ReadmeCodeSamplesTest { @Test public void testReadmeCodeSampleUsingFileSystemConstructionMethodA(@TempDir Path storageLocation) throws IOException, MasterkeyLoadingFailedException { MasterkeyLoader keyLoader = Mockito.mock(MasterkeyLoader.class); - Mockito.when(keyLoader.supportsScheme("test")).thenReturn(true); Mockito.when(keyLoader.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(new byte[64])); - CryptoFileSystemProperties properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); + CryptoFileSystemProperties properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoader(keyLoader).build(); CryptoFileSystemProvider.initialize(storageLocation, properties, URI.create("test:key")); FileSystem fileSystem = CryptoFileSystemProvider.newFileSystem(storageLocation, properties); @@ -44,9 +43,8 @@ public void testReadmeCodeSampleUsingFileSystemConstructionMethodA(@TempDir Path public void testReadmeCodeSampleUsingFileSystemConstructionMethodB(@TempDir Path storageLocation) throws IOException, MasterkeyLoadingFailedException { URI uri = CryptoFileSystemUri.create(storageLocation); MasterkeyLoader keyLoader = Mockito.mock(MasterkeyLoader.class); - Mockito.when(keyLoader.supportsScheme("test")).thenReturn(true); Mockito.when(keyLoader.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(new byte[64])); - CryptoFileSystemProperties properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); + CryptoFileSystemProperties properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoader(keyLoader).build(); CryptoFileSystemProvider.initialize(storageLocation, properties, URI.create("test:key")); FileSystem fileSystem = FileSystems.newFileSystem(uri, properties); diff --git a/src/test/java/org/cryptomator/cryptofs/RealFileSystemIntegrationTest.java b/src/test/java/org/cryptomator/cryptofs/RealFileSystemIntegrationTest.java index d0c65013..6706ddf3 100644 --- a/src/test/java/org/cryptomator/cryptofs/RealFileSystemIntegrationTest.java +++ b/src/test/java/org/cryptomator/cryptofs/RealFileSystemIntegrationTest.java @@ -25,6 +25,7 @@ import java.nio.file.Path; import java.nio.file.attribute.UserPrincipal; +import static org.cryptomator.cryptofs.CryptoFileSystemProperties.cryptoFileSystemProperties; import static org.cryptomator.cryptofs.CryptoFileSystemUri.create; public class RealFileSystemIntegrationTest { @@ -37,9 +38,8 @@ public static void setupClass(@TempDir Path tmpDir) throws IOException, Masterke pathToVault = tmpDir.resolve("vault"); Files.createDirectory(pathToVault); MasterkeyLoader keyLoader = Mockito.mock(MasterkeyLoader.class); - Mockito.when(keyLoader.supportsScheme("test")).thenReturn(true); Mockito.when(keyLoader.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(new byte[64])); - CryptoFileSystemProperties properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); + CryptoFileSystemProperties properties = cryptoFileSystemProperties().withKeyLoader(keyLoader).build(); CryptoFileSystemProvider.initialize(pathToVault, properties, URI.create("test:key")); fileSystem = new CryptoFileSystemProvider().newFileSystem(create(pathToVault), properties); } diff --git a/src/test/java/org/cryptomator/cryptofs/WriteFileWhileReadonlyChannelIsOpenTest.java b/src/test/java/org/cryptomator/cryptofs/WriteFileWhileReadonlyChannelIsOpenTest.java index 203f600f..2e39d116 100644 --- a/src/test/java/org/cryptomator/cryptofs/WriteFileWhileReadonlyChannelIsOpenTest.java +++ b/src/test/java/org/cryptomator/cryptofs/WriteFileWhileReadonlyChannelIsOpenTest.java @@ -19,6 +19,7 @@ import java.nio.file.StandardOpenOption; import static java.nio.file.StandardOpenOption.READ; +import static org.cryptomator.cryptofs.CryptoFileSystemProperties.cryptoFileSystemProperties; import static org.cryptomator.cryptofs.CryptoFileSystemUri.create; /** @@ -36,9 +37,8 @@ public void setup() throws IOException, MasterkeyLoadingFailedException { Path pathToVault = inMemoryFs.getRootDirectories().iterator().next().resolve("vault"); Files.createDirectory(pathToVault); MasterkeyLoader keyLoader = Mockito.mock(MasterkeyLoader.class); - Mockito.when(keyLoader.supportsScheme("test")).thenReturn(true); Mockito.when(keyLoader.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(new byte[64])); - CryptoFileSystemProperties properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); + CryptoFileSystemProperties properties = cryptoFileSystemProperties().withKeyLoader(keyLoader).build(); CryptoFileSystemProvider.initialize(pathToVault, properties, URI.create("test:key")); fileSystem = new CryptoFileSystemProvider().newFileSystem(create(pathToVault), properties); root = fileSystem.getPath("/"); diff --git a/src/test/java/org/cryptomator/cryptofs/attr/FileAttributeIntegrationTest.java b/src/test/java/org/cryptomator/cryptofs/attr/FileAttributeIntegrationTest.java index 11a6ee09..ffb26afa 100644 --- a/src/test/java/org/cryptomator/cryptofs/attr/FileAttributeIntegrationTest.java +++ b/src/test/java/org/cryptomator/cryptofs/attr/FileAttributeIntegrationTest.java @@ -62,9 +62,8 @@ public static void setupClass() throws IOException, MasterkeyLoadingFailedExcept pathToVault = inMemoryFs.getRootDirectories().iterator().next().resolve("vault"); Files.createDirectory(pathToVault); MasterkeyLoader keyLoader = Mockito.mock(MasterkeyLoader.class); - Mockito.when(keyLoader.supportsScheme("test")).thenReturn(true); Mockito.when(keyLoader.loadKey(Mockito.any())).thenAnswer(ignored -> new Masterkey(new byte[64])); - CryptoFileSystemProperties properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoaders(keyLoader).build(); + CryptoFileSystemProperties properties = CryptoFileSystemProperties.cryptoFileSystemProperties().withKeyLoader(keyLoader).build(); CryptoFileSystemProvider.initialize(pathToVault, properties, URI.create("test:key")); fileSystem = new CryptoFileSystemProvider().newFileSystem(create(pathToVault), properties); }