コード例 #1
0
            public void WithKeyAndClientId_ShouldUseBasicAuth()
            {
                var client = new AblyRest(new ClientOptions {
                    Key = ValidKey, ClientId = "123"
                });

                client.AblyAuth.AuthMethod.Should().Be(AuthMethod.Basic);
            }
コード例 #2
0
        public static void RestGenerateRandomKey()
        {
            var rest = new AblyRest("{{API_KEY}}");

            byte[] key     = Crypto.GenerateRandomKey(128);
            var    options = new ChannelOptions(key);
            var    channel = rest.Channels.Get("{{RANDOM_CHANNEL_NAME}}", options);
        }
コード例 #3
0
 public async void WithOutKeyValueThrowsException()
 {
     var client = new AblyRest(new ClientOptions()
     {
         Key = "111.222"
     });
     await Assert.ThrowsAsync <AblyException>(() => client.Auth.CreateTokenRequestAsync(null, null));
 }
コード例 #4
0
            public void WithTokenOnly_SetsTokenRenewableToFalse()
            {
                var rest = new AblyRest(new ClientOptions {
                    Token = "token_id"
                });

                rest.AblyAuth.TokenRenewable.Should().BeFalse();
            }
コード例 #5
0
ファイル: RestInitSpecs.cs プロジェクト: withakay/ably-dotnet
            public void WithKeyAndClientId_ShouldUseTokenAuth()
            {
                var client = new AblyRest(new ClientOptions {
                    Key = ValidKey, ClientId = "123"
                });

                Assert.Equal(AuthMethod.Token, client.AblyAuth.AuthMethod);
            }
コード例 #6
0
        public async Task RestGenerateRandomKey()
        {
            AblyRest rest = new AblyRest("{{API_KEY}}");

            byte[]         key     = Crypto.GenerateRandomKey(128);
            ChannelOptions options = new ChannelOptions(key);
            var            channel = rest.Channels.Get("{{RANDOM_CHANNEL_NAME}}", options);
        }
コード例 #7
0
        public void WhenMsgPackIsDisabled_AndUseBinaryIsTrue_ProtocolIsSetToJson()
        {
            var rest = new AblyRest(new ClientOptions {
                UseBinaryProtocol = true, Key = "best.test:key"
            });

            rest.Protocol.Should().Be(Protocol.Json);
        }
コード例 #8
0
        public void WhenUseBinaryIsFalse_ProtocolIsSetToJson()
        {
            var rest = new AblyRest(new ClientOptions {
                UseBinaryProtocol = false, Key = "best.test:key"
            });

            rest.Protocol.Should().Be(Protocol.Json);
        }
コード例 #9
0
            public void WithAuthUrl_SetsTokenRenewableToTrue()
            {
                var rest = new AblyRest(new ClientOptions {
                    AuthUrl = new Uri("http://boo")
                });

                rest.AblyAuth.TokenRenewable.Should().BeTrue();
            }
コード例 #10
0
            public void WithAuthCallback_SetsTokenRenewableToTrue()
            {
                var rest = new AblyRest(new ClientOptions {
                    AuthCallback = token => Task.FromResult <object>(new TokenDetails())
                });

                rest.AblyAuth.TokenRenewable.Should().BeTrue();
            }
コード例 #11
0
ファイル: TestAblyAuth.cs プロジェクト: ably/ably-dotnet
 public TestAblyAuth(ClientOptions options, AblyRest rest, Func <Task <DateTimeOffset> > serverTimeFunc = null)
     : base(options, rest)
 {
     if (serverTimeFunc != null)
     {
         ServerTime = serverTimeFunc;
     }
 }
コード例 #12
0
            public void WithUseTokenAuthSetToTrue_AuthMethodIsAlwaysTokenAuth()
            {
                var client = new AblyRest(new ClientOptions {
                    Key = ValidKey, UseTokenAuth = true
                });

                client.AblyAuth.AuthMethod.Should().Be(AuthMethod.Token);
            }
