예제 #1
0
        public void RemoveFromCacheTest()
        {
            //ARRANGE
            var readFromCache = false;
            var context       = new DbContextMock();

            context.Initialise();
            var cache = new CacheProviderMock();

            cache.ReadFrom += (_, __) => { readFromCache = true; };
            var federationPartyContextBuilder = new FederationPartyContextBuilder(context, cache);
            //ACT
            var before                     = cache.Contains("local");
            var federationContext          = federationPartyContextBuilder.BuildContext("local");
            var after                      = cache.Contains("local");
            var federationContextFromCache = federationPartyContextBuilder.BuildContext("local");

            federationPartyContextBuilder.RequestRefresh("local");
            var afterRemove = cache.Contains("local");

            //ASSERT
            Assert.IsFalse(before);
            Assert.IsTrue(after);
            Assert.IsTrue(readFromCache);
            Assert.AreSame(federationContext, federationContextFromCache);
            Assert.IsFalse(afterRemove);
        }
예제 #2
0
        public void Test1()
        {
            //ARRANGE
            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 context = new DBContext(connectionStringProvider, customConfiguration);

            var metadataContextBuilder = new MetadataContextBuilder((IDbContext)context, cacheProvider);
            //ACT
            var metadata = metadataContextBuilder.BuildContext();
            //ASSERT
        }
 public void SetCacheProviderGetAsyncSuccess()
 {
     CacheProviderMock
     .Setup(m => m.GetAsync <string>(It.IsAny <string>()))
     .ReturnsAsync(new CacheResult <string>
     {
         Success = true,
         Content = CachedResult,
     });
 }
        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);
        }
예제 #5
0
        public void PutCacheTest()
        {
            //ARRANGE
            var context = new DbContextMock();

            context.Initialise();
            var cache = new CacheProviderMock();
            var federationPartyContextBuilder = new FederationPartyContextBuilder(context, cache);
            //ACT
            var before            = cache.Contains("local");
            var federationContext = federationPartyContextBuilder.BuildContext("local");
            var after             = cache.Contains("local");

            //ASSERT
            Assert.IsFalse(before);
            Assert.IsTrue(after);
        }
        public void CreateAndSeed__test_db()
        {
            //ARRANGE
            var cacheProvider            = new CacheProviderMock();
            var customConfiguration      = new DbCustomConfiguration();
            var connectionStringProvider = new MetadataConnectionStringProviderMock();
            var connectingString         = connectionStringProvider.GetConnectionString();

            if (!connectingString.InitialCatalog.EndsWith("_Test"))
            {
                throw new InvalidOperationException("Database name needs to end with _Test");
            }

            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 context = new DBContext(connectionStringProvider, customConfiguration);

            var metadataContextBuilder = new MetadataContextBuilder((IDbContext)context, cacheProvider);
            var metadataRequest        = new MetadataGenerateRequest(MetadataType.SP, "local");
            //ACT
            var metadata = metadataContextBuilder.BuildContext(metadataRequest);

            //ASSERT
            Assert.IsNotNull(metadata);
        }
