예제 #1
0
 public XXssMiddleware(AppFunc next, XXssProtectionOptions options)
     : base(next)
 {
     _config = options;
     var headerGenerator = new HeaderGenerator();
     _headerResult = headerGenerator.CreateXXssProtectionResult(_config);
 }
        public void HeaderModuleTestInitialize()
        {
            _mockRequest = new Mock<HttpRequestBase>();
            _mockRequest.Setup(r => r.UserAgent).Returns("Ninja CSP browser");

            _responseHeaders = new NameValueCollection();
            _mockResponse = new Mock<HttpResponseBase>();
            _mockResponse.Setup(r => r.Headers).Returns(_responseHeaders);

            var mockedContext = new Mock<HttpContextBase>();
            mockedContext.SetupAllProperties();
            mockedContext.Setup(c => c.Request).Returns(_mockRequest.Object);
            mockedContext.Setup(c => c.Response).Returns(_mockResponse.Object);

            _expectedHeaderResult = new HeaderResult(HeaderResult.ResponseAction.Set, "SomeHeader", "SomeValue");
            _mockHeaderGenerator = new Mock<IHeaderGenerator>(MockBehavior.Strict);
            _mockHeaderResultHandler = new Mock<IHeaderResultHandler>(MockBehavior.Strict);
            _mockHeaderResultHandler.Setup(h => h.HandleHeaderResult(It.IsAny<HttpResponseBase>(), _expectedHeaderResult));

            _mockHandlerHelper = new Mock<IHandlerTypeHelper>();
            _mockCspReportHelper = new Mock<ICspReportHelper>(MockBehavior.Strict);

            _mockContext = mockedContext.Object;

            _config = new HttpHeaderSecurityConfigurationSection();
            _configHeaderSetter = new ConfigurationHeaderSetter(_config, _mockHeaderGenerator.Object, _mockHeaderResultHandler.Object, _mockHandlerHelper.Object, _mockCspReportHelper.Object);
            _nwebsecContext = new NWebsecContext();
        }
 public XDownloadOptionsMiddleware(AppFunc next)
     : base(next)
 {
     _config = new SimpleBooleanConfiguration { Enabled = true };
     var headerGenerator = new HeaderGenerator();
     _headerResult = headerGenerator.CreateXDownloadOptionsResult(_config);
 }
예제 #4
0
 public XfoMiddleware(AppFunc next, XFrameOptions options)
     : base(next)
 {
     _config = options;
     var headerGenerator = new HeaderGenerator();
     _headerResult = headerGenerator.CreateXfoResult(_config);
 }
예제 #5
0
        public HpkpMiddleware(AppFunc next, HpkpOptions options, bool reportOnly)
            : base(next)
        {
            _config = options.Config;

            var headerGenerator = new HeaderGenerator();
            _headerResult = headerGenerator.CreateHpkpResult(_config, reportOnly);
        }
예제 #6
0
        public HstsMiddleware(AppFunc next, HstsOptions options)
            : base(next)
        {
            _config = options;

            var headerGenerator = new HeaderGenerator();
            _headerResult = headerGenerator.CreateHstsResult(_config);
        }
예제 #7
0
        public XRobotsTagMiddleware(AppFunc next, XRobotsTagOptions options)
            : base(next)
        {
            _config = options.Config;

            var headerGenerator = new HeaderGenerator();
            _headerResult = headerGenerator.CreateXRobotsTagResult(_config);
        }
예제 #8
0
        public CspMiddleware(AppFunc next, ICspConfiguration options, bool reportOnly)
            : base(next)
        {
            _config = options;
            _reportOnly = reportOnly;

            var headerGenerator = new HeaderGenerator();
            _headerResult = headerGenerator.CreateCspResult(_config, reportOnly);
        }
        public void HandleHeaderResult_RemoveHeaderResult_RemovesHeader()
        {
            _responseHeaders.Set("NinjaHeader", "toberemoved");
            var headerResult = new HeaderResult(HeaderResult.ResponseAction.Remove, "NinjaHeader");

            _resultHandler.HandleHeaderResult(_httpResponse, headerResult);

            Assert.AreEqual(0, _responseHeaders.Count);
        }
        public void HandleHeaderResult_SetHeaderResult_SetsHeader()
        {
            var headerResult = new HeaderResult(HeaderResult.ResponseAction.Set, "NinjaHeader", "value");

            _resultHandler.HandleHeaderResult(_httpResponse, headerResult);

            Assert.AreEqual(1, _responseHeaders.Count);
            var headerValue = _responseHeaders.Get("NinjaHeader");
            Assert.IsNotNull(headerValue);
            Assert.AreEqual("value", headerValue);
        }
예제 #11
0
        public void HandleHeaderResult(HttpResponseBase response, HeaderResult result)
        {
            if (result == null)
            {
                return;
            }

            switch (result.Action)
            {
                case HeaderResult.ResponseAction.Set:
                    response.Headers.Set(result.Name, result.Value);
                    return;
                case HeaderResult.ResponseAction.Remove:
                    response.Headers.Remove(result.Name);
                    return;

            }
        }  
        public void Setup()
        {
            _contextHelper = new Mock<IContextConfigurationHelper>(MockBehavior.Strict);
            _configurationOverrideHelper = new Mock<IHeaderConfigurationOverrideHelper>(MockBehavior.Strict);
            _headerGenerator = new Mock<IHeaderGenerator>(MockBehavior.Strict);

            _expectedHeaderResult = new HeaderResult(HeaderResult.ResponseAction.Set, "ExpectedHeader", "ninjavalue");
            _headerResultHandler = new Mock<IHeaderResultHandler>(MockBehavior.Strict);
            _headerResultHandler.Setup(h => h.HandleHeaderResult(It.IsAny<HttpResponseBase>(), _expectedHeaderResult));

            _cspConfigurationOverrideHelper = new Mock<ICspConfigurationOverrideHelper>(MockBehavior.Strict);
            _reportHelper = new Mock<ICspReportHelper>(MockBehavior.Strict);

            _overrideHelper = new HeaderOverrideHelper(_contextHelper.Object,
                _configurationOverrideHelper.Object,
                _headerGenerator.Object,
                _headerResultHandler.Object,
                _cspConfigurationOverrideHelper.Object,
                _reportHelper.Object);

            _mockContext = new Mock<HttpContextBase>().Object;
        }