コード例 #1
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);
        }
コード例 #2
0
        public async Task Test_Find_Scope_by_ID_Async()
        {
            var dao = new IdentityServer3CassandraDao();
            await dao.EstablishConnectionAsync();

            var actualScope1 = new Scope()
            {
                Name = Guid.NewGuid().ToString(),
                Type = ScopeType.Identity,
                AllowUnrestrictedIntrospection = true,
                ClaimsRule              = Guid.NewGuid().ToString(),
                Description             = Guid.NewGuid().ToString(),
                DisplayName             = Guid.NewGuid().ToString(),
                Emphasize               = true,
                Enabled                 = true,
                IncludeAllClaimsForUser = true,
                Required                = true,
                ShowInDiscoveryDocument = true
            };
            var rec1 = new FlattenedScopeRecord(new FlattenedScopeHandle(actualScope1));
            await dao.UpsertScopeAsync(rec1);

            var actualScope2 = new Scope()
            {
                Name = Guid.NewGuid().ToString(),
                Type = ScopeType.Resource,
                AllowUnrestrictedIntrospection = true,
                ClaimsRule              = Guid.NewGuid().ToString(),
                Description             = Guid.NewGuid().ToString(),
                DisplayName             = Guid.NewGuid().ToString(),
                Emphasize               = true,
                Enabled                 = true,
                IncludeAllClaimsForUser = true,
                Required                = true,
                ShowInDiscoveryDocument = true
            };
            var rec2 = new FlattenedScopeRecord(new FlattenedScopeHandle(actualScope2));
            await dao.UpsertScopeAsync(rec2);

            var scope = await dao.FindScopeByIdAsync(rec1.Id);

            Assert.IsTrue(ScopeComparer.OrdinalIgnoreCase.Equals(scope, actualScope1));

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

            Assert.IsTrue(ScopeComparer.OrdinalIgnoreCase.Equals(scope, actualScope2));
        }
コード例 #3
0
        public async Task <Scope> CreateAsync(int i)
        {
            var dao = new IdentityServer3CassandraDao();
            await dao.EstablishConnectionAsync();

            var name = Guid.NewGuid().ToString();

            global::IdentityServer3.Core.Models.Scope record = new global::IdentityServer3.Core.Models.Scope()
            {
                AllowUnrestrictedIntrospection = true,
                Name                    = name,
                ClaimsRule              = "ClaimRule:" + i,
                Description             = "Description:" + i,
                DisplayName             = "DisplayName:" + i,
                Enabled                 = true,
                Emphasize               = true,
                IncludeAllClaimsForUser = true,
                Required                = true,
                Type                    = ScopeType.Identity,
                ScopeSecrets            = new List <Secret>()
                {
                    new Secret
                    {
                        Type        = "Type1:" + i,
                        Description = "Decription1:" + i,
                        Expiration  = DateTimeOffset.UtcNow,
                        Value       = "Value1:" + i
                    },
                    new Secret
                    {
                        Type        = "Type2:" + i,
                        Description = "Decription2:" + i,
                        Expiration  = DateTimeOffset.UtcNow,
                        Value       = "Value2:" + i
                    }
                },
                ShowInDiscoveryDocument = true,
                Claims = new List <ScopeClaim>()
                {
                    new ScopeClaim
                    {
                        AlwaysIncludeInIdToken = true, Description = "Decription1:" + i,
                        Name = "Name1:" + i
                    },
                    new ScopeClaim
                    {
                        AlwaysIncludeInIdToken = true, Description = "Decription2:" + i,
                        Name = "Name2:" + i
                    }
                }
            };
            var  scopeRecord = new FlattenedScopeRecord(new FlattenedScopeHandle(record));
            Guid id          = scopeRecord.Id;

            var result = await dao.UpsertScopeAsync(scopeRecord);

            Assert.IsTrue(result);

            var result2 = await dao.FindScopeByIdAsync(id);

            Assert.IsNotNull(result2);

            scopeRecord = new FlattenedScopeRecord(new FlattenedScopeHandle(result2));

            Assert.AreEqual(scopeRecord.Record.Name, name);
            Assert.AreEqual(scopeRecord.Id, id);

            var scope = await scopeRecord.Record.GetScopeAsync();

            Assert.AreEqual(record.Claims.Count, scope.Claims.Count);

            var differences = record.Claims.Except(scope.Claims, ScopeClaimComparer.MinimalScopeClaimComparer);

            Assert.IsTrue(!differences.Any());
            return(scope);
        }