Example #1
0
        public void SPMetadata_serialise_deserialise_Test()
        {
            ////ARRANGE
            var    logger         = new LogProviderMock();
            string metadataXml    = String.Empty;
            var    metadataWriter = new TestMetadatWriter(el => metadataXml = el.OuterXml);

            var contextBuilder  = new InlineMetadataContextBuilder();
            var metadataRequest = new MetadataGenerateRequest(MetadataType.SP, "local");
            var metadataContext = contextBuilder.BuildContext(metadataRequest);
            var context         = new FederationPartyConfiguration(metadataRequest.FederationPartyId, "localhost");

            context.MetadataContext = metadataContext;

            var configurationProvider = new CertificateValidationConfigurationProvider();
            var certificateValidator  = new CertificateValidator(configurationProvider);
            var ssoCryptoProvider     = new CertificateManager(logger);

            var metadataSerialiser = new FederationMetadataSerialiser(certificateValidator, logger);

            var metadataDispatcher = new FederationMetadataDispatcherMock(() => new[] { metadataWriter });

            var sPSSOMetadataProvider = new SPSSOMetadataProvider(metadataDispatcher, ssoCryptoProvider, metadataSerialiser, g => context, logger);

            //ACT
            sPSSOMetadataProvider.CreateMetadata(metadataRequest);
            var xmlReader            = XmlReader.Create(new StringReader(metadataXml));
            var deserialisedMetadata = metadataSerialiser.ReadMetadata(xmlReader) as EntityDescriptor;

            //ASSERT
            Assert.IsFalse(String.IsNullOrWhiteSpace(metadataXml));
            Assert.AreEqual(1, deserialisedMetadata.RoleDescriptors.Count);
        }
Example #2
0
        public void SPMetadata_serialise_deserialise_Test()
        {
            ////ARRANGE

            string metadataXml    = String.Empty;
            var    metadataWriter = new TestMetadatWriter(el => metadataXml = el.OuterXml);

            var contextBuilder = new InlineMetadataContextBuilder();
            var context        = contextBuilder.BuildContext();

            var configurationProvider = new CertificateValidationConfigurationProvider();
            var certificateValidator  = new CertificateValidator(configurationProvider);
            var ssoCryptoProvider     = new CertificateManager();

            var metadataSerialiser = new FederationMetadataSerialiser(certificateValidator);

            var sPSSOMetadataProvider = new SPSSOMetadataProvider(metadataWriter, ssoCryptoProvider, metadataSerialiser, g => context);

            //ACT
            sPSSOMetadataProvider.CreateMetadata(MetadataType.SP);
            var xmlReader            = XmlReader.Create(new StringReader(metadataXml));
            var deserialisedMetadata = metadataSerialiser.ReadMetadata(xmlReader) as EntityDescriptor;

            //ASSERT
            Assert.IsFalse(String.IsNullOrWhiteSpace(metadataXml));
            Assert.AreEqual(1, deserialisedMetadata.RoleDescriptors.Count);
        }
Example #3
0
        public void SPMetadataGenerationTest()
        {
            ////ARRANGE

            var result         = String.Empty;
            var metadataWriter = new TestMetadatWriter(el => result = el.OuterXml);
            //var metadataWriter = new TestMetadatWriter(el =>
            //{
            //    using (var writer = XmlWriter.Create(@"D:\Dan\Software\Apira\SPMetadata\SPMetadata.xml"))
            //    {
            //        el.WriteTo(writer);
            //        writer.Flush();
            //    }

            //});


            var contextBuilder = new InlineMetadataContextBuilder();
            var context        = contextBuilder.BuildContext();

            var configurationProvider = new CertificateValidationConfigurationProvider();
            var certificateValidator  = new CertificateValidator(configurationProvider);
            var ssoCryptoProvider     = new CertificateManager();

            var metadataSerialiser = new FederationMetadataSerialiser(certificateValidator);

            var sPSSOMetadataProvider = new SPSSOMetadataProvider(metadataWriter, ssoCryptoProvider, metadataSerialiser, g => context);

            //ACT
            sPSSOMetadataProvider.CreateMetadata(MetadataType.SP);
            //ASSERT
            Assert.IsFalse(String.IsNullOrWhiteSpace(result));
        }
