コード例 #1
0
        public void GetXContentTypeOptionsWithOverride_ConfigOverriden_ReturnsOverrideElement()
        {
            var configOverride = new SimpleBooleanConfiguration { Enabled = true };

            _headerConfigurationOverrideHelper.SetXContentTypeOptionsOverride(_mockContext, configOverride);

            Assert.AreSame(configOverride, _headerConfigurationOverrideHelper.GetXContentTypeOptionsWithOverride(_mockContext));
        }
コード例 #2
0
        public void CreateXDownloadOptionsResult_Disabled_ReturnsNull()
        {
            var downloadOptions = new SimpleBooleanConfiguration { Enabled = false };

            var result = _generator.CreateXDownloadOptionsResult(downloadOptions);

            Assert.IsNull(result);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);

        }
コード例 #6
0
 /// <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();
 }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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());
        }
コード例 #10
0
        public void GetXDownloadOptionsConfiguration_HasOwinConfig_ReturnsOwinConfig()
        {
            SetupOwinContext();
            var config = new SimpleBooleanConfiguration();
            _owinContext.XDownloadOptions = config;

            var result = _contextHelper.GetXDownloadOptionsConfiguration(_mockContext);

            Assert.AreSame(config, result);
        }
コード例 #11
0
        public void GetXDownloadOptionsConfiguration_NoOwinContext_ReturnsSystemWebConfig()
        {
            var config = new SimpleBooleanConfiguration();
            _systemWebContext.XDownloadOptions = config;

            var result = _contextHelper.GetXDownloadOptionsConfiguration(_mockContext);

            Assert.AreSame(config, result);
        }
コード例 #12
0
        public void GetXContentTypeOptionsConfiguration_OwinContextWithoutConfig_ReturnsSystemWebConfig()
        {
            SetupOwinContext();
            var config = new SimpleBooleanConfiguration();
            _systemWebContext.XContentTypeOptions = config;

            var result = _contextHelper.GetXContentTypeOptionsConfiguration(_mockContext);

            Assert.AreSame(config, result);
        }
コード例 #13
0
 /// <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();
 }