Exemple #1
0
        public static IConfigurationRepository CreateLockedDownConfiguration()
        {
            var repo = new InMemoryConfigurationRepository();

            repo.Global = new GlobalConfiguration
            {
                SiteName  = "Unit Test",
                IssuerUri = "http://test.identityserver.thinktecture.com",

                DefaultTokenLifetime = 10,
                MaximumTokenLifetime = 24,
                DefaultWSTokenType   = "urn:oasis:names:tc:SAML:2.0:assertion",

                EnableClientCertificateAuthentication = true,
                RequireRelyingPartyRegistration       = true,
                RequireEncryption = true,
            };

            repo.WSFederation = new WSFederationConfiguration
            {
                AllowReplyTo = false,
                RequireReplyToWithinRealm = true,
                RequireSslForReplyTo      = true
            };

            return(repo);
        }
Exemple #2
0
        public void DeleteConfiguration_ShouldThrowException_WhenConfigurationExistsButVersionDoesNot()
        {
            // arrange
            var key      = _fixture.Create <string>();
            var version  = _fixture.Create <Version>();
            var dataType = _fixture.Create <ValueType>().ToString();

            var wrongVersion = _fixture.Create <Version>();

            var store = new Dictionary
                        <string, Tuple <string, IDictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > > > >
            {
                {
                    key,
                    new Tuple <string, IDictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > > >(
                        dataType,
                        new Dictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > >
                    {
                        {
                            version,
                            new List <Tuple <Guid, int, string, IEnumerable <string> > >()
                        }
                    })
                }
            };

            _sut = new InMemoryConfigurationRepository(store);

            Func <Task> exceptionThrower = async() => await _sut
                                           .DeleteConfigurationVersion(key, wrongVersion)
                                           .ConfigureAwait(false);

            // act/assert
            exceptionThrower.ShouldThrow <ArgumentException>();
        }
Exemple #3
0
        public async Task GetConfiguration_ShouldReturnConfiguration_WhenItIsAvailable()
        {
            // arrange
            var key      = _fixture.Create <string>();
            var version  = _fixture.Create <Version>();
            var dataType = _fixture.Create <ValueType>();
            var valueId  = _fixture.Create <Guid>();
            var data     = _fixture.Create <string>();
            var sequence = _fixture.Create <int>();
            var tags     = _fixture.CreateMany <string>().ToList();

            _sut =
                new InMemoryConfigurationRepository(new Dictionary
                                                    <string, Tuple <string, IDictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > > > >
            {
                {
                    key,
                    new Tuple
                    <string, IDictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > > >(
                        dataType.ToString(),
                        new Dictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > >
                    {
                        { version, new List <Tuple <Guid, int, string, IEnumerable <string> > >
                          {
                              new Tuple <Guid, int, string, IEnumerable <string> >(
                                  valueId,
                                  sequence,
                                  data,
                                  tags)
                          } }
                    })
                }
            });

            var expectedConfig = new StoredConfig
            {
                Type   = dataType.ToString(),
                Values = new List <StoredConfigValues>
                {
                    new StoredConfigValues
                    {
                        Id = valueId,
                        EnvironmentTags = tags,
                        Data            = data,
                        Sequence        = sequence
                    }
                }
            };

            // act
            var config = await _sut
                         .GetConfiguration(key, version)
                         .ConfigureAwait(false);

            // assert
            config.ShouldBeEquivalentTo(
                expectedConfig,
                options => options
                .Excluding((ISubjectInfo si) => si.SelectedMemberInfo.Name == "CreatedAt"));
        }
Exemple #4
0
        public void AddNewConfiguration_ShouldThrowException_WhenItAlreadyExists()
        {
            // arrange
            var key      = _fixture.Create <string>();
            var version  = _fixture.Create <Version>();
            var dataType = _fixture.Create <ValueType>();

            _sut =
                new InMemoryConfigurationRepository(new Dictionary
                                                    <string, Tuple <string, IDictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > > > >
            {
                {
                    key,
                    new Tuple
                    <string, IDictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > > >(
                        dataType.ToString(),
                        new Dictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > >
                    {
                        { version, new List <Tuple <Guid, int, string, IEnumerable <string> > >() }
                    })
                }
            });

            Func <Task> exThrower = async() => await _sut
                                    .AddNewConfiguration(key, dataType.ToString(), DateTime.UtcNow)
                                    .ConfigureAwait(false);

            // act/assert
            exThrower
            .ShouldThrow <ArgumentException>();
        }
