public async Task RevokeAsync() { //Arrange var sut = new TokenHandleStore(NhibernateSession, ScopeStoreMock.Object, ClientStoreMock.Object); var subjectIdToRevoke = Guid.NewGuid().ToString(); var clientIdToRevoke = Guid.NewGuid().ToString(); 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 }; var testKeyToRevoke = Guid.NewGuid().ToString(); var testCodeToRevoke = ObjectCreator.GetTokenHandle(subjectIdToRevoke, clientIdToRevoke); var tokenHandleToRevoke = new Token { Key = testKeyToRevoke, SubjectId = testCodeToRevoke.SubjectId, ClientId = testCodeToRevoke.ClientId, JsonCode = ConvertToJson(testCodeToRevoke), Expiry = DateTime.UtcNow.AddSeconds(testCodeToRevoke.Client.AuthorizationCodeLifetime), TokenType = TokenType.TokenHandle }; ExecuteInTransaction(session => { session.Save(tokenHandle); session.Save(tokenHandleToRevoke); }); //Act await sut.RevokeAsync(subjectIdToRevoke, clientIdToRevoke); ExecuteInTransaction(session => { //Assert var tokenRevoked = session.Query <Token>() .SingleOrDefault(t => t.TokenType == TokenType.TokenHandle && t.Key == testKeyToRevoke); var tokenNotRevoked = session.Query <Token>() .SingleOrDefault(t => t.TokenType == TokenType.TokenHandle && t.Key == testKey); Assert.Null(tokenRevoked); Assert.NotNull(tokenNotRevoked); //CleanUp session.Delete(tokenNotRevoked); }); }
public void TestRevokeAsync() { var insert = InsertTestData(_clientStore, _scopeStore, _tokenHandleStore, 10); Guid id = insert[0].Id; var key = insert[0].Record.Key; var result = _tokenHandleStore.GetAsync(key); Assert.IsNotNull(result.Result); Assert.AreEqual(result.Result.ClientId, insert[0].Record.ClientId); var subject = insert[0].Record.SubjectId; var clientId = result.Result.ClientId; _tokenHandleStore.RevokeAsync(subject, clientId); result = _tokenHandleStore.GetAsync(key); Assert.IsNull(result.Result); }
public async Task TestRevokeAsync() { var insert = await CassandraTestHelper.InsertTestData_Tokens(10); ITokenHandleStore ths = new TokenHandleStore(); var subjectId = insert[0].SubjectId; var clientId = insert[0].ClientId; var find_metadata = await ths.GetAllAsync(subjectId); Assert.AreEqual(find_metadata.Count(), insert.Count); await ths.RevokeAsync(subjectId, clientId); find_metadata = await ths.GetAllAsync(subjectId); Assert.AreEqual(find_metadata.Count(), 0); }
public void RevokeAsync_WhenCalled_ExpectThrows() { // Arrange var mockCacheManager = new Mock<ICacheManager<Token>>(); var mockCacheConfiguration = new Mock<IConfiguration<RedisCacheConfigurationEntity>>(); mockCacheConfiguration.Setup(r => r.Get).Returns(new RedisCacheConfigurationEntity { CacheDuration = 1 }); var tokenHandleStore = new TokenHandleStore( mockCacheManager.Object, mockCacheConfiguration.Object); // Act and Assert var stopwatch = Stopwatch.StartNew(); Assert.Throws<NotImplementedException>( () => tokenHandleStore.RevokeAsync("string", "string").GetAwaiter().GetResult()); stopwatch.Stop(); this.WriteTimeElapsed(stopwatch); }