public void SetCspMixedContentOverride_NoCurrentOverride_ClonesConfigFromContextAndOverrides(bool reportOnly) { var contextConfig = new CspConfiguration(); var overrideConfig = new CspOverrideConfiguration(); //Returns CSP config from context _contextHelper.Setup(h => h.GetCspConfiguration(It.IsAny <HttpContext>(), reportOnly)).Returns(contextConfig); _contextHelper.Setup(h => h.GetCspConfigurationOverride(It.IsAny <HttpContext>(), reportOnly, false)).Returns(overrideConfig); //Returns cloned directive config from context config var clonedContextDirective = new CspMixedContentDirectiveConfiguration(); _directiveConfigMapper.Setup(m => m.GetCspMixedContentConfigCloned(contextConfig)).Returns(clonedContextDirective); //We need an override and a result. var directiveOverride = new CspMixedContentOverride(); var directiveOverrideResult = new CspMixedContentDirectiveConfiguration(); _directiveOverrideHelper.Setup(h => h.GetOverridenCspMixedContentConfig(directiveOverride, clonedContextDirective)).Returns(directiveOverrideResult); _cspConfigurationOverrideHelper.SetCspMixedContentOverride(MockContext, directiveOverride, reportOnly); //Verify that the override result was set on the override config. Assert.Same(directiveOverrideResult, overrideConfig.MixedContentDirective); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { _configurationOverrideHelper.SetCspMixedContentOverride(filterContext.HttpContext, _directive, ReportOnly); base.OnActionExecuting(filterContext); }