Exemple #5
0
        public async Task AddNewConfiguration_ShouldAddTheConfiguration_WhenItDoesNotExist()
        {
            // arrange
            var key      = _fixture.Create <string>();
            var version  = _fixture.Create <Version>();
            var dataType = _fixture.Create <ValueType>().ToString();

            _sut = new InMemoryConfigurationRepository();

            var createdAt = DateTime.UtcNow;
            var expected  = new StoredConfig
            {
                Type   = dataType,
                Values = new List <StoredConfigValues>()
            };

            // act
            await _sut
            .AddNewConfiguration(key, dataType, createdAt)
            .ConfigureAwait(false);

            // assert
            (await _sut
             .GetConfiguration(key)
             .ConfigureAwait(false))
            .ShouldBeEquivalentTo(
                expected,
                options => options
                .Excluding((ISubjectInfo si) => si.SelectedMemberInfo.Name == "CreatedAt"));
        }
Exemple #6
0
        public async Task AddNewValueToConfiguration_ShouldAddTheNewValue_WhenConfigurationExists()
        {
            // arrange
            var key      = _fixture.Create <string>();
            var version  = _fixture.Create <Version>();
            var dataType = _fixture.Create <ValueType>().ToString();
            var valueId  = _fixture.Create <Guid>();
            var data     = _fixture.Create <string>();
            var sequence = _fixture.Create <int>();
            var tags     = _fixture.CreateMany <string>().ToList();

            _sut =
                new InMemoryConfigurationRepository(new Dictionary
                                                    <string, Tuple <string, IDictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > > > >
            {
                {
                    key,
                    new Tuple <string, IDictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > > >(
                        dataType,
                        new Dictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > >
                    {
                        { version, new List <Tuple <Guid, int, string, IEnumerable <string> > >() }
                    })
                }
            });

            var createdAt = DateTime.UtcNow;

            var expected = new StoredConfig
            {
                Type   = dataType,
                Values = new List <StoredConfigValues>
                {
                    new StoredConfigValues
                    {
                        Id              = valueId,
                        Sequence        = 1,
                        EnvironmentTags = tags,
                        Data            = data,
                        CreatedAt       = createdAt
                    }
                }
            };

            // act
            await _sut
            .AddNewValueToConfiguration(key, version, valueId, tags, data, createdAt)
            .ConfigureAwait(false);

            // assert
            (await _sut
             .GetConfiguration(key, version)
             .ConfigureAwait(false))
            .ShouldBeEquivalentTo(
                expected,
                options => options
                .Excluding((ISubjectInfo si) => si.SelectedMemberInfo.Name == "CreatedAt"));
        }
Exemple #7
0
        public async Task DeleteValueOnConfiguration_ShouldDeleteValue_WhenConfigurationAndValueExistButIsNotTheLastOne()
        {
            // arrange
            var key      = _fixture.Create <string>();
            var version  = _fixture.Create <Version>();
            var dataType = _fixture.Create <ValueType>().ToString();
            var valueId  = _fixture.Create <Guid>();
            var data     = _fixture.Create <string>();
            var sequence = _fixture.Create <int>();
            var tags     = _fixture.CreateMany <string>().ToList();

            var store = new Dictionary
                        <string, Tuple <string, IDictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > > > >
            {
                {
                    key,
                    new Tuple <string, IDictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > > >(
                        dataType,
                        new Dictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > >
                    {
                        {
                            version,
                            new List <Tuple <Guid, int, string, IEnumerable <string> > >
                            {
                                new Tuple <Guid, int, string, IEnumerable <string> >(
                                    valueId,
                                    sequence,
                                    data,
                                    tags),
                                new Tuple <Guid, int, string, IEnumerable <string> >(
                                    _fixture.Create <Guid>(),
                                    _fixture.Create <int>(),
                                    _fixture.Create <string>(),
                                    _fixture.CreateMany <string>().ToArray())
                            }
                        }
                    })
                }
            };

            _sut = new InMemoryConfigurationRepository(store);

            // act
            await _sut
            .DeleteValueOnConfiguration(key, version, valueId)
            .ConfigureAwait(false);

            // assert
            store[key]
            .Item2[version]
            .FirstOrDefault(t => t.Item1 == valueId)
            .Should()
            .BeNull();
        }
Exemple #8
0
        public void Add_new_configuration__configuration_should_persisted_and_be_available_for_usage()
        {
            var repository        = new InMemoryConfigurationRepository();
            var testConfiguration = new TestConfiguration {
                SomeSpec = "test"
            };

            repository.AddConfig(testConfiguration);

            var configuration = repository.GetConfig <TestConfiguration>();

            Assert.AreEqual(testConfiguration, configuration);
        }
Exemple #9
0
        public async Task GetConfiguration_ShouldReturnNull_WhenNoConfigurationIsAvailable()
        {
            // arrange
            var key     = _fixture.Create <string>();
            var version = _fixture.Create <Version>();

            _sut = new InMemoryConfigurationRepository();

            // act
            var config = await _sut
                         .GetConfiguration(key, version)
                         .ConfigureAwait(false);

            // assert
            config.Should().BeNull();
        }
