public async Task TestAddRemoveKnownWatchedFolder() { using (FileSystemState state = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt"))) { KnownFolder knownFolder = New <IKnownFoldersDiscovery>().Discover().First(); FakeDataStore.AddFolder(knownFolder.My.FullName); await state.AddWatchedFolderAsync(new WatchedFolder(knownFolder.My.FullName, IdentityPublicTag.Empty)); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1)); Assert.That(state.AllWatchedFolders.Count(), Is.EqualTo(1)); await state.RemoveAndDecryptWatchedFolder(knownFolder.My); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(0)); Assert.That(state.AllWatchedFolders.Count(), Is.EqualTo(1)); await state.AddWatchedFolderAsync(new WatchedFolder(knownFolder.My.FullName, IdentityPublicTag.Empty)); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1)); Assert.That(state.AllWatchedFolders.Count(), Is.EqualTo(1)); await state.RemoveAndDecryptWatchedFolder(knownFolder.My); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(0)); Assert.That(state.AllWatchedFolders.Count(), Is.EqualTo(1)); } }
public async Task TestHandleSessionEventLogOffWithWatchedFolders(CryptoImplementation cryptoImplementation) { SetupAssembly.AssemblySetupCrypto(cryptoImplementation); MockAxCryptFile mock = new MockAxCryptFile(); bool called = false; mock.EncryptFilesUniqueWithBackupAndWipeMockAsync = async(IEnumerable <IDataContainer> folderInfos, EncryptionParameters encryptionParameters, IProgressContext progress) => { await Task.Delay(0); called = true; }; Mock <IStatusChecker> mockStatusChecker = new Mock <IStatusChecker>(); await Resolve.KnownIdentities.SetDefaultEncryptionIdentity(new LogOnIdentity("passphrase")); SessionNotificationHandler handler = new SessionNotificationHandler(Resolve.FileSystemState, Resolve.KnownIdentities, New <ActiveFileAction>(), mock, mockStatusChecker.Object); FakeDataStore.AddFolder(@"C:\WatchedFolder"); await Resolve.FileSystemState.AddWatchedFolderAsync(new WatchedFolder(@"C:\WatchedFolder", Resolve.KnownIdentities.DefaultEncryptionIdentity.Tag)); called = false; await handler.HandleNotificationAsync(new SessionNotification(SessionNotificationType.EncryptPendingFiles)); await handler.HandleNotificationAsync(new SessionNotification(SessionNotificationType.SignOut, Resolve.KnownIdentities.DefaultEncryptionIdentity)); Assert.That(called, Is.True, nameof(AxCryptFile.EncryptFoldersUniqueWithBackupAndWipeAsync) + " should be called when a signing out."); }
public async Task TestHandleSessionEventLogOn(CryptoImplementation cryptoImplementation) { SetupAssembly.AssemblySetupCrypto(cryptoImplementation); MockAxCryptFile mock = new MockAxCryptFile(); bool called = false; int folderCount = -1; mock.EncryptFilesUniqueWithBackupAndWipeMockAsync = async(IEnumerable <IDataContainer> folderInfos, EncryptionParameters encryptionParameters, IProgressContext progress) => { folderCount = folderInfos.Count(); called = true; await Task.Delay(0); }; Mock <IStatusChecker> mockStatusChecker = new Mock <IStatusChecker>(); SessionNotificationHandler handler = new SessionNotificationHandler(Resolve.FileSystemState, Resolve.KnownIdentities, New <ActiveFileAction>(), mock, mockStatusChecker.Object); FakeDataStore.AddFolder(@"C:\WatchedFolder"); LogOnIdentity key = new LogOnIdentity("passphrase"); await Resolve.FileSystemState.AddWatchedFolderAsync(new WatchedFolder(@"C:\WatchedFolder", key.Tag)); await handler.HandleNotificationAsync(new SessionNotification(SessionNotificationType.SignIn, key)); Assert.That(called, Is.True); Assert.That(folderCount, Is.EqualTo(1), "There should be one folder passed for encryption as a result of the event."); }
public async Task TestFileWasCreatedWhereAKnownFolderWasExpected() { IDataContainer betterCloudInfo = New <IDataContainer>(@"C:\BetterCloud"); IDataContainer fasterCloudInfo = New <IDataContainer>(@"C:\FasterCloud"); KnownFolder folder1 = new KnownFolder(betterCloudInfo, @"My AxCrypt", KnownFolderKind.GoogleDrive, null); KnownFolder folder2 = new KnownFolder(fasterCloudInfo, @"My AxCrypt", KnownFolderKind.Dropbox, null); FakeDataStore.AddFile(@"C:\BetterCloud\My AxCrypt", Stream.Null); FakeDataStore.AddFolder(folder2.My.FullName); KnownIdentities knownIdentities = new KnownIdentities(Resolve.FileSystemState, Resolve.SessionNotify); KnownFoldersViewModel vm = new KnownFoldersViewModel(Resolve.FileSystemState, Resolve.SessionNotify, knownIdentities); Assert.That(vm.KnownFolders.Count(), Is.EqualTo(0)); vm.KnownFolders = new KnownFolder[] { folder1, folder2 }; Assert.That(vm.KnownFolders.Count(), Is.EqualTo(2)); Assert.That(vm.KnownFolders.First().Enabled, Is.False); Assert.That(vm.KnownFolders.Last().Enabled, Is.False); await knownIdentities.SetDefaultEncryptionIdentity(new LogOnIdentity("aaa")); Assert.That(Resolve.FileSystemState.WatchedFolders.Count(), Is.EqualTo(1)); Assert.That(vm.KnownFolders.Count(), Is.EqualTo(2)); Assert.That(vm.KnownFolders.First().Enabled, Is.False); Assert.That(vm.KnownFolders.Last().Enabled, Is.True); }
public async Task TestSettingKnownFoldersAndLoggingOnAndOff() { KnownIdentities knownIdentities = new KnownIdentities(Resolve.FileSystemState, Resolve.SessionNotify); KnownFoldersViewModel vm = new KnownFoldersViewModel(Resolve.FileSystemState, Resolve.SessionNotify, knownIdentities); Assert.That(vm.KnownFolders.Count(), Is.EqualTo(0)); IDataContainer betterCloudInfo = New <IDataContainer>(@"C:\BetterCloud"); IDataContainer fasterCloudInfo = New <IDataContainer>(@"C:\FasterCloud"); KnownFolder folder1 = new KnownFolder(betterCloudInfo, @"My AxCrypt", KnownFolderKind.WindowsMyDocuments, null); KnownFolder folder2 = new KnownFolder(fasterCloudInfo, @"My AxCrypt", KnownFolderKind.Dropbox, null); FakeDataStore.AddFolder(folder1.My.FullName); FakeDataStore.AddFolder(folder2.My.FullName); vm.KnownFolders = new KnownFolder[] { folder1, folder2 }; Assert.That(vm.KnownFolders.Count(), Is.EqualTo(2)); Assert.That(vm.KnownFolders.First().Enabled, Is.False, "We are not signed in so the folder should not be enabled"); Assert.That(vm.KnownFolders.Last().Enabled, Is.False, "We are not signed in so the folder should not be enabled"); await knownIdentities.SetDefaultEncryptionIdentity(new LogOnIdentity("aaa")); Assert.That(vm.KnownFolders.Count(), Is.EqualTo(2)); Assert.That(vm.KnownFolders.First().Enabled, Is.True, "We are signed in so the folder should be enabled"); Assert.That(vm.KnownFolders.Last().Enabled, Is.True, "We are signed in so the folder should be enabled"); await knownIdentities.SetDefaultEncryptionIdentity(LogOnIdentity.Empty); Assert.That(vm.KnownFolders.Count(), Is.EqualTo(2)); Assert.That(vm.KnownFolders.First().Enabled, Is.False, "We are no longer signed in so the folder should not be enabled"); Assert.That(vm.KnownFolders.Last().Enabled, Is.False, "We are no longer signed in so the folder should not be enabled"); }
public async Task TestAlreadyKnownFoldersAndLoggingOn() { IDataContainer betterCloudInfo = New <IDataContainer>(@"C:\BetterCloud"); IDataContainer fasterCloudInfo = New <IDataContainer>(@"C:\FasterCloud"); KnownFolder folder1 = new KnownFolder(betterCloudInfo, @"My AxCrypt", KnownFolderKind.OneDrive, null); KnownFolder folder2 = new KnownFolder(fasterCloudInfo, @"My AxCrypt", KnownFolderKind.WindowsMyDocuments, null); FakeDataStore.AddFolder(folder1.My.FullName); FakeDataStore.AddFolder(folder2.My.FullName); await Resolve.FileSystemState.AddWatchedFolderAsync(new WatchedFolder(folder1.My.FullName, new LogOnIdentity("PassPhrase").Tag)); await Resolve.FileSystemState.AddWatchedFolderAsync(new WatchedFolder(folder2.My.FullName, new LogOnIdentity(new Passphrase("aaa")).Tag)); KnownIdentities knownIdentities = new KnownIdentities(Resolve.FileSystemState, Resolve.SessionNotify); KnownFoldersViewModel vm = new KnownFoldersViewModel(Resolve.FileSystemState, Resolve.SessionNotify, knownIdentities); Assert.That(vm.KnownFolders.Count(), Is.EqualTo(0)); vm.KnownFolders = new KnownFolder[] { folder1, folder2 }; Assert.That(vm.KnownFolders.Count(), Is.EqualTo(2)); Assert.That(vm.KnownFolders.First().Enabled, Is.False); Assert.That(vm.KnownFolders.Last().Enabled, Is.False); await knownIdentities.SetDefaultEncryptionIdentity(new LogOnIdentity("aaa")); Assert.That(vm.KnownFolders.Count(), Is.EqualTo(2)); Assert.That(vm.KnownFolders.First().Enabled, Is.False, "This folder should not be enabled, because it's not watched by the signed in identity."); Assert.That(vm.KnownFolders.Last().Enabled, Is.True, "This folder should be enabled, since it is watched by the signed in identity."); }
public async Task TestHandleSessionEvents(CryptoImplementation cryptoImplementation) { SetupAssembly.AssemblySetupCrypto(cryptoImplementation); MockAxCryptFile mock = new MockAxCryptFile(); int callTimes = 0; mock.EncryptFilesUniqueWithBackupAndWipeMockAsync = async(IEnumerable <IDataContainer> folderInfos, EncryptionParameters encryptionParameters, IProgressContext progress) => { await Task.Delay(0); if (folderInfos.First().FullName == @"C:\My Documents\".NormalizeFilePath()) { ++callTimes; } }; Mock <IStatusChecker> mockStatusChecker = new Mock <IStatusChecker>(); SessionNotificationHandler handler = new SessionNotificationHandler(Resolve.FileSystemState, Resolve.KnownIdentities, New <ActiveFileAction>(), mock, mockStatusChecker.Object); FakeDataStore.AddFolder(@"C:\My Documents"); LogOnIdentity key = new LogOnIdentity("passphrase"); await Resolve.FileSystemState.AddWatchedFolderAsync(new WatchedFolder(@"C:\My Documents", key.Tag)); List <SessionNotification> sessionEvents = new List <SessionNotification>(); sessionEvents.Add(new SessionNotification(SessionNotificationType.WatchedFolderAdded, new LogOnIdentity("passphrase1"), @"C:\My Documents\")); sessionEvents.Add(new SessionNotification(SessionNotificationType.WatchedFolderAdded, new LogOnIdentity("passphrase"), @"C:\My Documents\")); foreach (SessionNotification sessionEvent in sessionEvents) { await handler.HandleNotificationAsync(sessionEvent); } Assert.That(callTimes, Is.EqualTo(2)); }
public async Task TestNotificationEncryptPendingFilesInLoggedOnFolders(CryptoImplementation cryptoImplementation) { SetupAssembly.AssemblySetupCrypto(cryptoImplementation); FakeDataStore.AddFolder(@"C:\My Documents\"); Mock <AxCryptFile> mock = new Mock <AxCryptFile>(); mock.Setup(acf => acf.EncryptFoldersUniqueWithBackupAndWipeAsync(It.IsAny <IEnumerable <IDataContainer> >(), It.IsAny <EncryptionParameters>(), It.IsAny <IProgressContext>())); Mock <IStatusChecker> mockStatusChecker = new Mock <IStatusChecker>(); SessionNotificationHandler handler = new SessionNotificationHandler(Resolve.FileSystemState, Resolve.KnownIdentities, New <ActiveFileAction>(), mock.Object, mockStatusChecker.Object); LogOnIdentity defaultKey = new LogOnIdentity("default"); await Resolve.KnownIdentities.SetDefaultEncryptionIdentity(defaultKey); await Resolve.FileSystemState.AddWatchedFolderAsync(new WatchedFolder(@"C:\My Documents\", defaultKey.Tag)); List <SessionNotification> sessionEvents = new List <SessionNotification>(); sessionEvents.Add(new SessionNotification(SessionNotificationType.EncryptPendingFiles)); foreach (SessionNotification sessionEvent in sessionEvents) { await handler.HandleNotificationAsync(sessionEvent); } mock.Verify(acf => acf.EncryptFoldersUniqueWithBackupAndWipeAsync(It.Is <IEnumerable <IDataContainer> >(infos => infos.Any((i) => i.FullName == @"C:\My Documents\".NormalizeFolderPath())), It.IsAny <EncryptionParameters>(), It.IsAny <IProgressContext>()), Times.Exactly(1)); }
public void TestDragAndDropFilesPropertyBindSetsDragAndDropFileTypes() { using (MainViewModel mvm = New <MainViewModel>()) { string encryptedFilePath = @"C:\Folder\File-txt.axx"; mvm.DragAndDropFiles = new string[] { encryptedFilePath, }; Assert.That(mvm.DragAndDropFilesTypes, Is.EqualTo(FileInfoTypes.None)); string decryptedFilePath = @"C:\Folder\File.txt"; mvm.DragAndDropFiles = new string[] { decryptedFilePath, }; Assert.That(mvm.DragAndDropFilesTypes, Is.EqualTo(FileInfoTypes.None)); FakeDataStore.AddFile(encryptedFilePath, null); mvm.DragAndDropFiles = new string[] { encryptedFilePath, decryptedFilePath, }; Assert.That(mvm.DragAndDropFilesTypes, Is.EqualTo(FileInfoTypes.EncryptedFile)); FakeDataStore.AddFile(decryptedFilePath, null); mvm.DragAndDropFiles = new string[] { encryptedFilePath, decryptedFilePath, }; Assert.That(mvm.DragAndDropFilesTypes, Is.EqualTo(FileInfoTypes.EncryptableFile | FileInfoTypes.EncryptedFile)); string folderPath = @"C:\Folder\"; mvm.DragAndDropFiles = new string[] { encryptedFilePath, decryptedFilePath, folderPath }; Assert.That(mvm.DragAndDropFilesTypes, Is.EqualTo(FileInfoTypes.EncryptableFile | FileInfoTypes.EncryptedFile)); FakeDataStore.AddFolder(folderPath); mvm.DragAndDropFiles = new string[] { encryptedFilePath, decryptedFilePath, folderPath }; Assert.That(mvm.DragAndDropFilesTypes, Is.EqualTo(FileInfoTypes.EncryptableFile | FileInfoTypes.EncryptedFile)); } }
public async Task TestWatchedFolders() { using (FileSystemState state = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt"))) { Assert.That(state.WatchedFolders, Is.Not.Null, "There should be a Watched Folders instance."); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(0), "There should be no Watched folders."); FakeDataStore.AddFolder(_rootPath); await state.AddWatchedFolderAsync(new WatchedFolder(_rootPath, IdentityPublicTag.Empty)); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1), "There should be one Watched Folder."); await state.AddWatchedFolderAsync(new WatchedFolder(_rootPath, IdentityPublicTag.Empty)); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1), "There should still only be one Watched Folder."); await state.Save(); } using (FileSystemState state = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt"))) { Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1), "There should be one Watched Folder."); Assert.That(state.WatchedFolders.First().Matches(_rootPath), "The Watched Folder should be equal to this."); await state.RemoveAndDecryptWatchedFolder(Resolve.WorkFolder.FileInfo.FolderItemInfo("mystate.txt")); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1), "There should still be one Watched folders."); await state.RemoveAndDecryptWatchedFolder(New <IDataContainer>(_rootPath)); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(0), "There should be no Watched folders now."); } }
public static void Setup() { SetupAssembly.AssemblySetup(); TypeMap.Register.Singleton <ISettingsStore>(() => new SettingsStore(Resolve.WorkFolder.FileInfo.FileItemInfo("UserSettings.txt"))); TypeMap.Register.Singleton <UserSettingsVersion>(() => new UserSettingsVersion()); TypeMap.Register.Singleton <UserSettings>(() => new UserSettings(New <ISettingsStore>(), New <IterationCalculator>())); FakeDataStore.AddFolder(@"C:\Folder\"); }
public async Task TestWatchedFoldersNotLoggedOn() { KnownIdentities knownIdentities = new KnownIdentities(Resolve.FileSystemState, Resolve.SessionNotify); FakeDataStore.AddFolder(@"C:\WatchedFolder\"); await Resolve.FileSystemState.AddWatchedFolderAsync(new WatchedFolder(@"C:\WatchedFolder\", IdentityPublicTag.Empty)); IEnumerable <WatchedFolder> watchedFolders = knownIdentities.LoggedOnWatchedFolders; Assert.That(watchedFolders.Count(), Is.EqualTo(0), "When not logged on, no watched folders should be known."); }
public async Task TestSimpleCreateAsymmetricKeysStore() { FakeDataStore.AddFolder(@"C:\Temp"); IDataContainer workFolder = New <IDataContainer>(@"C:\Temp"); AccountStorage store = new AccountStorage(new LocalAccountService(new LogOnIdentity(EmailAddress.Parse(@"*****@*****.**"), new Passphrase("secret")), workFolder)); UserKeyPair userKeyPair = new UserKeyPair(EmailAddress.Parse("*****@*****.**"), 512); await store.ImportAsync(userKeyPair); Assert.That((await store.AllKeyPairsAsync()).First().KeyPair.PrivateKey, Is.Not.Null); Assert.That((await store.AllKeyPairsAsync()).First().KeyPair.PublicKey, Is.Not.Null); }
public async Task TestWatchedFolderRemoved() { using (FileSystemState state = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt"))) { FakeDataStore.AddFolder(_rootPath); await state.AddWatchedFolderAsync(new WatchedFolder(_rootPath, IdentityPublicTag.Empty)); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(1)); FakeDataStore.RemoveFileOrFolder(_rootPath); Assert.That(state.WatchedFolders.Count(), Is.EqualTo(0)); } }
public async Task TestSetFilesArePending() { await Resolve.KnownIdentities.SetDefaultEncryptionIdentity(new LogOnIdentity("passphrase")); FakeDataStore.AddFolder(@"C:\MyFolders\Folder1"); using (MainViewModel mvm = New <MainViewModel>()) { Assert.That(mvm.FilesArePending, Is.False); await Resolve.FileSystemState.AddWatchedFolderAsync(new WatchedFolder(@"C:\MyFolders\Folder1", Resolve.KnownIdentities.DefaultEncryptionIdentity.Tag)); FakeDataStore.AddFile(@"C:\MyFolders\Folder1\Encryptable.txt", Stream.Null); Assert.That(mvm.FilesArePending, Is.True); } }
public async Task TestNotifyWatchedFolderAdded() { await Resolve.KnownIdentities.SetDefaultEncryptionIdentity(new LogOnIdentity("passphrase")); FakeDataStore.AddFolder(@"C:\MyFolders\Folder1"); using (MainViewModel mvm = New <MainViewModel>()) { Assert.That(mvm.WatchedFolders.Count(), Is.EqualTo(0)); await Resolve.FileSystemState.AddWatchedFolderAsync(new WatchedFolder(@"C:\MyFolders\Folder1", Resolve.KnownIdentities.DefaultEncryptionIdentity.Tag)); Assert.That(mvm.WatchedFolders.Count(), Is.EqualTo(1)); Assert.That(mvm.WatchedFolders.First(), Is.EqualTo(@"C:\MyFolders\Folder1".NormalizeFolderPath())); } }
public async Task TestHandleSessionEventWatchedFolderRemoved() { FakeDataStore.AddFolder(@"C:\My Documents\"); MockAxCryptFile mock = new MockAxCryptFile(); Mock <IStatusChecker> mockStatusChecker = new Mock <IStatusChecker>(); bool called = false; mock.DecryptFilesUniqueWithWipeOfOriginalMockAsync = (IDataContainer fileInfo, LogOnIdentity decryptionKey, IStatusChecker statusChecker, IProgressContext progress) => { called = fileInfo.FullName == @"C:\My Documents\".NormalizeFilePath(); }; TypeMap.Register.New <AxCryptFile>(() => mock); SessionNotificationHandler handler = new SessionNotificationHandler(Resolve.FileSystemState, Resolve.KnownIdentities, New <ActiveFileAction>(), mock, mockStatusChecker.Object); await handler.HandleNotificationAsync(new SessionNotification(SessionNotificationType.WatchedFolderRemoved, new LogOnIdentity("passphrase"), @"C:\My Documents\")); Assert.That(called, Is.True); }
public async Task TestWatchedFolderChanged() { using (FileSystemState state = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt"))) { FakeDataStore.AddFolder(_rootPath); await state.AddWatchedFolderAsync(new WatchedFolder(_rootPath, IdentityPublicTag.Empty)); Assert.That(state.ActiveFileCount, Is.EqualTo(0)); FakeDataStore.AddFile(_encryptedAxxPath, new MemoryStream(Resources.helloworld_key_a_txt)); Assert.That(state.ActiveFileCount, Is.EqualTo(0)); state.Add(new ActiveFile(New <IDataStore>(_encryptedAxxPath), New <IDataStore>(_decryptedTxtPath), new LogOnIdentity("passphrase"), ActiveFileStatus.NotDecrypted, new V1Aes128CryptoFactory().CryptoId)); Assert.That(state.ActiveFileCount, Is.EqualTo(1)); New <IDataStore>(_encryptedAxxPath).Delete(); Assert.That(state.ActiveFileCount, Is.EqualTo(0), "When deleted, the active file count should be zero."); } }
public async Task TestWatchedFoldersWhenLoggedOn() { Passphrase key1 = new Passphrase("a"); LogOnIdentity key2 = new LogOnIdentity("b"); KnownIdentities knownIdentities = new KnownIdentities(Resolve.FileSystemState, Resolve.SessionNotify); FakeDataStore.AddFolder(@"C:\WatchedFolder1\"); FakeDataStore.AddFolder(@"C:\WatchedFolder2\"); await Resolve.FileSystemState.AddWatchedFolderAsync(new WatchedFolder(@"C:\WatchedFolder1\", new LogOnIdentity(key1).Tag)); await Resolve.FileSystemState.AddWatchedFolderAsync(new WatchedFolder(@"C:\WatchedFolder2\", key2.Tag)); await knownIdentities.SetDefaultEncryptionIdentity(key2); IEnumerable <WatchedFolder> watchedFolders = knownIdentities.LoggedOnWatchedFolders; Assert.That(watchedFolders.Count(), Is.EqualTo(1), "Only one of the two watched folders should be shown."); Assert.That(watchedFolders.First().Tag.Matches(key2.Tag), "The returned watched folder should be number 2."); }
public async Task TestEncryptCreateLoadDecryptWithAsymmetricKeysStore() { FakeDataStore.AddFolder(@"C:\Temp"); IDataContainer workFolder = New <IDataContainer>(@"C:\Temp\"); AccountStorage store = new AccountStorage(new LocalAccountService(new LogOnIdentity(EmailAddress.Parse(@"*****@*****.**"), new Passphrase("secret")), workFolder)); await Resolve.KnownIdentities.SetDefaultEncryptionIdentity(new LogOnIdentity("secret")); UserKeyPair userKeyPair = new UserKeyPair(EmailAddress.Parse("*****@*****.**"), 512); await store.ImportAsync(userKeyPair); string text = "AxCrypt encryption rules!"; byte[] encryptedBytes = (await store.AllKeyPairsAsync()).First().KeyPair.PublicKey.Transform(Encoding.UTF8.GetBytes(text)); store = new AccountStorage(new LocalAccountService(new LogOnIdentity(EmailAddress.Parse(@"*****@*****.**"), new Passphrase("secret")), workFolder)); byte[] decryptedBytes = (await store.AllKeyPairsAsync()).First().KeyPair.PrivateKey.Transform(encryptedBytes); Assert.That(decryptedBytes != null); string decryptedText = Encoding.UTF8.GetString(decryptedBytes); Assert.That(text, Is.EqualTo(decryptedText)); }
public static void TestExtensions_FileInfoTypeExtension() { FakeDataStore.AddFile(@"c:\test.txt", null); IDataStore fileInfo = New <IDataStore>(@"c:\test.txt"); Assert.That(fileInfo.Type(), Is.EqualTo(FileInfoTypes.EncryptableFile)); FakeDataStore.AddFile(@"c:\test-txt.axx", null); fileInfo = New <IDataStore>(@"c:\test-txt.axx"); Assert.That(fileInfo.Type(), Is.EqualTo(FileInfoTypes.EncryptedFile)); FakeDataStore.AddFolder(@"c:\test\"); IDataContainer folderInfo = New <IDataContainer>(@"c:\test\"); Assert.That(folderInfo.Type(), Is.EqualTo(FileInfoTypes.Folder)); fileInfo = New <IDataStore>(@"c:\not-there.txt"); Assert.That(fileInfo.Type(), Is.EqualTo(FileInfoTypes.NonExisting)); New <FileFilter>().AddUnencryptable(new Regex(@"^C:\{0}Windows\{0}".InvariantFormat(Path.DirectorySeparatorChar))); FakeDataStore.AddFile(@"C:\Windows\System.drv", null); fileInfo = New <IDataStore>(@"C:\Windows\System.drv"); Assert.That(fileInfo.Type(), Is.EqualTo(FileInfoTypes.OtherFile)); }
public void TestDragAndDropFilesPropertyBindSetsDroppableAsWatchedFolder() { using (MainViewModel mvm = New <MainViewModel>()) { string folder1Path = @"C:\Folder1\FilesFolder\".NormalizeFilePath(); mvm.DragAndDropFiles = new string[] { folder1Path, }; Assert.That(mvm.DroppableAsWatchedFolder, Is.False, "A folder that does not exist is not a candidate for watched folders."); FakeDataStore.AddFolder(folder1Path); mvm.DragAndDropFiles = new string[] { folder1Path, }; Assert.That(mvm.DroppableAsWatchedFolder, Is.True, "This is a candidate for watched folders."); New <FileFilter>().AddUnencryptable(new Regex(@"^C:\{0}Folder1\{0}".InvariantFormat(Path.DirectorySeparatorChar))); mvm.DragAndDropFiles = new string[] { folder1Path, }; Assert.That(mvm.DroppableAsWatchedFolder, Is.False, "A folder that matches a path filter is not a candidate for watched folders."); string folder2Path = @"C:\Folder1\FilesFolder2\".NormalizeFilePath(); FakeDataStore.AddFolder(folder2Path); TypeMap.Register.Singleton <FileFilter>(() => new FileFilter()); mvm.DragAndDropFiles = new string[] { folder1Path, folder2Path, }; Assert.That(mvm.DroppableAsWatchedFolder, Is.False, "Although both folders are ok, only a single folder is a candidate for watched folders."); } }