Beispiel #1
0
def validate_token():
    try:
        token = request.json["token"]
        decoded_token = auth_services.validate_token(token)
        response = {"token_validation": True, "user_id": decoded_token["id"]}
        return response, 200
    except Exception:
        return {"token_validation": False}, 401
Beispiel #2
0
    def test_register_with_valid_data(self, create_valid_data):
        session = get_session()

        encoded_jwt = auth_services.create_user(session, create_valid_data,
                                                UserRepository)
        decoded_token = auth_services.validate_token(encoded_jwt["token"])

        assert decoded_token["id"] == 1
Beispiel #3
0
 def verify_token(*args, **kwargs):
     try:
         token = request.headers["Token"]
         decoded_token = validate_token(token)
         request.user_info = decoded_token
         return f(*args, **kwargs)
     except:
         return "Favor fazer o login", 401
Beispiel #4
0
    def test_service_validate_token(self, valid_data, user):
        session = Mock()
        session.commit = MagicMock()

        repo = Mock()
        repo.get_one = MagicMock(return_value=user)

        encoded_jwt = auth_services.login(session, valid_data, repo)

        decoded_token = auth_services.validate_token(encoded_jwt["token"])

        assert decoded_token["id"] == user.id
Beispiel #5
0
def get_valid_user_fixture():
    user_data = {
        "name": "João",
        "email": "*****@*****.**",
        "password": "******",
    }
    session = get_session()
    jwt = auth_services.create_user(session, user_data, UserRepository)
    user_info = auth_services.validate_token(jwt["token"])
    user_info["token"] = jwt["token"]

    return user_info
Beispiel #6
0
    def test_update_valid_data(self, create_valid_data, update_valid_data):
        session = get_session()
        encoded_jwt = auth_services.create_user(session, create_valid_data,
                                                UserRepository)
        user_info = auth_services.validate_token(encoded_jwt["token"])
        user_services.update_user_data(
            session, {
                **update_valid_data, "id": user_info["id"]
            }, UserRepository)
        user = user_services.find_user(session, {"id": user_info["id"]},
                                       UserRepository)

        assert user["name"] == update_valid_data["name"]
        assert user["email"] == update_valid_data["email"]