Example #1
0
        public void Build_WhenNoValues_ReturnsNullValue()
        {
            var builder = new CrossOriginOpenerPolicyBuilder();

            var result = builder.Build();

            result.ConstantValue.Should().BeNullOrEmpty();
        }
Example #2
0
        public void Build_AddSameOriginAllowPopups_AddsValue()
        {
            var builder = new CrossOriginOpenerPolicyBuilder();

            builder.SameOriginAllowPopups();

            var result = builder.Build();

            result.ConstantValue.Should().Be("same-origin-allow-popups");
        }
Example #3
0
        public void Build_AddUnsafeNone_AddsValue()
        {
            var builder = new CrossOriginOpenerPolicyBuilder();

            builder.UnsafeNone();

            var result = builder.Build();

            result.ConstantValue.Should().Be("unsafe-none");
        }
Example #4
0
        /// <summary>
        /// Configure a Cross Origin Opener Policy
        /// </summary>
        /// <param name="configure">Configure the Cross Origin Opener Policy</param>
        /// <param name="asReportOnly">If true, the header is added as report only</param>
        /// <returns>The configured <see cref="CrossOriginOpenerPolicyHeader "/></returns>
        public static CrossOriginOpenerPolicyHeader Build(Action <CrossOriginOpenerPolicyBuilder> configure, bool asReportOnly)
        {
            var builder = new CrossOriginOpenerPolicyBuilder();

            configure(builder);

            var coopResult = builder.Build();

            return(new StaticCrossOriginOpenerPolicyHeader(coopResult.ConstantValue, asReportOnly));
        }
Example #5
0
        public void Build_AddSameOriginAllowPopups_WithReportEndpoint_AddsValue()
        {
            var builder = new CrossOriginOpenerPolicyBuilder();

            builder.SameOriginAllowPopups();
            builder.AddReport().To("default");

            var result = builder.Build();

            result.ConstantValue.Should().Be("same-origin-allow-popups; report-to=\"default\"");
        }
Example #6
0
        public void Build_AddUnsafeNone_WithReportEndpoint_AddsValue()
        {
            var builder = new CrossOriginOpenerPolicyBuilder();

            builder.UnsafeNone();
            builder.AddReport().To("default");

            var result = builder.Build();

            result.ConstantValue.Should().Be("unsafe-none; report-to=\"default\"");
        }