Exemplo n.º 1
0
 def __init__(self, request):
     self.request = request
     self.schema = ResetPasswordSchema().bind(request=self.request)
     self.form = request.create_form(
         schema=self.schema,
         action=self.request.route_path('account_reset'),
         buttons=(_('Save'),))
Exemplo n.º 2
0
    def test_it_is_invalid_with_expired_token(self, pyramid_csrf_request):
        pyramid_csrf_request.registry.password_reset_serializer = (
            self.FakeExpiredSerializer())
        schema = ResetPasswordSchema().bind(request=pyramid_csrf_request)

        with pytest.raises(colander.Invalid) as exc:
            schema.deserialize({"user": "******", "password": "******"})

        assert "user" in exc.value.asdict()
        assert "Reset code has expired." in exc.value.asdict()["user"]
Exemplo n.º 3
0
    def test_it_is_invalid_with_expired_token(self, pyramid_csrf_request):
        pyramid_csrf_request.registry.password_reset_serializer = (
            self.FakeExpiredSerializer())
        schema = ResetPasswordSchema().bind(request=pyramid_csrf_request)

        with pytest.raises(colander.Invalid) as exc:
            schema.deserialize({
                'user': '******',
                'password': '******',
            })

        assert 'user' in exc.value.asdict()
        assert 'Reset code has expired.' in exc.value.asdict()['user']
Exemplo n.º 4
0
    def test_it_returns_user_when_valid(self, pyramid_csrf_request,
                                        user_model):
        pyramid_csrf_request.registry.password_reset_serializer = (
            self.FakeSerializer())
        schema = ResetPasswordSchema().bind(request=pyramid_csrf_request)
        user = user_model.get_by_username.return_value
        user.password_updated = 0

        appstruct = schema.deserialize({
            'user': '******',
            'password': '******',
        })

        assert appstruct['user'] == user
Exemplo n.º 5
0
    def test_it_returns_user_when_valid(self, pyramid_csrf_request,
                                        user_model):
        pyramid_csrf_request.registry.password_reset_serializer = self.FakeSerializer(
        )
        schema = ResetPasswordSchema().bind(request=pyramid_csrf_request)
        user = user_model.get_by_username.return_value
        user.password_updated = 0

        appstruct = schema.deserialize({
            "user": "******",
            "password": "******"
        })

        assert appstruct["user"] == user
Exemplo n.º 6
0
    def test_it_is_invalid_if_user_has_already_reset_their_password(
            self, pyramid_csrf_request, user_model):
        pyramid_csrf_request.registry.password_reset_serializer = self.FakeSerializer(
        )
        schema = ResetPasswordSchema().bind(request=pyramid_csrf_request)
        user = user_model.get_by_username.return_value
        user.password_updated = 2

        with pytest.raises(colander.Invalid) as exc:
            schema.deserialize({"user": "******", "password": "******"})

        assert "user" in exc.value.asdict()
        assert "This reset code has already been used." in exc.value.asdict(
        )["user"]
Exemplo n.º 7
0
    def test_it_is_invalid_with_password_too_short(self, pyramid_csrf_request):
        schema = ResetPasswordSchema().bind(request=pyramid_csrf_request)

        with pytest.raises(colander.Invalid) as exc:
            schema.deserialize({"password": "******"})
        assert "password" in exc.value.asdict()
Exemplo n.º 8
0
 def schema(self, pyramid_csrf_request):
     return ResetPasswordSchema().bind(request=pyramid_csrf_request)