コード例 #1
0
 /// <summary>
 /// Update Private Key selection
 /// </summary>
 private void UpdateIdentity()
 {
     View.PkCheckboxEnabled = View.SelectedProtocol == Protocol.SFTP;
     if (View.SelectedProtocol == Protocol.SFTP)
     {
         if (Utils.IsNotBlank(View.Hostname))
         {
             OpenSshConfig.Host entry = OpenSshConfig.create().lookup(View.Hostname);
             if (null != entry.getIdentityFile())
             {
                 if (!View.PkCheckboxState)
                 {
                     // No previously manually selected key
                     View.PkCheckboxState = true;
                     View.PkLabel         =
                         LocalFactory.createLocal(entry.getIdentityFile().getAbsolutePath()).getAbbreviatedPath();
                 }
             }
             else
             {
                 View.PkCheckboxState = false;
                 View.PkLabel         = Locale.localizedString("No private key selected");
             }
             if (Utils.IsNotBlank(entry.getUser()))
             {
                 View.Username = entry.getUser();
             }
         }
     }
     else
     {
         View.PkCheckboxState = false;
         View.PkLabel         = Locale.localizedString("No private key selected");
     }
 }
コード例 #2
0
 public void testNoConfig()
 {
     OpenSshConfig.Host h = _osc.lookup("repo.or.cz");
     Assert.IsNotNull(h);
     Assert.AreEqual("repo.or.cz", h.getHostName());
     Assert.AreEqual(Environment.UserName, h.getUser());
     Assert.AreEqual(22, h.getPort());
     Assert.IsNull(h.getIdentityFile());
 }
コード例 #3
0
 public void testAlias_DoesNotMatch()
 {
     Config("Host orcz\n" + "\tHostName repo.or.cz\n");
     OpenSshConfig.Host h = _osc.lookup("repo.or.cz");
     Assert.IsNotNull(h);
     Assert.AreEqual("repo.or.cz", h.getHostName());
     Assert.AreEqual(Environment.UserName, h.getUser());
     Assert.AreEqual(22, h.port);
     Assert.IsNull(h.getIdentityFile());
 }
コード例 #4
0
 /// <summary>
 /// Update this host credentials from the OpenSSH configuration file in ~/.ssh/config
 /// </summary>
 private void ReadOpenSshConfiguration()
 {
     if (_host.getProtocol().equals(Protocol.SFTP))
     {
         OpenSshConfig.Host entry = OpenSshConfig.create().lookup(_host.getHostname());
         if (null != entry.getIdentityFile())
         {
             _host.getCredentials().setIdentity(
                 LocalFactory.createLocal(entry.getIdentityFile().getAbsolutePath()));
         }
         if (Utils.IsNotBlank(entry.getUser()))
         {
             _host.getCredentials().setUsername(entry.getUser());
         }
     }
     else
     {
         _host.getCredentials().setIdentity(null);
     }
 }
コード例 #5
0
        public void testAlias_OptionsInherit()
        {
            Config("Host orcz\n" + "\tHostName repo.or.cz\n" + "\n" + "Host *\n"
                   + "\tHostName not.a.host.example.com\n" + "\tPort 2222\n"
                   + "\tUser jex\n" + "\tIdentityFile .ssh/id_jex\n"
                   + "\tForwardX11 no\n");

            OpenSshConfig.Host h = _osc.lookup("orcz");
            Assert.IsNotNull(h);
            Assert.AreEqual("repo.or.cz", h.getHostName());
            Assert.AreEqual("jex", h.getUser());
            Assert.AreEqual(2222, h.getPort());
            Assert.AreEqual(new FileInfo(Path.Combine(_home.FullName, ".ssh/id_jex")).FullName, h.getIdentityFile().FullName);
        }
コード例 #6
0
        public void testAlias_OptionsKeywordCaseInsensitive()
        {
            Config("hOsT orcz\n" + "\thOsTnAmE repo.or.cz\n" + "\tPORT 2222\n"
                   + "\tuser jex\n" + "\tidentityfile .ssh/id_jex\n"
                   + "\tForwardX11 no\n");

            OpenSshConfig.Host h = _osc.lookup("orcz");
            Assert.IsNotNull(h);
            Assert.AreEqual("repo.or.cz", h.getHostName());
            Assert.AreEqual("jex", h.getUser());
            Assert.AreEqual(2222, h.getPort());
            Assert.AreEqual(new FileInfo(Path.Combine(_home.FullName, ".ssh/id_jex")).FullName, h.getIdentityFile().FullName);
        }