Inheritance: KeePass.Plugins.Plugin
示例#1
0
        public void InitializeTest()
        {
            const string initalizeResultName = "KEEAGENT_INIT_RESULT";

              using (KeePassAppDomain testDomain1 = new KeePassAppDomain()) {
            testDomain1.StartKeePass(true, true, 1, true);
            testDomain1.DoCallBack(delegate()
            {
              IPluginHost td1PluginHost = KeePass.Program.MainForm.PluginHost;
              try {
            KeeAgentExt td1KeeAgentExt = new KeeAgentExt();
            KeePass.Program.MainForm.Invoke((MethodInvoker)delegate()
            {
              bool td1InitalizeResult = td1KeeAgentExt.Initialize(td1PluginHost);
              td1KeeAgentExt.Terminate();
              AppDomain.CurrentDomain.SetData(initalizeResultName,
                td1InitalizeResult);
            });
              } catch (Exception) {
            // TODO do we want to pass this exception back to test?
              }
            });

            bool expected = true;
            bool actual = (bool)testDomain1.GetData(initalizeResultName);
            Assert.AreEqual(expected, actual);
              }
        }
 public KeeAgentColumnProvider(KeeAgentExt ext)
 {
     if (ext == null)
     throw new ArgumentNullException("ext");
       this.ext = ext;
       ext.agent.KeyAdded += Agent_KeyAddedOrRemoved;
       ext.agent.KeyRemoved += Agent_KeyAddedOrRemoved;
       var agentModeAgent = ext.agent as Agent;
       if (agentModeAgent != null) {
       agentModeAgent.Locked += Agent_Locked;
       }
 }
示例#3
0
        public void TestIOProtocolExt()
        {
            using (KeePassAppDomain testDomain1 = new KeePassAppDomain()) {
            testDomain1.StartKeePass(true, false, 1, true);
            testDomain1.DoCallBack(delegate()
            {
              KeePass.Program.MainForm.Invoke((MethodInvoker)delegate()
              {
            /* initialize plugins */

            KeeAgentExt td1KeeAgentExt = new KeeAgentExt();
            IOProtocolExtExt td1IOProtocolExt = new IOProtocolExtExt();

            IPluginHost td1PluginHost = KeePass.Program.MainForm.PluginHost;
            td1KeeAgentExt.Initialize(td1PluginHost);
            td1IOProtocolExt.Initialize(td1PluginHost);
            KeePass.Program.MainForm.FormClosing += delegate(
              Object source, FormClosingEventArgs args)
            {
              td1KeeAgentExt.Terminate();
              td1IOProtocolExt.Terminate();
            };

            var extType = td1KeeAgentExt.GetType ();
            var mAgentField = extType.GetField ("mAgent",
                                                BindingFlags.Instance | BindingFlags.NonPublic);
            var agent = mAgentField.GetValue (td1KeeAgentExt) as IAgent;

            // test not valid in client mode
            Assert.That(agent, Is.AssignableTo<Agent>());

            // override confirm callback so we don't have to click OK
            (agent as Agent).ConfirmUserPermissionCallback =
              delegate(ISshKey aKey)
              {
                return true;
              };

            /* load ssh key */
            var keyFileDir = Path.GetFullPath (Path.Combine (
              "..", "..", "..", "SshAgentLib", "SshAgentLibTests", "Resources"));
            var keyFilePath = Path.Combine(keyFileDir, "rsa_with_passphrase");
            Assert.That(File.Exists(keyFilePath), "Cannot locate key file: " + keyFilePath);

            KeyFormatter.GetPassphraseCallback getPassphraseCallback =
              delegate()
              {
                var passphrase = "passphrase";
                var securePassphrase = new SecureString();
                foreach (char c in passphrase) {
                  securePassphrase.AppendChar(c);
                }
                return securePassphrase;
              };
            var constraints = new List<Agent.KeyConstraint>();
            constraints.addConfirmConstraint();
            agent.AddKeyFromFile(keyFilePath, getPassphraseCallback, constraints);

            /* run test */
            IOConnectionInfo ioConnectionInfo = new IOConnectionInfo();
            ioConnectionInfo.Path = "sftp://satest/test.kdbx";
            ioConnectionInfo.UserName = "******";
            bool fileExists = IOConnection.FileExists(ioConnectionInfo);
            Assert.IsTrue(fileExists, "Is satest VM running?");

            /* the problem we are checking for is that IOConnection.FileExists
             * does not lock up. Originally, in KeeAgent, WinPagent ran on main
             * thread and caused lock-up here. So, we are looking to see if the
             * test times out or not. */
              });
            });
              }
        }
