refactor(securestore): remove password-based authentication in favor of key-file only
Simplify SecureStore by removing MasterKeyEnvVar and password-based methods, leaving only key-file authentication for better security practices.
This commit is contained in:
+3
-221
@@ -5,17 +5,6 @@ namespace JdeScoping.ConfigManager.Tests.ViewModels.Dialogs;
|
||||
|
||||
public class NewStoreDialogViewModelTests
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_DefaultsToUseKeyFile()
|
||||
{
|
||||
// Arrange & Act
|
||||
var sut = new NewStoreDialogViewModel();
|
||||
|
||||
// Assert
|
||||
sut.UseKeyFile.ShouldBeTrue();
|
||||
sut.UsePassword.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StorePath_WhenEmpty_IsValidReturnsFalse()
|
||||
{
|
||||
@@ -60,13 +49,12 @@ public class NewStoreDialogViewModelTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void KeyFilePath_WhenRequiredAndEmpty_IsValidReturnsFalse()
|
||||
public void KeyFilePath_WhenEmpty_IsValidReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel
|
||||
{
|
||||
StorePath = "/path/to/store.secure",
|
||||
UseKeyFile = true,
|
||||
KeyFilePath = ""
|
||||
};
|
||||
|
||||
@@ -75,13 +63,12 @@ public class NewStoreDialogViewModelTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void KeyFilePath_WhenRequiredAndEmpty_ValidationErrorReturnsKeyFilePathRequired()
|
||||
public void KeyFilePath_WhenEmpty_ValidationErrorReturnsKeyFilePathRequired()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel
|
||||
{
|
||||
StorePath = "/path/to/store.secure",
|
||||
UseKeyFile = true,
|
||||
KeyFilePath = ""
|
||||
};
|
||||
|
||||
@@ -90,13 +77,12 @@ public class NewStoreDialogViewModelTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void KeyFilePath_WhenRequiredAndProvided_IsValidReturnsTrue()
|
||||
public void KeyFilePath_WhenProvided_IsValidReturnsTrue()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel
|
||||
{
|
||||
StorePath = "/path/to/store.secure",
|
||||
UseKeyFile = true,
|
||||
KeyFilePath = "/path/to/key.key"
|
||||
};
|
||||
|
||||
@@ -105,134 +91,6 @@ public class NewStoreDialogViewModelTests
|
||||
sut.ValidationError.ShouldBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Password_WhenRequiredAndEmpty_IsValidReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel
|
||||
{
|
||||
StorePath = "/path/to/store.secure",
|
||||
UsePassword = true,
|
||||
Password = ""
|
||||
};
|
||||
|
||||
// Act & Assert
|
||||
sut.IsValid.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Password_WhenRequiredAndEmpty_ValidationErrorReturnsPasswordRequired()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel
|
||||
{
|
||||
StorePath = "/path/to/store.secure",
|
||||
UsePassword = true,
|
||||
Password = ""
|
||||
};
|
||||
|
||||
// Act & Assert
|
||||
sut.ValidationError.ShouldBe(SecureStoreStrings.PasswordRequired);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConfirmPassword_WhenRequiredAndDoesNotMatch_IsValidReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel
|
||||
{
|
||||
StorePath = "/path/to/store.secure",
|
||||
UsePassword = true,
|
||||
Password = "password123",
|
||||
ConfirmPassword = "differentPassword"
|
||||
};
|
||||
|
||||
// Act & Assert
|
||||
sut.IsValid.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConfirmPassword_WhenRequiredAndDoesNotMatch_ValidationErrorReturnsPasswordsDoNotMatch()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel
|
||||
{
|
||||
StorePath = "/path/to/store.secure",
|
||||
UsePassword = true,
|
||||
Password = "password123",
|
||||
ConfirmPassword = "differentPassword"
|
||||
};
|
||||
|
||||
// Act & Assert
|
||||
sut.ValidationError.ShouldBe(SecureStoreStrings.PasswordsDoNotMatch);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Password_WhenRequiredAndMatchesConfirmPassword_IsValidReturnsTrue()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel
|
||||
{
|
||||
StorePath = "/path/to/store.secure",
|
||||
UsePassword = true,
|
||||
Password = "password123",
|
||||
ConfirmPassword = "password123"
|
||||
};
|
||||
|
||||
// Act & Assert
|
||||
sut.IsValid.ShouldBeTrue();
|
||||
sut.ValidationError.ShouldBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UseKeyFile_WhenSetToTrue_SetsUsePasswordToFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel
|
||||
{
|
||||
UsePassword = true
|
||||
};
|
||||
|
||||
// Act
|
||||
sut.UseKeyFile = true;
|
||||
|
||||
// Assert
|
||||
sut.UseKeyFile.ShouldBeTrue();
|
||||
sut.UsePassword.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsePassword_WhenSetToTrue_SetsUseKeyFileToFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel
|
||||
{
|
||||
UseKeyFile = true
|
||||
};
|
||||
|
||||
// Act
|
||||
sut.UsePassword = true;
|
||||
|
||||
// Assert
|
||||
sut.UsePassword.ShouldBeTrue();
|
||||
sut.UseKeyFile.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsValid_WhenNeitherKeyFileNorPasswordSelected_ReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel
|
||||
{
|
||||
StorePath = "/path/to/store.secure"
|
||||
};
|
||||
// Manually set both to false (shouldn't happen in UI, but test edge case)
|
||||
sut.UseKeyFile = false;
|
||||
|
||||
// Act & Assert
|
||||
sut.IsValid.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StorePath_WhenChanged_RaisesPropertyChanged()
|
||||
{
|
||||
@@ -309,82 +167,6 @@ public class NewStoreDialogViewModelTests
|
||||
propertyChangedRaised.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Password_WhenChanged_RaisesPropertyChanged()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel();
|
||||
var propertyChangedRaised = false;
|
||||
sut.PropertyChanged += (s, e) =>
|
||||
{
|
||||
if (e.PropertyName == nameof(NewStoreDialogViewModel.Password))
|
||||
propertyChangedRaised = true;
|
||||
};
|
||||
|
||||
// Act
|
||||
sut.Password = "newpassword";
|
||||
|
||||
// Assert
|
||||
propertyChangedRaised.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConfirmPassword_WhenChanged_RaisesPropertyChanged()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel();
|
||||
var propertyChangedRaised = false;
|
||||
sut.PropertyChanged += (s, e) =>
|
||||
{
|
||||
if (e.PropertyName == nameof(NewStoreDialogViewModel.ConfirmPassword))
|
||||
propertyChangedRaised = true;
|
||||
};
|
||||
|
||||
// Act
|
||||
sut.ConfirmPassword = "newpassword";
|
||||
|
||||
// Assert
|
||||
propertyChangedRaised.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UseKeyFile_WhenChanged_RaisesPropertyChanged()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel { UseKeyFile = false };
|
||||
var propertyChangedRaised = false;
|
||||
sut.PropertyChanged += (s, e) =>
|
||||
{
|
||||
if (e.PropertyName == nameof(NewStoreDialogViewModel.UseKeyFile))
|
||||
propertyChangedRaised = true;
|
||||
};
|
||||
|
||||
// Act
|
||||
sut.UseKeyFile = true;
|
||||
|
||||
// Assert
|
||||
propertyChangedRaised.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsePassword_WhenChanged_RaisesPropertyChanged()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel();
|
||||
var propertyChangedRaised = false;
|
||||
sut.PropertyChanged += (s, e) =>
|
||||
{
|
||||
if (e.PropertyName == nameof(NewStoreDialogViewModel.UsePassword))
|
||||
propertyChangedRaised = true;
|
||||
};
|
||||
|
||||
// Act
|
||||
sut.UsePassword = true;
|
||||
|
||||
// Assert
|
||||
propertyChangedRaised.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Commands_AreInitialized()
|
||||
{
|
||||
|
||||
+5
-182
@@ -25,17 +25,6 @@ public class UnlockStoreDialogViewModelTests
|
||||
Should.Throw<ArgumentNullException>(() => new UnlockStoreDialogViewModel(null!));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_DefaultsToUseKeyFile()
|
||||
{
|
||||
// Arrange & Act
|
||||
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure");
|
||||
|
||||
// Assert
|
||||
sut.UseKeyFile.ShouldBeTrue();
|
||||
sut.UsePassword.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StorePath_IsReadOnly()
|
||||
{
|
||||
@@ -47,12 +36,11 @@ public class UnlockStoreDialogViewModelTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void KeyFilePath_WhenRequiredAndEmpty_IsValidReturnsFalse()
|
||||
public void KeyFilePath_WhenEmpty_IsValidReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure")
|
||||
{
|
||||
UseKeyFile = true,
|
||||
KeyFilePath = ""
|
||||
};
|
||||
|
||||
@@ -61,12 +49,11 @@ public class UnlockStoreDialogViewModelTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void KeyFilePath_WhenRequiredAndEmpty_ValidationErrorReturnsKeyFilePathRequired()
|
||||
public void KeyFilePath_WhenEmpty_ValidationErrorReturnsKeyFilePathRequired()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure")
|
||||
{
|
||||
UseKeyFile = true,
|
||||
KeyFilePath = ""
|
||||
};
|
||||
|
||||
@@ -75,12 +62,11 @@ public class UnlockStoreDialogViewModelTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void KeyFilePath_WhenRequiredAndWhitespace_IsValidReturnsFalse()
|
||||
public void KeyFilePath_WhenWhitespace_IsValidReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure")
|
||||
{
|
||||
UseKeyFile = true,
|
||||
KeyFilePath = " "
|
||||
};
|
||||
|
||||
@@ -90,12 +76,11 @@ public class UnlockStoreDialogViewModelTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void KeyFilePath_WhenRequiredAndFileDoesNotExist_IsValidReturnsFalse()
|
||||
public void KeyFilePath_WhenFileDoesNotExist_IsValidReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure")
|
||||
{
|
||||
UseKeyFile = true,
|
||||
KeyFilePath = "/nonexistent/path/to/key.key"
|
||||
};
|
||||
|
||||
@@ -104,12 +89,11 @@ public class UnlockStoreDialogViewModelTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void KeyFilePath_WhenRequiredAndFileDoesNotExist_ValidationErrorReturnsKeyFileNotFound()
|
||||
public void KeyFilePath_WhenFileDoesNotExist_ValidationErrorReturnsKeyFileNotFound()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure")
|
||||
{
|
||||
UseKeyFile = true,
|
||||
KeyFilePath = "/nonexistent/path/to/key.key"
|
||||
};
|
||||
|
||||
@@ -117,110 +101,6 @@ public class UnlockStoreDialogViewModelTests
|
||||
sut.ValidationError.ShouldBe(SecureStoreStrings.KeyFileNotFound);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Password_WhenRequiredAndEmpty_IsValidReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure")
|
||||
{
|
||||
UsePassword = true,
|
||||
Password = ""
|
||||
};
|
||||
|
||||
// Act & Assert
|
||||
sut.IsValid.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Password_WhenRequiredAndEmpty_ValidationErrorReturnsPasswordRequired()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure")
|
||||
{
|
||||
UsePassword = true,
|
||||
Password = ""
|
||||
};
|
||||
|
||||
// Act & Assert
|
||||
sut.ValidationError.ShouldBe(SecureStoreStrings.PasswordRequired);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Password_WhenRequiredAndWhitespace_IsValidReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure")
|
||||
{
|
||||
UsePassword = true,
|
||||
Password = " "
|
||||
};
|
||||
|
||||
// Act & Assert
|
||||
sut.IsValid.ShouldBeFalse();
|
||||
sut.ValidationError.ShouldBe(SecureStoreStrings.PasswordRequired);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Password_WhenRequiredAndProvided_IsValidReturnsTrue()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure")
|
||||
{
|
||||
UsePassword = true,
|
||||
Password = "password123"
|
||||
};
|
||||
|
||||
// Act & Assert
|
||||
sut.IsValid.ShouldBeTrue();
|
||||
sut.ValidationError.ShouldBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UseKeyFile_WhenSetToTrue_SetsUsePasswordToFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure")
|
||||
{
|
||||
UsePassword = true
|
||||
};
|
||||
|
||||
// Act
|
||||
sut.UseKeyFile = true;
|
||||
|
||||
// Assert
|
||||
sut.UseKeyFile.ShouldBeTrue();
|
||||
sut.UsePassword.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsePassword_WhenSetToTrue_SetsUseKeyFileToFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure")
|
||||
{
|
||||
UseKeyFile = true
|
||||
};
|
||||
|
||||
// Act
|
||||
sut.UsePassword = true;
|
||||
|
||||
// Assert
|
||||
sut.UsePassword.ShouldBeTrue();
|
||||
sut.UseKeyFile.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsValid_WhenNeitherKeyFileNorPasswordSelected_ReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure");
|
||||
// Manually set both to false (shouldn't happen in UI, but test edge case)
|
||||
sut.UseKeyFile = false;
|
||||
|
||||
// Act & Assert
|
||||
sut.IsValid.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void KeyFilePath_WhenChanged_RaisesPropertyChanged()
|
||||
{
|
||||
@@ -278,63 +158,6 @@ public class UnlockStoreDialogViewModelTests
|
||||
validationErrorPropertyChangedRaised.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Password_WhenChanged_RaisesPropertyChanged()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure");
|
||||
var propertyChangedRaised = false;
|
||||
sut.PropertyChanged += (s, e) =>
|
||||
{
|
||||
if (e.PropertyName == nameof(UnlockStoreDialogViewModel.Password))
|
||||
propertyChangedRaised = true;
|
||||
};
|
||||
|
||||
// Act
|
||||
sut.Password = "newpassword";
|
||||
|
||||
// Assert
|
||||
propertyChangedRaised.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UseKeyFile_WhenChanged_RaisesPropertyChanged()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure") { UseKeyFile = false };
|
||||
var propertyChangedRaised = false;
|
||||
sut.PropertyChanged += (s, e) =>
|
||||
{
|
||||
if (e.PropertyName == nameof(UnlockStoreDialogViewModel.UseKeyFile))
|
||||
propertyChangedRaised = true;
|
||||
};
|
||||
|
||||
// Act
|
||||
sut.UseKeyFile = true;
|
||||
|
||||
// Assert
|
||||
propertyChangedRaised.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsePassword_WhenChanged_RaisesPropertyChanged()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure");
|
||||
var propertyChangedRaised = false;
|
||||
sut.PropertyChanged += (s, e) =>
|
||||
{
|
||||
if (e.PropertyName == nameof(UnlockStoreDialogViewModel.UsePassword))
|
||||
propertyChangedRaised = true;
|
||||
};
|
||||
|
||||
// Act
|
||||
sut.UsePassword = true;
|
||||
|
||||
// Assert
|
||||
propertyChangedRaised.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BrowseKeyFilePathCommand_IsInitialized()
|
||||
{
|
||||
|
||||
@@ -61,31 +61,6 @@ public class SecureStoreManagerTests : IDisposable
|
||||
File.Exists(keyPath).ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateStoreWithPassword_CreatesStore()
|
||||
{
|
||||
// Arrange
|
||||
var storePath = Path.Combine(_testDirectory, "test.json");
|
||||
|
||||
// Act
|
||||
_sut.CreateStoreWithPassword(storePath, "testpassword123");
|
||||
|
||||
// Assert
|
||||
_sut.IsStoreOpen.ShouldBeTrue();
|
||||
_sut.CurrentStorePath.ShouldBe(storePath);
|
||||
File.Exists(storePath).ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateStoreWithPassword_WithEmptyPassword_ThrowsArgumentException()
|
||||
{
|
||||
// Arrange
|
||||
var storePath = Path.Combine(_testDirectory, "test.json");
|
||||
|
||||
// Act & Assert
|
||||
Should.Throw<ArgumentException>(() => _sut.CreateStoreWithPassword(storePath, ""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OpenStore_WithValidKeyFile_OpensStore()
|
||||
{
|
||||
@@ -114,22 +89,6 @@ public class SecureStoreManagerTests : IDisposable
|
||||
Should.Throw<FileNotFoundException>(() => _sut.OpenStore(storePath, keyPath));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OpenStoreWithPassword_OpensStore()
|
||||
{
|
||||
// Arrange
|
||||
var storePath = Path.Combine(_testDirectory, "test.json");
|
||||
var password = "testpassword123";
|
||||
_sut.CreateStoreWithPassword(storePath, password);
|
||||
_sut.CloseStore();
|
||||
|
||||
// Act
|
||||
_sut.OpenStoreWithPassword(storePath, password);
|
||||
|
||||
// Assert
|
||||
_sut.IsStoreOpen.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CloseStore_ClosesOpenStore()
|
||||
{
|
||||
|
||||
@@ -12,7 +12,6 @@ public class NewStoreDialogViewModelTests
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel();
|
||||
sut.StorePath = string.Empty;
|
||||
sut.UseKeyFile = true;
|
||||
sut.KeyFilePath = "/path/to/key.key";
|
||||
|
||||
// Act & Assert
|
||||
@@ -20,12 +19,11 @@ public class NewStoreDialogViewModelTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsValid_WhenUseKeyFileButKeyFilePathEmpty_ReturnsFalse()
|
||||
public void IsValid_WhenKeyFilePathEmpty_ReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel();
|
||||
sut.StorePath = "/path/to/store.json";
|
||||
sut.UseKeyFile = true;
|
||||
sut.KeyFilePath = string.Empty;
|
||||
|
||||
// Act & Assert
|
||||
@@ -33,87 +31,17 @@ public class NewStoreDialogViewModelTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsValid_WhenUsePasswordButPasswordEmpty_ReturnsFalse()
|
||||
public void IsValid_WithValidConfiguration_ReturnsTrue()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel();
|
||||
sut.StorePath = "/path/to/store.json";
|
||||
sut.UsePassword = true;
|
||||
sut.Password = string.Empty;
|
||||
|
||||
// Act & Assert
|
||||
sut.IsValid.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsValid_WhenPasswordsDoNotMatch_ReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel();
|
||||
sut.StorePath = "/path/to/store.json";
|
||||
sut.UsePassword = true;
|
||||
sut.Password = "password123";
|
||||
sut.ConfirmPassword = "different456";
|
||||
|
||||
// Act & Assert
|
||||
sut.IsValid.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsValid_WithValidKeyFileConfiguration_ReturnsTrue()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel();
|
||||
sut.StorePath = "/path/to/store.json";
|
||||
sut.UseKeyFile = true;
|
||||
sut.KeyFilePath = "/path/to/key.key";
|
||||
|
||||
// Act & Assert
|
||||
sut.IsValid.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsValid_WithValidPasswordConfiguration_ReturnsTrue()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel();
|
||||
sut.StorePath = "/path/to/store.json";
|
||||
sut.UsePassword = true;
|
||||
sut.Password = "password123";
|
||||
sut.ConfirmPassword = "password123";
|
||||
|
||||
// Act & Assert
|
||||
sut.IsValid.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UseKeyFile_WhenSetToTrue_SetsUsePasswordToFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel();
|
||||
sut.UsePassword = true;
|
||||
|
||||
// Act
|
||||
sut.UseKeyFile = true;
|
||||
|
||||
// Assert
|
||||
sut.UsePassword.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsePassword_WhenSetToTrue_SetsUseKeyFileToFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel();
|
||||
sut.UseKeyFile = true;
|
||||
|
||||
// Act
|
||||
sut.UsePassword = true;
|
||||
|
||||
// Assert
|
||||
sut.UseKeyFile.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidationError_WhenStorePathEmpty_ReturnsAppropriateMessage()
|
||||
{
|
||||
@@ -131,47 +59,18 @@ public class NewStoreDialogViewModelTests
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel();
|
||||
sut.StorePath = "/path/to/store.json";
|
||||
sut.UseKeyFile = true;
|
||||
sut.KeyFilePath = string.Empty;
|
||||
|
||||
// Act & Assert
|
||||
sut.ValidationError.ShouldBe("Key file path is required.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidationError_WhenPasswordEmpty_ReturnsAppropriateMessage()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel();
|
||||
sut.StorePath = "/path/to/store.json";
|
||||
sut.UsePassword = true;
|
||||
sut.Password = string.Empty;
|
||||
|
||||
// Act & Assert
|
||||
sut.ValidationError.ShouldBe("Password is required.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidationError_WhenPasswordsDoNotMatch_ReturnsAppropriateMessage()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel();
|
||||
sut.StorePath = "/path/to/store.json";
|
||||
sut.UsePassword = true;
|
||||
sut.Password = "password123";
|
||||
sut.ConfirmPassword = "different456";
|
||||
|
||||
// Act & Assert
|
||||
sut.ValidationError.ShouldBe("Passwords do not match.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidationError_WhenValid_ReturnsNull()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new NewStoreDialogViewModel();
|
||||
sut.StorePath = "/path/to/store.json";
|
||||
sut.UseKeyFile = true;
|
||||
sut.KeyFilePath = "/path/to/key.key";
|
||||
|
||||
// Act & Assert
|
||||
@@ -193,85 +92,17 @@ public class OpenStoreDialogViewModelTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsValid_WhenUseKeyFileButKeyFilePathEmpty_ReturnsFalse()
|
||||
public void IsValid_WhenKeyFilePathEmpty_ReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new OpenStoreDialogViewModel();
|
||||
sut.StorePath = "/path/to/store.json";
|
||||
sut.UseKeyFile = true;
|
||||
sut.KeyFilePath = string.Empty;
|
||||
|
||||
// Act & Assert
|
||||
sut.IsValid.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsValid_WhenUsePasswordButPasswordEmpty_ReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new OpenStoreDialogViewModel();
|
||||
sut.StorePath = "/path/to/store.json";
|
||||
sut.UsePassword = true;
|
||||
sut.Password = string.Empty;
|
||||
|
||||
// Act & Assert
|
||||
sut.IsValid.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsValid_WithValidKeyFileConfiguration_ReturnsTrue()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new OpenStoreDialogViewModel();
|
||||
sut.StorePath = "/path/to/store.json";
|
||||
sut.UseKeyFile = true;
|
||||
sut.KeyFilePath = "/path/to/key.key";
|
||||
|
||||
// Act & Assert
|
||||
sut.IsValid.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsValid_WithValidPasswordConfiguration_ReturnsTrue()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new OpenStoreDialogViewModel();
|
||||
sut.StorePath = "/path/to/store.json";
|
||||
sut.UsePassword = true;
|
||||
sut.Password = "password123";
|
||||
|
||||
// Act & Assert
|
||||
sut.IsValid.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UseKeyFile_WhenSetToTrue_SetsUsePasswordToFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new OpenStoreDialogViewModel();
|
||||
sut.UsePassword = true;
|
||||
|
||||
// Act
|
||||
sut.UseKeyFile = true;
|
||||
|
||||
// Assert
|
||||
sut.UsePassword.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsePassword_WhenSetToTrue_SetsUseKeyFileToFalse()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new OpenStoreDialogViewModel();
|
||||
sut.UseKeyFile = true;
|
||||
|
||||
// Act
|
||||
sut.UsePassword = true;
|
||||
|
||||
// Assert
|
||||
sut.UseKeyFile.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidationError_WhenStorePathEmpty_ReturnsAppropriateMessage()
|
||||
{
|
||||
@@ -303,7 +134,6 @@ public class OpenStoreDialogViewModelTests
|
||||
{
|
||||
var sut = new OpenStoreDialogViewModel();
|
||||
sut.StorePath = tempFile;
|
||||
sut.UseKeyFile = true;
|
||||
sut.KeyFilePath = string.Empty;
|
||||
|
||||
// Act & Assert
|
||||
@@ -324,7 +154,6 @@ public class OpenStoreDialogViewModelTests
|
||||
{
|
||||
var sut = new OpenStoreDialogViewModel();
|
||||
sut.StorePath = tempFile;
|
||||
sut.UseKeyFile = true;
|
||||
sut.KeyFilePath = "/nonexistent/key.key";
|
||||
|
||||
// Act & Assert
|
||||
@@ -335,27 +164,6 @@ public class OpenStoreDialogViewModelTests
|
||||
File.Delete(tempFile);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidationError_WhenPasswordEmpty_ReturnsAppropriateMessage()
|
||||
{
|
||||
// Arrange - Create temp store file so we get past that validation
|
||||
var tempFile = Path.GetTempFileName();
|
||||
try
|
||||
{
|
||||
var sut = new OpenStoreDialogViewModel();
|
||||
sut.StorePath = tempFile;
|
||||
sut.UsePassword = true;
|
||||
sut.Password = string.Empty;
|
||||
|
||||
// Act & Assert
|
||||
sut.ValidationError.ShouldBe("Password is required.");
|
||||
}
|
||||
finally
|
||||
{
|
||||
File.Delete(tempFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SecretEditDialogViewModelTests
|
||||
|
||||
+2
-32
@@ -97,27 +97,12 @@ public class MainWindowViewModelTests
|
||||
_mockStoreManager.GetKeys().Returns(new List<string>().AsReadOnly());
|
||||
|
||||
// Act
|
||||
await _sut.CreateNewStoreAsync(storePath, keyPath, null);
|
||||
await _sut.CreateNewStoreAsync(storePath, keyPath);
|
||||
|
||||
// Assert
|
||||
_mockStoreManager.Received(1).CreateStore(storePath, keyPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CreateNewStoreAsync_WithPassword_CallsStoreManagerCreateStoreWithPassword()
|
||||
{
|
||||
// Arrange
|
||||
var storePath = "/path/to/store.json";
|
||||
var password = "password123";
|
||||
_mockStoreManager.GetKeys().Returns(new List<string>().AsReadOnly());
|
||||
|
||||
// Act
|
||||
await _sut.CreateNewStoreAsync(storePath, null, password);
|
||||
|
||||
// Assert
|
||||
_mockStoreManager.Received(1).CreateStoreWithPassword(storePath, password);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task OpenExistingStoreAsync_WithKeyFile_CallsStoreManagerOpenStore()
|
||||
{
|
||||
@@ -127,27 +112,12 @@ public class MainWindowViewModelTests
|
||||
_mockStoreManager.GetKeys().Returns(new List<string>().AsReadOnly());
|
||||
|
||||
// Act
|
||||
await _sut.OpenExistingStoreAsync(storePath, keyPath, null);
|
||||
await _sut.OpenExistingStoreAsync(storePath, keyPath);
|
||||
|
||||
// Assert
|
||||
_mockStoreManager.Received(1).OpenStore(storePath, keyPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task OpenExistingStoreAsync_WithPassword_CallsStoreManagerOpenStoreWithPassword()
|
||||
{
|
||||
// Arrange
|
||||
var storePath = "/path/to/store.json";
|
||||
var password = "password123";
|
||||
_mockStoreManager.GetKeys().Returns(new List<string>().AsReadOnly());
|
||||
|
||||
// Act
|
||||
await _sut.OpenExistingStoreAsync(storePath, null, password);
|
||||
|
||||
// Assert
|
||||
_mockStoreManager.Received(1).OpenStoreWithPassword(storePath, password);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SaveSecretAsync_CallsStoreManagerSetSecret()
|
||||
{
|
||||
|
||||
@@ -45,15 +45,15 @@ public class NewStoreDialogTests
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
public void NewStoreDialog_HasRadioButtons()
|
||||
public void NewStoreDialog_HasKeyFilePathTextBox()
|
||||
{
|
||||
// Arrange & Act
|
||||
var dialog = new NewStoreDialog();
|
||||
dialog.Show();
|
||||
|
||||
// Assert
|
||||
var radioButtons = dialog.GetVisualDescendants().OfType<RadioButton>().ToList();
|
||||
radioButtons.Count.ShouldBeGreaterThanOrEqualTo(2);
|
||||
// Assert - Should have at least 2 text boxes: store path and key file path
|
||||
var textBoxes = dialog.GetVisualDescendants().OfType<TextBox>().ToList();
|
||||
textBoxes.Count.ShouldBeGreaterThanOrEqualTo(2);
|
||||
}
|
||||
|
||||
[AvaloniaFact]
|
||||
|
||||
Reference in New Issue
Block a user