Ejemplo n.º 1
0
    def test_register_redirect(self, pyramid_request):
        pyramid_request.method = "POST"
        pyramid_request.find_service = pretend.call_recorder(
            lambda *args, **kwargs: pretend.stub(
                csp_policy={},
                merge=lambda _: {},
                enabled=False,
                verify_response=pretend.call_recorder(lambda _: None),
                find_userid=pretend.call_recorder(lambda _: None),
                find_userid_by_email=pretend.call_recorder(lambda _: None),
                create_user=pretend.call_recorder(
                    lambda *args, **kwargs: pretend.stub(id=1),
                ),
            )
        )
        pyramid_request.route_path = pretend.call_recorder(lambda name: "/")
        pyramid_request.POST.update({
            "username": "******",
            "password": "******",
            "password_confirm": "MyStr0ng!shP455w0rd",
            "email": "*****@*****.**",
            "full_name": "full_name",
        })

        result = views.register(pyramid_request)
        assert isinstance(result, HTTPSeeOther)
        assert result.headers["Location"] == "/"
Ejemplo n.º 2
0
    def test_register_fails_with_admin_flag_set(self, db_request):
        admin_flag = (db_request.db.query(AdminFlag)
                      .filter(
                          AdminFlag.id == 'disallow-new-user-registration')
                      .first())
        admin_flag.enabled = True
        db_request.method = "POST"

        db_request.POST.update({
            "username": "******",
            "password": "******",
            "password_confirm": "MyStr0ng!shP455w0rd",
            "email": "*****@*****.**",
            "full_name": "full_name",
        })

        db_request.session.flash = pretend.call_recorder(
            lambda *a, **kw: None
        )

        db_request.route_path = pretend.call_recorder(lambda name: "/")

        result = views.register(db_request)

        assert isinstance(result, HTTPSeeOther)
        assert db_request.session.flash.calls == [
            pretend.call(
                ("New User Registration Temporarily Disabled "
                 "See https://pypi.org/help#admin-intervention for details"),
                queue="error"
            ),
        ]
Ejemplo n.º 3
0
 def test_redirect_authenticated_user(self):
     pyramid_request = pretend.stub(authenticated_userid=1)
     pyramid_request.route_path = pretend.call_recorder(
         lambda a: '/the-redirect'
     )
     result = views.register(pyramid_request)
     assert isinstance(result, HTTPSeeOther)
     assert result.headers["Location"] == "/the-redirect"
Ejemplo n.º 4
0
 def test_get(self, db_request):
     form_inst = pretend.stub()
     form = pretend.call_recorder(lambda *args, **kwargs: form_inst)
     db_request.find_service = pretend.call_recorder(
         lambda *args, **kwargs: pretend.stub(enabled=False,
                                              csp_policy=pretend.stub(),
                                              merge=lambda _: None))
     result = views.register(db_request, _form_class=form)
     assert result["form"] is form_inst
Ejemplo n.º 5
0
 def test_get(self, pyramid_request):
     form_inst = pretend.stub()
     form = pretend.call_recorder(lambda *args, **kwargs: form_inst)
     pyramid_request.find_service = pretend.call_recorder(
         lambda *args, **kwargs: pretend.stub(
             enabled=False,
             csp_policy=pretend.stub(),
             merge=lambda _: None,
         )
     )
     result = views.register(pyramid_request, _form_class=form)
     assert result["form"] is form_inst
Ejemplo n.º 6
0
    def test_register_honeypot(self, pyramid_request, monkeypatch):
        pyramid_request.method = "POST"
        create_user = pretend.call_recorder(lambda *args, **kwargs: None)
        add_email = pretend.call_recorder(lambda *args, **kwargs: None)
        pyramid_request.route_path = pretend.call_recorder(lambda name: "/")
        pyramid_request.POST = {"confirm_form": "*****@*****.**"}
        send_email = pretend.call_recorder(lambda *a: None)
        monkeypatch.setattr(views, "send_email_verification_email", send_email)

        result = views.register(pyramid_request)

        assert isinstance(result, HTTPSeeOther)
        assert result.headers["Location"] == "/"
        assert create_user.calls == []
        assert add_email.calls == []
        assert send_email.calls == []
