public void WithKeyAndClientId_ShouldUseBasicAuth() { var client = new AblyRest(new ClientOptions { Key = ValidKey, ClientId = "123" }); client.AblyAuth.AuthMethod.Should().Be(AuthMethod.Basic); }
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); }
public async void WithOutKeyValueThrowsException() { var client = new AblyRest(new ClientOptions() { Key = "111.222" }); await Assert.ThrowsAsync <AblyException>(() => client.Auth.CreateTokenRequestAsync(null, null)); }
public void WithTokenOnly_SetsTokenRenewableToFalse() { var rest = new AblyRest(new ClientOptions { Token = "token_id" }); rest.AblyAuth.TokenRenewable.Should().BeFalse(); }
public void WithKeyAndClientId_ShouldUseTokenAuth() { var client = new AblyRest(new ClientOptions { Key = ValidKey, ClientId = "123" }); Assert.Equal(AuthMethod.Token, client.AblyAuth.AuthMethod); }
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); }
public void WhenMsgPackIsDisabled_AndUseBinaryIsTrue_ProtocolIsSetToJson() { var rest = new AblyRest(new ClientOptions { UseBinaryProtocol = true, Key = "best.test:key" }); rest.Protocol.Should().Be(Protocol.Json); }
public void WhenUseBinaryIsFalse_ProtocolIsSetToJson() { var rest = new AblyRest(new ClientOptions { UseBinaryProtocol = false, Key = "best.test:key" }); rest.Protocol.Should().Be(Protocol.Json); }
public void WithAuthUrl_SetsTokenRenewableToTrue() { var rest = new AblyRest(new ClientOptions { AuthUrl = new Uri("http://boo") }); rest.AblyAuth.TokenRenewable.Should().BeTrue(); }
public void WithAuthCallback_SetsTokenRenewableToTrue() { var rest = new AblyRest(new ClientOptions { AuthCallback = token => Task.FromResult <object>(new TokenDetails()) }); rest.AblyAuth.TokenRenewable.Should().BeTrue(); }
public TestAblyAuth(ClientOptions options, AblyRest rest, Func <Task <DateTimeOffset> > serverTimeFunc = null) : base(options, rest) { if (serverTimeFunc != null) { ServerTime = serverTimeFunc; } }
public void WithUseTokenAuthSetToTrue_AuthMethodIsAlwaysTokenAuth() { var client = new AblyRest(new ClientOptions { Key = ValidKey, UseTokenAuth = true }); client.AblyAuth.AuthMethod.Should().Be(AuthMethod.Token); }
public void ShouldInitialiseAblyHttpClientWithCorrectTlsValue(bool tls) { var client = new AblyRest(new ClientOptions(ValidKey) { Tls = tls }); client.HttpClient.Options.IsSecure.Should().Be(tls); }
public void WithLogHandler_ShouldUseNewLogHandler() { _ = new AblyRest(new ClientOptions(ValidKey) { LogHandler = new TestLogHandler() }); Logger.LoggerSink.Should().BeOfType <TestLogHandler>(); }
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); }
public void WithAuthCallback_ShouldUseTokenAuth() { var client = new AblyRest(opts => { opts.AuthCallback = @params => Task.FromResult <object>(new TokenDetails()); }); client.AblyAuth.AuthMethod.Should().Be(AuthMethod.Token); }
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}"); }
public void WhenProtocolIsJson_RestProtocolIsSetToJson() { var rest = new AblyRest(new ClientOptions() { UseBinaryProtocol = false }); rest.Protocol.Should().Be(Protocol.Json); }
public void WithTokenDetailsButNoWayToRenew_ShouldLogErrorMessageWithError() { var testLogger = new TestLogger(NoMeansProvidedToRenewAuthToken); _ = new AblyRest(new ClientOptions { TokenDetails = new TokenDetails("test"), Logger = testLogger }); testLogger.MessageSeen.Should().BeTrue(); }
public void WhenProtocolIsMsgPack_ProtocolIsSetToMsgPack() { var rest = new AblyRest(new ClientOptions() { UseBinaryProtocol = true }); rest.Protocol.Should().Be(Defaults.Protocol); }
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); }
public void WhenClientIdInOptions_ShouldPassClientIdToAblyAuth() { var options = new ClientOptions(ValidKey) { ClientId = "123" }; var client = new AblyRest(options); client.AblyAuth.ClientId.Should().Be(options.ClientId); }
public void WithTokenAndClientId_InitializesClient() { var client = new AblyRest(opts => { opts.Token = "blah"; opts.ClientId = "123"; }); client.AblyAuth.AuthMethod.Should().Be(AuthMethod.Token); }
public void WithToken_ShouldUseTokenAuth() { var client = new AblyRest(opts => { opts.Key = "test.best:rest"; opts.Token = "blah"; }); client.AblyAuth.AuthMethod.Should().Be(AuthMethod.Token); }
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"); }
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); }
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); }
public void WithTokenAndClientId_InitializesClient() { var client = new AblyRest(opts => { opts.Token = "blah"; opts.ClientId = "123"; }); Assert.Equal(AuthMethod.Token, client.AblyAuth.AuthMethod); }
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); }
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); }