Exemple #10
0
        public void DeleteValueOnConfiguration_ShouldThrowException_WhenConfigurationAndVersionExistButValueDoesNot()
        {
            // arrange
            var key      = _fixture.Create <string>();
            var version  = _fixture.Create <Version>();
            var dataType = _fixture.Create <ValueType>().ToString();
            var valueId  = _fixture.Create <Guid>();
            var data     = _fixture.Create <string>();
            var sequence = _fixture.Create <int>();
            var tags     = _fixture.CreateMany <string>().ToList();

            var wrongValueId = _fixture.Create <Guid>();

            var store = new Dictionary
                        <string, Tuple <string, IDictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > > > >
            {
                {
                    key,
                    new Tuple <string, IDictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > > >(
                        dataType,
                        new Dictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > >
                    {
                        {
                            version,
                            new List <Tuple <Guid, int, string, IEnumerable <string> > >
                            {
                                new Tuple <Guid, int, string, IEnumerable <string> >(
                                    valueId,
                                    sequence,
                                    data,
                                    tags)
                            }
                        }
                    })
                }
            };

            _sut = new InMemoryConfigurationRepository(store);

            Func <Task> exceptionThrower = async() => await _sut
                                           .DeleteValueOnConfiguration(key, version, wrongValueId)
                                           .ConfigureAwait(false);

            // act/assert
            exceptionThrower.ShouldThrow <ArgumentException>();
        }
Exemple #11
0
        public void UpdateValueOnConfiguration_ShouldThrowException_WhenConfigurationExistsButNotTheVersion()
        {
            // arrange
            var key      = _fixture.Create <string>();
            var version  = _fixture.Create <Version>();
            var dataType = _fixture.Create <ValueType>().ToString();
            var valueId  = _fixture.Create <Guid>();
            var data     = _fixture.Create <string>();
            var tags     = _fixture.CreateMany <string>().ToList();

            var unknownVersion = _fixture.Create <Version>();

            _sut =
                new InMemoryConfigurationRepository(new Dictionary
                                                    <string, Tuple <string, IDictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > > > >
            {
                {
                    key,
                    new Tuple <string, IDictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > > >(
                        dataType,
                        new Dictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > >
                    {
                        { version, new List <Tuple <Guid, int, string, IEnumerable <string> > >
                          {
                              new Tuple <Guid, int, string, IEnumerable <string> >(
                                  valueId,
                                  1,
                                  data,
                                  tags)
                          } }
                    })
                }
            });


            Func <Task> exceptionThrower = async() => await _sut
                                           .UpdateValueOnConfiguration(key, unknownVersion, valueId, tags, data)
                                           .ConfigureAwait(false);

            // act/assert
            exceptionThrower
            .ShouldThrow <ArgumentException>();
        }
Exemple #12
0
        public async Task GetConfiguration_ShouldReturnNull_WhenKeyIsAvailableButVersionIsNot()
        {
            // arrange
            var key            = _fixture.Create <string>();
            var versionToQuery = _fixture.Create <Version>();
            var versionInStore = _fixture.Create <Version>();

            _sut =
                new InMemoryConfigurationRepository(new Dictionary
                                                    <string, Tuple <string, IDictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > > > >
            {
                {
                    key,
                    new Tuple
                    <string, IDictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > > >(
                        _fixture.Create <ValueType>().ToString(),
                        new Dictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > >
                    {
                        {
                            versionInStore,
                            new List <Tuple <Guid, int, string, IEnumerable <string> > >
                            {
                                new Tuple <Guid, int, string, IEnumerable <string> >(
                                    _fixture.Create <Guid>(),
                                    _fixture.Create <int>(),
                                    _fixture.Create <string>(),
                                    _fixture.CreateMany <string>().ToList())
                            }
                        }
                    })
                }
            });

            // act
            var config = await _sut
                         .GetConfiguration(key, versionToQuery)
                         .ConfigureAwait(false);

            // assert
            config.Should().BeNull();
        }
Exemple #13
0
        public async Task DeleteConfiguration_ShouldDeleteConfiguration_WhenConfigurationExists()
        {
            // arrange
            var key      = _fixture.Create <string>();
            var version  = _fixture.Create <Version>();
            var dataType = _fixture.Create <ValueType>().ToString();

            var store = new Dictionary
                        <string, Tuple <string, IDictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > > > >
            {
                {
                    key,
                    new Tuple <string, IDictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > > >(
                        dataType,
                        new Dictionary <Version, IList <Tuple <Guid, int, string, IEnumerable <string> > > >
                    {
                        {
                            version,
                            new List <Tuple <Guid, int, string, IEnumerable <string> > >()
                        }
                    })
                }
            };

            _sut = new InMemoryConfigurationRepository(store);

            // act
            await _sut
            .DeleteConfigurationVersion(key, version)
            .ConfigureAwait(false);

            // assert
            store[key]
            .Item2
            .ContainsKey(version)
            .Should()
            .BeFalse();
        }