Ejemplo n.º 7
0
    def test_register_redirect(self, db_request, monkeypatch):
        db_request.method = "POST"

        user = pretend.stub(id=pretend.stub())
        email = pretend.stub()
        create_user = pretend.call_recorder(lambda *args, **kwargs: user)
        add_email = pretend.call_recorder(lambda *args, **kwargs: email)
        db_request.find_service = pretend.call_recorder(
            lambda *args, **kwargs: pretend.stub(
                csp_policy={},
                merge=lambda _: {},
                enabled=False,
                verify_response=pretend.call_recorder(lambda _: None),
                find_userid=pretend.call_recorder(lambda _: None),
                find_userid_by_email=pretend.call_recorder(lambda _: None),
                update_user=lambda *args, **kwargs: None,
                create_user=create_user,
                add_email=add_email,
                check_password=lambda pw, tags=None: False,
            ))
        db_request.route_path = pretend.call_recorder(lambda name: "/")
        db_request.POST.update({
            "username": "******",
            "new_password": "******",
            "password_confirm": "MyStr0ng!shP455w0rd",
            "email": "*****@*****.**",
            "full_name": "full_name",
        })
        send_email = pretend.call_recorder(lambda *a: None)
        monkeypatch.setattr(views, "send_email_verification_email", send_email)

        result = views.register(db_request)

        assert isinstance(result, HTTPSeeOther)
        assert result.headers["Location"] == "/"
        assert create_user.calls == [
            pretend.call("username_value", "full_name", "MyStr0ng!shP455w0rd")
        ]
        assert add_email.calls == [
            pretend.call(user.id, "*****@*****.**", primary=True)
        ]
        assert send_email.calls == [pretend.call(db_request, (user, email))]
Ejemplo n.º 8
0
    def test_register_redirect(self, db_request, monkeypatch):
        db_request.method = "POST"

        user = pretend.stub(id=pretend.stub())
        email = pretend.stub()
        create_user = pretend.call_recorder(lambda *args, **kwargs: user)
        add_email = pretend.call_recorder(lambda *args, **kwargs: email)
        db_request.find_service = pretend.call_recorder(
            lambda *args, **kwargs: pretend.stub(
                csp_policy={},
                merge=lambda _: {},
                enabled=False,
                verify_response=pretend.call_recorder(lambda _: None),
                find_userid=pretend.call_recorder(lambda _: None),
                find_userid_by_email=pretend.call_recorder(lambda _: None),
                update_user=lambda *args, **kwargs: None,
                create_user=create_user,
                add_email=add_email,
            )
        )
        db_request.route_path = pretend.call_recorder(lambda name: "/")
        db_request.POST.update({
            "username": "******",
            "new_password": "******",
            "password_confirm": "MyStr0ng!shP455w0rd",
            "email": "*****@*****.**",
            "full_name": "full_name",
        })
        send_email = pretend.call_recorder(lambda *a: None)
        monkeypatch.setattr(views, 'send_email_verification_email', send_email)

        result = views.register(db_request)

        assert isinstance(result, HTTPSeeOther)
        assert result.headers["Location"] == "/"
        assert create_user.calls == [
            pretend.call('username_value', 'full_name', 'MyStr0ng!shP455w0rd'),
        ]
        assert add_email.calls == [
            pretend.call(user.id, '*****@*****.**', primary=True),
        ]
        assert send_email.calls == [pretend.call(db_request, email)]
Ejemplo n.º 9
0
 def test_redirect_authenticated_user(self):
     result = views.register(pretend.stub(authenticated_userid=1))
     assert isinstance(result, HTTPSeeOther)
     assert result.headers["Location"] == "/"
Ejemplo n.º 10
0
 def test_redirect_authenticated_user(self):
     result = views.register(pretend.stub(authenticated_userid=1))
     assert isinstance(result, HTTPSeeOther)
     assert result.headers["Location"] == "/"