Beispiel #1
0
        public void Read_Client_v3_Map_And_Copy_Client_v4_ToClean_Ids4_Database_ProofTest()
        {
            // Arrange
            var tool          = new DataMigrationTool(Configuration);
            var clientsConfig = new ClientsConfigData();

            var enableScopeToApiResource2ndLevelMapping = true;// otherwise client could not claim api scopes in authorization request

            tool.CleanUpIds4Db();
            // tool.SeedClientsDataToContextIfEmpty(clientsConfig);// - optional

            //Act
            var mappingResult = tool.CopyClientsScopesTreeFromIds3DbToIds4Db(enableScopeToApiResource2ndLevelMapping);

            // Assert  Clients
            var clientsDataCopiedFromIds3 = tool.Ids4Tool.GetIds4ClientsRoot();

            // Assert copied Clients to Ids4 database and mapping result - check if insertion to db passed properly
            Assert.Equal(mappingResult.Item2.Clients.Length, clientsDataCopiedFromIds3.Clients.Length);

            // Assert some Clients details by ClientId
            // AllowedGrantTypes mapping is not trivial - (see  Mapper profile 'Ids3ToIds4EntityProfile')
            foreach (var client in mappingResult.Item2.Clients)
            {
                var copiedClient = clientsDataCopiedFromIds3.Clients.FirstOrDefault(x => x.ClientId == client.ClientId);
                Assert.NotNull(copiedClient);
                Assert.NotNull(copiedClient.AllowedGrantTypes);
                Assert.True(copiedClient.AllowedGrantTypes.Count > 0, $"{client.ClientName}-{client.ClientId}");
            }

            // Assert Scopes
            Assert.Equal(mappingResult.Item1.Scopes.Length, clientsDataCopiedFromIds3.ApiResources.Length + clientsDataCopiedFromIds3.IdentityResources.Length);

            // Assert Scope Claims
            var apiScopes = clientsDataCopiedFromIds3.ApiResources
                            .SelectMany(x => x.Scopes).ToArray();

            // 1st level
            var apiResourceClaimsCount = clientsDataCopiedFromIds3.ApiResources.SelectMany(x => x.UserClaims).ToArray().Length;

            // 2nd level
            var apiScopeClaimsCount = apiScopes.SelectMany(y => y.UserClaims).ToArray().Length;

            var identityScopeClaimsCount = clientsDataCopiedFromIds3.IdentityResources
                                           .SelectMany(x => x.UserClaims).ToArray().Length;

            var claimsTotalSavedCount = (enableScopeToApiResource2ndLevelMapping ? apiScopeClaimsCount : apiResourceClaimsCount) + identityScopeClaimsCount;

            var claimsInScopesExpected = mappingResult.Item1.Scopes.SelectMany(x => x.ScopeClaims).ToArray().Length;

            Assert.Equal(claimsInScopesExpected, claimsTotalSavedCount);

            tool.SeedAdminClient(clientsConfig);
        }
Beispiel #2
0
        public void MigrateIds3ClientsToRestoredIds4Database()
        {
            // Arrange
            var tool          = new DataMigrationTool(Configuration);
            var clientsConfig = new ClientsConfigData();
            var enableScopeToApiResource2ndLevelMapping = true;

            tool.CleanUpIds4Db();
            //tool.SeedClientsDataToContextIfEmpty(clientsConfig);

            //Act
            var result = tool.CopyClientsScopesTreeFromIds3DbToIds4Db(enableScopeToApiResource2ndLevelMapping);

            // Assert  Clients
            var clientsDataCopiedFromIds3 = tool.Ids4Tool.GetIds4ClientsRoot();

            RoughlyCheckCopyResults(result, clientsDataCopiedFromIds3);

            tool.SeedAdminClient(clientsConfig);
        }