public async Task TestSimpleDecryptAndLaunch() { FakeLauncher launcher = new FakeLauncher(); bool called = false; TypeMap.Register.New <ILauncher>(() => { called = true; return(launcher); }); FileOperationsController controller = new FileOperationsController(); controller.QueryDecryptionPassphrase = (FileOperationEventArgs e) => { e.LogOnIdentity = new LogOnIdentity("a"); return(Task.FromResult <object>(null)); }; FileOperationContext status = await controller.DecryptAndLaunchAsync(New <IDataStore>(_helloWorldAxxPath)); Assert.That(status.ErrorStatus, Is.EqualTo(ErrorStatus.Success), "The status should indicate success."); Assert.That(called, Is.True, "There should be a call to launch."); Assert.That(Path.GetFileName(launcher.Path), Is.EqualTo("HelloWorld-Key-a.txt"), "The file should be decrypted and the name should be the original from the encrypted headers."); IDataStore destinationInfo = New <IDataStore>(launcher.Path); Assert.That(destinationInfo.IsAvailable, "After decryption the destination file should be created."); string fileContent; using (Stream stream = destinationInfo.OpenRead()) { fileContent = new StreamReader(stream).ReadToEnd(); } Assert.That(fileContent.Contains("Hello"), "A file named Hello World should contain that text when decrypted."); }
private Task <FileOperationContext> OpenEncryptedWorkAsync(IDataStore file, IProgressContext progress) { FileOperationsController operationsController = new FileOperationsController(progress); operationsController.QueryDecryptionPassphrase = HandleQueryOpenPassphraseEventAsync; operationsController.KnownKeyAdded = new AsyncDelegateAction <FileOperationEventArgs>(async(FileOperationEventArgs e) => { if (!_fileSystemState.KnownPassphrases.Any(i => i.Thumbprint == e.LogOnIdentity.Passphrase.Thumbprint)) { _fileSystemState.KnownPassphrases.Add(e.LogOnIdentity.Passphrase); } await _knownIdentities.AddAsync(e.LogOnIdentity); }); operationsController.SetConvertLegacyOptionCommandAsync = async() => { if (Resolve.UserSettings.EncryptionUpgradeMode != EncryptionUpgradeMode.NotDecided) { return; } if (!New <LicensePolicy>().Capabilities.Has(LicenseCapability.EditExistingFiles)) { return; } bool autoConvert = await New <IPopup>().ShowAsync(PopupButtons.OkCancel, Texts.OptionsConvertMenuItemText, Texts.LegacyOpenMessage) == PopupButtons.Ok; autoConvert = autoConvert && New <IVerifySignInPassword>().Verify(Texts.LegacyConversionVerificationPrompt); New <UserSettings>().EncryptionUpgradeMode = autoConvert ? EncryptionUpgradeMode.AutoUpgrade : EncryptionUpgradeMode.RetainWithoutUpgrade; }; return(operationsController.DecryptAndLaunchAsync(file)); }
public async Task TestCanceledDecryptAndLaunch() { FileOperationsController controller = new FileOperationsController(); controller.QueryDecryptionPassphrase = (FileOperationEventArgs e) => { e.Cancel = true; return(Task.FromResult <object>(null)); }; FileOperationContext status = await controller.DecryptAndLaunchAsync(New <IDataStore>(_helloWorldAxxPath)); Assert.That(status.ErrorStatus, Is.EqualTo(ErrorStatus.Canceled), "The status should indicate cancellation."); }