Example #4
0
        public async Task SPMetadataGenerationTest()
        {
            ////ARRANGE

            var result         = String.Empty;
            var metadataWriter = new TestMetadatWriter(el => result = el.OuterXml);

            var logger          = new LogProviderMock();
            var contextBuilder  = new InlineMetadataContextBuilder();
            var metadataRequest = new MetadataGenerateRequest(MetadataType.SP, "local");
            var metadataContext = contextBuilder.BuildContext(metadataRequest);
            var context         = new FederationPartyConfiguration(metadataRequest.FederationPartyId, "localhost");

            context.MetadataContext = metadataContext;
            var configurationProvider = new CertificateValidationConfigurationProvider();
            var certificateValidator  = new CertificateValidator(configurationProvider, logger);
            var ssoCryptoProvider     = new CertificateManager(logger);

            var metadataSerialiser = new FederationMetadataSerialiser(certificateValidator, logger);
            var metadataDispatcher = new FederationMetadataDispatcherMock(() => new[] { metadataWriter });

            var sPSSOMetadataProvider = new SPSSOMetadataProvider(metadataDispatcher, ssoCryptoProvider, metadataSerialiser, g => context, logger);

            //ACT
            await sPSSOMetadataProvider.CreateMetadata(metadataRequest);

            //ASSERT
            Assert.IsFalse(String.IsNullOrWhiteSpace(result));
        }
        public void SPMetadataGenerationTest_sql_source()
        {
            ////ARRANGE

            var result         = false;
            var metadataWriter = new TestMetadatWriter(el =>
            {
                result = true;
            });

            var cacheProvider            = new CacheProviderMock();
            var customConfiguration      = new DbCustomConfiguration();
            var connectionStringProvider = new MetadataConnectionStringProviderMock();
            var models = ReflectionHelper.GetAllTypes(new[] { typeof(MetadataContextBuilder).Assembly })
                         .Where(t => !t.IsAbstract && !t.IsInterface && typeof(BaseModel).IsAssignableFrom(t));

            customConfiguration.ModelsFactory = () => models;

            var seeders = ReflectionHelper.GetAllTypes(new[] { typeof(MetadataContextBuilder).Assembly })
                          .Where(t => !t.IsAbstract && !t.IsInterface && typeof(ISeeder).IsAssignableFrom(t))
                          .Select(x => (ISeeder)Activator.CreateInstance(x));

            seeders
            .OrderBy(x => x.SeedingOrder)
            .Aggregate(customConfiguration.Seeders, (c, next) => { c.Add(next); return(c); });

            object dbcontext = new DBContext(connectionStringProvider, customConfiguration);

            var metadataContextBuilder = new MetadataContextBuilder((IDbContext)dbcontext, cacheProvider);
            var metadataRequest        = new MetadataGenerateRequest(MetadataType.SP, "local");
            var metadatContext         = metadataContextBuilder.BuildContext(metadataRequest);
            var context = new FederationPartyConfiguration(metadataRequest.FederationPartyId, "localhost")
            {
                MetadataContext = metadatContext
            };
            var logger = new LogProviderMock();

            var configurationProvider = new CertificateValidationConfigurationProvider((IDbContext)dbcontext, cacheProvider);
            var certificateValidator  = new CertificateValidator(configurationProvider, logger);
            var ssoCryptoProvider     = new CertificateManager(logger);

            var metadataSerialiser = new FederationMetadataSerialiser(certificateValidator, logger);
            var metadataDispatcher = new FederationMetadataDispatcherMock(() => new[] { metadataWriter });

            var sPSSOMetadataProvider = new SPSSOMetadataProvider(metadataDispatcher, ssoCryptoProvider, metadataSerialiser, g => context, logger);

            //ACT
            sPSSOMetadataProvider.CreateMetadata(metadataRequest).Wait();
            //ASSERT
            Assert.IsTrue(result);
        }
