示例#1
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"]
示例#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"]
示例#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']
示例#4
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"]
示例#5
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"]
示例#6
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
示例#7
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
示例#8
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
示例#9
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()
示例#10
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()