Example #1
0
        public void AddDefaultPolicy_SetsDefaultPolicyName()
        {
            // Arrange
            var corsOptions    = new CorsOptions();
            var expectedPolicy = new CorsPolicy();

            // Act
            corsOptions.AddPolicy("policy1", new CorsPolicy());
            corsOptions.AddDefaultPolicy(expectedPolicy);
            corsOptions.AddPolicy("policy3", new CorsPolicy());

            // Assert
            var actualPolicy = corsOptions.GetPolicy(corsOptions.DefaultPolicyName);

            Assert.Same(expectedPolicy, actualPolicy);
        }
Example #2
0
        public void AddDefaultPolicy_UsingPolicyBuilder_SetsDefaultPolicyName()
        {
            // Arrange
            var        corsOptions    = new CorsOptions();
            CorsPolicy expectedPolicy = null;

            // Act
            corsOptions.AddPolicy("policy1", policyBuilder =>
            {
                policyBuilder.AllowAnyOrigin().Build();
            });
            corsOptions.AddDefaultPolicy(policyBuilder =>
            {
                expectedPolicy = policyBuilder.AllowAnyOrigin().Build();
            });
            corsOptions.AddPolicy("policy3", new CorsPolicy());

            // Assert
            var actualPolicy = corsOptions.GetPolicy(corsOptions.DefaultPolicyName);

            Assert.Same(expectedPolicy, actualPolicy);
        }
        public async Task GetsNamedPolicy(string policyName)
        {
            // Arrange
            var options = new CorsOptions();
            var policy = new CorsPolicy();
            options.AddPolicy(policyName, policy);

            var corsOptions = Options.Create(options);
            var policyProvider = new DefaultCorsPolicyProvider(corsOptions);

            // Act
            var actualPolicy = await policyProvider.GetPolicyAsync(new DefaultHttpContext(), policyName);

            // Assert
            Assert.Same(policy, actualPolicy);
        }
Example #4
0
        public async Task UsesTheDefaultPolicyName()
        {
            // Arrange
            var options = new CorsOptions();
            var policy  = new CorsPolicy();

            options.AddPolicy(options.DefaultPolicyName, policy);

            var corsOptions = new TestCorsOptions
            {
                Value = options
            };
            var policyProvider = new DefaultCorsPolicyProvider(corsOptions);

            // Act
            var actualPolicy = await policyProvider.GetPolicyAsync(new DefaultHttpContext(), policyName : null);

            // Assert
            Assert.Same(policy, actualPolicy);
        }