static bool TryGetUsernamePassword(URIish uri, CredentialItem[] items, out CredentialItem.Password passwordItem) { var actualUrl = new Uri(uri.ToString()); var username = (CredentialItem.Username)items.FirstOrDefault(i => i is CredentialItem.Username); var password = (CredentialItem.Password)items.FirstOrDefault(i => i is CredentialItem.Password); if (items.Length == 2 && username != null && password != null) { passwordItem = password; var passwordValue = PasswordService.GetWebPassword(actualUrl); if (passwordValue != null) { username.SetValue(actualUrl.UserInfo); password.SetValueNoCopy(passwordValue.ToArray()); return(true); } } else { passwordItem = null; } return(false); }
public override bool Get(URIish uri, params CredentialItem[] items) { bool result = false; CredentialItem.Password passwordItem = null; CredentialItem.StringType passphraseItem = null; // We always need to run the TryGet* methods as we need the passphraseItem/passwordItem populated even // if the password store contains an invalid password/no password if (TryGetUsernamePassword(uri, items, out passwordItem) || TryGetPassphrase(uri, items, out passphraseItem)) { // If the password store has a password and we already tried using it, it could be incorrect. // If this happens, do not return true and ask the user for a new password. if (!HasReset) { return(true); } } DispatchService.GuiSyncDispatch(delegate { CredentialsDialog dlg = new CredentialsDialog(uri, items); try { result = MessageService.ShowCustomDialog(dlg) == (int)Gtk.ResponseType.Ok; } finally { dlg.Destroy(); } }); HasReset = false; if (result) { if (passwordItem != null) { PasswordService.AddWebPassword(new Uri(uri.ToString()), new string (passwordItem.GetValue())); } else if (passphraseItem != null) { PasswordService.AddWebPassword(new Uri(uri.ToString()), passphraseItem.GetValue()); } } return(result); }
public void testFileProtoUnix() { const string str = "file:///home/m y"; var u = new URIish(str); Assert.AreEqual("file", u.Scheme); Assert.IsFalse(u.IsRemote); Assert.AreEqual("/home/m y", u.Path); Assert.AreEqual(str, u.ToString()); Assert.AreEqual(u, new URIish(str)); }
public void testUNC() { const string str = "\\\\some\\place"; var u = new URIish(str); Assert.IsNull(u.Scheme); Assert.IsFalse(u.IsRemote); Assert.AreEqual("//some/place", u.Path); Assert.AreEqual("//some/place", u.ToString()); Assert.AreEqual(u, new URIish(str)); }
public void testWindowsFile2() { const string str = "D:\\m y"; var u = new URIish(str); Assert.IsNull(u.Scheme); Assert.IsFalse(u.IsRemote); Assert.AreEqual("D:/m y", u.Path); Assert.AreEqual("D:/m y", u.ToString()); Assert.AreEqual(u, new URIish(str)); }
public void testUnixFile() { const string str = "/home/m y"; var u = new URIish(str); Assert.IsNull(u.Scheme); Assert.IsFalse(u.IsRemote); Assert.AreEqual(str, u.Path); Assert.AreEqual(str, u.ToString()); Assert.AreEqual(u, new URIish(str)); }
public void testGitProtoUnix() { const string str = "git://example.com/home/m y"; var u = new URIish(str); Assert.AreEqual("git", u.Scheme); Assert.IsTrue(u.IsRemote); Assert.AreEqual("example.com", u.Host); Assert.AreEqual("/home/m y", u.Path); Assert.AreEqual(str, u.ToString()); Assert.AreEqual(u, new URIish(str)); }
public void testSshProto() { const string str = "ssh://example.com/some/p ath"; var u = new URIish(str); Assert.AreEqual("ssh", u.Scheme); Assert.IsTrue(u.IsRemote); Assert.AreEqual("/some/p ath", u.Path); Assert.AreEqual("example.com", u.Host); Assert.AreEqual(-1, u.Port); Assert.AreEqual(str, u.ToString()); Assert.AreEqual(u, new URIish(str)); }
public void testScpStyleWithoutUser() { const string str = "example.com:some/p ath"; var u = new URIish(str); Assert.IsNull(u.Scheme); Assert.IsTrue(u.IsRemote); Assert.AreEqual("some/p ath", u.Path); Assert.AreEqual("example.com", u.Host); Assert.AreEqual(-1, u.Port); Assert.AreEqual(str, u.ToString()); Assert.AreEqual(u, new URIish(str)); }
public void testGitProtoWindowsPort() { const string str = "git://example.com:338/D:/m y"; var u = new URIish(str); Assert.AreEqual("git", u.Scheme); Assert.IsTrue(u.IsRemote); Assert.AreEqual("D:/m y", u.Path); Assert.AreEqual(338, u.Port); Assert.AreEqual("example.com", u.Host); Assert.AreEqual(str, u.ToString()); Assert.AreEqual(u, new URIish(str)); }
public void testAddURI() { readConfig(string.Empty); URIish uri = new URIish("/some/dir"); RemoteConfig rc = new RemoteConfig(config, "backup"); Assert.AreEqual(0, rc.URIs.Count); Assert.IsTrue(rc.AddURI(uri)); Assert.AreEqual(1, rc.URIs.Count); Assert.AreSame(uri, rc.URIs[0]); Assert.IsFalse(rc.AddURI(new URIish(uri.ToString()))); Assert.AreEqual(1, rc.URIs.Count); }
public void testSshProtoWithUserPassAndPort() { const string str = "ssh://*****:*****@example.com:33/some/p ath"; var u = new URIish(str); Assert.AreEqual("ssh", u.Scheme); Assert.IsTrue(u.IsRemote); Assert.AreEqual("/some/p ath", u.Path); Assert.AreEqual("example.com", u.Host); Assert.AreEqual("user", u.User); Assert.AreEqual("pass", u.Pass); Assert.AreEqual(33, u.Port); Assert.AreEqual(str, u.ToPrivateString()); Assert.AreEqual(u.SetPass(null).ToPrivateString(), u.ToString()); Assert.AreEqual(u, new URIish(str)); }
static bool TryGetPassphrase(URIish uri, CredentialItem[] items, out CredentialItem.StringType passphraseItem) { var actualUrl = new Uri(uri.ToString()); var passphrase = (CredentialItem.StringType)items.FirstOrDefault(i => i is CredentialItem.StringType); if (items.Length == 1 && passphrase != null) { passphraseItem = passphrase; var passphraseValue = PasswordService.GetWebPassword(actualUrl); if (passphraseValue != null) { passphrase.SetValue(passphraseValue); return(true); } } else { passphraseItem = null; } return(false); }
public CredentialsDialog(URIish uri, IEnumerable <CredentialItem> credentials) { this.Build(); labelTop.Text = string.Format(labelTop.Text, uri.ToString()); Gtk.Table table = new Gtk.Table(0, 0, false); table.ColumnSpacing = 6; vbox.PackStart(table, true, true, 0); uint r = 0; Widget firstEditor = null; foreach (CredentialItem c in credentials) { Label lab = new Label(c.GetPromptText() + ":"); lab.Xalign = 0; table.Attach(lab, 0, 1, r, r + 1); Table.TableChild tc = (Table.TableChild)table [lab]; tc.XOptions = AttachOptions.Shrink; Widget editor = null; if (c is CredentialItem.YesNoType) { CredentialItem.YesNoType cred = (CredentialItem.YesNoType)c; if (credentials.Count(i => i is CredentialItem.YesNoType) == 1) { singleYesNoCred = cred; buttonOk.Hide(); buttonYes.Show(); buttonNo.Show(); // Remove the last colon lab.Text = lab.Text.Substring(0, lab.Text.Length - 1); } else { CheckButton btn = new CheckButton(); editor = btn; btn.Toggled += delegate { cred.SetValue(btn.Active); }; } } else if (c is CredentialItem.StringType || c is CredentialItem.CharArrayType) { CredentialItem cred = c; Entry e = new Entry(); editor = e; e.ActivatesDefault = true; if (cred.IsValueSecure()) { e.Visibility = false; } e.Changed += delegate { if (cred is CredentialItem.StringType) { ((CredentialItem.StringType)cred).SetValue(e.Text); } else { ((CredentialItem.CharArrayType)cred).SetValue(e.Text.ToCharArray()); } }; if (c is CredentialItem.Username) { e.Text = uri.GetUser() ?? ""; } } if (editor != null) { table.Attach(editor, 1, 2, r, r + 1); tc = (Table.TableChild)table [lab]; tc.XOptions = AttachOptions.Fill; if (firstEditor == null) { firstEditor = editor; } } r++; } table.ShowAll(); Focus = firstEditor; Default = buttonOk; }