Beispiel #1
0
        public static void TestCanceledDecryptAndLaunch()
        {
            FileOperationsController controller = new FileOperationsController(_fileSystemState);

            controller.QueryDecryptionPassphrase += (object sender, FileOperationEventArgs e) =>
            {
                e.Cancel = true;
            };
            FileOperationStatus status = controller.DecryptAndLaunch(_helloWorldAxxPath);

            Assert.That(status, Is.EqualTo(FileOperationStatus.Canceled), "The status should indicate cancellation.");
        }
Beispiel #2
0
        public static void TestSimpleDecryptAndLaunchOnThreadWorker()
        {
            FakeLauncher           launcher    = null;
            FakeRuntimeEnvironment environment = (FakeRuntimeEnvironment)OS.Current;

            environment.Launcher = ((string path) =>
            {
                launcher = new FakeLauncher(path);
                return(launcher);
            });

            FileOperationsController controller = new FileOperationsController(_fileSystemState);

            controller.QueryDecryptionPassphrase += (object sender, FileOperationEventArgs e) =>
            {
                e.Passphrase = "a";
            };
            FileOperationStatus status = FileOperationStatus.Unknown;

            controller.Completed += (object sender, FileOperationEventArgs e) =>
            {
                status = e.Status;
            };

            using (ThreadWorker worker = new ThreadWorker(new ProgressContext()))
            {
                controller.DecryptAndLaunch(_helloWorldAxxPath, worker);
                worker.Join();
            }

            Assert.That(status, Is.EqualTo(FileOperationStatus.Success), "The status should indicate success.");

            Assert.That(launcher, Is.Not.Null, "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.");

            IRuntimeFileInfo destinationInfo = OS.Current.FileInfo(launcher.Path);

            Assert.That(destinationInfo.Exists, "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.");
        }
Beispiel #3
0
        private void OpenEncrypted(string file, IThreadWorker worker, ProgressContext progress)
        {
            FileOperationsController operationsController = new FileOperationsController(persistentState.Current, progress);

            operationsController.QueryDecryptionPassphrase += HandleQueryDecryptionPassphraseEvent;

            operationsController.KnownKeyAdded += (object sender, FileOperationEventArgs e) =>
            {
                persistentState.Current.KnownKeys.Add(e.Key);
            };

            operationsController.Completed += (object sender, FileOperationEventArgs e) =>
            {
                if (e.Status == FileOperationStatus.Canceled)
                {
                    return;
                }
                CheckStatusAndShowMessage(e.Status, e.OpenFileFullName);
            };

            operationsController.DecryptAndLaunch(file, worker);
        }