1b7bb26def
Simplify SecureStore by removing MasterKeyEnvVar and password-based methods, leaving only key-file authentication for better security practices.
171 lines
4.7 KiB
C#
171 lines
4.7 KiB
C#
using JdeScoping.ConfigManager.Constants;
|
|
using JdeScoping.ConfigManager.ViewModels.Dialogs;
|
|
|
|
namespace JdeScoping.ConfigManager.Tests.ViewModels.Dialogs;
|
|
|
|
public class UnlockStoreDialogViewModelTests
|
|
{
|
|
[Fact]
|
|
public void Constructor_SetsStorePathFromParameter()
|
|
{
|
|
// Arrange
|
|
var storePath = "/path/to/store.secure";
|
|
|
|
// Act
|
|
var sut = new UnlockStoreDialogViewModel(storePath);
|
|
|
|
// Assert
|
|
sut.StorePath.ShouldBe(storePath);
|
|
}
|
|
|
|
[Fact]
|
|
public void Constructor_ThrowsOnNullStorePath()
|
|
{
|
|
// Act & Assert
|
|
Should.Throw<ArgumentNullException>(() => new UnlockStoreDialogViewModel(null!));
|
|
}
|
|
|
|
[Fact]
|
|
public void StorePath_IsReadOnly()
|
|
{
|
|
// Arrange
|
|
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure");
|
|
|
|
// Assert - StorePath property has no setter, verified by checking it returns what was passed
|
|
sut.StorePath.ShouldBe("/path/to/store.secure");
|
|
}
|
|
|
|
[Fact]
|
|
public void KeyFilePath_WhenEmpty_IsValidReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure")
|
|
{
|
|
KeyFilePath = ""
|
|
};
|
|
|
|
// Act & Assert
|
|
sut.IsValid.ShouldBeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void KeyFilePath_WhenEmpty_ValidationErrorReturnsKeyFilePathRequired()
|
|
{
|
|
// Arrange
|
|
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure")
|
|
{
|
|
KeyFilePath = ""
|
|
};
|
|
|
|
// Act & Assert
|
|
sut.ValidationError.ShouldBe(SecureStoreStrings.KeyFilePathRequired);
|
|
}
|
|
|
|
[Fact]
|
|
public void KeyFilePath_WhenWhitespace_IsValidReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure")
|
|
{
|
|
KeyFilePath = " "
|
|
};
|
|
|
|
// Act & Assert
|
|
sut.IsValid.ShouldBeFalse();
|
|
sut.ValidationError.ShouldBe(SecureStoreStrings.KeyFilePathRequired);
|
|
}
|
|
|
|
[Fact]
|
|
public void KeyFilePath_WhenFileDoesNotExist_IsValidReturnsFalse()
|
|
{
|
|
// Arrange
|
|
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure")
|
|
{
|
|
KeyFilePath = "/nonexistent/path/to/key.key"
|
|
};
|
|
|
|
// Act & Assert
|
|
sut.IsValid.ShouldBeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void KeyFilePath_WhenFileDoesNotExist_ValidationErrorReturnsKeyFileNotFound()
|
|
{
|
|
// Arrange
|
|
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure")
|
|
{
|
|
KeyFilePath = "/nonexistent/path/to/key.key"
|
|
};
|
|
|
|
// Act & Assert
|
|
sut.ValidationError.ShouldBe(SecureStoreStrings.KeyFileNotFound);
|
|
}
|
|
|
|
[Fact]
|
|
public void KeyFilePath_WhenChanged_RaisesPropertyChanged()
|
|
{
|
|
// Arrange
|
|
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure");
|
|
var propertyChangedRaised = false;
|
|
sut.PropertyChanged += (s, e) =>
|
|
{
|
|
if (e.PropertyName == nameof(UnlockStoreDialogViewModel.KeyFilePath))
|
|
propertyChangedRaised = true;
|
|
};
|
|
|
|
// Act
|
|
sut.KeyFilePath = "/new/key/path";
|
|
|
|
// Assert
|
|
propertyChangedRaised.ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void KeyFilePath_WhenChanged_RaisesIsValidPropertyChanged()
|
|
{
|
|
// Arrange
|
|
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure");
|
|
var isValidPropertyChangedRaised = false;
|
|
sut.PropertyChanged += (s, e) =>
|
|
{
|
|
if (e.PropertyName == nameof(UnlockStoreDialogViewModel.IsValid))
|
|
isValidPropertyChangedRaised = true;
|
|
};
|
|
|
|
// Act
|
|
sut.KeyFilePath = "/new/key/path";
|
|
|
|
// Assert
|
|
isValidPropertyChangedRaised.ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void KeyFilePath_WhenChanged_RaisesValidationErrorPropertyChanged()
|
|
{
|
|
// Arrange
|
|
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure");
|
|
var validationErrorPropertyChangedRaised = false;
|
|
sut.PropertyChanged += (s, e) =>
|
|
{
|
|
if (e.PropertyName == nameof(UnlockStoreDialogViewModel.ValidationError))
|
|
validationErrorPropertyChangedRaised = true;
|
|
};
|
|
|
|
// Act
|
|
sut.KeyFilePath = "/new/key/path";
|
|
|
|
// Assert
|
|
validationErrorPropertyChangedRaised.ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void BrowseKeyFilePathCommand_IsInitialized()
|
|
{
|
|
// Arrange & Act
|
|
var sut = new UnlockStoreDialogViewModel("/path/to/store.secure");
|
|
|
|
// Assert
|
|
sut.BrowseKeyFilePathCommand.ShouldNotBeNull();
|
|
}
|
|
}
|