Example #1
0
        public void Анонимный_вход()
        {
            _httpRequest.SetupGet(request => request.Url).Returns(new Uri("http://localhost.rapidsoft.ru:80"));

            var agent = new Mock <Agent>();

            agent.Setup(a => a.GetSingle("com.sun.identity.agents.config.anonymous.user.enable")).Returns("true");

            _httpContext.SetupSet(c => c.User = It.Is <GenericPrincipal>(p => p.Identity.Name == "")).Verifiable();

            var module = new OpenAMHttpModule(agent.Object);

            module.OnAuthentication(_httpContext.Object);

            _httpContext.Verify();
        }
Example #2
0
        public void Аутентифицирует()
        {
            Login();

            _httpRequest.SetupGet(request => request.Url).Returns(new Uri("http://localhost.rapidsoft.ru:80"));

            var agent = new Mock <Agent>();

            agent.Setup(a => a.GetSingle("com.sun.identity.agents.config.userid.param")).Returns("UserId");

            _httpContext.SetupSet(c => c.User = It.Is <GenericPrincipal>(p => p.Identity.Name != "")).Verifiable();

            var module = new OpenAMHttpModule(agent.Object);

            module.OnAuthentication(_httpContext.Object);

            _httpContext.VerifyAll();
        }
Example #3
0
        public void Пропускает_фри_урлы_без_звезды()
        {
            _httpRequest.SetupGet(request => request.Url).Returns(new Uri("https://www.mysite.com:444/static/image.jpg"));

            var agent = new Mock <Agent>();

            agent.Setup(a => a.GetSingle("com.sun.identity.agents.config.anonymous.user.enable")).Returns("true");
            agent.Setup(a => a.GetOrderedArray("com.sun.identity.agents.config.notenforced.url"))
            .Returns(new[] { "https://www.mysite.com:444/static/image.jpg" });

            _httpContext.SetupSet(c => c.User = It.Is <GenericPrincipal>(p => p.Identity.Name == "")).Verifiable();

            var module = new OpenAMHttpModule(agent.Object);

            module.OnAuthentication(_httpContext.Object);

            _httpContext.Verify();
        }
Example #4
0
        public void Авторизует_если_настроено_без_авторизации()
        {
            Login();

            _httpRequest.SetupGet(request => request.Url).Returns(new Uri("https://www.mysite.com:444/"));

            var agent = new Mock <Agent>();

            agent.Setup(a => a.GetSingle("com.sun.identity.agents.config.userid.param")).Returns("UserId");
            agent.Setup(a => a.GetSingle("com.sun.identity.agents.config.sso.only")).Returns("true");

            _httpContext.SetupSet(c => c.User = It.Is <GenericPrincipal>(p => p.Identity.Name != "")).Verifiable();

            var module = new OpenAMHttpModule(agent.Object);

            module.OnAuthentication(_httpContext.Object);

            _httpContext.VerifyAll();
        }
Example #5
0
        public void Проверяет_IP_и_пропускает()
        {
            Login();

            _httpRequest.SetupGet(request => request.Url).Returns(new Uri("http://localhost.rapidsoft.ru:80"));

            var agent = new Mock <Agent>();

            agent.Setup(a => a.GetSingle("com.sun.identity.agents.config.userid.param")).Returns("UserId");
            agent.Setup(a => a.GetSingle("com.sun.identity.agents.config.client.ip.validation.enable")).Returns("true");

            _httpRequest.SetupGet(c => c.UserHostAddress).Returns("127.0.0.2");
            _httpContext.SetupSet(c => c.User = It.Is <GenericPrincipal>(p => p.Identity.Name != "")).Verifiable();

            var module = new OpenAMHttpModule(agent.Object);

            module.OnAuthentication(_httpContext.Object);

            _httpContext.VerifyAll();
        }
Example #6
0
        public void Мапит_свойства_полиси_в_куки()
        {
            Login();

            _httpRequest.SetupGet(request => request.Url).Returns(new Uri("http://localhost.rapidsoft.ru:80"));

            var agent = new Mock <Agent>();

            agent.Setup(a => a.GetSingle("com.sun.identity.agents.config.userid.param")).Returns("UserId");
            agent.Setup(a => a.GetSingle("com.sun.identity.agents.config.profile.attribute.fetch.mode")).Returns("HTTP_COOKIE");
            agent.Setup(a => a.GetArray("com.sun.identity.agents.config.profile.attribute.mapping"))
            .Returns(new[] { "[uid]=profile-pkn", "[mail]=profile-mail" });

            _httpRequest.SetupGet(c => c.ServerVariables).Returns(new NameValueCollection());

            var module = new OpenAMHttpModule(agent.Object);

            module.OnAuthentication(_httpContext.Object);

            Assert.IsNotNull(_httpContext.Object.Items["profile-pkn"]);
            Assert.IsNotNull(_httpRequest.Object.Cookies["profile-pkn"]);
        }
Example #7
0
        public void Мапит_свойства_сессии_в_сервер_вираблы()
        {
            Login();

            _httpRequest.SetupGet(request => request.Url).Returns(new Uri("http://localhost.rapidsoft.ru:80"));

            var agent = new Mock <Agent>();

            agent.Setup(a => a.GetSingle("com.sun.identity.agents.config.userid.param")).Returns("UserId");
            agent.Setup(a => a.GetSingle("com.sun.identity.agents.config.session.attribute.fetch.mode")).Returns("HTTP_HEADER");
            agent.Setup(a => a.GetArray("com.sun.identity.agents.config.session.attribute.mapping"))
            .Returns(new[] { "[MaxIdleTime]=profile-maxidletime", "[ignoreOTP]=profile-ignore-otp" });

            _httpRequest.SetupGet(c => c.ServerVariables).Returns(new NameValueCollection());

            var module = new OpenAMHttpModule(agent.Object);

            module.OnAuthentication(_httpContext.Object);

            Assert.IsNotNull(_httpContext.Object.Items["profile-maxidletime"]);
            //Assert.IsNotNull(_httpRequest.Object.ServerVariables["profile-maxidletime"]);
            Assert.IsNotNull(_httpContext.Object.Items["profile-ignore-otp"]);
            //Assert.IsNotNull(_httpRequest.Object.ServerVariables["profile-ignore-otp"]);
        }
Example #8
0
        public void Проверяет_IP_и_пропускает_с_вираблами()
        {
            Login();

            _httpRequest.SetupGet(request => request.Url).Returns(new Uri("http://localhost.rapidsoft.ru:80"));

            var agent = new Mock <Agent>();

            agent.Setup(a => a.GetSingle("com.sun.identity.agents.config.userid.param")).Returns("UserId");
            agent.Setup(a => a.GetSingle("com.sun.identity.agents.config.client.ip.validation.enable")).Returns("true");
            agent.Setup(a => a.GetSingle("com.sun.identity.agents.config.client.ip.header")).Returns("HTTP_x-forwarded-for");

            var col = new NameValueCollection();

            col.Add("HTTP_x-forwarded-for", "127.0.0.2, 127.0.0.3");
            _httpRequest.SetupGet(c => c.ServerVariables).Returns(col);
            _httpContext.SetupSet(c => c.User = It.Is <GenericPrincipal>(p => p.Identity.Name != "")).Verifiable();

            var module = new OpenAMHttpModule(agent.Object);

            module.OnAuthentication(_httpContext.Object);

            _httpContext.Verify();
        }