Refactored handler.py
This commit is contained in:
+21
-29
@@ -40,12 +40,12 @@ class TestAppBase(AsyncHTTPTestCase):
|
||||
self.assertEqual(response.code, 400)
|
||||
self.assertIn(b'Bad Request', response.body)
|
||||
|
||||
def assert_status_in(self, data, status):
|
||||
def assert_status_in(self, status, data):
|
||||
self.assertIsNone(data['encoding'])
|
||||
self.assertIsNone(data['id'])
|
||||
self.assertIn(status, data['status'])
|
||||
|
||||
def assert_status_equal(self, data, status):
|
||||
def assert_status_equal(self, status, data):
|
||||
self.assertIsNone(data['encoding'])
|
||||
self.assertIsNone(data['id'])
|
||||
self.assertEqual(status, data['status'])
|
||||
@@ -172,7 +172,7 @@ class TestAppBasic(TestAppBase):
|
||||
|
||||
def test_app_with_wrong_credentials(self):
|
||||
response = self.sync_post('/', self.body + 's')
|
||||
self.assert_status_in(json.loads(to_str(response.body)), 'Authentication failed.') # noqa
|
||||
self.assert_status_in('Authentication failed.', json.loads(to_str(response.body))) # noqa
|
||||
|
||||
def test_app_with_correct_credentials(self):
|
||||
response = self.sync_post('/', self.body)
|
||||
@@ -442,10 +442,10 @@ class TestAppBasic(TestAppBase):
|
||||
self.body_dict.update(username='keyonly', password='foo')
|
||||
response = yield self.async_post('/', self.body_dict)
|
||||
self.assertEqual(response.code, 200)
|
||||
self.assert_status_in(json.loads(to_str(response.body)), 'Bad authentication type') # noqa
|
||||
self.assert_status_in('Bad authentication type', json.loads(to_str(response.body))) # noqa
|
||||
|
||||
@tornado.testing.gen_test
|
||||
def test_app_with_user_pass2fa_with_correct_password_and_passcode(self):
|
||||
def test_app_with_user_pass2fa_with_correct_passwords(self):
|
||||
self.body_dict.update(username='pass2fa', password='password',
|
||||
totp='passcode')
|
||||
response = yield self.async_post('/', self.body_dict)
|
||||
@@ -454,25 +454,7 @@ class TestAppBasic(TestAppBase):
|
||||
self.assert_status_none(data)
|
||||
|
||||
@tornado.testing.gen_test
|
||||
def test_app_with_user_pass2fa_with_wrong_password(self):
|
||||
self.body_dict.update(username='pass2fa', password='wrongpassword',
|
||||
totp='passcode')
|
||||
response = yield self.async_post('/', self.body_dict)
|
||||
self.assertEqual(response.code, 200)
|
||||
data = json.loads(to_str(response.body))
|
||||
self.assertIn('Authentication failed', data['status'])
|
||||
|
||||
@tornado.testing.gen_test
|
||||
def test_app_with_user_pass2fa_with_wrong_passcode(self):
|
||||
self.body_dict.update(username='pass2fa', password='password',
|
||||
totp='wrongpasscode')
|
||||
response = yield self.async_post('/', self.body_dict)
|
||||
self.assertEqual(response.code, 200)
|
||||
data = json.loads(to_str(response.body))
|
||||
self.assertIn('Authentication failed', data['status'])
|
||||
|
||||
@tornado.testing.gen_test
|
||||
def test_app_with_user_pass2fa_with_wrong_pkey_correct_passwords(self): # noqa
|
||||
def test_app_with_user_pass2fa_with_wrong_pkey_correct_passwords(self):
|
||||
url = self.get_url('/')
|
||||
privatekey = read_file(make_tests_data_path('user_rsa_key'))
|
||||
self.body_dict.update(username='pass2fa', password='password',
|
||||
@@ -482,7 +464,7 @@ class TestAppBasic(TestAppBase):
|
||||
self.assert_status_none(data)
|
||||
|
||||
@tornado.testing.gen_test
|
||||
def test_app_with_user_pkey2fa_with_correct_password_and_passcode(self):
|
||||
def test_app_with_user_pkey2fa_with_correct_passwords(self):
|
||||
url = self.get_url('/')
|
||||
privatekey = read_file(make_tests_data_path('user_rsa_key'))
|
||||
self.body_dict.update(username='pkey2fa', password='password',
|
||||
@@ -499,7 +481,7 @@ class TestAppBasic(TestAppBase):
|
||||
privatekey=privatekey, totp='passcode')
|
||||
response = yield self.async_post(url, self.body_dict)
|
||||
data = json.loads(to_str(response.body))
|
||||
self.assertIn('Authentication failed', data['status'])
|
||||
self.assert_status_in('Authentication failed', data)
|
||||
|
||||
@tornado.testing.gen_test
|
||||
def test_app_with_user_pkey2fa_with_wrong_passcode(self):
|
||||
@@ -509,7 +491,17 @@ class TestAppBasic(TestAppBase):
|
||||
privatekey=privatekey, totp='wrongpasscode')
|
||||
response = yield self.async_post(url, self.body_dict)
|
||||
data = json.loads(to_str(response.body))
|
||||
self.assertIn('Authentication failed', data['status'])
|
||||
self.assert_status_in('Authentication failed', data)
|
||||
|
||||
@tornado.testing.gen_test
|
||||
def test_app_with_user_pkey2fa_with_empty_passcode(self):
|
||||
url = self.get_url('/')
|
||||
privatekey = read_file(make_tests_data_path('user_rsa_key'))
|
||||
self.body_dict.update(username='pkey2fa', password='password',
|
||||
privatekey=privatekey, totp='')
|
||||
response = yield self.async_post(url, self.body_dict)
|
||||
data = json.loads(to_str(response.body))
|
||||
self.assert_status_in('Need a verification code', data)
|
||||
|
||||
|
||||
class OtherTestBase(TestAppBase):
|
||||
@@ -747,13 +739,13 @@ class TestAppWithCrossOriginOperation(OtherTestBase):
|
||||
def test_app_with_wrong_event_origin(self):
|
||||
body = dict(self.body, _origin='localhost')
|
||||
response = yield self.async_post('/', body)
|
||||
self.assert_status_equal(json.loads(to_str(response.body)), 'Cross origin operation is not allowed.') # noqa
|
||||
self.assert_status_equal('Cross origin operation is not allowed.', json.loads(to_str(response.body))) # noqa
|
||||
|
||||
@tornado.testing.gen_test
|
||||
def test_app_with_wrong_header_origin(self):
|
||||
headers = dict(Origin='localhost')
|
||||
response = yield self.async_post('/', self.body, headers=headers)
|
||||
self.assert_status_equal(json.loads(to_str(response.body)), 'Cross origin operation is not allowed.') # noqa
|
||||
self.assert_status_equal('Cross origin operation is not allowed.', json.loads(to_str(response.body)), ) # noqa
|
||||
|
||||
@tornado.testing.gen_test
|
||||
def test_app_with_correct_event_origin(self):
|
||||
|
||||
Reference in New Issue
Block a user