コード例 #1
0
        public async Task TestRevokeAsync()
        {
            var store         = new ConsentStore();
            var insertClients = await CassandraTestHelper.InsertTestData_Clients(2);

            // we are going to associate a bunch of tokens to this one client
            var subject = Guid.NewGuid().ToString();

            foreach (var client in insertClients)
            {
                await CassandraTestHelper.InsertTestData_Consents(client.ClientId, subject, 1);
            }

            var result = await store.LoadAllAsync(subject);

            Assert.AreEqual(2, result.Count());

            foreach (var client in insertClients)
            {
                await store.RevokeAsync(subject, client.ClientId);
            }
            result = await store.LoadAllAsync(subject);

            Assert.AreEqual(0, result.Count());
        }
コード例 #2
0
        public async Task Test_Create_Add_RedirectUris_ByClientIdAsync()
        {
            var adminStore = new IdentityServer3AdminStore();
            var insert     = await CassandraTestHelper.InsertTestData_Clients(1);

            var result = await adminStore.FindClientByIdAsync(insert[0].ClientId);

            Assert.IsNotNull(result);
            var original = result.RedirectUris;

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

            List <string> newData = new List <string>()
            {
                Guid.NewGuid().ToString()
            };

            await adminStore.AddRedirectUrisToClientAsync(insert[0].ClientId, newData);

            var finalList = new List <string>();

            finalList.AddRange(original);
            finalList.AddRange(newData);

            result = await adminStore.FindClientByIdAsync(insert[0].ClientId);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.RedirectUris.Count(), finalList.Count);


            var ff = result.RedirectUris.Except(finalList);

            Assert.IsFalse(ff.Any());
        }
コード例 #3
0
        public async Task Test_Create_Add_AllowedCorsOrigins_ByClientIdAsync()
        {
            var adminStore = new IdentityServer3AdminStore();
            var insert     = await CassandraTestHelper.InsertTestData_Clients(1);

            var result = await adminStore.FindClientByIdAsync(insert[0].ClientId);

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

            List <string> allowedCorsOrigins = new List <string>()
            {
                Guid.NewGuid().ToString()
            };

            await adminStore.AddAllowedCorsOriginsToClientAsync(insert[0].ClientId, allowedCorsOrigins);

            var finalList = new List <string>();

            finalList.AddRange(allowedCorsOrigins);
            finalList.AddRange(result.AllowedCorsOrigins);

            result = await adminStore.FindClientByIdAsync(insert[0].ClientId);

            Assert.AreEqual(result.AllowedCorsOrigins.Count(), finalList.Count);


            var ff = result.AllowedCorsOrigins.Except(finalList);

            Assert.IsFalse(ff.Any());
        }
コード例 #4
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);
        }
コード例 #5
0
        public async Task Test_Create_Find_Delete_Scope_Async()
        {
            var dao = new IdentityServer3CassandraDao();
            await dao.EstablishConnectionAsync();

            var insertResult = await CassandraTestHelper.InsertTestData_Scopes(1);

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

            Assert.AreEqual(result.Count(), insertResult.Count);

            var scope = await dao.FindScopeByNameAsync(nameList[0]);

            Assert.IsNotNull(scope);
            Assert.AreEqual(scope.Name, nameList[0]);
            FlattenedScopeRecord fsr = new FlattenedScopeRecord(new FlattenedScopeHandle(scope));

            scope = await dao.FindScopeByIdAsync(fsr.Id);

            Assert.IsNotNull(scope);
            Assert.AreEqual(scope.Name, nameList[0]);

            await dao.DeleteScopeAsync(scope);

            scope = await dao.FindScopeByNameAsync(scope.Name);

            Assert.IsNull(scope);

            scope = await dao.FindScopeByIdAsync(fsr.Id);

            Assert.IsNull(scope);
        }
