Esempio n. 1
0
        public void WillNotFlushReductionsOnFlushUrlWhenAuthorizedUsersIsAnonymousButBlockedByIpFilterAndReturn401()
        {
            var testable = new TestableFlushHandler();

            testable.Mock <IRRConfiguration>().Setup(x => x.AuthorizedUserList).Returns(RRConfiguration.Anonymous);
            testable.Mock <IRRConfiguration>().Setup(x => x.IpFilterList).Returns(new[] { "1.2.3.4", " 3.4.5.6" });
            testable.Mock <IRRConfiguration>().Setup(x => x.ResourceVirtualPath).Returns("/RRContent");
            var context  = new Mock <HttpContextBase>();
            var response = new Mock <HttpResponseBase>();

            response.SetupProperty(x => x.StatusCode);
            context.Setup(x => x.Request.Url).Returns(new Uri("http://host/RRContent/flush/page.aspx"));
            var identity = new Mock <IIdentity>();

            identity.Setup(x => x.IsAuthenticated).Returns(false);
            context.Setup(x => x.User.Identity).Returns(identity.Object);
            context.Setup(x => x.Response).Returns(response.Object);
            context.Setup(x => x.Server).Returns(new Mock <HttpServerUtilityBase>().Object);
            context.Setup(x => x.Request.UserHostAddress).Returns("10.0.0.1");
            context.Setup(x => x.Request.ServerVariables).Returns(new NameValueCollection {
                { "HTTP_X_FORWARDED_FOR", "9.9.9.9" }
            });

            testable.ClassUnderTest.ProcessRequest(context.Object);

            testable.Mock <IStore>().Verify(x => x.Flush(It.IsAny <Guid>()), Times.Never());
            Assert.Equal(401, response.Object.StatusCode);
        }
        public void WillNotFlushReductionsOnFlushUrlWhenCurrentUserIsAuthorizedUserButBlockedByIpFilterAndReturn401()
        {
            var testable = new TestableFlushHandler();

            testable.Mock <IRRConfiguration>().Setup(x => x.AuthorizedUserList).Returns(new[] { "user1", "user2" });
            testable.Mock <IRRConfiguration>().Setup(x => x.IpFilterList).Returns(new[] { "1.2.3.4", " 3.4.5.6" });
            testable.Mock <IRRConfiguration>().Setup(x => x.SpriteVirtualPath).Returns("/RRContent");
            var context  = new Mock <HttpContextBase>();
            var response = new Mock <HttpResponseBase>();

            response.SetupProperty(x => x.StatusCode);
            context.Setup(x => x.Request.Url).Returns(new Uri("http://host/RRContent/flush/page.aspx"));
            var identity = new Mock <IIdentity>();

            identity.Setup(x => x.IsAuthenticated).Returns(true);
            identity.Setup(x => x.Name).Returns("user2");
            context.Setup(x => x.User.Identity).Returns(identity.Object);
            context.Setup(x => x.Response).Returns(response.Object);
            context.Setup(x => x.Server).Returns(new Mock <HttpServerUtilityBase>().Object);
            context.Setup(x => x.Request.UserHostAddress).Returns("9.9.9.9");

            testable.ClassUnderTest.ProcessRequest(context.Object);

            testable.Mock <IStore>().Verify(x => x.Flush(It.IsAny <Guid>()), Times.Never());
            Assert.Equal(401, response.Object.StatusCode);
        }
Esempio n. 3
0
        public void WillFlushFailuresOnFlushFailureUrlWhenAndAuthorizedUsersIsAnonymousAndNull()
        {
            var testable = new TestableFlushHandler();

            testable.Mock <IRRConfiguration>().Setup(x => x.AuthorizedUserList).Returns(RRConfiguration.Anonymous);
            testable.Mock <IRRConfiguration>().Setup(x => x.ResourceVirtualPath).Returns("/RRContent");
            var context = new Mock <HttpContextBase>();

            context.Setup(x => x.Response).Returns(new Mock <HttpResponseBase>().Object);
            context.Setup(x => x.Request.Url).Returns(new Uri("http://host/RRContent/FlushFailures/page.aspx"));
            context.Setup(x => x.Server).Returns(new Mock <HttpServerUtilityBase>().Object);
            context.Setup(x => x.User).Returns(null as IPrincipal);

            testable.ClassUnderTest.ProcessRequest(context.Object);

            testable.Mock <IReducingQueue>().Verify(x => x.ClearFailures(), Times.Once());
        }
Esempio n. 4
0
        public void WillSetPhysicalPathToMappedVirtualPathOnFlush()
        {
            var testable = new TestableFlushHandler();
            var context  = new Mock <HttpContextBase>();

            context.Setup(x => x.Response).Returns(new Mock <HttpResponseBase>().Object);
            testable.Mock <IRRConfiguration>().Setup(x => x.ResourceVirtualPath).Returns("/RRContent");
            testable.Mock <IRRConfiguration>().Setup(x => x.AuthorizedUserList).Returns(RRConfiguration.Anonymous);
            testable.Mock <IHostingEnvironmentWrapper>().Setup(x => x.MapPath("/RRContent")).Returns("physical");
            context.Setup(x => x.Request.Url).Returns(new Uri("http://host/RRContent/FlushFailures/page.aspx"));
            var identity = new Mock <IIdentity>();

            identity.Setup(x => x.IsAuthenticated).Returns(false);
            context.Setup(x => x.User.Identity).Returns(identity.Object);

            testable.ClassUnderTest.ProcessRequest(context.Object);

            testable.Mock <IRRConfiguration>().VerifySet(x => x.ResourcePhysicalPath = "physical", Times.Once());
        }
