Ejemplo n.º 1
0
        public async Task WithAuthUrlTokenRequest_GetsResultAndPostToRetrieveToken()
        {
            var rest    = GetRestClient();
            var options = new AuthOptions {
                AuthUrl = new Uri("http://authUrl")
            };
            List <AblyRequest> requests = new List <AblyRequest>();
            var requestData             = new TokenRequest {
                KeyName = KeyId, Capability = new Capability(), Mac = "mac"
            };

            rest.ExecuteHttpRequest = (x) =>
            {
                requests.Add(x);
                if (x.Url == options.AuthUrl.ToString())
                {
                    return(JsonHelper.Serialize(requestData).ToAblyResponse());
                }

                return(DummyTokenResponse.ToTask());
            };

            var tokenParams = new TokenParams {
                Capability = new Capability()
            };

            await rest.Auth.RequestTokenAsync(tokenParams, options);

            requests.Count.Should().Be(2);
            var last = requests.Last().PostData as TokenRequest;

            last.Should().BeEquivalentTo(requestData);
        }
Ejemplo n.º 2
0
        public async Task RequestToken_WithQueryTime_SendsTimeRequestAndUsesReturnedTimeForTheRequest()
        {
            var rest        = GetRestClient();
            var currentTime = DateTimeOffset.UtcNow;

            rest.ExecuteHttpRequest = x =>
            {
                if (x.Url.Contains("time"))
                {
                    return(("[" + currentTime.ToUnixTimeInMilliseconds() + "]").ToAblyJsonResponse());
                }

                // Assert
                var data = x.PostData as TokenRequest;
                data.Timestamp.Should().BeCloseTo(currentTime, TimeSpan.FromMilliseconds(100));
                return(DummyTokenResponse.ToTask());
            };
            var tokenParams = new TokenParams
            {
                Capability = new Capability(),
                ClientId   = "ClientId",
                Ttl        = TimeSpan.FromMinutes(10)
            };

            // Act
            await rest.Auth.RequestTokenAsync(
                tokenParams,
                AuthOptions.FromExisting(rest.Options).Merge(new AuthOptions {
                QueryTime = true
            }));
        }
Ejemplo n.º 3
0
 private Task <AblyResponse> AuthExecuteHttpRequest(AblyRequest request)
 {
     if (request.Url.Contains("authUrl"))
     {
         return(JsonHelper.Serialize(new TokenRequest {
             ClientId = "123"
         }).ToAblyResponse());
     }
     return(DummyTokenResponse.ToTask());
 }
Ejemplo n.º 4
0
        public async Task RequestToken_WithoutQueryTime_SendsTimeRequestAndUsesReturnedTimeForTheRequest()
        {
            var rest = GetRestClient();

            rest.ExecuteHttpRequest = x =>
            {
                Assert.False(x.Url.Contains("time"));
                return(DummyTokenResponse.ToTask());
            };

            var tokenParams = new TokenParams {
                Capability = new Capability(), ClientId = "ClientId", Ttl = TimeSpan.FromMinutes(10)
            };

            //Act
            await rest.Auth.RequestTokenAsync(tokenParams, new AuthOptions()
            {
                QueryTime = false
            });
        }