コード例 #1
0
ファイル: AuthSandboxSpecs.cs プロジェクト: ably/ably-dotnet
        public IEnumerator RealtimeClient_ConnectedWithExpiringToken_WhenTokenExpired_ShouldNotRetryAndHaveError([ValueSource(nameof(_protocols))] Protocol protocol)
        {
            return(UniTask.ToCoroutine(async() =>
            {
                var helper = new RSA4Helper(this);

                // Create a token that is valid long enough for a successful connection to occur
                var authClient = await AblySandbox.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);
            }));
        }
コード例 #2
0
ファイル: AuthSandboxSpecs.cs プロジェクト: ably/ably-dotnet
        public IEnumerator RealtimeClient_NewInstanceWithExpiredToken_ShouldNotRetryAndHaveError([ValueSource(nameof(_protocols))] Protocol protocol)
        {
            return(UniTask.ToCoroutine(async() =>
            {
                var helper = new RSA4Helper(this);
                var authClient = await AblySandbox.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);
            }));
        }
コード例 #3
0
ファイル: AuthSandboxSpecs.cs プロジェクト: ably/ably-dotnet
 public IEnumerator RSA4Helper_RestClient_ShouldTrackRequests([ValueSource(nameof(_protocols))] Protocol protocol)
 {
     return(UniTask.ToCoroutine(async() =>
     {
         var authClient = await AblySandbox.GetRestClient(protocol);
         var token = await authClient.Auth.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);
     }));
 }