コード例 #6
0
        public async Task Test_Create_Add_ClientClaims_ByClientIdAsync()
        {
            var adminStore = new IdentityServer3AdminStore();
            var insert     = await CassandraTestHelper.InsertTestData_Clients(1);

            var result = await adminStore.FindClientByIdAsync(insert[0].ClientId);

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

            var original = result.Claims;

            var newClaims = new List <Claim> {
                new Claim(Constants.ClaimTypes.Subject, Guid.NewGuid().ToString()),
                new Claim(Constants.ClaimTypes.PreferredUserName, Guid.NewGuid().ToString()),
            };

            var finalList = new List <Claim>();

            finalList.AddRange(original);
            finalList.AddRange(newClaims);


            await adminStore.AddClaimsToClientAsync(insert[0].ClientId, newClaims);

            result = await adminStore.FindClientByIdAsync(insert[0].ClientId);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Claims.Count(), finalList.Count);

            var ff = result.Claims.Except(finalList, ClaimComparer.DeepComparer);

            Assert.IsFalse(ff.Any());
        }
コード例 #7
0
        public async Task Test_Create_Add_ScopeByClientIdAsync()
        {
            var insert = await CassandraTestHelper.InsertTestData_Clients(1);

            var adminStore = new IdentityServer3AdminStore();
            // await adminStore.CleanupClientByIdAsync(insert[0].ClientId);
            var result = await adminStore.FindClientByIdAsync(insert[0].ClientId);

            var originalAllowedScopes = result.AllowedScopes;

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

            List <Scope> scopes = new List <Scope>()
            {
                new Scope()
                {
                    AllowUnrestrictedIntrospection = true,
                    Name    = Guid.NewGuid().ToString(),
                    Enabled = true
                },
                new Scope()
                {
                    AllowUnrestrictedIntrospection = true,
                    Name    = Guid.NewGuid().ToString(),
                    Enabled = true
                }
            };

            foreach (var scope in scopes)
            {
                await adminStore.CreateScopeAsync(scope);
            }


            var query = from item in scopes
                        let c = item.Name
                                select c;

            List <string> addedScopeNames = query.ToList();
            List <string> finalExpected   = new List <string>();

            finalExpected.AddRange(addedScopeNames);
            finalExpected.AddRange(result.AllowedScopes);

            await adminStore.AddScopesToClientAsync(insert[0].ClientId, addedScopeNames);



            result = await adminStore.FindClientByIdAsync(insert[0].ClientId);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.AllowedScopes.Count(), finalExpected.Count);


            var ff = result.AllowedScopes.Except(finalExpected);

            Assert.IsFalse(ff.Any());
        }
コード例 #8
0
        public async Task Test_CreateClientAsync()
        {
            var adminStore = new IdentityServer3AdminStore();
            var insert     = await CassandraTestHelper.InsertTestData_Clients(1);

            var result = await adminStore.FindClientByIdAsync(insert[0].ClientId);

            Assert.AreEqual(insert[0].ClientName, result.ClientName);
        }
コード例 #9
0
        public async Task TestGetAllAsync()
        {
            var insert = await CassandraTestHelper.InsertTestData_Tokens(10);

            ITokenHandleStore ths = new TokenHandleStore();

            var find_metadata = await ths.GetAllAsync(insert[0].SubjectId);

            Assert.AreEqual(find_metadata.Count(), insert.Count);
        }
コード例 #10
0
        public static async Task <List <FlattenedConsentHandle> > InsertTestData_Consents(int count = 1)
        {
            var insertClients = await CassandraTestHelper.InsertTestData_Clients(1); // only add one client

            // we are going to associate a bunch of tokens to this one client

            var client  = insertClients[0];
            var subject = Guid.NewGuid().ToString();

            return(await InsertTestData_Consents(client.ClientId, subject, count));
        }