예제 #7
0
        public void ServiceProviderSingleSignOnDescriptorBuilderTest_db_contex_provider()
        {
            //ARRANGE
            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 context = metadataContextBuilder.BuildContext();
            var spDescriptorConfigurtion = context.EntityDesriptorConfiguration.RoleDescriptors.First() as SPSSODescriptorConfiguration;
            var descriptorBuilder        = new ServiceProviderSingleSignOnDescriptorBuilder();
            //ACT
            var descriptor         = descriptorBuilder.BuildDescriptor(spDescriptorConfigurtion);
            var organisation       = descriptor.Organization;
            var protocolsSupported = descriptor.ProtocolsSupported;
            var assertionServices  = descriptor.AssertionConsumerServices;
            var keys = descriptor.Keys;

            //ASSERT
            //assert sp descriptor attributes

            Assert.AreEqual(spDescriptorConfigurtion.WantAssertionsSigned, descriptor.WantAssertionsSigned);
            Assert.AreEqual(spDescriptorConfigurtion.AuthenticationRequestsSigned, descriptor.AuthenticationRequestsSigned);
            Assert.AreEqual(spDescriptorConfigurtion.AssertionConsumerServices.Count, descriptor.AssertionConsumerServices.Count);
            foreach (var s in spDescriptorConfigurtion.AssertionConsumerServices)
            {
                var descriptorService = assertionServices[s.Index];
                Assert.AreEqual(s.Index, descriptorService.Index);
                Assert.AreEqual(s.Location, descriptorService.Location);
                Assert.AreEqual(s.Binding, descriptorService.Binding);
                Assert.AreEqual(s.IsDefault, descriptorService.IsDefault);
            }

            //assert sso descriptor attributes
            Assert.AreEqual(spDescriptorConfigurtion.ArtifactResolutionServices.Count, descriptor.ArtifactResolutionServices.Count);
            foreach (var s in spDescriptorConfigurtion.ArtifactResolutionServices)
            {
                var descriptorService = descriptor.ArtifactResolutionServices[s.Index];
                Assert.AreEqual(s.Index, descriptorService.Index);
                Assert.AreEqual(s.Location, descriptorService.Location);
                Assert.AreEqual(s.Binding, descriptorService.Binding);
            }
            Assert.True(Enumerable.SequenceEqual(descriptor.NameIdentifierFormats, spDescriptorConfigurtion.NameIdentifierFormats));

            Assert.AreEqual(spDescriptorConfigurtion.SingleLogoutServices.Count, descriptor.SingleLogoutServices.Count);
            foreach (var s in spDescriptorConfigurtion.SingleLogoutServices)
            {
                var descriptorService = descriptor.SingleLogoutServices.Single(x => x.Location == s.Location);
                Assert.AreEqual(s.ResponseLocation, descriptorService.ResponseLocation);
                Assert.AreEqual(s.Binding, descriptorService.Binding);
            }

            //assert role descriptor attributes
            Assert.AreEqual(spDescriptorConfigurtion.ErrorUrl, descriptor.ErrorUrl);
            Assert.AreEqual(spDescriptorConfigurtion.ValidUntil.DateTime, descriptor.ValidUntil);
            Assert.True(Enumerable.SequenceEqual(descriptor.ProtocolsSupported, spDescriptorConfigurtion.ProtocolSupported));
            Assert.AreEqual(spDescriptorConfigurtion.KeyDescriptors.Count, descriptor.Keys.Count);
            for (var i = 0; i < spDescriptorConfigurtion.KeyDescriptors.Count; i++)
            {
                var descriptorKey = descriptor.Keys.ElementAt(i);
                var configKey     = spDescriptorConfigurtion.KeyDescriptors.ElementAt(i);
                Assert.AreEqual(configKey.Use.ToString(), descriptorKey.Use.ToString());
            }

            //organisation
            Assert.AreEqual(spDescriptorConfigurtion.Organisation.Names.Count, organisation.Names.Count);
            foreach (var n in spDescriptorConfigurtion.Organisation.Names)
            {
                var targetName = organisation.Names[n.Language];
                Assert.AreEqual(n.Name, targetName.Name);
            }
            Assert.AreEqual(spDescriptorConfigurtion.Organisation.Names.Count, organisation.DisplayNames.Count);
            foreach (var n in spDescriptorConfigurtion.Organisation.Names)
            {
                var targetName = organisation.DisplayNames[n.Language];
                Assert.AreEqual(n.DisplayName, targetName.Name);
            }
            Assert.AreEqual(spDescriptorConfigurtion.Organisation.Urls.Count, organisation.Urls.Count);
            foreach (var n in spDescriptorConfigurtion.Organisation.Urls)
            {
                var targetName = organisation.Urls[n.Language];
                Assert.AreEqual(n.Url, targetName.Uri);
            }

            //contacts
            var configContacts = spDescriptorConfigurtion.Organisation.OrganisationContacts;

            Assert.AreEqual(configContacts.PersonContact.Count, descriptor.Contacts.Count);
            for (var i = 0; i < configContacts.PersonContact.Count; i++)
            {
                var source = configContacts.PersonContact.ElementAt(i);
                var targer = descriptor.Contacts.ElementAt(i);
                Assert.AreEqual(source.ContactType.ToString(), targer.Type.ToString());
                Assert.AreEqual(source.ForeName, targer.GivenName);
                Assert.AreEqual(source.SurName, targer.Surname);
                Assert.IsTrue(Enumerable.SequenceEqual(source.Emails, targer.EmailAddresses));
                Assert.IsTrue(Enumerable.SequenceEqual(source.PhoneNumbers, targer.TelephoneNumbers));
            }
        }
 public void SetCacheProviderGetAsyncFailure()
 {
     CacheProviderMock
     .Setup(m => m.GetAsync <string>(It.IsAny <string>()))
     .ReturnsAsync(CacheResult <string> .Failure);
 }