public async Task WithDefaultTokenParams_ShouldSetTokenRequestValuesCorrectly()
            {
                var client = GetClientWithTokenParams();

                var request = await client.Auth.CreateTokenRequestAsync();

                request.Capability.Should().Be(Capability.AllowAll);
                request.ClientId.Should().Be("123");
                request.KeyName.Should().Be(ApiKey.Parse(client.Options.Key).KeyName);
                request.Ttl.Should().Be(TimeSpan.FromHours(2));
                request.Timestamp.Should().Be(Now.AddMinutes(1));
                request.Nonce.Should().Be("defaultnonce");
            }
Example #2
0
            public async Task WithDefaultTokenParams_ShouldSetTokenRequestValuesCorrectly()
            {
                var client = GetClientWithTokenParams();

                var request = await CreateTokenRequest(client);

                request.Capability.Should().Be(Capability.AllowAll);
                request.ClientId.Should().Be("123");
                request.KeyName.Should().Be(ApiKey.Parse(client.Options.Key).KeyName);
                request.Ttl.Should().Be(TimeSpan.FromHours(2));
                Debug.Assert(request.Timestamp.HasValue, "Expected a 'Value', got none.");
                request.Timestamp.Value.Should().BeCloseTo(Now.AddMinutes(1), TimeSpan.FromMilliseconds(100));
                request.Nonce.Should().Be("defaultnonce");
            }
Example #3
0
 private AblyRest GetClientWithTokenParams()
 {
     return(GetRestClient(null, options =>
     {
         options.DefaultTokenParams = new TokenParams
         {
             Ttl = TimeSpan.FromHours(2),
             Capability = Capability.AllowAll,
             ClientId = "123",
             Timestamp = Now.AddMinutes(1),
             Nonce = "defaultnonce"
         };
     }));
 }
            public async Task WithOverrideTokenParams_ShouldSetTokenRequestValuesCorrectly()
            {
                var client = GetClientWithTokenParams();

                var overridingTokenParams = new TokenParams()
                {
                    Ttl        = TimeSpan.FromHours(1),
                    ClientId   = "999",
                    Capability = new Capability(),
                    Nonce      = "overrideNonce",
                    Timestamp  = Now.AddMinutes(10)
                };

                var request = await client.Auth.CreateTokenRequestAsync(overridingTokenParams);

                request.Capability.Should().Be(Capability.Empty);
                request.ClientId.Should().Be("999");
                request.Ttl.Should().Be(TimeSpan.FromHours(1));
                request.Timestamp.Should().Be(Now.AddMinutes(10));
                request.Nonce.Should().Be("overrideNonce");
            }
Example #5
0
            public async Task WithOverrideTokenParams_ShouldSetTokenRequestValuesCorrectly()
            {
                var client = GetClientWithTokenParams();

                var overridingTokenParams = new TokenParams
                {
                    Ttl        = TimeSpan.FromHours(1),
                    ClientId   = "999",
                    Capability = new Capability(),
                    Nonce      = "overrideNonce",
                    Timestamp  = Now.AddMinutes(10)
                };

                var request = await CreateTokenRequest(client, overridingTokenParams);

                request.Capability.Should().Be(Capability.Empty);
                request.ClientId.Should().Be("999");
                request.Ttl.Should().Be(TimeSpan.FromHours(1));
                Debug.Assert(request.Timestamp.HasValue, "Expected a 'Value', got none.");
                request.Timestamp.Value.Should().BeCloseTo(Now.AddMinutes(10), TimeSpan.FromMilliseconds(500));
                request.Nonce.Should().Be("overrideNonce");
            }