Beispiel #1
0
        public void Ids4_DataMigrationTool_Must_Read_Client_Root()
        {
            var dataIds4Tool = new DataMigrationTool(Configuration).Ids4Tool;

            var res = dataIds4Tool.GetIds4ClientsRoot();

            Assert.NotNull(res.Clients);
        }
Beispiel #2
0
        public void Ids3_DataMigrationTool_Must_Read_Client_Root()
        {
            var dataIds3Tool = new DataMigrationTool(Configuration).Ids3Tool;

            var res = dataIds3Tool.GetIds3ClientsRoot();

            Assert.NotNull(res.Clients);
            Assert.True(res.Clients.Length > 1);// put your number
        }
Beispiel #3
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 #4
0
        public void Read_Client3_And_MapTo_Client4_ProofTest()
        {
            // Arrange
            var tool = new DataMigrationTool(Configuration);

            //Act
            var result = tool.ReadIds3DbAndMapClientsScopesTreeToIds4Schema(true);

            // Assert
            // todo: ApiResourceClaims Scope !!
            var claimsIdSource = result.Item1.Scopes.Where(x => x.Type == 0).SelectMany(x => x.ScopeClaims)
                                 .Select(x => new
            {
                x.Name,
                ScopeName = x.Scope?.Name
            }).ToArray();

            var claimsIdTarget = result.Item2.IdentityResources.Where(x => x.UserClaims != null).SelectMany(x => x.UserClaims)
                                 .Select(x => new
            {
                x.Type,
                x.IdentityResourceId,
                IdentityResourceName = x.IdentityResource?.Name
            }).ToArray();


            var claimsResSource = result.Item1.Scopes.Where(x => x.Type == 1).SelectMany(x => x.ScopeClaims)
                                  .Select(x => new
            {
                x.Name,
                ScopeName = x.Scope?.Name
            }).ToArray();

            var claimsResTarget = result.Item2.ApiResources.Where(x => x.UserClaims != null).SelectMany(x => x.UserClaims)
                                  .Select(x => new
            {
                x.Type,
                x.ApiResourceId,
                ApiResourceName = x.ApiResource?.Name
            }).ToArray();


            Assert.Equal(claimsIdSource.Length, claimsIdTarget.Length);
            Assert.Equal(claimsResSource.Length, claimsResTarget.Length);
        }
Beispiel #5
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);
        }