public async Task TestCreateTokenHandleAsync() { var dao = new IdentityServer3CassandraDao(); await dao.EstablishConnectionAsync(); int i = 0; var claims = new List <Claim>() { new Claim("Type 0:" + i, "Value 0:" + i), new Claim("Type 1:" + i, "Value 1:" + i) }; var json = JsonConvert.SerializeObject(claims); var insert = await CassandraTestHelper.InsertTestData_Clients(1); var flat = new FlattenedTokenHandle { Key = Guid.NewGuid().ToString(), Audience = "Audience:" + i, Claims = JsonConvert.SerializeObject(claims), ClientId = insert[0].ClientId, CreationTime = DateTimeOffset.UtcNow, Expires = DateTimeOffset.UtcNow, Issuer = "Issuer:" + i, Lifetime = 1, SubjectId = "SubjectId:" + i, Type = "Type:" + i, Version = 1 }; IClientStore cs = new ClientStore(); ITokenHandleStore ths = new TokenHandleStore(); var result = await dao.CreateTokenHandleAsync(flat); var result_of_find = await dao.FindTokenByKey(flat.Key, cs); Token tt = result_of_find; Assert.AreEqual(flat.ClientId, result_of_find.ClientId); var newKey = Guid.NewGuid().ToString(); await ths.StoreAsync(newKey, tt); result_of_find = await ths.GetAsync(newKey); Assert.AreEqual(flat.ClientId, result_of_find.ClientId); await ths.RemoveAsync(newKey); result_of_find = await ths.GetAsync(newKey); Assert.AreEqual(result_of_find, null); }
public void GetAsync_WhenCalled_ExpectResponse() { // Arrange var mockCacheConfiguration = new Mock<IConfiguration<RedisCacheConfigurationEntity>>(); mockCacheConfiguration.Setup(r => r.Get).Returns( new RedisCacheConfigurationEntity { CacheDuration = 10, RedisCacheDefaultPrefix = "DEFAULT", UseObjectCompression = false }); var jsonSettingsFactory = new JsonSettingsFactory(new CustomMappersConfiguration()); var cacheManager = new RedisCacheManager<Token>( RedisHelpers.ConnectionMultiplexer, mockCacheConfiguration.Object, jsonSettingsFactory.Create()); var tokenStore = new TokenHandleStore( cacheManager, mockCacheConfiguration.Object); // Act var stopwatch = Stopwatch.StartNew(); var token = tokenStore.GetAsync("Existing").Result; stopwatch.Stop(); // Assert this.WriteTimeElapsed(stopwatch); Assert.That(token, Is.Not.Null); }
public void GetAsync_WhenCalled_ExpectResponse() { // Arrange var mockCacheManager = new Mock<ICacheManager<Token>>(); var mockCacheConfiguration = new Mock<IConfiguration<RedisCacheConfigurationEntity>>(); mockCacheConfiguration.Setup(r => r.Get).Returns(new RedisCacheConfigurationEntity { CacheDuration = 1 }); var keyCallback = default(string); mockCacheManager.Setup(r => r.GetAsync(It.IsAny<string>())) .Callback((string s) => keyCallback = s) .ReturnsAsync(new Token()); var tokenHandleStore = new TokenHandleStore( mockCacheManager.Object, mockCacheConfiguration.Object); // Act var stopwatch = Stopwatch.StartNew(); var authorizationCode = tokenHandleStore.GetAsync("string").Result; stopwatch.Stop(); // Assert this.WriteTimeElapsed(stopwatch); Assert.That(authorizationCode, Is.Not.Null); Assert.That(keyCallback, Is.EqualTo("THS_string")); }
public async Task TestStoreAsync() { try { var subjectSeed = Guid.NewGuid().ToString(); var th = MakeTokenHandle(subjectSeed, 0); TokenHandleRecord tokenHandleRecord = new TokenHandleRecord(th); Guid id = tokenHandleRecord.Id; var key = th.Key; var result = await _tokenHandleStore.GetAsync(key); Assert.IsNull(result); Token token = await th.MakeIdentityServerTokenAsync(_clientStore); await _tokenHandleStore.StoreAsync(key, token); result = await _tokenHandleStore.GetAsync(key); tokenHandleRecord = new TokenHandleRecord(new TokenHandle(key, result)); Assert.AreEqual(tokenHandleRecord.Id, id); } catch (Exception e) { } }
public async Task GetAsync() { //Arrange var sut = new TokenHandleStore(NhibernateSession, ScopeStoreMock.Object, ClientStoreMock.Object); var testKey = Guid.NewGuid().ToString(); var testCode = ObjectCreator.GetTokenHandle(); var tokenHandle = new Token { Key = testKey, SubjectId = testCode.SubjectId, ClientId = testCode.ClientId, JsonCode = ConvertToJson(testCode), Expiry = DateTime.UtcNow.AddSeconds(testCode.Client.AuthorizationCodeLifetime), TokenType = TokenType.TokenHandle }; SetupScopeStoreMock(); ExecuteInTransaction(session => { session.Save(tokenHandle); }); //Act var token = await sut.GetAsync(testKey); //Assert Assert.NotNull(token); //CleanUp ExecuteInTransaction(session => { session.Delete(tokenHandle); }); }