-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
153 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
JWT ID blacklist checker | ||
""" | ||
from flask import current_app as app | ||
|
||
|
||
@app.jwt.token_in_blacklist_loader | ||
def check_if_token_in_blacklist(decrypted_token): | ||
""" | ||
Checks whether the identity of the token is blacklisted | ||
Returns: | ||
True if it's blacklisted, false otherwise | ||
""" | ||
with app.app_context(): | ||
jti = decrypted_token['jti'] # JWT ID | ||
return jti in app.blacklist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ | |
|
||
# Add routes here | ||
add(r.Signup, '/auth/signup') # POST | ||
add(r.Login, '/auth/login') # POST |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
""" | ||
This module tests login | ||
""" | ||
import unittest | ||
import json | ||
|
||
from ridemyway.tests.tests_v2 import V2BaseTest | ||
from ridemyway.tests.tests_v2.urls import SIGNUP, LOGIN | ||
from ridemyway.tests.tests_v2.data import VALID_DRIVER | ||
|
||
|
||
class TestLogin(V2BaseTest): | ||
""" | ||
Tests login API endpoint | ||
- Auth: '/api/v2/auth/login' # POST | ||
""" | ||
def signup(self): | ||
self.client().post(SIGNUP, data=VALID_DRIVER) | ||
|
||
def test_user_can_login_successfully(self): | ||
self.signup() | ||
self.response = self.client().post(LOGIN, data=VALID_DRIVER) | ||
self.assertEqual(self.response.status_code, 200, | ||
msg='Should return 200 status code for successful login') | ||
result = json.loads(self.response.data.decode()) | ||
self.assertTrue(result['access_token'] is not False, | ||
msg='Should return access token') | ||
|
||
def test_non_user_cannot_login(self): | ||
NON_USER = { | ||
'username': 'null', | ||
'password': 'null[pass]' | ||
} | ||
self.response = self.client().post(LOGIN, data=NON_USER) | ||
self.assertEqual(self.response.status_code, 401, | ||
msg='Should return 401 status code for non users') | ||
result = json.loads(self.response.data.decode()) | ||
self.assertTrue(result['status'] == 'failed', | ||
msg='Should return status failed in response data') | ||
|
||
def test_non_matching_credentials_not_authorized(self): | ||
self.signup() | ||
FAKE_PASSWORD = { | ||
'username': 'driver', | ||
'password': 'fake[pass]' | ||
} | ||
self.response = self.client().post(LOGIN, data=FAKE_PASSWORD) | ||
self.assertEqual(self.response.status_code, 401, | ||
msg='Should return 401 status code for fake users') | ||
result = json.loads(self.response.data.decode()) | ||
self.assertTrue(result['status'] == 'failed', | ||
msg='Should return status failed in response data') | ||
|
||
def test_required_details_are_provided(self): | ||
self.response = self.client().post(LOGIN, data={}) | ||
self.assertEqual(self.response.status_code, 400, | ||
msg='Should return 400 status code for empty data') | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters