Пример #1
0
        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());
        }
Пример #2
0
        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());
        }
Пример #3
0
        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);

        }
Пример #4
0
        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);

        }
Пример #5
0
        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);

        }
Пример #6
0
        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);
        }
Пример #7
0
        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);
            
        }
Пример #8
0
        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);

        }
Пример #9
0
        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);
        }
Пример #10
0
        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());
        }
Пример #11
0
 public CredentialService(HttpCredentialCache credentialCache)
 {
     _credentialCache = credentialCache;
 }
Пример #12
0
        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)));
        }