コード例 #11
0
        public static async Task <List <FlattenedAuthorizationCodeHandle> > InsertTestData_AuthorizationCode(int count = 1)
        {
            var dao = new IdentityServer3CassandraDao();
            await dao.EstablishConnectionAsync();

            IClientStore clientStore  = new ClientStore();
            var          insertTokens = await CassandraTestHelper.InsertTestData_Tokens(count); // only add one client

            var clientId     = insertTokens[0].ClientId;
            var clientRecord = await clientStore.FindClientByIdAsync(clientId);

            List <FlattenedAuthorizationCodeHandle> result = new List <FlattenedAuthorizationCodeHandle>();
            int i = 0;

            foreach (var insertToken in insertTokens)
            {
                var claimIdentityRecords = new List <ClaimIdentityRecord>()
                {
                    new ClaimIdentityRecord()
                    {
                        AuthenticationType = Constants.PrimaryAuthenticationType,
                        ClaimTypeRecords   = new List <ClaimTypeRecord>()
                        {
                            new ClaimTypeRecord()
                            {
                                Type      = Constants.ClaimTypes.Subject,
                                Value     = "Value:" + i,
                                ValueType = "VALUETYPE:" + i
                            }
                        }
                    }
                };
                FlattenedAuthorizationCodeHandle handle = new FlattenedAuthorizationCodeHandle
                {
                    ClientId        = clientId,
                    SubjectId       = insertToken.SubjectId,
                    Expires         = DateTimeOffset.UtcNow.AddMinutes(5),
                    CreationTime    = DateTimeOffset.UtcNow,
                    IsOpenId        = true,
                    RedirectUri     = "REDIRECTURI/" + i,
                    WasConsentShown = true,
                    Nonce           = "NONCE:" + i,

                    ClaimIdentityRecords = new FlattenedAuthorizationCodeHandle().SerializeClaimsIdentityRecords(claimIdentityRecords),
                    RequestedScopes      = new FlattenedAuthorizationCodeHandle().SerializeRequestScopes(clientRecord.AllowedScopes),
                    Key = Guid.NewGuid().ToString()
                };
                ++i;
                result.Add(handle);
            }
            await dao.CreateManyAuthorizationCodeHandleAsync(result);

            return(result);
        }
コード例 #12
0
        public async Task TestGetAllAsync()
        {
            var insert = await CassandraTestHelper.InsertTestData_AuthorizationCode(10);

            var subjectId = insert[0].SubjectId;
            var clientId  = insert[0].ClientId;
            IAuthorizationCodeStore authStore = new AuthorizationCodeStore();
            var find_metadata = await authStore.GetAllAsync(subjectId);

            Assert.AreEqual(find_metadata.Count(), insert.Count);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        public async Task Test_FindScopesAsync()
        {
            var dao = new IdentityServer3CassandraDao();
            await dao.EstablishConnectionAsync();

            var insertResult = await CassandraTestHelper.InsertTestData_Scopes(1);

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

            Assert.AreEqual(result.Count(), insertResult.Count);
        }
コード例 #15
0
        public async Task TestCreateRefreshTokenHandleAsync()
        {
            var dao = new IdentityServer3CassandraDao();
            await dao.EstablishConnectionAsync();

            IClientStore cs     = new ClientStore();
            var          insert = await CassandraTestHelper.InsertTestData_RefreshTokens(cs);

            foreach (var rth in insert)
            {
                var result = await dao.FindRefreshTokenByKey(rth.Key, cs);

                Assert.AreEqual(result.ClientId, rth.ClientId);
            }
        }
コード例 #16
0
        public async Task Test_Create_Add_Delete_ClientSecrets_ByClientIdAsync()
        {
            var adminStore = new IdentityServer3AdminStore();
            var insert     = await CassandraTestHelper.InsertTestData_Clients(1);

            var result = await adminStore.FindClientByIdAsync(insert[0].ClientId);

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

            var original = result.ClientSecrets;

            List <Secret> newSecrets = new List <Secret>();

            for (int i = 0; i < 2; ++i)
            {
                newSecrets.Add(new Secret()
                {
                    Value       = Guid.NewGuid().ToString(),
                    Description = Guid.NewGuid().ToString(),
                    Expiration  = DateTimeOffset.UtcNow.AddHours(1),
                    Type        = Guid.NewGuid().ToString()
                });
            }
            var finalList = new List <Secret>();

            finalList.AddRange(original);
            finalList.AddRange(newSecrets);

            await adminStore.AddClientSecretsToClientAsync(insert[0].ClientId, newSecrets);

            result = await adminStore.FindClientByIdAsync(insert[0].ClientId);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.ClientSecrets.Count(), finalList.Count);

            var ff = result.ClientSecrets.Except(finalList, SecretComparer.OrdinalIgnoreCase);

            Assert.IsFalse(ff.Any());

            await adminStore.DeleteClientSecretsFromClientAsync(insert[0].ClientId, result.ClientSecrets);

            result = await adminStore.FindClientByIdAsync(insert[0].ClientId);

            Assert.IsNotNull(result);

            Assert.IsFalse(result.ClientSecrets.Any());
        }