Esempio n. 5
0
        public void WillFlushFailuresOnFlushFailureUrlWithTrailingSlashWhenAndAuthorizedUsersIsAnonymous()
        {
            var testable = new TestableFlushHandler();

            testable.Mock <IRRConfiguration>().Setup(x => x.AuthorizedUserList).Returns(RRConfiguration.Anonymous);
            testable.Mock <IRRConfiguration>().Setup(x => x.ResourceVirtualPath).Returns("/RRContent");
            var context = new Mock <HttpContextBase>();

            context.Setup(x => x.Response).Returns(new Mock <HttpResponseBase>().Object);
            context.Setup(x => x.Request.Url).Returns(new Uri("http://host/RRContent/FlushFailures/"));
            context.Setup(x => x.Server).Returns(new Mock <HttpServerUtilityBase>().Object);
            var identity = new Mock <IIdentity>();

            identity.Setup(x => x.IsAuthenticated).Returns(false);
            context.Setup(x => x.User.Identity).Returns(identity.Object);

            testable.ClassUnderTest.ProcessRequest(context.Object);

            testable.Mock <IReducingQueue>().Verify(x => x.ClearFailures(), Times.Once());
        }
Esempio n. 6
0
        public void WillFlushReductionsOnFlushUrlWithTrailingSlashWhenCurrentUserIsAuthorizedUser()
        {
            var testable = new TestableFlushHandler();

            testable.Mock <IRRConfiguration>().Setup(x => x.AuthorizedUserList).Returns(new[] { "user1", "user2" });
            testable.Mock <IRRConfiguration>().Setup(x => x.ResourceVirtualPath).Returns("/RRContent");
            var context = new Mock <HttpContextBase>();

            context.Setup(x => x.Response).Returns(new Mock <HttpResponseBase>().Object);
            context.Setup(x => x.Request.Url).Returns(new Uri("http://host/RRContent/flush/"));
            var identity = new Mock <IIdentity>();

            identity.Setup(x => x.IsAuthenticated).Returns(true);
            identity.Setup(x => x.Name).Returns("user2");
            context.Setup(x => x.User.Identity).Returns(identity.Object);
            context.Setup(x => x.Server).Returns(new Mock <HttpServerUtilityBase>().Object);

            testable.ClassUnderTest.ProcessRequest(context.Object);

            testable.Mock <IStore>().Verify(x => x.Flush(Guid.Empty), Times.Once());
        }
Esempio n. 7
0
        public void WillFlushReductionsOnFlushUrlWhenAndAuthorizedUsersIsAnonymous(string url, string key)
        {
            var testable = new TestableFlushHandler();

            testable.Mock <IRRConfiguration>().Setup(x => x.AuthorizedUserList).Returns(RRConfiguration.Anonymous);
            testable.Mock <IRRConfiguration>().Setup(x => x.ResourceVirtualPath).Returns("/RRContent");
            var context = new Mock <HttpContextBase>();

            context.Setup(x => x.Response).Returns(new Mock <HttpResponseBase>().Object);
            context.Setup(x => x.Request.Url).Returns(new Uri(url));
            var identity = new Mock <IIdentity>();

            identity.Setup(x => x.IsAuthenticated).Returns(false);
            context.Setup(x => x.User.Identity).Returns(identity.Object);
            context.Setup(x => x.Server).Returns(new Mock <HttpServerUtilityBase>().Object);
            var keyGuid = Guid.Parse(key);

            testable.ClassUnderTest.ProcessRequest(context.Object);

            testable.Mock <IStore>().Verify(x => x.Flush(keyGuid), Times.Once());
        }
Esempio n. 8
0
        public void WillFlushReductionsOnFlushUrlWhenCurrentUserIsAuthorizedUserAndEquivalentIpv6IsInIpFilter()
        {
            var testable = new TestableFlushHandler();

            testable.Mock <IRRConfiguration>().Setup(x => x.AuthorizedUserList).Returns(new[] { "user1", "user2" });
            testable.Mock <IRRConfiguration>().Setup(x => x.IpFilterList).Returns(new[] { "3780:0:c307:0:2c45:0:81c7:9273" });
            testable.Mock <IRRConfiguration>().Setup(x => x.ResourceVirtualPath).Returns("/RRContent");
            var context = new Mock <HttpContextBase>();

            context.Setup(x => x.Response).Returns(new Mock <HttpResponseBase>().Object);
            context.Setup(x => x.Request.Url).Returns(new Uri("http://host/RRContent/flush/page.aspx"));
            var identity = new Mock <IIdentity>();

            identity.Setup(x => x.IsAuthenticated).Returns(true);
            identity.Setup(x => x.Name).Returns("user2");
            context.Setup(x => x.User.Identity).Returns(identity.Object);
            context.Setup(x => x.Server).Returns(new Mock <HttpServerUtilityBase>().Object);
            context.Setup(x => x.Request.UserHostAddress).Returns("3780:0000:c307:0000:2c45:0000:81c7:9273");

            testable.ClassUnderTest.ProcessRequest(context.Object);

            testable.Mock <IStore>().Verify(x => x.Flush(Guid.Empty), Times.Once());
        }