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 = new TokenParams() { Ttl = TimeSpan.FromHours(2), Timestamp = Now.AddHours(1) }; var customAuthOptions = new AuthOptions() { UseTokenAuth = true }; await testAblyAuth.AuthoriseAsync(customTokenParams, customAuthOptions); var expectedTokenParams = customTokenParams.Clone(); expectedTokenParams.Timestamp = null; testAblyAuth.CurrentTokenParams.ShouldBeEquivalentTo(expectedTokenParams); testAblyAuth.CurrentAuthOptions.Should().BeSameAs(customAuthOptions); testAblyAuth.CurrentAuthOptions.Force.Should().BeFalse(); }
public async Task AuthoriseUseRequestTokenToCreateTokensAndPassesTokenParamsAndAuthOptions() { var client = GetRestClient(); var testAblyAuth = new TestAblyAuth(client.Options, client); var customTokenParams = new TokenParams() { Ttl = TimeSpan.FromHours(2) }; var customAuthOptions = new AuthOptions() { UseTokenAuth = true }; await testAblyAuth.AuthoriseAsync(customTokenParams, customAuthOptions); testAblyAuth.RequestTokenCalled.Should().BeTrue("Token creation was not delegated to RequestToken"); testAblyAuth.LastRequestTokenParams.Should().BeSameAs(customTokenParams); testAblyAuth.LastRequestAuthOptions.Should().BeSameAs(customAuthOptions); }
public async Task Authorize_RestClientAuthoriseMethodsShouldBeMarkedObsoleteAndLogADeprecationWarning() { /* Check for Obsolete Attribute */ MethodBase method = typeof(AblyAuth).GetMethod("Authorise"); method.Should().NotBeNull(); var attr = (ObsoleteAttribute)method?.GetCustomAttribute(typeof(ObsoleteAttribute)); attr.Should().NotBeNull(); method = typeof(AblyAuth).GetMethod("AuthoriseAsync"); method.Should().NotBeNull(); attr = (ObsoleteAttribute)method?.GetCustomAttribute(typeof(ObsoleteAttribute)); attr.Should().NotBeNull(); method = typeof(AblyAuth).GetMethod("Authorize"); method.Should().NotBeNull(); attr = (ObsoleteAttribute)method?.GetCustomAttribute(typeof(ObsoleteAttribute)); attr.Should().BeNull(); method = typeof(AblyAuth).GetMethod("AuthorizeAsync"); method.Should().NotBeNull(); attr = (ObsoleteAttribute)method?.GetCustomAttribute(typeof(ObsoleteAttribute)); attr.Should().BeNull(); #pragma warning disable CS0618 // Type or member is obsolete /* Check for logged warning */ var testLogger1 = new TestLogger("AuthoriseAsync is deprecated and will be removed in the future, please replace with a call to AuthorizeAsync"); var client = GetRestClient(setOptionsAction: options => { options.Logger = testLogger1; }); var testAblyAuth = new TestAblyAuth(client.Options, client); _ = await testAblyAuth.AuthoriseAsync(); testLogger1.MessageSeen.Should().BeTrue(); var testLogger2 = new TestLogger("Authorise is deprecated and will be removed in the future, please replace with a call to Authorize"); client = GetRestClient(setOptionsAction: options => { options.Logger = testLogger2; }); testAblyAuth = new TestAblyAuth(client.Options, client); _ = testAblyAuth.Authorise(); testLogger2.MessageSeen.Should().BeTrue(); #pragma warning restore CS0618 // Type or member is obsolete }
public async Task ShouldKeepTokenParamsAndAuthOptionsExcetpForceAndCurrentTimestamp() { var client = GetRestClient(); var testAblyAuth = new TestAblyAuth(client.Options, client); var customTokenParams = new TokenParams() { Ttl = TimeSpan.FromHours(2), Timestamp = Now.AddHours(1) }; var customAuthOptions = new AuthOptions() { UseTokenAuth = true, Force = true }; await testAblyAuth.AuthoriseAsync(customTokenParams, customAuthOptions); var expectedTokenParams = customTokenParams.Clone(); expectedTokenParams.Timestamp = null; testAblyAuth.CurrentTokenParams.ShouldBeEquivalentTo(expectedTokenParams); testAblyAuth.CurrentAuthOptions.Should().BeSameAs(customAuthOptions); testAblyAuth.CurrentTokenParams.Timestamp.Should().Be(null); testAblyAuth.CurrentAuthOptions.Force.Should().BeFalse(); }