public static string SetCredentialsToUrl(this string url, Credentials credentials) { if (credentials.IsNotDefined()) return url; const string pattern = "(.+//)(.*@)?(.+)"; var match = Regex.Match(url, pattern); if (!match.Success) return url; return match.Groups[1] + credentials.UserName + ":" + credentials.Password + "@" + match.Groups[3]; }
public void SetCredentialsToUrlTest_UrlWithCredentials() { var url = @"http://*****:*****@someurl.com/rep"; var credentials = new Credentials("user", "password"); var result = url.SetCredentialsToUrl(credentials); Assert.AreEqual(@"http://*****:*****@someurl.com/rep", result); }
public UserOptions() { BranchTags = new List<BranchTagInfo>(); BranchLinks = new BranchLinkInfoList(); UserCredentials = new Credentials(); }