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 })); }
public async Task ShouldKeepCurrentTokenParamsAndOptionsEvenIfCurrentTokenIsValidAndNoNewTokenIsRequested() { var client = GetRestClient( null, opts => opts.TokenDetails = new TokenDetails("boo") { Expires = Now.AddHours(10) }); var testAblyAuth = new TestAblyAuth(client.Options, client); var customTokenParams = TokenParams.WithDefaultsApplied(); customTokenParams.Ttl = TimeSpan.FromHours(2); customTokenParams.Timestamp = Now.AddHours(1); var customAuthOptions = AuthOptions.FromExisting(testAblyAuth.Options); customAuthOptions.UseTokenAuth = true; await testAblyAuth.AuthorizeAsync(customTokenParams, customAuthOptions); var expectedTokenParams = customTokenParams.Clone(); expectedTokenParams.Timestamp = null; testAblyAuth.CurrentTokenParams.Should().BeEquivalentTo(expectedTokenParams); testAblyAuth.CurrentAuthOptions.Should().BeSameAs(customAuthOptions); }
public async Task ShouldKeepTokenParamsAndAuthOptionsExceptForceAndCurrentTimestamp() { var client = GetRestClient(); var testAblyAuth = new TestAblyAuth(client.Options, client); var customTokenParams = TokenParams.WithDefaultsApplied(); _ = customTokenParams.Merge(new TokenParams { Ttl = TimeSpan.FromHours(2), Timestamp = Now.AddHours(1) }); var customAuthOptions = AuthOptions.FromExisting(testAblyAuth.Options); customAuthOptions.UseTokenAuth = true; await testAblyAuth.AuthorizeAsync(customTokenParams, customAuthOptions); var expectedTokenParams = customTokenParams.Clone(); expectedTokenParams.Timestamp = null; testAblyAuth.CurrentTokenParams.Should().BeEquivalentTo(expectedTokenParams); testAblyAuth.CurrentAuthOptions.Should().BeSameAs(customAuthOptions); testAblyAuth.CurrentTokenParams.Timestamp.Should().Be(null); }
public async Task RequestToken_WithoutQueryTime_SendsTimeRequestAndUsesReturnedTimeForTheRequest() { var rest = GetRestClient(); rest.ExecuteHttpRequest = x => { Assert.DoesNotContain("time", x.Url); 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 = false })); }