コード例 #17
0
        public async Task Test_Create_Add_ScopesSecretsAsync()
        {
            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 secretComparer = SecretComparer.OrdinalIgnoreCase;
            var scopeComparer  = ScopeComparer.OrdinalIgnoreCase;

            var scope       = await insertResult[0].Record.MakeIdentityServerScopeAsync();
            var storedScope = stored.FirstOrDefault();

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

            List <Secret> secrets = new List <Secret>();

            for (int i = 0; i < 2; ++i)
            {
                secrets.Add(new Secret()
                {
                    Value       = Guid.NewGuid().ToString(),
                    Description = Guid.NewGuid().ToString(),
                    Expiration  = DateTimeOffset.UtcNow.AddHours(1),
                    Type        = Guid.NewGuid().ToString()
                });
            }
            List <Secret> expected = storedScope.ScopeSecrets.Union(secrets, SecretComparer.OrdinalIgnoreCase).ToList();
            await adminStore.AddScopeSecretsAsync(insertResult[0].Record.Name, secrets);

            stored = await adminStore.FindScopesAsync(nameList);

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

            var query = from item in storedScope.ScopeSecrets
                        where !expected.Contains(item, secretComparer)
                        select item;
            var finalList = query.ToList();

            Assert.IsTrue(finalList.Count == 0);
        }
コード例 #18
0
        public async Task Test_Create_Add_ScopeClaimsAsync()
        {
            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()
                });
            }
            List <ScopeClaim> expected = storedScope.Claims.Union(claims, ScopeClaimComparer.MinimalScopeClaimComparer).ToList();

            await adminStore.AddScopeClaimsAsync(insertResult[0].Record.Name, claims);

            stored = await adminStore.FindScopesAsync(nameList);

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

            var query = from item in storedScope.Claims
                        where !expected.Contains(item, scopeClaimComparer)
                        select item;
            var finalList = query.ToList();

            Assert.IsTrue(finalList.Count == 0);
        }
コード例 #19
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);
        }
コード例 #20
0
        public async Task TestRemoveAsync()
        {
            var insert = await CassandraTestHelper.InsertTestData_Tokens(1);

            ITokenHandleStore ths = new TokenHandleStore();
            var subjectId         = insert[0].SubjectId;
            var clientId          = insert[0].ClientId;
            var key           = insert[0].Key;
            var find_metadata = await ths.GetAllAsync(subjectId);

            Assert.AreEqual(find_metadata.Count(), insert.Count);

            await ths.RemoveAsync(key);

            find_metadata = await ths.GetAllAsync(subjectId);

            Assert.AreEqual(find_metadata.Count(), 0);
        }
