public void Settings_TryGetSetting_ScopedConfig() { const string remoteUrl = "http://example.com/foo/bar/bazz.git"; const string scope1 = "example.com"; const string scope2 = "example.com/foo/bar"; const string envarName = "GCM_TESTVAR"; const string section = "gcmtest"; const string property = "bar"; var remoteUri = new Uri(remoteUrl); const string expectedValue = "Hello, World!"; const string otherValue = "Goodbye, World!"; var envars = new TestEnvironment(); var git = new TestGit(); git.Configuration.Local[$"{section}.{scope1}.{property}"] = new [] { otherValue }; git.Configuration.Local[$"{section}.{scope2}.{property}"] = new [] { expectedValue }; var settings = new Settings(envars, git) { RemoteUri = remoteUri }; var result = settings.TryGetSetting(envarName, section, property, out string actualValue); Assert.True(result); Assert.Equal(expectedValue, actualValue); }
public void Settings_TryGetSetting_EnvarSet_ReturnsTrueOutValue() { const string remoteUrl = "http://example.com/foo.git"; const string envarName = "GCM_TESTVAR"; const string section = "gcmtest"; const string property = "bar"; var remoteUri = new Uri(remoteUrl); const string expectedValue = "Hello, World!"; var envars = new TestEnvironment { Variables = { [envarName] = expectedValue } }; var git = new TestGit(); var settings = new Settings(envars, git) { RemoteUri = remoteUri }; var result = settings.TryGetSetting(envarName, section, property, out string actualValue); Assert.True(result); Assert.Equal(expectedValue, actualValue); }
public void Settings_TryGetSetting_RepoConfig_ReturnsTrueAndValue() { const string repositoryPath = "/tmp/repos/foo/.git"; const string remoteUrl = "http://example.com/foo.git"; const string envarName = "GCM_TESTVAR"; const string section = "gcmtest"; const string property = "bar"; var remoteUri = new Uri(remoteUrl); const string expectedValue = "Hello, World!"; var envars = new TestEnvironment(); var git = new TestGit(); var repo = git.AddRepository(repositoryPath); repo.Configuration[$"{section}.{property}"] = expectedValue; var settings = new Settings(envars, git, repositoryPath) { RemoteUri = remoteUri }; var result = settings.TryGetSetting(envarName, section, property, out string actualValue); Assert.True(result); Assert.Equal(expectedValue, actualValue); }
public void Settings_ProviderOverride_EnvarAndConfigSet_ReturnsEnvarValue() { const string repositoryPath = "/tmp/repos/foo/.git"; const string remoteUrl = "http://example.com/foo.git"; const string section = Constants.GitConfiguration.Credential.SectionName; const string property = Constants.GitConfiguration.Credential.Provider; var remoteUri = new Uri(remoteUrl); const string expectedValue = "provider1"; const string otherValue = "provider2"; var envars = new TestEnvironment { Variables = { [Constants.EnvironmentVariables.GcmProvider] = expectedValue } }; var git = new TestGit(); git.GlobalConfiguration[$"{section}.{property}"] = otherValue; var settings = new Settings(envars, git, repositoryPath) { RemoteUri = remoteUri }; string actualValue = settings.ProviderOverride; Assert.Equal(expectedValue, actualValue); }
public void Settings_TryGetSetting_EnvarAndConfig_EnvarTakesPrecedence() { const string remoteUrl = "http://example.com/foo.git"; const string envarName = "GCM_TESTVAR"; const string section = "gcmtest"; const string property = "bar"; var remoteUri = new Uri(remoteUrl); const string expectedValue = "Hello, World!"; const string otherValue = "Goodbye, World!"; var envars = new TestEnvironment { Variables = { [envarName] = expectedValue } }; var git = new TestGit(); git.Configuration.Local[$"{section}.{property}"] = new[] { otherValue }; var settings = new Settings(envars, git) { RemoteUri = remoteUri }; var result = settings.TryGetSetting(envarName, section, property, out string actualValue); Assert.True(result); Assert.Equal(expectedValue, actualValue); }
public void AzureReposAuthorityCache_UpdateAuthority_CachedAuthority_UpdatesAuthority() { const string orgName = "contoso"; string key = CreateKey(orgName); const string oldAuthority = "https://old-login.contoso.com"; const string expectedAuthority = "https://login.contoso.com"; var git = new TestGit { Configuration = { Global = { [key] = new[] { oldAuthority } } } }; var trace = new NullTrace(); var cache = new AzureDevOpsAuthorityCache(trace, git); cache.UpdateAuthority(orgName, expectedAuthority); Assert.True(git.Configuration.Global.TryGetValue(key, out IList <string> values)); Assert.Single(values); string actualAuthority = values[0]; Assert.Equal(expectedAuthority, actualAuthority); }
public async Task Application_ConfigureAsync_HelperSetWithOthersFollowing_ClearsEntriesSetsHelper() { const string emptyHelper = ""; const string gcmConfigName = "manager-core"; const string executablePath = "/usr/local/share/gcm-core/git-credential-manager-core"; string key = $"{Constants.GitConfiguration.Credential.SectionName}.{Constants.GitConfiguration.Credential.Helper}"; IConfigurableComponent application = new Application(new TestCommandContext(), executablePath); var environment = new Mock <IEnvironment>(); var git = new TestGit(); git.GlobalConfiguration.Dictionary[key] = new List <string> { "bar", emptyHelper, executablePath, "foo" }; await application.ConfigureAsync( environment.Object, EnvironmentVariableTarget.User, git, GitConfigurationLevel.Global); Assert.Single(git.GlobalConfiguration.Dictionary); Assert.True(git.GlobalConfiguration.Dictionary.TryGetValue(key, out var actualValues)); Assert.Equal(2, actualValues.Count); Assert.Equal(emptyHelper, actualValues[0]); Assert.Equal(gcmConfigName, actualValues[1]); }
public void Settings_LegacyAuthorityOverride_EnvarAndConfigSet_ReturnsEnvarValue() { const string repositoryPath = "/tmp/repos/foo/.git"; const string remoteUrl = "http://example.com/foo.git"; const string section = Constants.GitConfiguration.Credential.SectionName; const string property = Constants.GitConfiguration.Credential.Authority; var remoteUri = new Uri(remoteUrl); const string expectedValue = "provider1"; const string otherValue = "provider2"; var envars = new EnvironmentVariables(new Dictionary <string, string> { [Constants.EnvironmentVariables.GcmAuthority] = expectedValue }); var git = new TestGit(new Dictionary <string, string> { [$"{section}.{property}"] = otherValue }); var settings = new Settings(envars, git) { RepositoryPath = repositoryPath, RemoteUri = remoteUri }; var actualValue = settings.LegacyAuthorityOverride; Assert.Equal(expectedValue, actualValue); }
public void AzureReposBindingManager_GetBinding_LocalAndGlobalUsers_ReturnsBinding() { const string orgUserLocal = "john.doe"; const string orgUserGlobal = "jane.doe"; const string orgName = "org"; string orgKey = CreateKey(orgName); var git = new TestGit { Configuration = { Global = { [orgKey] = new[] { orgUserGlobal } }, Local = { [orgKey] = new[] { orgUserLocal } } } }; var trace = new NullTrace(); var manager = new AzureReposBindingManager(trace, git); AzureReposBinding binding = manager.GetBinding(orgName); Assert.Equal(orgName, binding.Organization); Assert.Equal(orgUserGlobal, binding.GlobalUserName); Assert.Equal(orgUserLocal, binding.LocalUserName); }
public void Settings_ProxyConfiguration_GitHttpConfig_ReturnsValue() { const string repositoryPath = "/tmp/repos/foo/.git"; const string remoteUrl = "http://example.com/foo.git"; const string section = Constants.GitConfiguration.Http.SectionName; const string property = Constants.GitConfiguration.Http.Proxy; var remoteUri = new Uri(remoteUrl); var expectedValue = new Uri("http://john.doe:[email protected]"); var envars = new EnvironmentVariables(new Dictionary <string, string>()); var git = new TestGit(new Dictionary <string, string> { [$"{section}.{property}"] = expectedValue.ToString() }); var settings = new Settings(envars, git) { RemoteUri = remoteUri, RepositoryPath = repositoryPath }; Uri actualValue = settings.GetProxyConfiguration(out bool actualIsDeprecated); Assert.Equal(expectedValue, actualValue); Assert.False(actualIsDeprecated); }
public void Test1() { var args = new[] { "test2", "test3" }; var firstArg = TestGit.ParseOutFirstArg(args); Assert.AreEqual(firstArg, "test2"); }
public void Settings_LegacyAuthorityOverride_EnvarAndConfigSet_ReturnsEnvarValue() { const string remoteUrl = "http://example.com/foo.git"; const string section = Constants.GitConfiguration.Credential.SectionName; const string property = Constants.GitConfiguration.Credential.Authority; var remoteUri = new Uri(remoteUrl); const string expectedValue = "provider1"; const string otherValue = "provider2"; var envars = new TestEnvironment { Variables = { [Constants.EnvironmentVariables.GcmAuthority] = expectedValue } }; var git = new TestGit(); git.Configuration.Global[$"{section}.{property}"] = new[] { otherValue }; var settings = new Settings(envars, git) { RemoteUri = remoteUri }; var actualValue = settings.LegacyAuthorityOverride; Assert.Equal(expectedValue, actualValue); }
public void AzureReposAuthorityCache_EraseAuthority_CachedAuthority_RemovesAuthority() { const string orgName = "contoso"; string key = CreateKey(orgName); const string authority = "https://login.contoso.com"; string otherKey = CreateKey("fabrikam"); const string otherAuthority = "https://fabrikam.com/login"; var git = new TestGit { Configuration = { Global = { [key] = new[] { authority }, [otherKey] = new[] { otherAuthority } } } }; var trace = new NullTrace(); var cache = new AzureDevOpsAuthorityCache(trace, git); cache.EraseAuthority(orgName); // Only the other entries should remain Assert.False(git.Configuration.Global.ContainsKey(key)); Assert.Single(git.Configuration.Global); Assert.True(git.Configuration.Global.TryGetValue(otherKey, out IList <string> values)); Assert.Single(values); string actualOtherAuthority = values[0]; Assert.Equal(otherAuthority, actualOtherAuthority); }
public void Settings_TryGetSetting_EnvarAndConfig_EnvarTakesPrecedence() { const string repositoryPath = "/tmp/repos/foo/.git"; const string remoteUrl = "http://example.com/foo.git"; const string envarName = "GCM_TESTVAR"; const string section = "gcmtest"; const string property = "bar"; var remoteUri = new Uri(remoteUrl); const string expectedValue = "Hello, World!"; const string otherValue = "Goodbye, World!"; var envars = new EnvironmentVariables(new Dictionary <string, string> { [envarName] = expectedValue, }); var git = new TestGit(); git.AddRepository(repositoryPath, new Dictionary <string, string> { [$"{section}.{property}"] = otherValue }); var settings = new Settings(envars, git) { RepositoryPath = repositoryPath, RemoteUri = remoteUri }; var result = settings.TryGetSetting(envarName, section, property, out string actualValue); Assert.True(result); Assert.Equal(expectedValue, actualValue); }
public void AzureReposBindingManager_GetBinding_Null_ThrowException() { var git = new TestGit(); var trace = new NullTrace(); var manager = new AzureReposBindingManager(trace, git); Assert.Throws <ArgumentNullException>(() => manager.GetBinding(null)); }
public void AzureReposAuthorityCache_GetAuthority_Null_ThrowException() { var trace = new NullTrace(); var git = new TestGit(); var cache = new AzureDevOpsAuthorityCache(trace, git); Assert.Throws <ArgumentNullException>(() => cache.GetAuthority(null)); }
public void AzureReposBindingManager_Bind_NullOrganization_ThrowException() { var trace = new NullTrace(); var git = new TestGit(); var manager = new AzureReposBindingManager(trace, git); Assert.Throws <ArgumentNullException>(() => manager.Bind(null, "user", false)); }
public void Settings_IsWindowsIntegratedAuthenticationEnabled_ConfigUnset_ReturnsTrue() { var envars = new TestEnvironment(); var git = new TestGit(); var settings = new Settings(envars, git); Assert.True(settings.IsWindowsIntegratedAuthenticationEnabled); }
public void Settings_IsSecretTracingEnabled_EnvarUnset_ReturnsFalse() { var envars = new EnvironmentVariables(new Dictionary <string, string>()); var git = new TestGit(); var settings = new Settings(envars, git); Assert.False(settings.IsSecretTracingEnabled); }
public void Settings_IsInteractionAllowed_EnvarUnset_ReturnsTrue() { var envars = new TestEnvironment(); var git = new TestGit(); var settings = new Settings(envars, git); Assert.True(settings.IsInteractionAllowed); }
public void Settings_IsTerminalPromptsEnabled_EnvarUnset_ReturnsTrue() { var envars = new TestEnvironment(); var git = new TestGit(); var settings = new Settings(envars, git); Assert.True(settings.IsTerminalPromptsEnabled); }
public void Settings_IsTerminalPromptsEnabled_EnvarUnset_ReturnsTrue() { var envars = new EnvironmentVariables(new Dictionary <string, string>()); var git = new TestGit(); var settings = new Settings(envars, git); Assert.True(settings.IsTerminalPromptsEnabled); }
public void Settings_IsSecretTracingEnabled_EnvarUnset_ReturnsFalse() { var envars = new TestEnvironment(); var git = new TestGit(); var settings = new Settings(envars, git); Assert.False(settings.IsSecretTracingEnabled); }
public void AzureReposBindingManager_GetBindings_NoUsers_ReturnsEmpty() { var git = new TestGit(); var trace = new NullTrace(); var manager = new AzureReposBindingManager(trace, git); IList <AzureReposBinding> actual = manager.GetBindings().ToList(); Assert.Empty(actual); }
public void Settings_IsTracingEnabled_EnvarUnset_ReturnsFalse() { var envars = new EnvironmentVariables(new Dictionary <string, string>()); var git = new TestGit(); var settings = new Settings(envars, git); var result = settings.GetTracingEnabled(out string actualValue); Assert.False(result); }
public void AzureReposAuthorityCache_GetAuthority_NoCachedAuthority_ReturnsNull() { string key = CreateKey("contoso"); var trace = new NullTrace(); var git = new TestGit(); var cache = new AzureDevOpsAuthorityCache(trace, git); string authority = cache.GetAuthority(key); Assert.Null(authority); }
public void Settings_IsDebuggingEnabled_EnvarTruthy_ReturnsTrue() { var envars = new EnvironmentVariables(new Dictionary <string, string> { [Constants.EnvironmentVariables.GcmDebug] = "1" }); var git = new TestGit(); var settings = new Settings(envars, git); Assert.True(settings.IsDebuggingEnabled); }
public void Settings_IsTerminalPromptsEnabled_EnvarFalsey_ReturnsFalse() { var envars = new EnvironmentVariables(new Dictionary <string, string> { [Constants.EnvironmentVariables.GitTerminalPrompts] = "0" }); var git = new TestGit(); var settings = new Settings(envars, git); Assert.False(settings.IsTerminalPromptsEnabled); }
public void AzureReposBindingManager_GetBinding_NoUser_ReturnsNull() { const string orgName = "org"; var trace = new NullTrace(); var git = new TestGit(); var manager = new AzureReposBindingManager(trace, git); AzureReposBinding binding = manager.GetBinding(orgName); Assert.Null(binding); }
public void AzureReposBindingManager_UnbindLocal_NoUser_DoesNothing() { const string orgName = "org"; var trace = new NullTrace(); var git = new TestGit(); var manager = new AzureReposBindingManager(trace, git); manager.Unbind(orgName, true); Assert.Empty(git.Configuration.Local); }