Example #1
0
        public void StartAgent_NoSecretKeys_ThrowsGpgError()
        {
            var transportMock = new Mock <IGpgTransport>();

            transportMock.Setup(
                t => t.CallGpg(It.IsNotNull <string>(), It.IsAny <string>()))
            .Returns(new GpgResultBuilder()
                     .WithStdout("")
                     .Build());
            var gpg = new GPG(transportMock.Object, Mock.Of <IGpgAgent>(), StubGpgResultVerifier.AlwaysValid, new GpgConfig());

            Should.Throw <GpgError>(() => gpg.StartAgent());
        }
Example #2
0
        public void StartAgent_CallsListSecretKeys()
        {
            var transportMock = new Mock <IGpgTransport>();

            transportMock.Setup(
                t => t.CallGpg(It.IsNotNull <string>(), It.IsAny <string>()))
            .Returns(new GpgResultBuilder()
                     .WithStdout("secret keys")
                     .Build());
            var gpg = new GPG(transportMock.Object, Mock.Of <IGpgAgent>(), StubGpgResultVerifier.AlwaysValid, new GpgConfig());

            gpg.StartAgent();

            transportMock.Verify(t => t.CallGpg(It.IsRegex("--list-secret-keys"), null), Times.Once);
        }
Example #3
0
        public void StartAgent_ChecksAgentAlive()
        {
            var transportMock = new Mock <IGpgTransport>();

            transportMock.Setup(
                t => t.CallGpg(It.IsNotNull <string>(), It.IsAny <string>()))
            .Returns(new GpgResultBuilder()
                     .WithStdout("secret keys")
                     .Build());
            var agentMock = new Mock <IGpgAgent>();
            var gpg       = new GPG(transportMock.Object, agentMock.Object, StubGpgResultVerifier.AlwaysValid, new GpgConfig());

            gpg.StartAgent();

            agentMock.Verify(a => a.EnsureAgentResponsive(), Times.Once);
        }
Example #4
0
 /// <summary>
 /// Checks if all components are configured correctly.
 /// </summary>
 private void RunInitialCheck()
 {
     if (!Directory.Exists(ConfigManager.Config.PasswordStore.Location))
     {
         notificationService.ShowErrorWindow($"Could not find the password store at {Path.GetFullPath(ConfigManager.Config.PasswordStore.Location)}. Please make sure it exists.");
         Exit();
         return;
     }
     try
     {
         Log.Send("Using GPG version " + gpg.GetVersion());
     }
     catch (Win32Exception)
     {
         notificationService.ShowErrorWindow("Could not find GPG. Make sure your gpg-path is set correctly.");
         Exit();
         return;
     }
     catch (Exception e)
     {
         notificationService.ShowErrorWindow($"Failed to initialise GPG. {e.GetType().Name}: {e.Message}");
         Exit();
         return;
     }
     if (ConfigManager.Config.Gpg.GpgAgent.Preload)
     {
         Task.Run(() =>
         {
             try
             {
                 gpg.StartAgent();
             }
             catch (GpgError err)
             {
                 notificationService.ShowErrorWindow(err.Message);
             }
             // Ignore other exceptions. If it turns out GPG is misconfigured,
             // these errors will surface upon decryption/encryption.
             // The reason we catch GpgErrors here is so we can notify the user
             // if we don't detect any decryption keys.
         });
     }
 }