コード例 #21
0
        public async Task TestRemoveAsync()
        {
            var insert = await CassandraTestHelper.InsertTestData_AuthorizationCode(1);

            var subjectId = insert[0].SubjectId;
            var clientId  = insert[0].ClientId;
            var key       = insert[0].Key;
            IAuthorizationCodeStore authStore = new AuthorizationCodeStore();
            var find_metadata = await authStore.GetAsync(key);

            Assert.IsNotNull(find_metadata);

            await authStore.RemoveAsync(key);

            find_metadata = await authStore.GetAsync(key);

            Assert.IsNull(find_metadata);
        }
コード例 #22
0
        public async Task Test_Create_Add_Delete_AllowedCustomGrantTypesByClientIdAsync()
        {
            var adminStore = new IdentityServer3AdminStore();
            var insert     = await CassandraTestHelper.InsertTestData_Clients(1);

            var result = await adminStore.FindClientByIdAsync(insert[0].ClientId);

            Assert.IsNotNull(result);

            var originalAllowedCustomGrantTypes = result.AllowedCustomGrantTypes;

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

            List <string> newAllowedCustomGrantTypes = new List <string>()
            {
                Guid.NewGuid().ToString()
            };
            var finalList = new List <string>();

            finalList.AddRange(originalAllowedCustomGrantTypes);
            finalList.AddRange(newAllowedCustomGrantTypes);

            await adminStore.AddAllowedCustomGrantTypesToClientAsync(insert[0].ClientId, newAllowedCustomGrantTypes);


            result = await adminStore.FindClientByIdAsync(insert[0].ClientId);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.AllowedCustomGrantTypes.Count(), finalList.Count);


            var ff = result.AllowedCustomGrantTypes.Except(finalList);

            Assert.IsFalse(ff.Any());

            await
            adminStore.DeleteAllowedCustomGrantTypesFromClientAsync(insert[0].ClientId,
                                                                    result.AllowedCustomGrantTypes);

            result = await adminStore.FindClientByIdAsync(insert[0].ClientId);

            Assert.IsNotNull(result);
            Assert.IsFalse(result.AllowedCustomGrantTypes.Any());
        }
コード例 #23
0
        public async Task TestRevokeAsync()
        {
            IClientStore cs     = new ClientStore();
            var          insert = await CassandraTestHelper.InsertTestData_RefreshTokens(cs, 10);

            IRefreshTokenStore ths = new RefreshTokenHandleStore();
            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);
        }
コード例 #24
0
        public static async Task <List <FlattenedTokenHandle> > InsertTestData_Tokens(int count = 1)
        {
            var dao = new IdentityServer3CassandraDao();
            await dao.EstablishConnectionAsync();

            var insertClients = await CassandraTestHelper.InsertTestData_Clients(1); // only add one client

            // we are going to associate a bunch of tokens to this one client

            var client    = insertClients[0];
            var subjectId = Guid.NewGuid().ToString();
            List <FlattenedTokenHandle> result = new List <FlattenedTokenHandle>();

            for (int i = 0; i < count; ++i)
            {
                var claims = new List <Claim>()
                {
                    new Claim(Constants.ClaimTypes.Subject, subjectId),
                    new Claim(Constants.ClaimTypes.Name, "Name:" + i)
                };
                var json = JsonConvert.SerializeObject(claims);

                var flat = new FlattenedTokenHandle
                {
                    Key          = Guid.NewGuid().ToString(),
                    Audience     = "Audience:" + i,
                    Claims       = JsonConvert.SerializeObject(claims),
                    ClientId     = client.ClientId,
                    CreationTime = DateTimeOffset.UtcNow,
                    Expires      = DateTimeOffset.UtcNow,
                    Issuer       = "Issuer:" + i,
                    Lifetime     = 1,
                    SubjectId    = subjectId,
                    Type         = "Type:" + i,
                    Version      = 1
                };

                result.Add(flat);
            }
            await dao.CreateManyTokenHandleAsync(result);

            return(result);
        }
コード例 #25
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);
        }