コード例 #13
0
        public void ShouldInitialiseAblyHttpClientWithCorrectTlsValue(bool tls)
        {
            var client = new AblyRest(new ClientOptions(ValidKey)
            {
                Tls = tls
            });

            client.HttpClient.Options.IsSecure.Should().Be(tls);
        }
コード例 #14
0
ファイル: RestSpecs.cs プロジェクト: ably/ably-dotnet
            public void WithLogHandler_ShouldUseNewLogHandler()
            {
                _ = new AblyRest(new ClientOptions(ValidKey)
                {
                    LogHandler = new TestLogHandler()
                });

                Logger.LoggerSink.Should().BeOfType <TestLogHandler>();
            }
コード例 #15
0
        public void WhenProtocolIsNotDefined_AndMsgPackDisabled_DefaultsToJson()
        {
            Defaults.Protocol.Should().Be(Protocol.Json);
            var rest = new AblyRest(new ClientOptions {
                Key = "best.test:key"
            });

            rest.Protocol.Should().Be(Protocol.Json);
        }
コード例 #16
0
            public void WithAuthCallback_ShouldUseTokenAuth()
            {
                var client = new AblyRest(opts =>
                {
                    opts.AuthCallback = @params => Task.FromResult <object>(new TokenDetails());
                });

                client.AblyAuth.AuthMethod.Should().Be(AuthMethod.Token);
            }
コード例 #17
0
        public static async Task RestStatsSamples()
        {
            var rest = new AblyRest("{{API_KEY}}");
            PaginatedResult <Stats> results = await rest.StatsAsync(new StatsRequestParams { Unit = StatsIntervalGranularity.Hour });

            Stats thisHour = results.Items[0];

            Console.WriteLine($"Published this hour {thisHour.Inbound.All.All.Count}");
        }
コード例 #18
0
        public void WhenProtocolIsJson_RestProtocolIsSetToJson()
        {
            var rest = new AblyRest(new ClientOptions()
            {
                UseBinaryProtocol = false
            });

            rest.Protocol.Should().Be(Protocol.Json);
        }
コード例 #19
0
            public void WithTokenDetailsButNoWayToRenew_ShouldLogErrorMessageWithError()
            {
                var testLogger = new TestLogger(NoMeansProvidedToRenewAuthToken);

                _ = new AblyRest(new ClientOptions {
                    TokenDetails = new TokenDetails("test"), Logger = testLogger
                });
                testLogger.MessageSeen.Should().BeTrue();
            }
コード例 #20
0
        public void WhenProtocolIsMsgPack_ProtocolIsSetToMsgPack()
        {
            var rest = new AblyRest(new ClientOptions()
            {
                UseBinaryProtocol = true
            });

            rest.Protocol.Should().Be(Defaults.Protocol);
        }
コード例 #21
0
            public void WithTokenDetails_ShouldUseTokenAuth()
            {
                var client = new AblyRest(opts =>
                {
                    opts.Key          = "test.best:rest";
                    opts.TokenDetails = new TokenDetails("123");
                });

                client.AblyAuth.AuthMethod.Should().Be(AuthMethod.Token);
            }
コード例 #22
0
            public void WhenClientIdInOptions_ShouldPassClientIdToAblyAuth()
            {
                var options = new ClientOptions(ValidKey)
                {
                    ClientId = "123"
                };
                var client = new AblyRest(options);

                client.AblyAuth.ClientId.Should().Be(options.ClientId);
            }
コード例 #23
0
ファイル: RestSpecs.cs プロジェクト: ably/ably-dotnet
            public void WithTokenAndClientId_InitializesClient()
            {
                var client = new AblyRest(opts =>
                {
                    opts.Token    = "blah";
                    opts.ClientId = "123";
                });

                client.AblyAuth.AuthMethod.Should().Be(AuthMethod.Token);
            }
コード例 #24
0
            public void WithToken_ShouldUseTokenAuth()
            {
                var client = new AblyRest(opts =>
                {
                    opts.Key   = "test.best:rest";
                    opts.Token = "blah";
                });

                client.AblyAuth.AuthMethod.Should().Be(AuthMethod.Token);
            }
