public async Task AddAsync_WhenRelyingPartyHasNullEncryptionCert_ExpectEncryptionCertReturnedAsNull(DbContextOptions <WsFederationConfigurationDbContext> options)
        {
            // arrange
            var entity = new RelyingParty
            {
                Realm = Guid.NewGuid().ToString(),
                EncryptionCertificate = null
            };

            // act
            using (var ctx = new WsFederationConfigurationDbContext(options))
            {
                await ctx.RelyingParties.AddAsync(entity);

                await ctx.SaveChangesAsync();
            }

            // assert
            RelyingParty foundEntity;

            using (var ctx = new WsFederationConfigurationDbContext(options))
            {
                foundEntity = ctx.RelyingParties.FirstOrDefault(x => x.Realm == entity.Realm);
            }

            foundEntity.Should().NotBeNull();
            foundEntity.EncryptionCertificate.Should().BeNull();
        }
        public async Task AddAsync_WhenRelyingPartyContainingBasicPropertiesAdded_ExpectSaveChangesSuccess(DbContextOptions <WsFederationConfigurationDbContext> options)
        {
            // arrange
            var entity = new RelyingParty
            {
                Realm                    = Guid.NewGuid().ToString(),
                TokenType                = Guid.NewGuid().ToString(),
                DigestAlgorithm          = Guid.NewGuid().ToString(),
                SignatureAlgorithm       = Guid.NewGuid().ToString(),
                SamlNameIdentifierFormat = Guid.NewGuid().ToString()
            };

            // act
            using (var ctx = new WsFederationConfigurationDbContext(options))
            {
                await ctx.RelyingParties.AddAsync(entity);

                await ctx.SaveChangesAsync();
            }

            // assert
            RelyingParty foundEntity;

            using (var ctx = new WsFederationConfigurationDbContext(options))
            {
                foundEntity = ctx.RelyingParties.FirstOrDefault(x => x.Realm == entity.Realm);
            }

            foundEntity.Should().NotBeNull();
            foundEntity.Realm.Should().Be(entity.Realm);
            foundEntity.TokenType.Should().Be(entity.TokenType);
            foundEntity.DigestAlgorithm.Should().Be(entity.DigestAlgorithm);
            foundEntity.SignatureAlgorithm.Should().Be(entity.SignatureAlgorithm);
            foundEntity.SamlNameIdentifierFormat.Should().Be(entity.SamlNameIdentifierFormat);
        }
 public WsFederationConfigurationDbContextTests()
 {
     foreach (var options in TestDatabaseProviders.SelectMany(x => x.Select(y => (DbContextOptions <WsFederationConfigurationDbContext>)y)).ToList())
     {
         using (var ctx = new WsFederationConfigurationDbContext(options))
             ctx.Database.EnsureCreated();
     }
 }
        public async Task AddAsync_WhenModelHasClaimsMappings_ExpectClaimsMappingsMappedCorrectly(DbContextOptions <WsFederationConfigurationDbContext> options)
        {
            // arrange
            var mappings = new List <WsFedClaimMap>
            {
                new WsFedClaimMap {
                    OriginalClaimType = "sub", NewClaimType = ClaimTypes.NameIdentifier
                },
                new WsFedClaimMap {
                    OriginalClaimType = "name", NewClaimType = ClaimTypes.Name
                }
            };

            var entity = new RelyingParty
            {
                Realm        = Guid.NewGuid().ToString(),
                ClaimMapping = mappings
            };

            // act
            using (var ctx = new WsFederationConfigurationDbContext(options))
            {
                await ctx.RelyingParties.AddAsync(entity);

                await ctx.SaveChangesAsync();
            }

            // assert
            RelyingParty foundEntity;

            using (var ctx = new WsFederationConfigurationDbContext(options))
            {
                foundEntity = ctx.RelyingParties.Include(x => x.ClaimMapping).FirstOrDefault(x => x.Realm == entity.Realm);
            }

            foundEntity.ClaimMapping.Should().NotBeNull();
            foundEntity.ClaimMapping.Should().NotBeEmpty();
            foundEntity.ClaimMapping.Should().HaveCount(mappings.Count);

            foreach (var mappedMapping in foundEntity.ClaimMapping)
            {
                var matchingMapping = mappings.FirstOrDefault(x => x.OriginalClaimType == mappedMapping.OriginalClaimType);
                matchingMapping.Should().NotBeNull();
                mappedMapping.NewClaimType.Should().Be(matchingMapping.NewClaimType);
            }
        }
        public async Task AddAsync_WhenRelyingPartyHasPublicEncryptionCert_ExpectEncryptionCertReturned(DbContextOptions <WsFederationConfigurationDbContext> options)
        {
            // arrange
            var certToStore = new X509Certificate2("Resources/idsrv3test.cer");
            var entity      = new RelyingParty
            {
                Realm = Guid.NewGuid().ToString(),
                EncryptionCertificate = certToStore.GetRawCertData()
            };

            // act
            using (var ctx = new WsFederationConfigurationDbContext(options))
            {
                await ctx.RelyingParties.AddAsync(entity);

                await ctx.SaveChangesAsync();
            }

            // assert
            RelyingParty foundEntity;

            using (var ctx = new WsFederationConfigurationDbContext(options))
            {
                foundEntity = ctx.RelyingParties.FirstOrDefault(x => x.Realm == entity.Realm);
            }

            foundEntity.Should().NotBeNull();
            foundEntity.EncryptionCertificate.Should().NotBeNull();

            var parsedCert = new X509Certificate2(entity.EncryptionCertificate);

            parsedCert.Should().NotBeNull();
            parsedCert.Thumbprint.Should().Be(certToStore.Thumbprint);
            parsedCert.SubjectName.Name.Should().Be(certToStore.SubjectName.Name);
            parsedCert.HasPrivateKey.Should().Be(certToStore.HasPrivateKey);
        }
Exemplo n.º 6
0
 public RelyingPartyStoreTests()
 {
     inMemContext = new WsFederationConfigurationDbContext(new DbContextOptionsBuilder <WsFederationConfigurationDbContext>()
                                                           .UseInMemoryDatabase(nameof(RelyingPartyStoreTests)).Options);
     store = new RelyingPartyStore(inMemContext);
 }