コード例 #1
0
        public void GetXFrameoptionsWithOverride_ConfigOverriden_ReturnsOverrideElement()
        {
            var configOverride = new XFrameOptionsConfiguration { Policy = XfoPolicy.Deny };

            _headerConfigurationOverrideHelper.SetXFrameoptionsOverride(_mockContext, configOverride);

            Assert.AreSame(configOverride, _headerConfigurationOverrideHelper.GetXFrameoptionsWithOverride(_mockContext));
        }
コード例 #2
0
        public void CreateXfoResult_Disabled_ReturnsNull()
        {
            var xFrameConfig = new XFrameOptionsConfiguration { Policy = XfoPolicy.Disabled };

            var result = _generator.CreateXfoResult(xFrameConfig);

            Assert.IsNull(result);
        }
コード例 #3
0
        public void GetXFrameOptionsConfiguration_NoOwinContext_ReturnsSystemWebConfig()
        {
            var config = new XFrameOptionsConfiguration();
            _systemWebContext.XFrameOptions = config;

            var result = _contextHelper.GetXFrameOptionsConfiguration(_mockContext);

            Assert.AreSame(config, result);
        }
コード例 #4
0
        public void CreateXfoResult_DisabledWithSameOriginInOldConfig_ReturnsRemoveXfoResult()
        {
            var xFrameConfig = new XFrameOptionsConfiguration { Policy = XfoPolicy.Disabled };
            var oldXFrameConfig = new XFrameOptionsConfiguration { Policy = XfoPolicy.SameOrigin };

            var result = _generator.CreateXfoResult(xFrameConfig,oldXFrameConfig);

            Assert.IsNotNull(result);
            Assert.AreEqual(HeaderResult.ResponseAction.Remove, result.Action);
            Assert.AreEqual("X-Frame-Options", result.Name);
        }
コード例 #5
0
        public void CreateXfoResult_Sameorigin_ReturnsSetXfoSameOriginResult()
        {
            var xFrameConfig = new XFrameOptionsConfiguration { Policy = XfoPolicy.SameOrigin };

            var result = _generator.CreateXfoResult(xFrameConfig);

            Assert.IsNotNull(result);
            Assert.AreEqual(HeaderResult.ResponseAction.Set, result.Action);
            Assert.AreEqual("X-Frame-Options", result.Name);
            Assert.AreEqual("SameOrigin", result.Value);
        }
コード例 #6
0
        public void SetXFrameoptionsHeader_NoOverride_DoesNothing()
        {
            var contextConfig = new XFrameOptionsConfiguration();
            _contextHelper.Setup(h => h.GetXFrameOptionsConfiguration(It.IsAny<HttpContextBase>())).Returns(contextConfig);
            _configurationOverrideHelper.Setup(h => h.GetXFrameoptionsWithOverride(It.IsAny<HttpContextBase>())).Returns((XFrameOptionsConfiguration)null);

            _overrideHelper.SetXFrameoptionsHeader(_mockContext);

            _headerGenerator.Verify(g => g.CreateXfoResult(It.IsAny<XFrameOptionsConfiguration>(), It.IsAny<XFrameOptionsConfiguration>()), Times.Never);
            _headerResultHandler.Verify(h => h.HandleHeaderResult(It.IsAny<HttpResponseBase>(), It.IsAny<HeaderResult>()), Times.Never);
        }
コード例 #7
0
        public void SetXFrameoptionsHeader_Override_CreatesAndHandlesHeaderResult()
        {
            var contextConfig = new XFrameOptionsConfiguration();
            var overrideConfig = new XFrameOptionsConfiguration();
            _contextHelper.Setup(h => h.GetXFrameOptionsConfiguration(It.IsAny<HttpContextBase>())).Returns(contextConfig);
            _configurationOverrideHelper.Setup(h => h.GetXFrameoptionsWithOverride(It.IsAny<HttpContextBase>())).Returns(overrideConfig);
            _headerGenerator.Setup(g => g.CreateXfoResult(overrideConfig, contextConfig)).Returns(_expectedHeaderResult);

            _overrideHelper.SetXFrameoptionsHeader(_mockContext);

            _headerResultHandler.Verify(h => h.HandleHeaderResult(It.IsAny<HttpResponseBase>(), _expectedHeaderResult), Times.Once);
        }
コード例 #8
0
        public void GetXFrameOptionsConfiguration_HasOwinConfig_ReturnsOwinConfig()
        {
            SetupOwinContext();
            var config = new XFrameOptionsConfiguration();
            _owinContext.XFrameOptions = config;

            var result = _contextHelper.GetXFrameOptionsConfiguration(_mockContext);

            Assert.AreSame(config, result);
        }