2016-04-13 15:33:54 +02:00
|
|
|
import responses
|
2016-03-04 14:08:10 +01:00
|
|
|
|
2016-03-25 16:05:36 +01:00
|
|
|
from common_test_class import AbstractPillarTest, TEST_EMAIL_USER, TEST_EMAIL_ADDRESS
|
2016-03-25 12:22:31 +01:00
|
|
|
|
2016-03-04 14:47:48 +01:00
|
|
|
|
2016-03-25 15:57:17 +01:00
|
|
|
class AuthenticationTests(AbstractPillarTest):
|
2016-03-04 14:08:10 +01:00
|
|
|
def test_make_unique_username(self):
|
2016-03-25 15:57:17 +01:00
|
|
|
from application.utils import authentication as auth
|
2016-03-04 14:08:10 +01:00
|
|
|
|
2016-03-25 15:57:17 +01:00
|
|
|
with self.app.test_request_context():
|
2016-03-04 14:08:10 +01:00
|
|
|
# This user shouldn't exist yet.
|
2016-03-04 14:49:48 +01:00
|
|
|
self.assertEqual(TEST_EMAIL_USER, auth.make_unique_username(TEST_EMAIL_ADDRESS))
|
2016-03-04 14:08:10 +01:00
|
|
|
|
|
|
|
# Add a user, then test again.
|
2016-03-04 14:49:48 +01:00
|
|
|
auth.create_new_user(TEST_EMAIL_ADDRESS, TEST_EMAIL_USER, 'test1234')
|
2016-03-04 15:19:01 +01:00
|
|
|
self.assertEqual('%s1' % TEST_EMAIL_USER, auth.make_unique_username(TEST_EMAIL_ADDRESS))
|
2016-03-04 14:47:48 +01:00
|
|
|
|
2016-04-13 15:33:54 +02:00
|
|
|
@responses.activate
|
2016-03-04 18:43:20 +01:00
|
|
|
def test_validate_token__not_logged_in(self):
|
2016-03-25 15:57:17 +01:00
|
|
|
from application.utils import authentication as auth
|
|
|
|
|
|
|
|
with self.app.test_request_context():
|
2016-03-04 18:43:20 +01:00
|
|
|
self.assertFalse(auth.validate_token())
|
|
|
|
|
2016-04-13 15:33:54 +02:00
|
|
|
@responses.activate
|
2016-03-04 14:47:48 +01:00
|
|
|
def test_validate_token__unknown_token(self):
|
2016-03-04 15:19:01 +01:00
|
|
|
"""Test validating of invalid token, unknown both to us and Blender ID."""
|
|
|
|
|
2016-03-25 15:57:17 +01:00
|
|
|
from application.utils import authentication as auth
|
|
|
|
|
2016-04-13 15:33:54 +02:00
|
|
|
self.mock_blenderid_validate_unhappy()
|
2016-04-12 15:24:50 +02:00
|
|
|
with self.app.test_request_context(
|
|
|
|
headers={'Authorization': self.make_header('unknowntoken')}):
|
2016-03-04 14:49:48 +01:00
|
|
|
self.assertFalse(auth.validate_token())
|
2016-03-04 15:19:01 +01:00
|
|
|
|
2016-04-13 15:33:54 +02:00
|
|
|
@responses.activate
|
2016-03-04 15:19:01 +01:00
|
|
|
def test_validate_token__unknown_but_valid_token(self):
|
|
|
|
"""Test validating of valid token, unknown to us but known to Blender ID."""
|
|
|
|
|
2016-03-25 15:57:17 +01:00
|
|
|
from application.utils import authentication as auth
|
|
|
|
|
2016-04-13 15:33:54 +02:00
|
|
|
self.mock_blenderid_validate_happy()
|
2016-04-12 15:24:50 +02:00
|
|
|
with self.app.test_request_context(
|
|
|
|
headers={'Authorization': self.make_header('knowntoken')}):
|
2016-03-04 15:19:01 +01:00
|
|
|
self.assertTrue(auth.validate_token())
|