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_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()));
        }
 public void Setup()
 {
     _mapper = new CspConfigMapper();
 }
        public void GetCspSandboxConfigCloned_NoDirective_ReturnsNull()
        {
            var config = new CspConfiguration(false);
            var mapper = new CspConfigMapper();

            var clone = mapper.GetCspSandboxConfigCloned(config);

            Assert.IsNull(clone);
        }
        public void GetCspSandboxConfigCloned_Configured_ClonesDirective()
        {
            var firstDirective = new CspSandboxDirectiveConfiguration
            {
                AllowForms = true,
                AllowPointerLock = true,
                AllowPopups = true
            };
            var firstConfig = new CspConfiguration(false) { SandboxDirective = firstDirective };
            var secondDirective = new CspSandboxDirectiveConfiguration()
            {
                AllowSameOrigin = true,
                AllowScripts = true,
                AllowTopNavigation = true,
                Enabled = true
            };
            var secondConfig = new CspConfiguration(false) { SandboxDirective = secondDirective };
            var mapper = new CspConfigMapper();

            var firstResult = mapper.GetCspSandboxConfigCloned(firstConfig);
            var secondResult = mapper.GetCspSandboxConfigCloned(secondConfig);

            Assert.That(firstResult, Is.EqualTo(firstDirective).Using(new CspSandboxDirectiveConfigurationComparer()));
            Assert.That(secondResult, Is.EqualTo(secondDirective).Using(new CspSandboxDirectiveConfigurationComparer()));
        }
        public void GetCspPluginTypesConfigCloned_Configured_ClonesDirective()
        {
            var firstDirective = new CspPluginTypesDirectiveConfiguration()
            {
                Enabled = false,
                MediaTypes = new[] { "application/pdf" }
            };
            var firstConfig = new CspConfiguration(false) { PluginTypesDirective = firstDirective };

            var secondDirective = new CspPluginTypesDirectiveConfiguration()
            {
                Enabled = true,
                MediaTypes = new[] { "image/png", "application/pdf" }
            };
            var secondConfig = new CspConfiguration(false) { PluginTypesDirective = secondDirective };
            var mapper = new CspConfigMapper();

            var firstResult = mapper.GetCspPluginTypesConfigCloned(firstConfig);
            var secondResult = mapper.GetCspPluginTypesConfigCloned(secondConfig);

            Assert.That(firstResult, Is.EqualTo(firstDirective).Using(new CspPluginTypesDirectiveConfigurationComparer()));
            Assert.That(secondResult, Is.EqualTo(secondDirective).Using(new CspPluginTypesDirectiveConfigurationComparer()));
        }