public void GetCspDirectiveConfigCloned_NoConfig_ReturnsNull()
        {
            var mapper = new CspConfigMapper();

            var clone = mapper.GetCspDirectiveConfigCloned(null, CspDirectives.ScriptSrc);

            Assert.Null(clone);
        }
        public void GetCspDirectiveConfigCloned_NoDirective_ReturnsNull()
        {
            var config = new CspConfiguration(false);
            var mapper = new CspConfigMapper();

            var clone = mapper.GetCspDirectiveConfigCloned(config, CspDirectives.ScriptSrc);

            Assert.IsNull(clone);
        }
        public void GetCspDirectiveConfigCloned_DefaultDirective_ClonesDirective()
        {
            var directive = new CspDirectiveConfiguration();

            var config = new CspConfiguration(false)
            {
                ScriptSrcDirective = directive
            };
            var mapper = new CspConfigMapper();

            var clone = mapper.GetCspDirectiveConfigCloned(config, CspDirectives.ScriptSrc);


            Assert.AreNotSame(directive, clone);
            Assert.That(clone, Is.EqualTo(directive).Using(new CspDirectiveConfigurationComparer()));
        }
        public void GetCspDirectiveConfigCloned_DefaultDirective_ClonesDirective()
        {
            var directive = new CspDirectiveConfiguration();

            var config = new CspConfiguration(false)
            {
                ScriptSrcDirective = directive
            };
            var mapper = new CspConfigMapper();

            var clone = mapper.GetCspDirectiveConfigCloned(config, CspDirectives.ScriptSrc);


            Assert.NotSame(directive, clone);
            Assert.Equal(clone, directive, new CspDirectiveConfigurationEqualityComparer());
        }
        public void GetCspDirectiveConfigCloned_Configured_ClonesDirective()
        {
            var directive = new CspDirectiveConfiguration
            {
                Enabled         = false,
                NoneSrc         = true,
                SelfSrc         = true,
                UnsafeEvalSrc   = true,
                UnsafeInlineSrc = false,
                CustomSources   = new[] { "https://www.nwebsec.com", "www.klings.org" }
            };

            var config = new CspConfiguration(false)
            {
                ScriptSrcDirective = directive
            };
            var mapper = new CspConfigMapper();

            var clone = mapper.GetCspDirectiveConfigCloned(config, CspDirectives.ScriptSrc);

            Assert.AreNotSame(directive, clone);
            Assert.That(clone, Is.EqualTo(directive).Using(new CspDirectiveConfigurationComparer()));
        }