Exemplo n.º 1
0
        public void EncryptPassword_RoundTrips()
        {
            const string password  = "******";
            var          encrypted = ServerSettingsModel.EncryptPassword(password);
            var          decrypted = ServerSettingsModel.DecryptPassword(encrypted);

            Assert.AreEqual(password, decrypted);
            Assert.AreNotEqual(password, encrypted);
        }
Exemplo n.º 2
0
 public void GetIsReadyForInternetSendReceive_HasFullLangForgeUrlAndSavedCredentials_ReturnsTrue()
 {
     using (new MercurialIniForTests())
     {
         Settings.Default.LanguageForgeUser     = "******";
         Settings.Default.LanguageForgePass     = ServerSettingsModel.EncryptPassword("password");
         ServerSettingsModel.PasswordForSession = null;
         Assert.IsTrue(GetIsReady(@"LanguageForge = https://hg-public.languageforge.org/xyz"));
     }
 }
Exemplo n.º 3
0
        public void InitFromUri_UsernameAndPass_OverwritesSettings()
        {
            Settings.Default.LanguageForgeUser = "******";
            Settings.Default.LanguageForgePass = ServerSettingsModel.EncryptPassword("settings");
            var m = new ServerSettingsModel();

            m.InitFromUri("https://*****:*****@hg-public.languageforge.org/tps");
            Assert.AreEqual("jan", m.Username);
            Assert.AreEqual("pass", m.Password);
            Assert.AreEqual("tps", m.ProjectId);
        }
Exemplo n.º 4
0
        public void InitFromUri_NoUsernameOrPass_UsesSettings()
        {
            const string user = "******";
            const string pass = "******";

            Settings.Default.LanguageForgeUser = user;
            Settings.Default.LanguageForgePass = ServerSettingsModel.EncryptPassword(pass);
            var m = new ServerSettingsModel();

            m.InitFromUri("https://hg.languageforge.org/tpi");
            Assert.AreEqual(user, m.Username);
            Assert.AreEqual(pass, m.Password);
            Assert.AreEqual("tpi", m.ProjectId);
        }
Exemplo n.º 5
0
        public void RemoveCredentialsFromIniIfNecessary_PreservesOtherData(string savedUser, string savedPass, string newSavedPass)
        {
            const string iniUsername    = "******";
            const string urlEnd         = "hg-private.languageforge.org/auc-flex";
            const string oldUrl         = "https://" + "dinah:shibboleth@" + urlEnd;
            const string newUrl         = "https://" + urlEnd;
            const string networkDirName = "Old Network Share";
            const string networkDirRepo = "//chorus-box/projects/Wao";

            Chorus.Properties.Settings.Default.LanguageForgeUser = savedUser;
            Chorus.Properties.Settings.Default.LanguageForgePass = ServerSettingsModel.EncryptPassword(savedPass);

            using (var tempDir = new TemporaryFolder("HgRepoURI"))
            {
                var repo    = new HgRepository(tempDir.Path, _progress);
                var iniPath = repo.GetPathToHgrc();
                Directory.CreateDirectory(Path.GetDirectoryName(iniPath));
                var ini = repo.GetMercurialConfigForRepository();
                ini.Sections.GetOrCreate("ui").Set("username", iniUsername);
                var paths = ini.Sections.GetOrCreate("paths");
                paths.Set(networkDirName, networkDirRepo);
                paths.Set("LanguageForge", oldUrl);
                ini.Save();

                // SUT
                repo.RemoveCredentialsFromIniIfNecessary();

                ini = repo.GetMercurialConfigForRepository();
                Assert.AreEqual(iniUsername, ini.Sections["ui"].GetValue("username"), "Other data should be preserved");
                var newPaths = ini.Sections["paths"];
                Assert.AreEqual(2, newPaths.ItemCount);
                Assert.AreEqual(networkDirRepo, newPaths.GetValue(networkDirName));
                var actualUrl = newPaths.GetValue(newPaths.GetKeys().First(k => !k.Equals(networkDirName)));
                Assert.AreEqual(newUrl, actualUrl);
                Assert.AreEqual("dinah", Chorus.Properties.Settings.Default.LanguageForgeUser, "username is always saved");
                Assert.AreEqual("shibboleth", ServerSettingsModel.PasswordForSession, "should have read password from file");
                if (string.IsNullOrEmpty(newSavedPass))
                {
                    Assert.That(Chorus.Properties.Settings.Default.LanguageForgePass, Is.Null.Or.Empty);
                }
                else
                {
                    Assert.That(ServerSettingsModel.DecryptPassword(Chorus.Properties.Settings.Default.LanguageForgePass),
                                Is.EqualTo(newSavedPass), "should have saved the password to user settings");
                }
            }
        }
Exemplo n.º 6
0
        public void RememberPassword(string cachedPassword, string savedPassword, bool expectedRememberPassword)
        {
            Settings.Default.LanguageForgeUser     = "******";
            Settings.Default.LanguageForgePass     = ServerSettingsModel.EncryptPassword(savedPassword);
            ServerSettingsModel.PasswordForSession = cachedPassword;

            var sut = new ServerSettingsModel();

            Assert.AreEqual(expectedRememberPassword, sut.RememberPassword);
            if (expectedRememberPassword)
            {
                Assert.AreEqual(savedPassword, sut.Password);
            }
            else
            {
                Assert.That(sut.Password, Is.Null.Or.Empty);
            }
        }
Exemplo n.º 7
0
 public void PasswordForSession_UsesSaved([Values(null, "", "myPass")] string password)
 {
     Settings.Default.LanguageForgePass     = ServerSettingsModel.EncryptPassword(password);
     ServerSettingsModel.PasswordForSession = null;
     Assert.AreEqual(password, ServerSettingsModel.PasswordForSession);
 }
Exemplo n.º 8
0
 public void EncryptPassword_NullAndEmptyDoNotCrash()
 {
     Assert.DoesNotThrow(() => ServerSettingsModel.EncryptPassword(null));
     Assert.DoesNotThrow(() => ServerSettingsModel.EncryptPassword(string.Empty));
 }