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

            var actualScope1 = new Scope()
            {
                Name = Guid.NewGuid().ToString(),
                Type = ScopeType.Identity
            };
            await dao.UpsertScopeAsync(new FlattenedScopeRecord(new FlattenedScopeHandle(actualScope1)));

            var actualScope2 = new Scope()
            {
                Name = Guid.NewGuid().ToString(),
                Type = ScopeType.Resource
            };
            await dao.UpsertScopeAsync(new FlattenedScopeRecord(new FlattenedScopeHandle(actualScope2)));

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

            Assert.AreEqual(scope.Type, actualScope1.Type);
            Assert.AreEqual(scope.Name, actualScope1.Name);

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

            Assert.AreEqual(scope.Type, actualScope2.Type);
            Assert.AreEqual(scope.Name, actualScope2.Name);
        }
Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
        public static async Task <List <FlattenedScopeRecord> > InsertTestData_Scopes(int count = 1)
        {
            var dao = new IdentityServer3CassandraDao();
            await dao.EstablishConnectionAsync();

            var result = new List <FlattenedScopeRecord>();

            for (int i = 0; i < count; ++i)
            {
                var name = "ScopeName:" + Guid.NewGuid();
                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));
                await dao.UpsertScopeAsync(scopeRecord);

                result.Add(scopeRecord);
            }
            //   await dao.UpsertManyScopeAsync(result);
            return(result);
        }