Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions app/api/resources/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,13 @@ def post(cls):
The return value is an access token and the expiry timestamp.
The token is valid for 1 week.
"""
user_id = get_jwt_identity()
access_token = create_access_token(identity=user_id)
req_user = get_jwt_identity()
user = DAO.get_user(req_user["id"])

if user.password_hash != req_user["password"]:
return messages.TOKEN_IS_INVALID, HTTPStatus.UNAUTHORIZED

access_token = create_access_token(identity=req_user["id"])

from run import application

Expand Down Expand Up @@ -472,7 +477,9 @@ def post(cls):
)

access_token = create_access_token(identity=user.id)
refresh_token = create_refresh_token(identity=user.id)
refresh_token = create_refresh_token(
identity={"id": user.id, "password": user.password_hash}
)

from run import application

Expand Down
22 changes: 21 additions & 1 deletion tests/users/test_api_refresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from datetime import timedelta

from flask import json
from http import HTTPStatus

from app import messages
from app.database.sqlalchemy_extension import db
Expand Down Expand Up @@ -31,7 +32,10 @@ def setUp(self):

def test_user_refresh(self):
with self.client:
refresh_header = get_test_request_header(user1["username"], refresh=True)
refresh_header = get_test_request_header(
{"id": self.first_user.id, "password": self.first_user.password_hash},
refresh=True,
)
response = self.client.post(
"/refresh",
headers=refresh_header,
Expand Down Expand Up @@ -83,6 +87,22 @@ def test_user_refresh_expired_token(self):
self.assertEqual(401, actual_response.status_code)
self.assertEqual(expected_response, json.loads(actual_response.data))

def test_user_refresh_reset_password(self):
refresh_header = get_test_request_header(
{"id": self.first_user.id, "password": "new_password_hash"},
refresh=True,
)
expected_response = messages.TOKEN_IS_INVALID
actual_response = self.client.post(
"/refresh",
follow_redirects=True,
headers=refresh_header,
content_type="application/json",
)

self.assertEqual(HTTPStatus.UNAUTHORIZED, actual_response.status_code)
self.assertEqual(expected_response, json.loads(actual_response.data))


if __name__ == "__main__":
unittest.main()