コード例 #26
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);
        }
コード例 #27
0
        async Task TestCreateAsync()
        {
            var insert = await CassandraTestHelper.InsertTestData_Clients(1);

            Assert.IsFalse(true);
        }
コード例 #28
0
        public async Task Test_Create_Modify_ClientAsync()
        {
            var dao = new IdentityServer3CassandraDao();
            await dao.EstablishConnectionAsync();

            var adminStore = new IdentityServer3AdminStore();

            global::IdentityServer3.Core.Models.Client dd = new global::IdentityServer3.Core.Models.Client();
            var insert = await CassandraTestHelper.InsertTestData_Clients(1);

            var result = await adminStore.FindClientByIdAsync(insert[0].ClientId);

            Assert.AreEqual(insert[0].ClientName, result.ClientName);
            int           expectedInt    = 1961;
            string        expectedString = Guid.NewGuid().ToString();
            List <string> expectedList   = new List <string>()
            {
                expectedString
            };

            #region PROPERTY_VALUES

            List <PropertyValue> propertyList = new List <PropertyValue>
            {
                new PropertyValue()
                {
                    Name  = "Claims",
                    Value = new List <Claim>()
                    {
                        new Claim("Type:" + expectedString, "Value:" + expectedString, "ValueType:" + expectedString, "Issuer:" + expectedString, "OriginalIssuer:" + expectedString,
                                  new ClaimsIdentity(new List <Claim>()
                        {
                            new Claim("Type:" + expectedString, "Value:" + expectedString)
                        }))
                    }
                },
                new PropertyValue()
                {
                    Name  = "ClientSecrets",
                    Value = new List <Secret>
                    {
                        new Secret(expectedString.Sha256()),
                    }
                },
                new PropertyValue()
                {
                    Name  = "ClientUri",
                    Value = expectedString
                },
                new PropertyValue()
                {
                    Name  = "ClientName",
                    Value = expectedString
                },
                new PropertyValue()
                {
                    Name  = "AbsoluteRefreshTokenLifetime",
                    Value = expectedInt
                },
                new PropertyValue()
                {
                    Name  = "AccessTokenLifetime",
                    Value = expectedInt
                },
                new PropertyValue()
                {
                    Name  = "AccessTokenType",
                    Value = expectedInt
                },
                new PropertyValue()
                {
                    Name  = "AllowAccessToAllCustomGrantTypes",
                    Value = !result.AllowAccessToAllCustomGrantTypes
                },
                new PropertyValue()
                {
                    Name  = "AllowAccessToAllScopes",
                    Value = !result.AllowAccessToAllScopes
                },
                new PropertyValue()
                {
                    Name  = "AllowAccessTokensViaBrowser",
                    Value = !result.AllowAccessTokensViaBrowser
                },
                new PropertyValue()
                {
                    Name  = "AllowClientCredentialsOnly",
                    Value = !result.AllowClientCredentialsOnly
                },
                new PropertyValue()
                {
                    Name  = "AllowRememberConsent",
                    Value = !result.AllowRememberConsent
                },
                new PropertyValue()
                {
                    Name  = "AlwaysSendClientClaims",
                    Value = !result.AlwaysSendClientClaims
                },
                new PropertyValue()
                {
                    Name  = "AuthorizationCodeLifetime",
                    Value = expectedInt
                },
                new PropertyValue()
                {
                    Name  = "Enabled",
                    Value = !result.Enabled
                },
                new PropertyValue()
                {
                    Name  = "EnableLocalLogin",
                    Value = !result.EnableLocalLogin
                },
                new PropertyValue()
                {
                    Name  = "Flow",
                    Value = expectedInt
                },
                new PropertyValue()
                {
                    Name  = "IdentityTokenLifetime",
                    Value = expectedInt
                },
                new PropertyValue()
                {
                    Name  = "IncludeJwtId",
                    Value = !result.IncludeJwtId
                },
                new PropertyValue()
                {
                    Name  = "LogoutSessionRequired",
                    Value = !result.LogoutSessionRequired
                },
                new PropertyValue()
                {
                    Name  = "LogoutUri",
                    Value = expectedString
                },
                new PropertyValue()
                {
                    Name  = "PrefixClientClaims",
                    Value = !result.PrefixClientClaims
                },
                new PropertyValue()
                {
                    Name  = "RefreshTokenExpiration",
                    Value = expectedInt
                },
                new PropertyValue()
                {
                    Name  = "RefreshTokenUsage",
                    Value = expectedInt
                },
                new PropertyValue()
                {
                    Name  = "RequireConsent",
                    Value = !result.RequireConsent
                },
                new PropertyValue()
                {
                    Name  = "RequireSignOutPrompt",
                    Value = !result.RequireSignOutPrompt
                },
                new PropertyValue()
                {
                    Name  = "SlidingRefreshTokenLifetime",
                    Value = expectedInt
                },
                new PropertyValue()
                {
                    Name  = "UpdateAccessTokenClaimsOnRefresh",
                    Value = !result.UpdateAccessTokenClaimsOnRefresh
                },
                new PropertyValue()
                {
                    Name  = "AllowedCorsOrigins",
                    Value = expectedList
                },
                new PropertyValue()
                {
                    Name  = "AllowedCustomGrantTypes",
                    Value = expectedList
                },
                new PropertyValue()
                {
                    Name  = "AllowedScopes",
                    Value = expectedList
                },
                new PropertyValue()
                {
                    Name  = "IdentityProviderRestrictions",
                    Value = expectedList
                },
                new PropertyValue()
                {
                    Name  = "PostLogoutRedirectUris",
                    Value = expectedList
                },
                new PropertyValue()
                {
                    Name  = "RedirectUris",
                    Value = expectedList
                },
                new PropertyValue()
                {
                    Name  = "LogoUri",
                    Value = expectedString
                },
            };
            #endregion

            await dao.UpdateClientByIdAsync(result.ClientId, propertyList);

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

            foreach (var property in propertyList)
            {
                var castTo      = property.Value.GetType();
                var valueRaw    = result2.GetPropertyValue(property.Name);
                var valueActual = Cast(valueRaw, castTo);

                var valueExpected = property.Value;
                if (castTo == typeof(List <string>))
                {
                    var propertyValue = (List <string>)Convert.ChangeType(property.Value, castTo);
                    var resultValue   = (List <string>)Convert.ChangeType(valueRaw, castTo);
                    Assert.AreEqual(propertyValue.Count, resultValue.Count);
                    var v = from x in propertyValue
                            where !resultValue.Contains(x)
                            select x;
                    Assert.IsFalse(v.Any());
                }
                else if (castTo == typeof(List <Secret>))
                {
                    var propertyValue = (List <Secret>)Convert.ChangeType(property.Value, castTo);
                    var resultValue   = (List <Secret>)Convert.ChangeType(valueRaw, castTo);
                    Assert.AreEqual(propertyValue.Count, resultValue.Count);

                    IEnumerable <Secret> except =
                        propertyValue.Except(resultValue, SecretComparer.OrdinalIgnoreCase);
                    Assert.IsFalse(except.Any());
                }
                else if (castTo == typeof(List <Claim>))
                {
                    var propertyValue = (List <Claim>)Convert.ChangeType(property.Value, castTo);
                    var resultValue   = (List <Claim>)Convert.ChangeType(valueRaw, castTo);
                    Assert.AreEqual(propertyValue.Count, resultValue.Count);

                    IEnumerable <Claim> except =
                        propertyValue.Except(resultValue, ClaimComparer.MinimalComparer);
                    Assert.IsFalse(except.Any());
                }

                else
                {
                    Assert.AreEqual(valueActual, valueExpected);
                }
            }
        }
コード例 #29
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);
        }