public void GetXContentTypeOptionsWithOverride_ConfigOverriden_ReturnsOverrideElement()
        {
            var configOverride = new SimpleBooleanConfiguration { Enabled = true };

            _headerConfigurationOverrideHelper.SetXContentTypeOptionsOverride(_mockContext, configOverride);

            Assert.AreSame(configOverride, _headerConfigurationOverrideHelper.GetXContentTypeOptionsWithOverride(_mockContext));
        }
        public void CreateXDownloadOptionsResult_Disabled_ReturnsNull()
        {
            var downloadOptions = new SimpleBooleanConfiguration { Enabled = false };

            var result = _generator.CreateXDownloadOptionsResult(downloadOptions);

            Assert.IsNull(result);
        }
        public void CreateXDownloadOptionsResult_Enabled_ReturnsSetXDownloadOptionsResult()
        {
            var downloadOptions = new SimpleBooleanConfiguration { Enabled = true };

            var result = _generator.CreateXDownloadOptionsResult(downloadOptions);

            Assert.IsNotNull(result);
            Assert.AreEqual(HeaderResult.ResponseAction.Set, result.Action);
            Assert.AreEqual("X-Download-Options", result.Name);
            Assert.AreEqual("noopen", result.Value);
        }
        public void CreateXContentTypeOptionsResult_Enabled_ReturnsSetXXContentTypeOptionsResult()
        {
            var contentTypeOptions = new SimpleBooleanConfiguration { Enabled = true };

            var result = _generator.CreateXContentTypeOptionsResult(contentTypeOptions);

            Assert.IsNotNull(result);
            Assert.AreEqual(HeaderResult.ResponseAction.Set, result.Action);
            Assert.AreEqual("X-Content-Type-Options", result.Name);
            Assert.AreEqual("nosniff", result.Value);
        }
        public void CreateXDownloadOptionsResult_DisabledButEnabledInOldConfig_ReturnsRemoveXDownloadOptionsResult()
        {
            var downloadOptions = new SimpleBooleanConfiguration { Enabled = false };
            var oldDownloadOptions = new SimpleBooleanConfiguration { Enabled = true };

            var result = _generator.CreateXDownloadOptionsResult(downloadOptions, oldDownloadOptions);

            Assert.IsNotNull(result);
            Assert.AreEqual(HeaderResult.ResponseAction.Remove, result.Action);
            Assert.AreEqual("X-Download-Options", result.Name);

        }
 /// <summary>
 /// Initializes a new instance of the <see cref="XContentTypeOptionsAttribute"/> class
 /// </summary>
 public XContentTypeOptionsAttribute()
 {
     _config = new SimpleBooleanConfiguration { Enabled = true };
     _headerConfigurationOverrideHelper = new HeaderConfigurationOverrideHelper();
     _headerOverrideHelper = new HeaderOverrideHelper();
 }
        public void SetXDownloadOptionsHeader_Override_CreatesAndHandlesHeaderResult()
        {
            var contextConfig = new SimpleBooleanConfiguration();
            var overrideConfig = new SimpleBooleanConfiguration();
            _contextHelper.Setup(h => h.GetXDownloadOptionsConfiguration(It.IsAny<HttpContextBase>())).Returns(contextConfig);
            _configurationOverrideHelper.Setup(h => h.GetXDownloadOptionsWithOverride(It.IsAny<HttpContextBase>())).Returns(overrideConfig);
            _headerGenerator.Setup(g => g.CreateXDownloadOptionsResult(overrideConfig, contextConfig)).Returns(_expectedHeaderResult);

            _overrideHelper.SetXDownloadOptionsHeader(_mockContext);

            _headerResultHandler.Verify(h => h.HandleHeaderResult(It.IsAny<HttpResponseBase>(), _expectedHeaderResult), Times.Once);
        }
        public void SetXDownloadOptionsHeader_NoOverride_DoesNothing()
        {
            var contextConfig = new SimpleBooleanConfiguration();
            _contextHelper.Setup(h => h.GetXDownloadOptionsConfiguration(It.IsAny<HttpContextBase>())).Returns(contextConfig);
            _configurationOverrideHelper.Setup(h => h.GetXDownloadOptionsWithOverride(It.IsAny<HttpContextBase>())).Returns((SimpleBooleanConfiguration)null);

            _overrideHelper.SetXDownloadOptionsHeader(_mockContext);

            _headerGenerator.Verify(g => g.CreateXDownloadOptionsResult(It.IsAny<SimpleBooleanConfiguration>(), It.IsAny<SimpleBooleanConfiguration>()), Times.Never);
            _headerResultHandler.Verify(h => h.HandleHeaderResult(It.IsAny<HttpResponseBase>(), It.IsAny<HeaderResult>()), Times.Never);
        }
        public void SetNoCacheHeaders_OverrideAndEnabled_SetsCacheHeaders()
        {
            //Get ASP.NET stuff in order
            var cachePolicy = new Mock<HttpCachePolicyBase>();
            var responseHeaders = new NameValueCollection();
            var response = new Mock<HttpResponseBase>();
            response.Setup(r => r.Cache).Returns(cachePolicy.Object);
            response.Setup(r => r.Headers).Returns(responseHeaders);
            Mock.Get(_mockContext).Setup(c => c.Response).Returns(response.Object);

            var overrideConfig = new SimpleBooleanConfiguration { Enabled = true };
            _configurationOverrideHelper.Setup(h => h.GetNoCacheHeadersWithOverride(It.IsAny<HttpContextBase>())).Returns(overrideConfig);

            _overrideHelper.SetNoCacheHeaders(_mockContext);

            cachePolicy.Verify(c => c.SetCacheability(HttpCacheability.NoCache), Times.Once());
            cachePolicy.Verify(c => c.SetNoStore(), Times.Once());
            cachePolicy.Verify(c => c.SetRevalidation(HttpCacheRevalidation.AllCaches), Times.Once());
        }
        public void GetXDownloadOptionsConfiguration_HasOwinConfig_ReturnsOwinConfig()
        {
            SetupOwinContext();
            var config = new SimpleBooleanConfiguration();
            _owinContext.XDownloadOptions = config;

            var result = _contextHelper.GetXDownloadOptionsConfiguration(_mockContext);

            Assert.AreSame(config, result);
        }
        public void GetXDownloadOptionsConfiguration_NoOwinContext_ReturnsSystemWebConfig()
        {
            var config = new SimpleBooleanConfiguration();
            _systemWebContext.XDownloadOptions = config;

            var result = _contextHelper.GetXDownloadOptionsConfiguration(_mockContext);

            Assert.AreSame(config, result);
        }
        public void GetXContentTypeOptionsConfiguration_OwinContextWithoutConfig_ReturnsSystemWebConfig()
        {
            SetupOwinContext();
            var config = new SimpleBooleanConfiguration();
            _systemWebContext.XContentTypeOptions = config;

            var result = _contextHelper.GetXContentTypeOptionsConfiguration(_mockContext);

            Assert.AreSame(config, result);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SetNoCacheHttpHeadersAttribute"/> class
 /// </summary>
 public SetNoCacheHttpHeadersAttribute()
 {
     _config = new SimpleBooleanConfiguration { Enabled = true };
     _configurationOverrideHelper = new HeaderConfigurationOverrideHelper();
     _headerOverrideHelper = new HeaderOverrideHelper();
 }