public void GetCorsPolicyAsync_NoAllowedOriginsNoCallback_DoesNotAllowOrigin()
 {
     var policy = new Core.Configuration.CorsPolicy();
     var subject = new CorsPolicyProvider(policy, new string[] { "/" });
     var cp = subject.GetCorsPolicyAsync(Request("http://foo.com")).Result;
     cp.Should().BeNull();
 }
        public void GetCorsPolicyAsync_PolicyAllowsAll_AllowsRandomOrigin()
        {
            var policy = Core.Configuration.CorsPolicy.AllowAll;
            var subject = new CorsPolicyProvider(policy, new string[] { "/" });

            var rnd = new Random().Next();
            var origin = "http://foo" + rnd + ".com";
            var cp = subject.GetCorsPolicyAsync(Request(origin)).Result;
            AssertAllowed(origin, cp);
        }
        public void GetCorsPolicyAsync_OriginIsInAllowedOriginsButNoOriginRequested_DoesNotAllowOrigin()
        {
            var origin = "http://foo.com";
            var policy = new Core.Configuration.CorsPolicy();
            policy.AllowedOrigins.Add(origin);
            var subject = new CorsPolicyProvider(policy, new string[] { "/" });

            var cp = subject.GetCorsPolicyAsync(Request(null)).Result;
            cp.Should().BeNull();
        }
        public void GetCorsPolicyAsync_OriginIsInAllowedOrigins_AllowOrigin()
        {
            var origin = "http://foo.com";
            var policy = new Core.Configuration.CorsPolicy();
            policy.AllowedOrigins.Add(origin);
            var subject = new CorsPolicyProvider(policy, new string[] { "/" });

            var cp = subject.GetCorsPolicyAsync(Request(origin)).Result;
            AssertAllowed(origin, cp);
        }
        public void GetCorsPolicyAsync_PathEndsWithSlash_NormalizesPathCorrectly()
        {
            var origin = "http://foo.com";
            var policy = Core.Configuration.CorsPolicy.AllowAll;

            var subject = new CorsPolicyProvider(policy, new string[] { "bar/" });

            var cp = subject.GetCorsPolicyAsync(Request(origin, "/bar")).Result;
            AssertAllowed(origin, cp);
        }
        public void GetCorsPolicyAsync_NoMatchingPaths_DoesNotAllowOrigin()
        {
            var origin = "http://foo.com";
            var policy = Core.Configuration.CorsPolicy.AllowAll;

            var subject = new CorsPolicyProvider(policy, new string[] { "/bar", "/baz", "/quux" });

            var cp = subject.GetCorsPolicyAsync(Request(origin, "/bad")).Result;
            cp.Should().BeNull();
        }
        public void GetCorsPolicyAsync_MatchingPaths_AllowsOrigin()
        {
            var origin = "http://foo.com";
            var policy = Core.Configuration.CorsPolicy.AllowAll;

            var subject = new CorsPolicyProvider(policy, new string[] { "/bar", "/baz", "/quux" });

            var cp = subject.GetCorsPolicyAsync(Request(origin, "/baz")).Result;
            AssertAllowed(origin, cp);
        }
        public void GetCorsPolicyAsync_CallbackDoesNotAllowOrigin_DoesNotAllowOrigin()
        {
            var origin = "http://foo.com";
            var policy = new Core.Configuration.CorsPolicy();
            policy.PolicyCallback = o => Task.FromResult(false);
            var subject = new CorsPolicyProvider(policy, new string[] { "/" });

            var cp = subject.GetCorsPolicyAsync(Request(origin)).Result;
            cp.Should().BeNull();
        }
        public void GetCorsPolicyAsync_CallbackAllowOriginButNoOriginRequested_DoesNotAllowOrigin()
        {
            var policy = new Core.Configuration.CorsPolicy();
            policy.PolicyCallback = o => Task.FromResult(true);
            var subject = new CorsPolicyProvider(policy, new string[] { "/" });

            var cp = subject.GetCorsPolicyAsync(Request()).Result;
            cp.Should().BeNull();
        }
        public void GetCorsPolicyAsync_CallbackAllowOrigin_AllowOrigin()
        {
            var origin = "http://foo.com";
            var policy = new Core.Configuration.CorsPolicy();
            policy.PolicyCallback = o => Task.FromResult(true);
            var subject = new CorsPolicyProvider(policy, new string[] { "/" });

            var cp = subject.GetCorsPolicyAsync(Request(origin)).Result;
            AssertAllowed(origin, cp);
        }