Example #6
0
        public void SPMetadataGeneration_create_file()
        {
            ////ARRANGE

            var result         = false;
            var path           = @"D:\Dan\Software\Apira\SPMetadata\SPMetadataTest.xml";
            var metadataWriter = new TestMetadatWriter(el =>
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                using (var writer = XmlWriter.Create(path))
                {
                    el.WriteTo(writer);
                    writer.Flush();
                }
                result = true;
            });

            var logger                = new LogProviderMock();
            var contextBuilder        = new InlineMetadataContextBuilder();
            var metadataRequest       = new MetadataGenerateRequest(MetadataType.SP, "local");
            var metadatContext        = contextBuilder.BuildContext(metadataRequest);
            var context               = new FederationPartyConfiguration(metadataRequest.FederationPartyId, "localhost");
            var configurationProvider = new CertificateValidationConfigurationProvider();
            var certificateValidator  = new CertificateValidator(configurationProvider);
            var ssoCryptoProvider     = new CertificateManager(logger);

            var metadataSerialiser = new FederationMetadataSerialiser(certificateValidator, logger);
            var metadataDispatcher = new FederationMetadataDispatcherMock(() => new[] { metadataWriter });

            var sPSSOMetadataProvider = new SPSSOMetadataProvider(metadataDispatcher, ssoCryptoProvider, metadataSerialiser, g => context, logger);

            //ACT
            sPSSOMetadataProvider.CreateMetadata(metadataRequest);
            //ASSERT
            Assert.IsTrue(result);
        }