コード例 #25
0
            public void WithKeyNoClientIdAndAuthToken_ShouldSetCurrentToken()
            {
                ClientOptions options = new ClientOptions {
                    Key = ValidKey, ClientId = "123", Token = "blah"
                };
                var client = new AblyRest(options);

                client.AblyAuth.AuthMethod.Should().Be(AuthMethod.Token);
                client.AblyAuth.CurrentToken.Token.Should().Be("blah");
            }
コード例 #26
0
        public AblyAuthController()
        {
            var key = Environment.GetEnvironmentVariable("ABLY_API_KEY");

            if (string.IsNullOrEmpty(key))
            {
                throw new Exception("ABLY_API_KEY environment variable needs to be set before running this app!");
            }
            _client = new AblyRest(key);
        }
コード例 #27
0
            private AblyRest CreateClient(Action <ClientOptions> optionsClient)
            {
                var options = new ClientOptions(ValidKey);

                optionsClient?.Invoke(options);
                var client = new AblyRest(options);

                client.HttpClient.CreateInternalHttpClient(TimeSpan.FromSeconds(10), _handler);
                return(client);
            }
コード例 #28
0
            public void WithTokenAndClientId_InitializesClient()
            {
                var client = new AblyRest(opts =>
                {
                    opts.Token    = "blah";
                    opts.ClientId = "123";
                });

                Assert.Equal(AuthMethod.Token, client.AblyAuth.AuthMethod);
            }
コード例 #29
0
            public void WithAuthUrl_ShouldUseTokenAuth()
            {
                var client = new AblyRest(opts =>
                {
                    opts.Key     = "test.best:rest";
                    opts.AuthUrl = new Uri("http://authUrl");
                });

                client.AblyAuth.AuthMethod.Should().Be(AuthMethod.Token);
            }
コード例 #30
0
ファイル: RestSpecs.cs プロジェクト: ably/ably-dotnet
            public async Task WhenUsingAFallbackHost_AfterFallbackRetryTimeoutPasses_ShouldRetryMainHost()
            {
                DateTimeOffset        now     = DateTimeOffset.UtcNow;
                Func <DateTimeOffset> nowFunc = () => now;
                var options = new ClientOptions(ValidKey)
                {
                    FallbackRetryTimeout = TimeSpan.FromSeconds(10), NowFunc = nowFunc
                };
                var client       = new AblyRest(options);
                var requestCount = 0;

                _response.StatusCode = HttpStatusCode.BadGateway;

                HttpResponseMessage GetResponse(HttpRequestMessage unused)
                {
                    try
                    {
                        switch (requestCount)
                        {
                        case 0:
                            return(new HttpResponseMessage(HttpStatusCode.BadGateway));

                        case 1:
                            return(new HttpResponseMessage(HttpStatusCode.OK));

                        case 2:
                            now = now.AddSeconds(20);
                            return(new HttpResponseMessage(HttpStatusCode.OK));

                        default:
                            return(new HttpResponseMessage(HttpStatusCode.OK));
                        }
                    }
                    finally
                    {
                        requestCount++;
                    }
                }

                var handler = new FakeHttpMessageHandler(GetResponse);

                client.HttpClient.CreateInternalHttpClient(TimeSpan.FromSeconds(6), handler);

                MakeAnyRequest(client);                // This will generate 2 requests - 1 failed and 1 succeed
                MakeAnyRequest(client);                // This will generate 1 request which should be using fallback host
                MakeAnyRequest(client);                // This will generate 1 request which should be back to the default host

                handler.Requests.Count.Should().Be(4); // First attempt is with rest.ably.io
                var attemptedHosts = handler.Requests.Select(x => x.RequestUri.Host).ToList();

                attemptedHosts[0].Should().Be(Defaults.RestHost);
                attemptedHosts[1].Should().BeOneOf(Defaults.FallbackHosts);
                attemptedHosts[2].Should().BeOneOf(Defaults.FallbackHosts);
                attemptedHosts[3].Should().Be(Defaults.RestHost);
            }