public async Task LoadAsync()
        {
            string subjectToGet = "subject1";
            string clientToGet  = "client1";

            //Arrange
            var sut          = new ConsentStore(NhibernateSession);
            var testConsent1 = ObjectCreator.GetConsent(clientToGet, subjectToGet);
            var testConsent2 = ObjectCreator.GetConsent();
            var testConsent3 = ObjectCreator.GetConsent();

            ExecuteInTransaction(session =>
            {
                session.Save(testConsent1);
                session.Save(testConsent2);
                session.Save(testConsent3);
            });

            //Act
            var result = await sut.LoadAsync(testConsent1.Subject, testConsent1.ClientId);

            //Assert
            Assert.NotNull(result);
            Assert.True(result.ClientId.Equals(testConsent1.ClientId) &&
                        result.Subject.Equals(testConsent1.Subject));

            //CleanUp
            ExecuteInTransaction(session =>
            {
                session.Delete(testConsent1);
                session.Delete(testConsent2);
                session.Delete(testConsent3);
            });
        }
        public async Task RevokeAsync()
        {
            //Arrange
            var sut             = new ConsentStore(NhibernateSession);
            var testConsent1    = ObjectCreator.GetConsent();
            var testConsent2    = ObjectCreator.GetConsent();
            var testConsent3    = ObjectCreator.GetConsent();
            var consentToRevoke = ObjectCreator.GetConsent();

            ExecuteInTransaction(session =>
            {
                session.Save(testConsent1);
                session.Save(testConsent2);
                session.Save(testConsent3);
                session.Save(consentToRevoke);
            });

            //Act
            await sut.RevokeAsync(consentToRevoke.Subject, consentToRevoke.ClientId);

            //Assert
            var revokedConsent = await sut.LoadAsync(consentToRevoke.Subject, consentToRevoke.ClientId);

            Assert.Null(revokedConsent);

            //CleanUp
            ExecuteInTransaction(session =>
            {
                session.Delete(testConsent1);
                session.Delete(testConsent2);
                session.Delete(testConsent3);
            });
        }
        public void TestCreateAsync()
        {
            string testData = System.IO.File.ReadAllText(Path.Combine(TargetFolder, @"clients.json"));

            Consent consent = new Consent()
            {
                ClientId = "CLIENTID", Scopes = new List <string>()
                {
                    "a", "b"
                }, Subject = "SUBJECT"
            };
            ConsentRecord consentRecord = new ConsentRecord(new ConsentHandle(consent));

            _consentStore.CreateAsync(consentRecord.Record);

            var           result = _consentStore.LoadAsync(consent.Subject, consent.ClientId);
            ConsentRecord consentRecordStored = new ConsentRecord(new ConsentHandle(result.Result));


            Assert.AreEqual(consentRecord.Id, consentRecordStored.Id);
        }
        public async Task UpdateAsync_WithUpdatedScopes()
        {
            //Arrange
            var sut          = new ConsentStore(NhibernateSession);
            var testConsent1 = ObjectCreator.GetConsent();
            var testConsent2 = ObjectCreator.GetConsent();
            var testConsent3 = ObjectCreator.GetConsent();

            ExecuteInTransaction(session =>
            {
                session.Save(testConsent1);
                session.Save(testConsent2);
                session.Save(testConsent3);
            });

            var modelToUpdate = await sut.LoadAsync(testConsent1.Subject, testConsent1.ClientId);

            modelToUpdate.Scopes = ObjectCreator.GetScopes(5).Select(s => s.Name);

            //Act
            await sut.UpdateAsync(modelToUpdate);

            //Assert
            var updatedModel = await sut.LoadAsync(modelToUpdate.Subject, modelToUpdate.ClientId);

            Assert.NotNull(updatedModel);
            Assert.True(updatedModel.Scopes.Count() == 5);

            //CleanUp
            ExecuteInTransaction(session =>
            {
                session.Delete(testConsent1);
                session.Delete(testConsent2);
                session.Delete(testConsent3);
            });
        }
Exemplo n.º 5
0
        public async Task TestCreateTokenHandleAsync()
        {
            var dao = new IdentityServer3CassandraDao();
            await dao.EstablishConnectionAsync();

            var store = new ConsentStore();

            var insert = await CassandraTestHelper.InsertTestData_Consents(1);

            var flat = insert[0];
            FlattenedConsentRecord fcr = new FlattenedConsentRecord(flat);
            var result = await dao.FindConsentByIdAsync(fcr.Id);

            Assert.AreEqual(result.ClientId, flat.ClientId);
            Assert.AreEqual(result.Subject, flat.Subject);

            result = await store.LoadAsync(flat.Subject, flat.ClientId);

            Assert.AreEqual(result.ClientId, flat.ClientId);
            Assert.AreEqual(result.Subject, flat.Subject);
        }
        public async Task UpdateAsync_WithNewId()
        {
            var updatedClientId = "updatedClientId";

            //Arrange
            var sut          = new ConsentStore(NhibernateSession);
            var testConsent1 = ObjectCreator.GetConsent();
            var testConsent2 = ObjectCreator.GetConsent();
            var testConsent3 = ObjectCreator.GetConsent();

            ExecuteInTransaction(session =>
            {
                session.Save(testConsent1);
                session.Save(testConsent2);
                session.Save(testConsent3);
            });

            var modelToUpdate = await sut.LoadAsync(testConsent1.Subject, testConsent1.ClientId);

            //Act
            modelToUpdate.ClientId = updatedClientId;
            await sut.UpdateAsync(modelToUpdate);

            ExecuteInTransaction(session =>
            {
                //Assert
                var updatedEntity = session.Query <IdentityServer3.Contrib.Nhibernate.Entities.Consent>()
                                    .SingleOrDefault(c => c.ClientId == modelToUpdate.ClientId && c.Subject == modelToUpdate.Subject);

                Assert.NotNull(updatedEntity);

                //CleanUp
                session.Delete(testConsent1);
                session.Delete(testConsent2);
                session.Delete(testConsent3);
                session.Delete(updatedEntity);
            });
        }
Exemplo n.º 7
0
        public async Task TestUpdateAsync()
        {
            var store         = new ConsentStore();
            var insertClients = await CassandraTestHelper.InsertTestData_Clients(1);

            var     client  = insertClients[0];
            Consent consent = new Consent()
            {
                ClientId = client.ClientId,
                Scopes   = new List <string>()
                {
                    "Scope 0:",
                    "Scope 1:"
                },
                Subject = Guid.NewGuid().ToString()
            };
            await store.UpdateAsync(consent);

            var result = await store.LoadAsync(consent.Subject, consent.ClientId);

            Assert.AreEqual(consent.ClientId, result.ClientId);
            Assert.AreEqual(consent.Subject, result.Subject);
        }