public void Add_basic_credential_to_cache() { var cache = new HttpCredentialCache { new BasicCredentials(new Uri("http://example.org"), username: "", password: "") }; Assert.Equal(1, cache.Count()); }
public void Fail_to_find_creds_because_no_challeng() { var cache = new HttpCredentialCache { new FooCredentials(new Uri("http://example.org/")) }; var creds = cache.GetMatchingCredentials(new Uri("http://example.org/"), new AuthenticationHeaderValue[] { }); Assert.Null(creds); }
public void Fail_to_find_creds() { var cache = new HttpCredentialCache { new FooCredentials(new Uri("http://example.org/")) }; var creds = cache.GetMatchingCredentials(new Uri("http://example.org/"), new[] { new AuthenticationHeaderValue("someotherauth", "asdasdasd") }); Assert.Null(creds); }
public void Retreive_credentials_from_cache_with_trailing_slash() { var cache = new HttpCredentialCache { new FooCredentials(new Uri("http://example.org/")) }; var creds = cache.GetMatchingCredentials(new Uri("http://example.org/"), new[] { new AuthenticationHeaderValue("fooauth", "asdasdasd") }); Assert.NotNull(creds); }
public void Retreive_credentials_from_cache_using_realm() { var basicCredentials = new BasicCredentials(new Uri("http://example.org"), username: "", password: "") { Realm = "foo" }; var cache = new HttpCredentialCache { basicCredentials, }; var creds = cache.GetMatchingCredentials(new Uri("http://example.org"), new[] { new AuthenticationHeaderValue("basic", "Realm=\"foo\"") }); Assert.Same(basicCredentials, creds); }
public void Retreive_credentials_from_cache() { var basicCredentials = new BasicCredentials(new Uri("http://example.org"), username: "", password: ""); var cache = new HttpCredentialCache { new FooCredentials(new Uri("http://example.org")), basicCredentials, new BasicCredentials(new Uri("http://example.net"), username: "", password: ""), new BasicCredentials(new Uri("http://example.org"), username: "", password: "") {Realm = "foo"}, }; var creds = cache.GetMatchingCredentials(new Uri("http://example.org"), new[] { new AuthenticationHeaderValue("basic","foo") }); Assert.Same(basicCredentials, creds); }
public void Reuse_last_used_credentials() { // Arrange var cache = new HttpCredentialCache { new BasicCredentials(new Uri("http://example.org"), username: "", password: "") }; var authService = new CredentialService(cache); var request = new HttpRequestMessage(){RequestUri = new Uri("http://example.org")}; authService.CreateAuthenticationHeaderFromChallenge(request, new[] { new AuthenticationHeaderValue("basic", "") }); // Act var header = authService.CreateAuthenticationHeaderFromRequest(request); // Assert Assert.Equal("basic", header.Scheme); }
public void Reuse_last_used_credentials() { // Arrange var cache = new HttpCredentialCache { new BasicCredentials(new Uri("http://example.org"), username: "", password: "") }; var authService = new CredentialService(cache); var request = new HttpRequestMessage() { RequestUri = new Uri("http://example.org") }; authService.CreateAuthenticationHeaderFromChallenge(request, new[] { new AuthenticationHeaderValue("basic", "") }); // Act var header = authService.CreateAuthenticationHeaderFromRequest(request); // Assert Assert.Equal("basic", header.Scheme); }
public async Task Gateway_key_with_wrong_host() { // Arrange var cache = new HttpCredentialCache { new GatewayKey(new Uri("http://example.org/foo"), "gateway-key","key value goes here") }; var authService = new CredentialService(cache); var request = new HttpRequestMessage() { RequestUri = new Uri("http://example.org") }; var invoker = new HttpMessageInvoker(new AuthMessageHandler(new DummyHttpHandler(), authService)); // Act var response = await invoker.SendAsync(request, new System.Threading.CancellationToken()); // Assert Assert.False(request.Headers.Contains("gateway-key")); //Assert.Equal("key value goes here", request.Headers.GetValues("gateway-key").First()); }
public CredentialService(HttpCredentialCache credentialCache) { _credentialCache = credentialCache; }
private static HttpClient CreateClient() { var handler = new HttpClientHandler(); handler.AllowAutoRedirect = false; var apiKeyId = Environment.GetEnvironmentVariable("STORMPATH_APIKEY_ID",EnvironmentVariableTarget.User); var apiKeySecret = Environment.GetEnvironmentVariable("STORMPATH_APIKEY_SECRET", EnvironmentVariableTarget.User); Debug.Assert(!String.IsNullOrEmpty(apiKeyId) && !String.IsNullOrEmpty(apiKeyId), "Set API key as environment variables to run tests"); var httpCredentialCache = new HttpCredentialCache() { new BasicCredentials(new Uri("https://api.stormpath.com"), apiKeyId, apiKeySecret) { Realm = "Stormpath IAM"} }; return new HttpClient(new AuthMessageHandler(handler, new CredentialService(httpCredentialCache))); }