Wire disable all keyrings setting checkbox to the KeychainManager

This commit is contained in:
Ralph Plawetzki
2022-09-13 14:01:02 +02:00
parent e6c7fed662
commit 17d3d7307d
3 changed files with 11 additions and 4 deletions

View File

@@ -3,6 +3,7 @@ package org.cryptomator.common.keychain;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import org.cryptomator.common.settings.Settings;
import org.cryptomator.integrations.keychain.KeychainAccessException;
import org.cryptomator.integrations.keychain.KeychainAccessProvider;
@@ -20,10 +21,12 @@ public class KeychainManager implements KeychainAccessProvider {
private final ObjectExpression<KeychainAccessProvider> keychain;
private final LoadingCache<String, BooleanProperty> passphraseStoredProperties;
private final Settings settings;
@Inject
KeychainManager(ObjectExpression<KeychainAccessProvider> selectedKeychain) {
KeychainManager(ObjectExpression<KeychainAccessProvider> selectedKeychain, Settings settings) {
this.keychain = selectedKeychain;
this.settings = settings;
this.passphraseStoredProperties = CacheBuilder.newBuilder() //
.weakValues() //
.build(CacheLoader.from(this::createStoredPassphraseProperty));
@@ -72,7 +75,7 @@ public class KeychainManager implements KeychainAccessProvider {
@Override
public boolean isSupported() {
return keychain.getValue() != null;
return keychain.getValue() != null && !settings.disableAllKeyrings().get();
}
@Override

View File

@@ -66,6 +66,7 @@ public class GeneralPreferencesController implements FxController {
keychainBackendChoiceBox.setConverter(new KeychainProviderDisplayNameConverter());
Bindings.bindBidirectional(settings.keychainProvider(), keychainBackendChoiceBox.valueProperty(), keychainSettingsConverter);
disableAllKeyringsCheckbox.selectedProperty().bindBidirectional(settings.disableAllKeyrings());
keychainBackendChoiceBox.disableProperty().bindBidirectional(settings.disableAllKeyrings());
}
public boolean isAutoStartSupported() {

View File

@@ -1,12 +1,14 @@
package org.cryptomator.common.keychain;
import org.cryptomator.common.settings.Settings;
import org.cryptomator.integrations.keychain.KeychainAccessException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import javafx.application.Platform;
import javafx.beans.property.ReadOnlyBooleanProperty;
@@ -19,9 +21,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class KeychainManagerTest {
private static final Settings settings = Mockito.mock(Settings.class);
@Test
public void testStoreAndLoad() throws KeychainAccessException {
KeychainManager keychainManager = new KeychainManager(new SimpleObjectProperty<>(new MapKeychainAccess()));
KeychainManager keychainManager = new KeychainManager(new SimpleObjectProperty<>(new MapKeychainAccess()), settings);
keychainManager.storePassphrase("test", "Test", "asd");
Assertions.assertArrayEquals("asd".toCharArray(), keychainManager.loadPassphrase("test"));
}
@@ -39,7 +42,7 @@ public class KeychainManagerTest {
@Test
public void testPropertyChangesWhenStoringPassword() throws KeychainAccessException, InterruptedException {
KeychainManager keychainManager = new KeychainManager(new SimpleObjectProperty<>(new MapKeychainAccess()));
KeychainManager keychainManager = new KeychainManager(new SimpleObjectProperty<>(new MapKeychainAccess()), settings);
ReadOnlyBooleanProperty property = keychainManager.getPassphraseStoredProperty("test");
Assertions.assertFalse(property.get());