public void RemovePasswordForLog_RemovesOnlyThePassword() { try { const string password = "******"; const string logFormat = "Cannot connect to https://someone:{0}@hg-public.languageforge.org/flex-proj; check your {1} and try again."; ServerSettingsModel.PasswordForSession = password; // SUT var scrubbed = ServerSettingsModel.RemovePasswordForLog(string.Format(logFormat, password, password)); Assert.AreEqual(string.Format(logFormat, ServerSettingsModel.PasswordAsterisks, password), scrubbed); } finally { ServerSettingsModel.PasswordForSession = null; } }
public void RemovePasswordForLog_NullAndEmptyDoNotCrash() { Assert.DoesNotThrow(() => ServerSettingsModel.RemovePasswordForLog(null)); Assert.DoesNotThrow(() => ServerSettingsModel.RemovePasswordForLog(string.Empty)); }
/// <returns>true if there was a successful pull</returns> private bool PullFromOneSource(HgRepository repo, RepositoryAddress source, Dictionary <RepositoryAddress, bool> connectionAttempt) { var resolvedUri = source.GetPotentialRepoUri(repo.Identifier, RepoProjectName, _progress); if (source is UsbKeyRepositorySource) { _progress.WriteMessage("Looking for USB flash drives..."); var potential = source.GetPotentialRepoUri(repo.Identifier, RepoProjectName, _progress); if (null == potential) { _progress.WriteWarning("No USB flash drive found"); } else if (string.Empty == potential) { _progress.WriteMessage("Did not find this project on any USB flash drive."); } } else { _progress.WriteMessage("Connecting to {0}...", source.Name); } var canConnect = source.CanConnect(repo, RepoProjectName, _progress); if (!connectionAttempt.ContainsKey(source)) { connectionAttempt.Add(source, canConnect); } if (canConnect) { try { ThrowIfCancelPending(); } catch (Exception error) { throw new SynchronizationException(error, WhatToDo.CheckSettings, "Error while pulling {0} at {1}", source.Name, ServerSettingsModel.RemovePasswordForLog(resolvedUri)); } //NB: this returns false if there was nothing to get. try { return(repo.Pull(source, resolvedUri)); } catch (HgCommonException err) { // These kinds of errors are worth an immediate dialog, to make sure we get the user's attention. ErrorReport.NotifyUserOfProblem(err.Message); // The main sync routine will catch the exception, abort any other parts of the Send/Receive, // and log the problem. throw; } // Any other kind of exception will be caught and logged at a higher level. } if (source is UsbKeyRepositorySource) { //already informed them, above return(false); } _progress.WriteError("Could not connect to {0} at {1}", source.Name, ServerSettingsModel.RemovePasswordForLog(resolvedUri)); return(false); }