예제 #1
0
 def test_PasswordSchema_password_equal_to_max(self):
     password = fake.pystr(
         min_chars=Limits.MAX_USER_PASSWORD_LENGTH,
         max_chars=Limits.MAX_USER_PASSWORD_LENGTH,
     )
     body = get_mock_password_body(password=password)
     errors = password_schema.validate(body)
     assert not errors
예제 #2
0
 def test_PasswordSchema_no_password(self):
     body = get_mock_password_body()
     del body["password"]
     errors = password_schema.validate(body)
     assert errors == {
         "password": [
             "Missing data for required field.",
         ],
     }
예제 #3
0
def users_user_password_POST(user, **_):
    errors = password_schema.validate(request.json)

    if errors:
        return build_400_error_response(errors)

    parsed_schema = password_schema.dump(request.json)

    update_user_password(user, parsed_schema["password"])

    return "", 204
예제 #4
0
 def test_PasswordSchema_password_greater_than_max(self):
     password = fake.pystr(
         min_chars=Limits.MAX_USER_PASSWORD_LENGTH + 1,
         max_chars=Limits.MAX_USER_PASSWORD_LENGTH + 1,
     )
     body = get_mock_password_body(password=password)
     errors = password_schema.validate(body)
     assert errors == {
         "password": [
             f"Length must be between {Limits.MIN_USER_PASSWORD_LENGTH} "
             f"and {Limits.MAX_USER_PASSWORD_LENGTH}.",
         ],
     }
예제 #5
0
def reset_password_token_POST(token):
    errors = password_schema.validate(request.json)

    if errors:
        return build_400_error_response(errors)

    user = get_user_from_password_reset_token(token)

    if not user:
        return build_400_error_response({
            "token": [
                "Invalid token.",
            ],
        })

    parsed_schema = password_schema.dump(request.json)

    update_user_password(user, parsed_schema["password"])

    return "", 204
예제 #6
0
 def test_PasswordSchema_unrecognised_field(self):
     body = get_mock_password_body()
     key = fake.pystr()
     body[key] = fake.pystr()
     assert not password_schema.validate(body)
     assert key not in password_schema.dump(body)