示例#4
0
        public void TestOptionsPersistance()
        {
            // used for passing Options objects to/from AppDomain
              const string optionsPropertyName = "KEEAGENT_OPTIONS";

              /* test case options */

              bool requestedLoggingEnabled = true;
              string requestedLogFileName =
              Environment.GetEnvironmentVariable("TEMP");
              if (string.IsNullOrEmpty(requestedLogFileName)) {
            requestedLogFileName =
            Environment.GetEnvironmentVariable("TMP");
              }
              if (string.IsNullOrEmpty(requestedLogFileName)) {
            requestedLogFileName = "/tmp";
              }
              Assert.That (Directory.Exists (requestedLogFileName));

              // verify that requested options are not default to ensure a
              // valid test
              Options requestedOptions = new Options();
              Assert.AreNotEqual(requestedOptions.LoggingEnabled,
              requestedLoggingEnabled);
              Assert.AreNotEqual(requestedOptions.LogFileName,
              requestedLogFileName);

              requestedOptions.LoggingEnabled = requestedLoggingEnabled;
              requestedOptions.LogFileName = requestedLogFileName;

              /* first instance of KeePass is used to set options to
               * requested values */

              using (KeePassAppDomain testDomain1 = new KeePassAppDomain()) {
            testDomain1.StartKeePass(true, false, 1, true);
            testDomain1.SetData(optionsPropertyName, requestedOptions);
            testDomain1.DoCallBack(delegate()
            {
              KeePass.Program.MainForm.Invoke((MethodInvoker)delegate()
              {
            KeeAgentExt td1KeeAgentExt = new KeeAgentExt();
            IPluginHost td1PluginHost =
                KeePass.Program.MainForm.PluginHost;
            Options td1RequestedOptions = (Options)AppDomain
                .CurrentDomain.GetData(optionsPropertyName);
            td1KeeAgentExt.Initialize(td1PluginHost);
            td1KeeAgentExt.Options.Notification =
                td1RequestedOptions.Notification;
            td1KeeAgentExt.Options.LoggingEnabled =
                td1RequestedOptions.LoggingEnabled;
            td1KeeAgentExt.Options.LogFileName =
                td1RequestedOptions.LogFileName;
            var extType = td1KeeAgentExt.GetType ();
            var saveGlobalOptionsMethod =
              extType.GetMethod ("SaveGlobalOptions",
                                 BindingFlags.Instance | BindingFlags.NonPublic);
            saveGlobalOptionsMethod.Invoke (td1KeeAgentExt, null);
            td1PluginHost.MainWindow.SaveConfig();
            AppDomain.CurrentDomain.SetData(optionsPropertyName,
                td1KeeAgentExt.Options);
              });
            });
              }

              /* second instance of KeePass reads options to verify that they
               * were saved in the .config file */

              using (KeePassAppDomain testDomain2 = new KeePassAppDomain()) {
            testDomain2.StartKeePass(true, false, 1, false);
            testDomain2.DoCallBack(delegate()
            {
              KeePass.Program.MainForm.Invoke((MethodInvoker)delegate()
              {
            KeeAgentExt td2KeeAgentExt = new KeeAgentExt();
            IPluginHost td2PluginHost =
                KeePass.Program.MainForm.PluginHost;
            td2KeeAgentExt.Initialize(td2PluginHost);
            AppDomain.CurrentDomain.SetData(optionsPropertyName,
                td2KeeAgentExt.Options);
              });
            });
            Options actual = (Options)testDomain2.GetData(optionsPropertyName);
            Assert.AreEqual(requestedLoggingEnabled, actual.LoggingEnabled);
            Assert.AreEqual(requestedLogFileName, actual.LogFileName);
              }
        }