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 void SetUp() { IDataStore knownPublicKeysStore = new FakeInMemoryDataStoreItem("knownpublickeys.txt"); TypeMap.Register.Singleton <IAsymmetricFactory>(() => new BouncyCastleAsymmetricFactory()); TypeMap.Register.Singleton <IEmailParser>(() => new EmailParser()); TypeMap.Register.Singleton <AxCryptOnlineState>(() => new AxCryptOnlineState()); TypeMap.Register.Singleton <FileLocker>(() => new FileLocker()); TypeMap.Register.Singleton <IPortableFactory>(() => new PortableFactory()); TypeMap.Register.Singleton <INow>(() => new FakeNow()); TypeMap.Register.Singleton <UserPublicKeyUpdateStatus>(() => new UserPublicKeyUpdateStatus()); TypeMap.Register.Singleton <KnownIdentities>(() => new KnownIdentities(Resolve.FileSystemState, Resolve.SessionNotify)); TypeMap.Register.Singleton <FileSystemState>(() => FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("FileSystemState.txt"))); TypeMap.Register.Singleton <WorkFolder>(() => new WorkFolder(Path.GetPathRoot(Environment.CurrentDirectory) + @"WorkFolder\")); TypeMap.Register.Singleton <SessionNotify>(() => new SessionNotify()); TypeMap.Register.Singleton <UserSettingsVersion>(() => new UserSettingsVersion()); TypeMap.Register.Singleton <ISettingsStore>(() => new SettingsStore(null)); TypeMap.Register.Singleton <UserSettings>(() => (new FakeUserSettings(new IterationCalculator())).Initialize()); TypeMap.Register.New <IStringSerializer>(() => new StringSerializer(New <IAsymmetricFactory>().GetSerializers())); TypeMap.Register.New <KnownPublicKeys>(() => KnownPublicKeys.Load(knownPublicKeysStore, Resolve.Serializer)); TypeMap.Register.New <ILogging>(() => new Logging()); TypeMap.Register.New <string, IDataStore>((path) => new FakeDataStore(path)); TypeMap.Register.New <Sha256>(() => PortableFactory.SHA256Managed()); TypeMap.Register.New <string, IDataContainer>((path) => new FakeDataContainer(path)); New <AxCryptOnlineState>().IsOnline = true; }
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 TestForEach() { using (FileSystemState state = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt"))) { ActiveFile activeFile; activeFile = new ActiveFile(New <IDataStore>(_encrypted1AxxPath), New <IDataStore>(_decrypted1TxtPath), new LogOnIdentity("passphrase1"), ActiveFileStatus.AssumedOpenAndDecrypted | ActiveFileStatus.Error | ActiveFileStatus.IgnoreChange | ActiveFileStatus.NotShareable, new V1Aes128CryptoFactory().CryptoId); state.Add(activeFile); activeFile = new ActiveFile(New <IDataStore>(_encrypted2AxxPath), New <IDataStore>(_decrypted2TxtPath), new LogOnIdentity("passphrase2"), ActiveFileStatus.AssumedOpenAndDecrypted | ActiveFileStatus.Error | ActiveFileStatus.IgnoreChange | ActiveFileStatus.NotShareable, new V1Aes128CryptoFactory().CryptoId); state.Add(activeFile); activeFile = new ActiveFile(New <IDataStore>(_encrypted3AxxPath), New <IDataStore>(_decrypted3TxtPath), new LogOnIdentity("passphrase"), ActiveFileStatus.AssumedOpenAndDecrypted | ActiveFileStatus.Error | ActiveFileStatus.IgnoreChange | ActiveFileStatus.NotShareable, new V1Aes128CryptoFactory().CryptoId); state.Add(activeFile); Assert.That(state.ActiveFiles.Count(), Is.EqualTo(3), "There should be three."); int i = 0; await state.ForEach((ActiveFile activeFileArgument) => { ++i; return(Task.FromResult(activeFileArgument)); }); Assert.That(i, Is.EqualTo(3), "The iteration should have visited three active files."); i = 0; await state.ForEach((ActiveFile activeFileArgument) => { ++i; return(Task.FromResult(new ActiveFile(activeFileArgument, activeFile.Status | ActiveFileStatus.Error))); }); Assert.That(i, Is.EqualTo(3), "The iteration should have visited three active files."); } }
public void Setup() { SetupAssembly.AssemblySetup(); SetupAssembly.AssemblySetupCrypto(_cryptoImplementation); TypeMap.Register.Singleton <FileSystemState>(() => FileSystemState.Create(New <IDataStore>(_fileSystemStateFilePath))); }
public void TestLoadNew() { using (FileSystemState state = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt"))) { Assert.That(state, Is.Not.Null, "An instance should always be instantiated."); Assert.That(state.ActiveFiles.Count(), Is.EqualTo(0), "A new state should not have any active files."); } }
public static void RegisterTypeFactories(string workFolderPath, IEnumerable <Assembly> assemblies) { RegisterTypeFactories(assemblies); TypeMap.Register.Singleton <WorkFolderWatcher>(() => new WorkFolderWatcher()); TypeMap.Register.Singleton <WorkFolder>(() => new WorkFolder(workFolderPath), () => New <WorkFolderWatcher>()); TypeMap.Register.New <KnownPublicKeys>(() => KnownPublicKeys.Load(Resolve.WorkFolder.FileInfo.FileItemInfo("UserPublicKeys.txt"), New <IStringSerializer>())); TypeMap.Register.Singleton <FileSystemState>(() => FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("FileSystemState.txt"))); }
private async Task ClearPassphraseMemoryAction() { IDataStore fileSystemStateInfo = Resolve.FileSystemState.PathInfo; using (FileLock fileSystemStateFileLock = New <FileLocker>().Acquire(fileSystemStateInfo)) { New <AxCryptFile>().Wipe(fileSystemStateFileLock, new ProgressContext()); } TypeMap.Register.Singleton <FileSystemState>(() => FileSystemState.Create(fileSystemStateInfo)); TypeMap.Register.Singleton <KnownIdentities>(() => new KnownIdentities(_fileSystemState, Resolve.SessionNotify)); await Resolve.SessionNotify.NotifyAsync(new SessionNotification(SessionNotificationType.SessionStart)); }
public async Task TestCheckActiveFilesKeyIsNotSetWithoutKnownKey() { DateTime utcNow = New <INow>().Utc; FakeDataStore.AddFile(_anAxxPath, utcNow, utcNow, utcNow, FakeDataStore.ExpandableMemoryStream(Resources.helloworld_key_a_txt)); LogOnIdentity passphrase = new LogOnIdentity("a"); New <AxCryptFile>().Decrypt(New <IDataStore>(_anAxxPath), New <IDataStore>(_decryptedFile1), passphrase, AxCryptOptions.None, new ProgressContext()); ActiveFile activeFile = new ActiveFile(New <IDataStore>(_anAxxPath), New <IDataStore>(_decryptedFile1), passphrase, ActiveFileStatus.AssumedOpenAndDecrypted, new V1Aes128CryptoFactory().CryptoId); Resolve.FileSystemState.Add(activeFile); await Resolve.FileSystemState.Save(); TypeMap.Register.Singleton <FileSystemState>(() => FileSystemState.Create(New <IDataStore>(_fileSystemStateFilePath))); IDataStore decryptedFileInfo = New <IDataStore>(_decryptedFile1); decryptedFileInfo.SetFileTimes(utcNow.AddSeconds(30), utcNow.AddSeconds(30), utcNow.AddSeconds(30)); ((FakeNow)New <INow>()).TimeFunction = (() => { return(utcNow.AddMinutes(1)); }); bool changedWasRaised = false; Resolve.SessionNotify.AddCommand((SessionNotification notification) => { changedWasRaised = notification.NotificationType == SessionNotificationType.ActiveFileChange; return(Constant.CompletedTask); }); activeFile = Resolve.FileSystemState.FindActiveFileFromEncryptedPath(_anAxxPath); Assert.That(activeFile.Identity == LogOnIdentity.Empty, "The key should be null after loading of new FileSystemState"); await New <ActiveFileAction>().CheckActiveFiles(new ProgressContext()); Assert.That(changedWasRaised, Is.False, "The ActiveFile should be not be modified because the file was modified as well and thus cannot be deleted."); await Resolve.KnownIdentities.AddAsync(new LogOnIdentity("x")); await Resolve.KnownIdentities.AddAsync(new LogOnIdentity("y")); await New <ActiveFileAction>().CheckActiveFiles(new ProgressContext()); Assert.That(changedWasRaised, Is.False, "The ActiveFile should be not be modified because the file was modified as well and thus cannot be deleted."); activeFile = Resolve.FileSystemState.FindActiveFileFromEncryptedPath(_anAxxPath); Assert.That(activeFile.Identity == LogOnIdentity.Empty, "The key should still be null after the checking of active files."); Assert.That(activeFile.Status.HasMask(ActiveFileStatus.AssumedOpenAndDecrypted), Is.True, "The file should still be there."); Assert.That(activeFile.ThumbprintMatch(passphrase.Passphrase), Is.True, "The active file should still be known to be decryptable with the original passphrase."); }
public void TestFindEncryptedPath() { using (FileSystemState state = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt"))) { ActiveFile activeFile = new ActiveFile(New <IDataStore>(_encryptedAxxPath), New <IDataStore>(_decryptedTxtPath), new LogOnIdentity("passphrase"), ActiveFileStatus.AssumedOpenAndDecrypted | ActiveFileStatus.Error | ActiveFileStatus.IgnoreChange | ActiveFileStatus.NotShareable, new V1Aes128CryptoFactory().CryptoId); state.Add(activeFile); ActiveFile byEncryptedPath = state.FindActiveFileFromEncryptedPath(_encryptedAxxPath); Assert.That(byEncryptedPath.EncryptedFileInfo.FullName, Is.EqualTo(_encryptedAxxPath), "The search should return the same path."); ActiveFile notFoundEncrypted = state.FindActiveFileFromEncryptedPath(Path.Combine(_rootPath, "notfoundfile.txt")); Assert.That(notFoundEncrypted, Is.Null, "A search that does not succeed should return 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 TestStatusMaskAtLoad() { using (FileSystemState state = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt"))) { FakeDataStore.AddFile(_encryptedAxxPath, FakeDataStore.TestDate1Utc, FakeDataStore.TestDate2Utc, FakeDataStore.TestDate3Utc, new MemoryStream(Resources.helloworld_key_a_txt)); ActiveFile activeFile = new ActiveFile(New <IDataStore>(_encryptedAxxPath), New <IDataStore>(_decryptedTxtPath), new LogOnIdentity("passphrase"), ActiveFileStatus.AssumedOpenAndDecrypted | ActiveFileStatus.Error | ActiveFileStatus.IgnoreChange | ActiveFileStatus.NotShareable, new V1Aes128CryptoFactory().CryptoId); state.Add(activeFile); await state.Save(); FileSystemState reloadedState = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt")); Assert.That(reloadedState, Is.Not.Null, "An instance should always be instantiated."); Assert.That(reloadedState.ActiveFiles.Count(), Is.EqualTo(1), "The reloaded state should have one active file."); Assert.That(reloadedState.ActiveFiles.First().Status, Is.EqualTo(ActiveFileStatus.AssumedOpenAndDecrypted | ActiveFileStatus.NoProcessKnown), "When reloading saved state, some statuses should be masked away and NoProcessKnown added."); } }
public void TestArgumentNull() { using (FileSystemState state = new FileSystemState()) { ActiveFile nullActiveFile = null; string nullPath = null; Func <ActiveFile, Task <ActiveFile> > nullAction = null; IDataStore nullFileInfo = null; Assert.Throws <ArgumentNullException>(() => { state.RemoveActiveFile(nullActiveFile); }); Assert.Throws <ArgumentNullException>(() => { state.Add(nullActiveFile); }); Assert.Throws <ArgumentNullException>(() => { state.FindActiveFileFromEncryptedPath(nullPath); }); Assert.ThrowsAsync <ArgumentNullException>(async() => { await state.ForEach(nullAction); }); Assert.Throws <ArgumentNullException>(() => { FileSystemState.Create(nullFileInfo); }); } }
public async Task TestUpdateActiveFileWithKeyIfKeyMatchesThumbprintWithWrongThumbprint() { IDataStore encryptedFileInfo = New <IDataStore>(_anAxxPath); IDataStore decryptedFileInfo = New <IDataStore>(_decryptedFile1); LogOnIdentity key = new LogOnIdentity("a"); ActiveFile activeFile = new ActiveFile(encryptedFileInfo, decryptedFileInfo, key, ActiveFileStatus.AssumedOpenAndDecrypted | ActiveFileStatus.NotShareable, new V1Aes128CryptoFactory().CryptoId); Resolve.FileSystemState.Add(activeFile); await Resolve.FileSystemState.Save(); TypeMap.Register.Singleton <FileSystemState>(() => FileSystemState.Create(New <IDataStore>(_fileSystemStateFilePath))); LogOnIdentity wrongKey = new LogOnIdentity("b"); bool updateWasMade = await New <ActiveFileAction>().UpdateActiveFileWithKeyIfKeyMatchesThumbprint(wrongKey); Assert.That(updateWasMade, Is.False, "Since there are only ActiveFiles with wrong keys in the list, no update should be made."); }
public async Task TestUpdateActiveFileWithKeyIfKeyMatchesThumbprintWithMatchingThumbprint() { IDataStore encryptedFileInfo = New <IDataStore>(_anAxxPath); IDataStore decryptedFileInfo = New <IDataStore>(_decryptedFile1); LogOnIdentity key = new LogOnIdentity("passphrase"); FakeDataStore.AddFile(_anAxxPath, FakeDataStore.TestDate1Utc, FakeDataStore.TestDate2Utc, FakeDataStore.TestDate3Utc, new MemoryStream(Resources.helloworld_key_a_txt)); ActiveFile activeFile = new ActiveFile(encryptedFileInfo, decryptedFileInfo, key, ActiveFileStatus.AssumedOpenAndDecrypted | ActiveFileStatus.NotShareable, new V1Aes128CryptoFactory().CryptoId); Resolve.FileSystemState.Add(activeFile); await Resolve.FileSystemState.Save(); TypeMap.Register.Singleton <FileSystemState>(() => FileSystemState.Create(New <IDataStore>(_fileSystemStateFilePath))); bool updateWasMade = await New <ActiveFileAction>().UpdateActiveFileWithKeyIfKeyMatchesThumbprint(key); Assert.That(updateWasMade, Is.True, "Since there is an ActiveFile with the right thumbprint in the list, an update should be made."); }
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 TestLoadExistingWithNonExistingFile() { ActiveFile activeFile; using (FileSystemState state = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt"))) { Assert.That(state, Is.Not.Null, "An instance should always be instantiated."); Assert.That(state.ActiveFiles.Count(), Is.EqualTo(0), "A new state should not have any active files."); activeFile = new ActiveFile(New <IDataStore>(_encryptedAxxPath), New <IDataStore>(_decryptedTxtPath), new LogOnIdentity("passphrase"), ActiveFileStatus.AssumedOpenAndDecrypted, new V1Aes128CryptoFactory().CryptoId); state.Add(activeFile); await state.Save(); } using (FileSystemState reloadedState = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt"))) { Assert.That(reloadedState, Is.Not.Null, "An instance should always be instantiated."); Assert.That(reloadedState.ActiveFiles.Count(), Is.EqualTo(0), "The reloaded state should not have an active file, since it is non-existing."); } }
public void TestInvalidJson() { string badJson = @"{abc:1{}"; IDataStore stateInfo = Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt"); using (Stream stream = stateInfo.OpenWrite()) { byte[] bytes = Encoding.UTF8.GetBytes(badJson); stream.Write(bytes, 0, bytes.Length); } using (FileSystemState state = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt"))) { Assert.That(state.ActiveFileCount, Is.EqualTo(0), "After loading damaged state, the count should be zero."); ActiveFile decryptedFile1 = new ActiveFile(New <IDataStore>(_encryptedAxxPath), New <IDataStore>(_decryptedTxtPath), new LogOnIdentity("passphrase"), ActiveFileStatus.AssumedOpenAndDecrypted, new V1Aes128CryptoFactory().CryptoId); state.Add(decryptedFile1); Assert.That(state.ActiveFileCount, Is.EqualTo(1), "After adding a file, the count should be one."); } }
public void TestDecryptedActiveFiles() { using (FileSystemState state = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt"))) { ActiveFile decryptedFile1 = new ActiveFile(New <IDataStore>(_encryptedAxxPath), New <IDataStore>(_decryptedTxtPath), new LogOnIdentity("passphrase1"), ActiveFileStatus.AssumedOpenAndDecrypted, new V1Aes128CryptoFactory().CryptoId); state.Add(decryptedFile1); ActiveFile decryptedFile2 = new ActiveFile(New <IDataStore>(_encrypted2AxxPath), New <IDataStore>(_decrypted2TxtPath), new LogOnIdentity("passphrase2"), ActiveFileStatus.DecryptedIsPendingDelete, new V1Aes128CryptoFactory().CryptoId); state.Add(decryptedFile2); ActiveFile notDecryptedFile = new ActiveFile(New <IDataStore>(_encrypted3AxxPath), New <IDataStore>(_decrypted3TxtPath), new LogOnIdentity("passphrase3"), ActiveFileStatus.NotDecrypted, new V1Aes128CryptoFactory().CryptoId); state.Add(notDecryptedFile); ActiveFile errorFile = new ActiveFile(New <IDataStore>(_encrypted4AxxPath), New <IDataStore>(_decrypted4TxtPath), new LogOnIdentity("passphrase"), ActiveFileStatus.Error, new V1Aes128CryptoFactory().CryptoId); state.Add(errorFile); IList <ActiveFile> decryptedFiles = state.DecryptedActiveFiles; Assert.That(decryptedFiles.Count, Is.EqualTo(2), "There should be two decrypted files."); Assert.That(decryptedFiles.Contains(decryptedFile1), "A file marked as AssumedOpenAndDecrypted should be found."); Assert.That(decryptedFiles.Contains(decryptedFile2), "A file marked as DecryptedIsPendingDelete should be found."); Assert.That(decryptedFiles.Contains(notDecryptedFile), Is.Not.True, "A file marked as NotDecrypted should not be found."); } }
public async Task TestLoadExistingWithExistingFile() { ActiveFile activeFile; using (FileSystemState state = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt"))) { Assert.That(state, Is.Not.Null, "An instance should always be instantiated."); Assert.That(state.ActiveFiles.Count(), Is.EqualTo(0), "A new state should not have any active files."); activeFile = new ActiveFile(New <IDataStore>(_encryptedAxxPath), New <IDataStore>(_decryptedTxtPath), new LogOnIdentity("passphrase"), ActiveFileStatus.AssumedOpenAndDecrypted, new V1Aes128CryptoFactory().CryptoId); state.Add(activeFile); await state.Save(); } FakeDataStore.AddFile(_encryptedAxxPath, FakeDataStore.TestDate1Utc, FakeDataStore.TestDate2Utc, FakeDataStore.TestDate3Utc, Stream.Null); using (FileSystemState reloadedState = FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("mystate.txt"))) { Assert.That(reloadedState, Is.Not.Null, "An instance should always be instantiated."); Assert.That(reloadedState.ActiveFiles.Count(), Is.EqualTo(1), "The reloaded state should have one active file."); Assert.That(reloadedState.ActiveFiles.First().ThumbprintMatch(activeFile.Identity.Passphrase), Is.True, "The reloaded thumbprint should match the key."); } }
public static void AssemblySetup() { IDataStore knownPublicKeysStore = new FakeInMemoryDataStoreItem("knownpublickeys.txt"); TypeMap.Register.Singleton <INow>(() => new FakeNow()); TypeMap.Register.Singleton <IReport>(() => new FakeReport()); TypeMap.Register.Singleton <IPortableFactory>(() => new PortableFactory()); TypeMap.Register.Singleton <WorkFolder>(() => new WorkFolder(Path.GetPathRoot(Environment.CurrentDirectory) + @"WorkFolder\")); TypeMap.Register.Singleton <IRuntimeEnvironment>(() => new FakeRuntimeEnvironment()); TypeMap.Register.Singleton <ILogging>(() => new FakeLogging()); TypeMap.Register.Singleton <ISettingsStore>(() => new SettingsStore(null)); TypeMap.Register.Singleton <UserSettingsVersion>(() => new UserSettingsVersion()); TypeMap.Register.Singleton <UserSettings>(() => (new FakeUserSettings(New <IterationCalculator>())).Initialize()); TypeMap.Register.Singleton <KnownIdentities>(() => new KnownIdentities(Resolve.FileSystemState, Resolve.SessionNotify)); TypeMap.Register.Singleton <ProcessState>(() => new ProcessState()); TypeMap.Register.Singleton <IUIThread>(() => new FakeUIThread()); TypeMap.Register.Singleton <IProgressBackground>(() => new FakeProgressBackground()); TypeMap.Register.Singleton <SessionNotify>(() => new SessionNotify()); TypeMap.Register.Singleton <FileSystemState>(() => FileSystemState.Create(Resolve.WorkFolder.FileInfo.FileItemInfo("FileSystemState.txt"))); TypeMap.Register.Singleton <IStatusChecker>(() => new FakeStatusChecker()); TypeMap.Register.Singleton <IRandomGenerator>(() => new FakeRandomGenerator()); TypeMap.Register.Singleton <CryptoFactory>(() => CreateCryptoFactory()); TypeMap.Register.Singleton <ActiveFileWatcher>(() => new ActiveFileWatcher()); TypeMap.Register.Singleton <IAsymmetricFactory>(() => new BouncyCastleAsymmetricFactory()); TypeMap.Register.Singleton <IEmailParser>(() => new EmailParser()); TypeMap.Register.Singleton <ICache>(() => new FakeCache()); TypeMap.Register.Singleton <AxCryptOnlineState>(() => new AxCryptOnlineState()); TypeMap.Register.Singleton <CryptoPolicy>(() => new CryptoPolicy(new Assembly[0])); TypeMap.Register.Singleton <IVersion>(() => new FakeVersion()); TypeMap.Register.Singleton <IInternetState>(() => new FakeInternetState()); TypeMap.Register.Singleton <ICryptoPolicy>(() => New <LicensePolicy>().Capabilities.CryptoPolicy); TypeMap.Register.Singleton <LicensePolicy>(() => new PremiumForcedLicensePolicy()); TypeMap.Register.Singleton <InactivitySignOut>(() => new InactivitySignOut(TimeSpan.Zero)); TypeMap.Register.Singleton <FileLocker>(() => new FileLocker()); TypeMap.Register.Singleton <FileFilter>(() => new FileFilter()); TypeMap.Register.Singleton <IVerifySignInPassword>(() => new FakeVerifySignInPassword()); TypeMap.Register.Singleton <IPopup>(() => new FakePopup()); TypeMap.Register.Singleton <IKnownFoldersDiscovery>(() => new FakeKnownFoldersDiscovery()); TypeMap.Register.Singleton <IGlobalNotification>(() => new FakeGlobalNotification()); TypeMap.Register.Singleton <CanOpenEncryptedFile>(() => new CanOpenEncryptedFile()); TypeMap.Register.New <AxCryptFactory>(() => new AxCryptFactory()); TypeMap.Register.New <AxCryptFile>(() => new AxCryptFile()); TypeMap.Register.New <ActiveFileAction>(() => new ActiveFileAction()); TypeMap.Register.New <FileOperation>(() => new FileOperation(Resolve.FileSystemState, Resolve.SessionNotify)); TypeMap.Register.New <IdentityViewModel>(() => new IdentityViewModel(Resolve.FileSystemState, Resolve.KnownIdentities, Resolve.UserSettings, Resolve.SessionNotify)); TypeMap.Register.New <FileOperationViewModel>(() => new FileOperationViewModel(Resolve.FileSystemState, Resolve.SessionNotify, Resolve.KnownIdentities, Resolve.ParallelFileOperation, New <IStatusChecker>(), New <IdentityViewModel>())); TypeMap.Register.New <KnownPublicKeys>(() => KnownPublicKeys.Load(knownPublicKeysStore, New <IStringSerializer>())); TypeMap.Register.New <MainViewModel>(() => new MainViewModel(Resolve.FileSystemState, Resolve.UserSettings)); TypeMap.Register.New <string, IDataStore>((path) => new FakeDataStore(path)); TypeMap.Register.New <string, IDataContainer>((path) => new FakeDataContainer(path)); TypeMap.Register.New <string, IDataItem>((path) => CreateDataItem(path)); TypeMap.Register.New <string, IFileWatcher>((path) => new FakeFileWatcher(path)); TypeMap.Register.New <IterationCalculator>(() => new FakeIterationCalculator()); TypeMap.Register.New <IProtectedData>(() => new FakeDataProtection()); TypeMap.Register.New <IStringSerializer>(() => new StringSerializer(New <IAsymmetricFactory>().GetSerializers())); TypeMap.Register.New <LogOnIdentity, IAccountService>((LogOnIdentity identity) => new DeviceAccountService(new LocalAccountService(identity, Resolve.WorkFolder.FileInfo), new NullAccountService(identity))); TypeMap.Register.New <ISystemCryptoPolicy>(() => new ProCryptoPolicy()); TypeMap.Register.New <GlobalApiClient>(() => new GlobalApiClient(Resolve.UserSettings.RestApiBaseUrl, Resolve.UserSettings.ApiTimeout)); TypeMap.Register.New <AxCryptApiClient>(() => new AxCryptApiClient(Resolve.KnownIdentities.DefaultEncryptionIdentity.ToRestIdentity(), Resolve.UserSettings.RestApiBaseUrl, Resolve.UserSettings.ApiTimeout)); TypeMap.Register.New <AxCryptUpdateCheck>(() => new AxCryptUpdateCheck(New <IVersion>().Current)); TypeMap.Register.New <ISingleThread>(() => new SingleThread()); Resolve.UserSettings.SetKeyWrapIterations(new V1Aes128CryptoFactory().CryptoId, 1234); Resolve.UserSettings.ThumbprintSalt = Salt.Zero; Resolve.Log.SetLevel(LogLevel.Debug); }