Exemple #1
0
        public async Task DynamoRoleStore_Update_UpdatesRole()
        {
            var roleName = TestUtils.RandomString(10);
            var role     = new DynamoIdentityRole(roleName);

            using (var dbProvider = DynamoDbServerTestUtils.CreateDatabase())
            {
                var roleStore = new DynamoRoleStore <DynamoIdentityRole>();
                await roleStore.EnsureInitializedAsync(dbProvider.Client, dbProvider.Context);

                await roleStore.CreateAsync(role, CancellationToken.None);

                role.AddClaim(new Claim("test", "test"));

                // ACT
                await roleStore.UpdateAsync(role, CancellationToken.None);

                // ASSERT
                var result = await roleStore.FindByIdAsync(role.Id, CancellationToken.None);

                Assert.Equal(role.Id, result.Id);
                Assert.Contains("test", result.ClaimTypes);
                Assert.Contains("test", result.ClaimValues);
            }
        }
Exemple #2
0
        public async Task DynamoRoleStore_Delete_DeletesRole()
        {
            var roleName = TestUtils.RandomString(10);
            var role     = new DynamoIdentityRole(roleName);

            using (var dbProvider = DynamoDbServerTestUtils.CreateDatabase())
            {
                var roleStore = new DynamoRoleStore <DynamoIdentityRole>();
                await roleStore.EnsureInitializedAsync(dbProvider.Client, dbProvider.Context);

                await roleStore.CreateAsync(role, CancellationToken.None);

                await Task.Delay(2000);

                role = await roleStore.FindByIdAsync(role.Id, CancellationToken.None);

                // ACT
                await roleStore.DeleteAsync(role, CancellationToken.None);

                // ASSERT
                var result = await roleStore.FindByIdAsync(role.Id, CancellationToken.None);

                Assert.Null(result);
            }
        }
Exemple #3
0
        public async Task DynamoRoleStore_FindByName_FindsRole()
        {
            var roleName = TestUtils.RandomString(10);
            var role     = new DynamoIdentityRole(roleName);

            Assert.Equal(roleName.ToUpper(), role.NormalizedName);

            using (var dbProvider = DynamoDbServerTestUtils.CreateDatabase())
            {
                var roleStore = new DynamoRoleStore <DynamoIdentityRole>();
                await roleStore.EnsureInitializedAsync(dbProvider.Client, dbProvider.Context);

                await roleStore.CreateAsync(role, CancellationToken.None);

                // ACT
                var result = await roleStore.FindByNameAsync(roleName.ToUpper(), CancellationToken.None);

                // ASSERT
                Assert.NotNull(result);
                Assert.Equal(roleName, result.Name);
                Assert.Equal(role.Id, result.Id);
            }
        }
Exemple #4
0
        public Program(ILoggerFactory loggerFactory,
                       DynamoUserStore <DynamoIdentityUser, DynamoIdentityRole> userStore,
                       DynamoRoleStore <DynamoIdentityRole> roleStore,
                       DynamoRoleUsersStore <DynamoIdentityRole, DynamoIdentityUser> roleUsersStore,
                       ILookupNormalizer keyNormalizer,
                       string dbUrl,
                       string regionName,
                       string tableNamePrefix)
        {
            this.logger         = loggerFactory.CreateLogger <Program>();
            this.userStore      = userStore;
            this.roleStore      = roleStore;
            this.roleUsersStore = roleUsersStore;
            this.keyNormalizer  = keyNormalizer;

            var dbConfig = new AmazonDynamoDBConfig
            {
                ServiceURL = dbUrl
            };

            if (regionName != null)
            {
                var region = RegionEndpoint.GetBySystemName(regionName);
                dbConfig.RegionEndpoint = region;
            }

            var client = new AmazonDynamoDBClient(dbConfig);

            var contextConfig = new DynamoDBContextConfig
            {
                TableNamePrefix = tableNamePrefix
            };

            var context = new DynamoDBContext(client, contextConfig);

            var prefix = tableNamePrefix ?? "";

            roleUsersTableName = $"{prefix}roleUsers";
            usersTableName     = $"{prefix}users";
            rolesTableName     = $"{prefix}roles";

            var tables = client.ListTablesAsync().Result;

            if (!tables.TableNames.Contains(usersTableName))
            {
                throw new Exception($"can't find table {usersTableName}");
            }

            if (!tables.TableNames.Contains(rolesTableName))
            {
                throw new Exception($"can't find table {rolesTableName}");
            }

            if (!tables.TableNames.Contains(roleUsersTableName))
            {
                throw new Exception($"can't find table {roleUsersTableName}");
            }

            roleUsersStore.EnsureInitializedAsync(client, context, roleUsersTableName).Wait();
            userStore.EnsureInitializedAsync(client, context, usersTableName).Wait();
            roleStore.EnsureInitializedAsync(client, context, rolesTableName).Wait();
        }