Ejemplo n.º 1
0
        public async Task Test_TruncateTablesAsync()
        {
            var dao = new IdentityServer3CassandraDao();
            await dao.EstablishConnectionAsync();

            await dao.TruncateTablesAsync();
        }
Ejemplo n.º 2
0
        public async Task Test_Create_Page_ByScopeIdAsync()
        {
            var dao = new IdentityServer3CassandraDao();
            await dao.EstablishConnectionAsync();

            await dao.TruncateTablesAsync();

            List <Scope> addedScopes = new List <Scope>();
            int          nNumber     = 100;
            var          adminStore  = new IdentityServer3AdminStore();

            for (int i = 0; i < nNumber; ++i)
            {
                addedScopes.Add(await CreateAsync(nNumber));
            }

            var pageSize = 9;

            byte[] pagingState  = null;
            int    runningCount = 0;

            do
            {
                var items = await adminStore.PageScopesAsync(pageSize, pagingState);

                pagingState   = items.PagingState;
                runningCount += items.Count();
            } while (pagingState != null);
            Assert.AreEqual(100, runningCount);
        }
Ejemplo n.º 3
0
        public async Task Test_Create_Page_ByClientIdAsync()
        {
            var dao = new IdentityServer3CassandraDao();
            await dao.EstablishConnectionAsync();

            await dao.TruncateTablesAsync();

            int nNumber    = 100;
            var adminStore = new IdentityServer3AdminStore();
            var insert     = await CassandraTestHelper.InsertTestData_Clients(nNumber);

            foreach (var item in insert)
            {
                var result = await adminStore.FindClientByIdAsync(item.ClientId);

                Assert.IsNotNull(result);
                Assert.AreEqual(item.ClientName, result.ClientName);
            }


            var pageSize = 9;

            byte[] pagingState  = null;
            int    runningCount = 0;

            do
            {
                var items = await adminStore.PageClientsAsync(pageSize, pagingState);

                pagingState   = items.PagingState;
                runningCount += items.Count();
            } while (pagingState != null);
            Assert.AreEqual(100, runningCount);
        }
Ejemplo n.º 4
0
        public async Task TestUpdateAsync()
        {
            var dao = new IdentityServer3CassandraDao();
            await dao.EstablishConnectionAsync();

            var insert = await CassandraTestHelper.InsertTestData_Clients(1);

            var result = await dao.FindClientByClientIdAsync(insert[0].ClientId);

            Assert.AreEqual(insert[0].ClientName, result.ClientName);

            await dao.TruncateTablesAsync();

            result = await dao.FindClientByClientIdAsync(insert[0].ClientId);

            Assert.IsNull(result);
        }
Ejemplo n.º 5
0
        public async Task Test_Create_Add_Update_ScopeClaimsAsync()
        {
            var dao = new IdentityServer3CassandraDao();
            await dao.EstablishConnectionAsync();



            await dao.CreateTablesAsync();

            await dao.TruncateTablesAsync();

            var insertResult = await CassandraTestHelper.InsertTestData_Scopes(1);

            var queryNames = from item in insertResult
                             select item.Record.Name;
            var nameList = queryNames.ToList();

            var adminStore = new IdentityServer3AdminStore();
            var stored     = await adminStore.FindScopesAsync(nameList);

            Assert.AreEqual(stored.Count(), insertResult.Count);
            var scopeClaimComparer = ScopeClaimComparer.MinimalScopeClaimComparer;
            var scopeComparer      = ScopeComparer.OrdinalIgnoreCase;
            var scope       = await insertResult[0].Record.MakeIdentityServerScopeAsync();
            var storedScope = stored.FirstOrDefault();

            Assert.IsTrue(scopeComparer.Equals(scope, storedScope));

            List <ScopeClaim> claims = new List <ScopeClaim>();

            for (int i = 0; i < 2; ++i)
            {
                claims.Add(new ScopeClaim
                {
                    Name = Guid.NewGuid().ToString(),
                    AlwaysIncludeInIdToken = true,
                    Description            = Guid.NewGuid().ToString()
                });
            }
            await adminStore.UpdateScopeByNameAsync(storedScope.Name, new List <PropertyValue>()
            {
                new PropertyValue()
                {
                    Name  = "Claims",
                    Value = claims
                }
            });


            stored = await adminStore.FindScopesAsync(nameList);

            storedScope = stored.FirstOrDefault();
            Assert.IsTrue(scopeComparer.Equals(scope, storedScope));


            var query = from item in storedScope.Claims
                        where !claims.Contains(item, ScopeClaimComparer.DeepScopeClaimComparer)
                        select item;
            var finalList = query.ToList();

            Assert.IsTrue(finalList.Count == 0);

            // Do NOT update name
            foreach (var claim in claims)
            {
                claim.Description            = Guid.NewGuid().ToString();
                claim.AlwaysIncludeInIdToken = !claim.AlwaysIncludeInIdToken;
            }

            await adminStore.UpdateScopeClaimsAsync(storedScope.Name, claims);

            stored = await adminStore.FindScopesAsync(nameList);

            storedScope = stored.FirstOrDefault();
            Assert.IsTrue(scopeComparer.Equals(scope, storedScope));


            query = from item in storedScope.Claims
                    where !claims.Contains(item, ScopeClaimComparer.DeepScopeClaimComparer)
                    select item;

            finalList = query.ToList();
            Assert.IsTrue(finalList.Count == 0);
        }