Beispiel #1
0
        public void RequestToken_WithAuthUrl_GetsResultAndPostToRetrieveToken()
        {
            var options = new AuthOptions
            {
                AuthUrl = "http://authUrl"
            };
            List <AblyRequest> requests = new List <AblyRequest>();
            var requestdata             = new TokenRequestPostData {
                keyName = GetKeyId(), capability = "123"
            };
            Func <AblyRequest, AblyResponse> executeHttpRequest = (x) =>
            {
                requests.Add(x);
                if (x.Url == options.AuthUrl)
                {
                    return(new AblyResponse {
                        TextResponse = JsonConvert.SerializeObject(requestdata)
                    });
                }
                return(new AblyResponse {
                    TextResponse = _dummyTokenResponse
                });
            };
            var rest = GetClient(executeHttpRequest);

            var tokenRequest = new TokenRequest {
                KeyName = GetKeyId(), Capability = new Capability()
            };

            rest.Auth.RequestToken(tokenRequest, options);

            Assert.Equal(2, requests.Count);
            Assert.Equal(requestdata, requests.Last().PostData);
        }
Beispiel #2
0
        public void RequestToken_WithAuthUrl_SendPostRequestToAuthUrl()
        {
            var rest    = GetRestClient();
            var options = new AuthOptions
            {
                AuthUrl     = "http://authUrl",
                AuthHeaders = new Dictionary <string, string> {
                    { "Test", "Test" }
                },
                AuthParams = new Dictionary <string, string> {
                    { "Test", "Test" }
                },
                AuthMethod = HttpMethod.Post
            };
            AblyRequest authRequest = null;
            var         requestdata = new TokenRequestPostData {
                keyName = GetKeyId(), capability = "123"
            };

            rest.ExecuteHttpRequest = (x) =>
            {
                if (x.Url == options.AuthUrl)
                {
                    authRequest = x;
                    return(new AblyResponse {
                        TextResponse = JsonConvert.SerializeObject(requestdata)
                    });
                }
                return(new AblyResponse {
                    TextResponse = _dummyTokenResponse
                });
            };

            var tokenRequest = new TokenRequest {
                KeyName = GetKeyId(), Capability = new Capability()
            };

            rest.Auth.RequestToken(tokenRequest, options);

            Assert.Equal(HttpMethod.Post, authRequest.Method);

            Assert.Equal(options.AuthHeaders, authRequest.Headers);
            Assert.Equal(options.AuthParams, authRequest.PostParameters);
            Assert.Equal(options.AuthUrl, authRequest.Url);
        }
Beispiel #3
0
        public void RequestToken_WithAuthUrlAndDefaultAuthMethod_SendsGetRequestToTheUrl()
        {
            var options = new AuthOptions
            {
                AuthUrl     = "http://authUrl",
                AuthHeaders = new Dictionary <string, string> {
                    { "Test", "Test" }
                },
                AuthParams = new Dictionary <string, string> {
                    { "Test", "Test" }
                },
            };

            AblyRequest authRequest = null;
            var         requestdata = new TokenRequestPostData {
                keyName = GetKeyId(), capability = "123"
            };
            Func <AblyRequest, AblyResponse> executeHttpRequest = x =>
            {
                if (x.Url == options.AuthUrl)
                {
                    authRequest = x;
                    return(new AblyResponse {
                        TextResponse = JsonConvert.SerializeObject(requestdata)
                    });
                }
                return(new AblyResponse {
                    TextResponse = _dummyTokenResponse
                });
            };
            var rest = GetClient(executeHttpRequest);

            var tokenRequest = new TokenRequest {
                KeyName = GetKeyId(), Capability = new Capability()
            };

            //Act
            rest.Auth.RequestToken(tokenRequest, options);

            //Assert
            Assert.Equal(HttpMethod.Get, authRequest.Method);
            Assert.Equal(options.AuthHeaders, authRequest.Headers);
            Assert.Equal(options.AuthParams, authRequest.QueryParameters);
        }