✅ Finish test suite implementation
This commit is contained in:
parent
2023c9dc35
commit
3cfd5f03c0
1 changed files with 59 additions and 43 deletions
102
tests.py
102
tests.py
|
@ -4,6 +4,7 @@ import unittest
|
||||||
import uuid
|
import uuid
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
from urllib.parse import quote
|
||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
|
|
||||||
from cryptography.fernet import Fernet
|
from cryptography.fernet import Fernet
|
||||||
|
@ -205,14 +206,13 @@ class SnapPassRoutesTestCase(TestCase):
|
||||||
with freeze_time("2020-05-08 12:00:00") as frozen_time:
|
with freeze_time("2020-05-08 12:00:00") as frozen_time:
|
||||||
password = 'my name is my passport. verify me.'
|
password = 'my name is my passport. verify me.'
|
||||||
rv = self.app.post(
|
rv = self.app.post(
|
||||||
'/api/v2/passwords/',
|
'/api/v2/passwords',
|
||||||
headers={'Accept': 'application/json'},
|
headers={'Accept': 'application/json'},
|
||||||
json={'password': password, 'ttl': '1209600'},
|
json={'password': password, 'ttl': '1209600'},
|
||||||
)
|
)
|
||||||
|
|
||||||
json_content = rv.get_json()
|
json_content = rv.get_json()
|
||||||
key = re.search(r'https://localhost/([^"]+)', json_content['link']).group(1)
|
key = unquote(json_content['token'])
|
||||||
key = unquote(key)
|
|
||||||
|
|
||||||
frozen_time.move_to("2020-05-22 11:59:59")
|
frozen_time.move_to("2020-05-22 11:59:59")
|
||||||
self.assertEqual(snappass.get_password(key), password)
|
self.assertEqual(snappass.get_password(key), password)
|
||||||
|
@ -224,14 +224,13 @@ class SnapPassRoutesTestCase(TestCase):
|
||||||
with freeze_time("2020-05-08 12:00:00") as frozen_time:
|
with freeze_time("2020-05-08 12:00:00") as frozen_time:
|
||||||
password = 'my name is my passport. verify me.'
|
password = 'my name is my passport. verify me.'
|
||||||
rv = self.app.post(
|
rv = self.app.post(
|
||||||
'/api/set_password/',
|
'/api/v2/passwords',
|
||||||
headers={'Accept': 'application/json'},
|
headers={'Accept': 'application/json'},
|
||||||
json={'password': password},
|
json={'password': password},
|
||||||
)
|
)
|
||||||
|
|
||||||
json_content = rv.get_json()
|
json_content = rv.get_json()
|
||||||
key = re.search(r'https://localhost/([^"]+)', json_content['link']).group(1)
|
key = unquote(json_content['token'])
|
||||||
key = unquote(key)
|
|
||||||
|
|
||||||
frozen_time.move_to("2020-05-22 11:59:59")
|
frozen_time.move_to("2020-05-22 11:59:59")
|
||||||
self.assertEqual(snappass.get_password(key), password)
|
self.assertEqual(snappass.get_password(key), password)
|
||||||
|
@ -242,107 +241,124 @@ class SnapPassRoutesTestCase(TestCase):
|
||||||
def test_set_password_api_v2_no_password(self):
|
def test_set_password_api_v2_no_password(self):
|
||||||
with freeze_time("2020-05-08 12:00:00") as frozen_time:
|
with freeze_time("2020-05-08 12:00:00") as frozen_time:
|
||||||
rv = self.app.post(
|
rv = self.app.post(
|
||||||
'/api/set_password/',
|
'/api/v2/passwords',
|
||||||
headers={'Accept': 'application/json'},
|
headers={'Accept': 'application/json'},
|
||||||
json={'password': None},
|
json={'password': ''},
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(rv.status, 400)
|
self.assertEqual(rv.status_code, 400)
|
||||||
|
|
||||||
json_content = rv.get_json()
|
json_content = rv.get_json()
|
||||||
key = re.search(r'https://localhost/([^"]+)', json_content['link']).group(1)
|
invalid_params = json_content['invalid-params']
|
||||||
key = unquote(key)
|
self.assertEqual(len(invalid_params), 1)
|
||||||
|
bad_password = invalid_params[0]
|
||||||
# TODO : Search for ProblemDetails propreties about Password
|
self.assertEqual(bad_password['name'], 'password')
|
||||||
|
|
||||||
def test_set_password_api_v2_too_big_ttl(self):
|
def test_set_password_api_v2_too_big_ttl(self):
|
||||||
with freeze_time("2020-05-08 12:00:00") as frozen_time:
|
with freeze_time("2020-05-08 12:00:00") as frozen_time:
|
||||||
password = 'my name is my passport. verify me.'
|
password = 'my name is my passport. verify me.'
|
||||||
rv = self.app.post(
|
rv = self.app.post(
|
||||||
'/api/v2/passwords/',
|
'/api/v2/passwords',
|
||||||
headers={'Accept': 'application/json'},
|
headers={'Accept': 'application/json'},
|
||||||
json={'password': password, 'ttl': '1209600000'},
|
json={'password': password, 'ttl': '1209600000'},
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(rv.status, 400)
|
self.assertEqual(rv.status_code, 400)
|
||||||
|
|
||||||
json_content = rv.get_json()
|
json_content = rv.get_json()
|
||||||
key = re.search(r'https://localhost/([^"]+)', json_content['link']).group(1)
|
invalid_params = json_content['invalid-params']
|
||||||
key = unquote(key)
|
self.assertEqual(len(invalid_params), 1)
|
||||||
|
bad_ttl = invalid_params[0]
|
||||||
|
self.assertEqual(bad_ttl['name'], 'ttl')
|
||||||
|
|
||||||
|
def test_set_password_api_v2_no_password_and_too_big_ttl(self):
|
||||||
|
with freeze_time("2020-05-08 12:00:00") as frozen_time:
|
||||||
|
password = 'my name is my passport. verify me.'
|
||||||
|
rv = self.app.post(
|
||||||
|
'/api/v2/passwords',
|
||||||
|
headers={'Accept': 'application/json'},
|
||||||
|
json={'password': '', 'ttl': '1209600000'},
|
||||||
|
)
|
||||||
|
|
||||||
# TODO : Search for ProblemDetails propreties about TTL
|
self.assertEqual(rv.status_code, 400)
|
||||||
|
|
||||||
|
json_content = rv.get_json()
|
||||||
|
invalid_params = json_content['invalid-params']
|
||||||
|
self.assertEqual(len(invalid_params), 2)
|
||||||
|
bad_password = invalid_params[0]
|
||||||
|
self.assertEqual(bad_password['name'], 'password')
|
||||||
|
bad_ttl = invalid_params[1]
|
||||||
|
self.assertEqual(bad_ttl['name'], 'ttl')
|
||||||
|
|
||||||
def test_check_password_api_v2(self):
|
def test_check_password_api_v2(self):
|
||||||
with freeze_time("2020-05-08 12:00:00") as frozen_time:
|
with freeze_time("2020-05-08 12:00:00") as frozen_time:
|
||||||
password = 'my name is my passport. verify me.'
|
password = 'my name is my passport. verify me.'
|
||||||
rv = self.app.post(
|
rv = self.app.post(
|
||||||
'/api/v2/password/',
|
'/api/v2/passwords',
|
||||||
headers={'Accept': 'application/json'},
|
headers={'Accept': 'application/json'},
|
||||||
json={'password': password},
|
json={'password': password},
|
||||||
)
|
)
|
||||||
|
|
||||||
json_content = rv.get_json()
|
json_content = rv.get_json()
|
||||||
key = re.search(r'https://localhost/([^"]+)', json_content['link']).group(1)
|
key = unquote(json_content['token'])
|
||||||
key = unquote(key)
|
|
||||||
|
|
||||||
rvc = self.app.head('/api/v2/password/' + quote(key))
|
rvc = self.app.head('/api/v2/passwords/' + quote(key))
|
||||||
self.assertEqual(rv.status, 200)
|
self.assertEqual(rv.status_code, 200)
|
||||||
|
|
||||||
def test_check_password_api_v2_bad_keys(self):
|
def test_check_password_api_v2_bad_keys(self):
|
||||||
with freeze_time("2020-05-08 12:00:00") as frozen_time:
|
with freeze_time("2020-05-08 12:00:00") as frozen_time:
|
||||||
password = 'my name is my passport. verify me.'
|
password = 'my name is my passport. verify me.'
|
||||||
rv = self.app.post(
|
rv = self.app.post(
|
||||||
'/api/v2/password/',
|
'/api/v2/passwords',
|
||||||
headers={'Accept': 'application/json'},
|
headers={'Accept': 'application/json'},
|
||||||
json={'password': password},
|
json={'password': password},
|
||||||
)
|
)
|
||||||
|
|
||||||
json_content = rv.get_json()
|
json_content = rv.get_json()
|
||||||
key = re.search(r'https://localhost/([^"]+)', json_content['link']).group(1)
|
key = unquote(json_content['token'])
|
||||||
key = unquote(key)
|
|
||||||
|
|
||||||
rvc = self.app.head('/api/v2/password/' + quote(key + key))
|
rvc = self.app.head('/api/v2/passwords/' + quote(key[::-1]))
|
||||||
self.assertEqual(rv.status, 404)
|
self.assertEqual(rvc.status_code, 404)
|
||||||
|
|
||||||
# TODO : Search for ProblemDetails propreties about Password
|
|
||||||
|
|
||||||
def test_retrieve_password_api_v2(self):
|
def test_retrieve_password_api_v2(self):
|
||||||
with freeze_time("2020-05-08 12:00:00") as frozen_time:
|
with freeze_time("2020-05-08 12:00:00") as frozen_time:
|
||||||
password = 'my name is my passport. verify me.'
|
password = 'my name is my passport. verify me.'
|
||||||
rv = self.app.post(
|
rv = self.app.post(
|
||||||
'/api/v2/password/',
|
'/api/v2/passwords',
|
||||||
headers={'Accept': 'application/json'},
|
headers={'Accept': 'application/json'},
|
||||||
json={'password': password},
|
json={'password': password},
|
||||||
)
|
)
|
||||||
|
|
||||||
json_content = rv.get_json()
|
json_content = rv.get_json()
|
||||||
key = re.search(r'https://localhost/([^"]+)', json_content['link']).group(1)
|
key = unquote(json_content['token'])
|
||||||
key = unquote(key)
|
|
||||||
|
|
||||||
rvc = self.app.get('/api/v2/password/' + quote(key))
|
rvc = self.app.get('/api/v2/passwords/' + quote(key))
|
||||||
self.assertEqual(rv.status, 200)
|
self.assertEqual(rv.status_code, 200)
|
||||||
|
|
||||||
json_content_retrieved = rvc.get_json()
|
json_content_retrieved = rvc.get_json()
|
||||||
retrieved_password = json_content['password']
|
retrieved_password = json_content_retrieved['password']
|
||||||
self.assertEqual(retrieved_password, password)
|
self.assertEqual(retrieved_password, password)
|
||||||
|
|
||||||
def test_retrieve_password_api_v2_bad_keys(self):
|
def test_retrieve_password_api_v2_bad_keys(self):
|
||||||
with freeze_time("2020-05-08 12:00:00") as frozen_time:
|
with freeze_time("2020-05-08 12:00:00") as frozen_time:
|
||||||
password = 'my name is my passport. verify me.'
|
password = 'my name is my passport. verify me.'
|
||||||
rv = self.app.post(
|
rv = self.app.post(
|
||||||
'/api/v2/password/',
|
'/api/v2/passwords',
|
||||||
headers={'Accept': 'application/json'},
|
headers={'Accept': 'application/json'},
|
||||||
json={'password': password},
|
json={'password': password},
|
||||||
)
|
)
|
||||||
|
|
||||||
json_content = rv.get_json()
|
json_content = rv.get_json()
|
||||||
key = re.search(r'https://localhost/([^"]+)', json_content['link']).group(1)
|
key = unquote(json_content['token'])
|
||||||
key = unquote(key)
|
|
||||||
|
|
||||||
rvc = self.app.head('/api/v2/password/' + quote(key + key))
|
rvc = self.app.get('/api/v2/passwords/' + quote(key[::-1]))
|
||||||
self.assertEqual(rv.status, 404)
|
self.assertEqual(rvc.status_code, 404)
|
||||||
|
|
||||||
# TODO : Search for ProblemDetails propreties about Password
|
json_content_retrieved = rvc.get_json()
|
||||||
|
invalid_params = json_content_retrieved['invalid-params']
|
||||||
|
self.assertEqual(len(invalid_params), 1)
|
||||||
|
bad_token = invalid_params[0]
|
||||||
|
self.assertEqual(bad_token['name'], 'token')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in a new issue