Example #7
0
        public void SPMetadataGeneration_create_file()
        {
            ////ARRANGE

            var result         = false;
            var path           = @"D:\Dan\Software\Apira\SPMetadata\SPMetadataTest.xml";
            var metadataWriter = new TestMetadatWriter(el =>
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                using (var writer = XmlWriter.Create(path))
                {
                    el.WriteTo(writer);
                    writer.Flush();
                }
                result = true;
            });


            var contextBuilder = new InlineMetadataContextBuilder();
            var context        = contextBuilder.BuildContext();

            var configurationProvider = new CertificateValidationConfigurationProvider();
            var certificateValidator  = new CertificateValidator(configurationProvider);
            var ssoCryptoProvider     = new CertificateManager();

            var metadataSerialiser = new FederationMetadataSerialiser(certificateValidator);

            var sPSSOMetadataProvider = new SPSSOMetadataProvider(metadataWriter, ssoCryptoProvider, metadataSerialiser, g => context);

            //ACT
            sPSSOMetadataProvider.CreateMetadata(MetadataType.SP);
            //ASSERT
            Assert.IsTrue(result);
        }
        public void SPMetadataProviderTest()
        {
            var result         = String.Empty;
            var metadataWriter = new TestMetadatWriter(el => result = el.OuterXml);

            //var metadataWriter = new SSOMetadataFileWriter();

            var ssoCryptoProvider   = new CertificateManager();
            var xmlSignatureManager = new XmlSignatureManager();

            var sPSSOMetadataProvider = new SPSSOMetadataProvider(metadataWriter, ssoCryptoProvider, xmlSignatureManager);

            var configuration = new SPSSOMetadataConfiguration
            {
                AuthnRequestsSigned        = true,
                DescriptorId               = "Idp1",
                EntityId                   = new Uri("http://*****:*****@"D:\SPSSOMetadata.xml",
                SupportedProtocols         = new[] { "urn:oasis:names:tc:SAML:2.0:protocol" },
                SignMetadata               = true,
                ConsumerServices           = new ConsumerServiceContext[] { new ConsumerServiceContext
                                                                            {
                                                                                Index     = 0,
                                                                                IsDefault = true,
                                                                                Binding   = "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST",
                                                                                Location  = "http://*****:*****@"D:\Dan\Software\SGWI\ThirdParty\devCertsPackage\employeeportaldev.safeguardworld.com.pfx",
                                                      CertificatePassword = StringExtensions.ToSecureString("$Password1!"),
                                                      Usage = "signing",
                                                      DefaultForMetadataSigning = true
                                                  } }
            };

            sPSSOMetadataProvider.CreateMetadata(configuration);
        }
Example #9
0
        public void SPMetadataGenerationTest()
        {
            ////ARRANGE

            var result         = String.Empty;
            var metadataWriter = new TestMetadatWriter(el => result = el.OuterXml);
            //var metadataWriter = new TestMetadatWriter(el =>
            //{
            //    using (var writer = XmlWriter.Create(@"D:\Dan\Software\Apira\SPMetadata\SPMetadata.xml"))
            //    {
            //        el.WriteTo(writer);
            //        writer.Flush();
            //    }

            //});

            var logger          = new LogProviderMock();
            var contextBuilder  = new InlineMetadataContextBuilder();
            var metadataRequest = new MetadataGenerateRequest(MetadataType.SP, "local");
            var metadataContext = contextBuilder.BuildContext(metadataRequest);
            var context         = new FederationPartyConfiguration(metadataRequest.FederationPartyId, "localhost");

            context.MetadataContext = metadataContext;
            var configurationProvider = new CertificateValidationConfigurationProvider();
            var certificateValidator  = new CertificateValidator(configurationProvider);
            var ssoCryptoProvider     = new CertificateManager(logger);

            var metadataSerialiser = new FederationMetadataSerialiser(certificateValidator, logger);
            var metadataDispatcher = new FederationMetadataDispatcherMock(() => new[] { metadataWriter });

            var sPSSOMetadataProvider = new SPSSOMetadataProvider(metadataDispatcher, ssoCryptoProvider, metadataSerialiser, g => context, logger);

            //ACT
            sPSSOMetadataProvider.CreateMetadata(metadataRequest);
            //ASSERT
            Assert.IsFalse(String.IsNullOrWhiteSpace(result));
        }
        public async Task IdPMetadata_serialise_deserialise_Test()
        {
            ////ARRANGE
            var    logger         = new LogProviderMock();
            string metadataXml    = String.Empty;
            var    metadataWriter = new TestMetadatWriter(el => metadataXml = el.OuterXml);

            CertificateValidationRulesFactory.InstanceCreator = ValidationRuleInstanceCreatorMock.CreateInstance;
            var contextBuilder  = new InlineMetadataContextBuilder();
            var metadataRequest = new MetadataGenerateRequest(MetadataType.Idp, "local");
            var metadataContext = contextBuilder.BuildContext(metadataRequest);
            var context         = new FederationPartyConfiguration(metadataRequest.FederationPartyId, "localhost");

            context.MetadataContext = metadataContext;

            var configurationProvider = new CertificateValidationConfigurationProvider();
            var certificateValidator  = new CertificateValidator(configurationProvider, logger);
            var ssoCryptoProvider     = new CertificateManager(logger);

            var metadataSerialiser = new FederationMetadataSerialiser(certificateValidator, logger);

            var metadataDispatcher = new FederationMetadataDispatcherMock(() => new[] { metadataWriter });

            var idPSSOMetadataProvider = new IdpSSOMetadataProvider(metadataDispatcher, ssoCryptoProvider, metadataSerialiser, g => context, logger);

            //ACT
            await idPSSOMetadataProvider.CreateMetadata(metadataRequest);

            var xmlReader            = XmlReader.Create(new StringReader(metadataXml));
            var deserialisedMetadata = metadataSerialiser.Deserialise(xmlReader) as EntityDescriptor;

            //ASSERT
            Assert.IsFalse(String.IsNullOrWhiteSpace(metadataXml));
            Assert.AreEqual(1, deserialisedMetadata.RoleDescriptors.Count);
            Assert.IsInstanceOf <IdentityProviderSingleSignOnDescriptor>(deserialisedMetadata.RoleDescriptors.Single());
        }