public async Task RealtimeClient_NewInstanceWithExpiredToken_ShouldNotRetryAndHaveError(Protocol protocol) { var helper = new Rsa4Helper(this); var authClient = await GetRestClient(protocol); var almostExpiredToken = await authClient.AblyAuth.RequestTokenAsync(new TokenParams { ClientId = "123", Ttl = TimeSpan.FromMilliseconds(1) }); await Task.Delay(TimeSpan.FromMilliseconds(2)); // Modify the expiry date to fool the client it has a valid token almostExpiredToken.Expires = DateTimeOffset.UtcNow.AddHours(1); // get a realtime client with no key var realtimeClient = await helper.GetRealTimeClientWithRequests(protocol, almostExpiredToken, invalidateKey : true); bool connected = false; realtimeClient.Connection.Once(ConnectionEvent.Connected, (_) => { connected = true; }); // assert that there is no pre-existing error realtimeClient.Connection.ErrorReason.Should().BeNull(); await realtimeClient.WaitForState(ConnectionState.Failed); realtimeClient.Connection.State.Should().Be(ConnectionState.Failed); connected.Should().BeFalse(); realtimeClient.Connection.ErrorReason.Code.Should().Be(ErrorCodes.NoMeansProvidedToRenewAuthToken); helper.Requests.Count.Should().Be(0); }
public async Task RSA4Helper_RestClient_ShouldTrackRequests(Protocol protocol) { var authClient = await GetRestClient(protocol); var token = await authClient.AblyAuth.RequestTokenAsync(new TokenParams { ClientId = "123" }); var helper = new Rsa4Helper(this); var restClient = await helper.GetRestClientWithRequests(protocol, token, invalidateKey : true); helper.Requests.Count.Should().Be(0); await restClient.TimeAsync(); helper.Requests.Count.Should().Be(1); var realtimeClient = await helper.GetRealTimeClientWithRequests(protocol, token, invalidateKey : true); helper.Requests.Count.Should().Be(1); await realtimeClient.RestClient.TimeAsync(); helper.Requests.Count.Should().Be(2); }
public async Task RealtimeClient_ConnectedWithExpiringToken_WhenTokenExpired_ShouldNotRetryAndHaveError(Protocol protocol) { var helper = new Rsa4Helper(this); // Create a token that is valid long enough for a successful connection to occur var authClient = await GetRestClient(protocol); var almostExpiredToken = await authClient.AblyAuth.RequestTokenAsync(new TokenParams { ClientId = "123", Ttl = TimeSpan.FromMilliseconds(8000) }); // get a realtime client with no Key, AuthUrl, or authCallback var realtimeClient = await helper.GetRealTimeClientWithRequests(protocol, almostExpiredToken, invalidateKey : true); await realtimeClient.WaitForState(ConnectionState.Connected); // assert that there is no pre-existing error realtimeClient.Connection.ErrorReason.Should().BeNull(); await realtimeClient.WaitForState(ConnectionState.Failed); realtimeClient.Connection.State.Should().Be(ConnectionState.Failed); realtimeClient.Connection.ErrorReason.Code.Should().Be(ErrorCodes.NoMeansProvidedToRenewAuthToken); helper.Requests.Count.Should().Be(0); }