🎨 flake8
This commit is contained in:
parent
26b26f9c25
commit
04235c1edc
2 changed files with 109 additions and 102 deletions
|
@ -102,6 +102,7 @@ def parse_token(token):
|
||||||
|
|
||||||
return storage_key, decryption_key
|
return storage_key, decryption_key
|
||||||
|
|
||||||
|
|
||||||
def as_validation_problem(request, problem_type, problem_title, invalid_params):
|
def as_validation_problem(request, problem_type, problem_title, invalid_params):
|
||||||
base_url = set_base_url(request)
|
base_url = set_base_url(request)
|
||||||
|
|
||||||
|
@ -112,6 +113,7 @@ def as_validation_problem(request, problem_type, problem_title, invalid_params):
|
||||||
}
|
}
|
||||||
return as_problem_response(problem)
|
return as_problem_response(problem)
|
||||||
|
|
||||||
|
|
||||||
def as_not_found_problem(request, problem_type, problem_title, invalid_params):
|
def as_not_found_problem(request, problem_type, problem_title, invalid_params):
|
||||||
base_url = set_base_url(request)
|
base_url = set_base_url(request)
|
||||||
|
|
||||||
|
@ -248,6 +250,7 @@ def api_handle_password():
|
||||||
else:
|
else:
|
||||||
abort(500)
|
abort(500)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/v2/passwords', methods=['POST'])
|
@app.route('/api/v2/passwords', methods=['POST'])
|
||||||
def api_v2_set_password():
|
def api_v2_set_password():
|
||||||
password = request.json.get('password')
|
password = request.json.get('password')
|
||||||
|
@ -269,7 +272,12 @@ def api_v2_set_password():
|
||||||
|
|
||||||
if len(invalid_params) > 0:
|
if len(invalid_params) > 0:
|
||||||
# Return a ProblemDetails expliciting issue with Password and/or TTL
|
# Return a ProblemDetails expliciting issue with Password and/or TTL
|
||||||
return as_validation_problem(request, "set-password-validation-error", "The password and/or the TTL are invalid.", invalid_params)
|
return as_validation_problem(
|
||||||
|
request,
|
||||||
|
"set-password-validation-error",
|
||||||
|
"The password and/or the TTL are invalid.",
|
||||||
|
invalid_params
|
||||||
|
)
|
||||||
|
|
||||||
token = set_password(password, ttl)
|
token = set_password(password, ttl)
|
||||||
url_token = quote_plus(token)
|
url_token = quote_plus(token)
|
||||||
|
@ -285,6 +293,7 @@ def api_v2_set_password():
|
||||||
}
|
}
|
||||||
return jsonify(response_content)
|
return jsonify(response_content)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/v2/passwords/<token>', methods=['HEAD'])
|
@app.route('/api/v2/passwords/<token>', methods=['HEAD'])
|
||||||
def api_v2_check_password(token):
|
def api_v2_check_password(token):
|
||||||
token = unquote_plus(token)
|
token = unquote_plus(token)
|
||||||
|
@ -295,13 +304,19 @@ def api_v2_check_password(token):
|
||||||
# Return OK, to indicate that password still exists
|
# Return OK, to indicate that password still exists
|
||||||
return ('', 200)
|
return ('', 200)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/v2/passwords/<token>', methods=['GET'])
|
@app.route('/api/v2/passwords/<token>', methods=['GET'])
|
||||||
def api_v2_retrieve_password(token):
|
def api_v2_retrieve_password(token):
|
||||||
token = unquote_plus(token)
|
token = unquote_plus(token)
|
||||||
password = get_password(token)
|
password = get_password(token)
|
||||||
if not password:
|
if not password:
|
||||||
# Return NotFound, to indicate that password does not exists (anymore or at all)
|
# Return NotFound, to indicate that password does not exists (anymore or at all)
|
||||||
return as_not_found_problem(request, "get-password-error", "The password doesn't exist.", [{ "name": "token"}])
|
return as_not_found_problem(
|
||||||
|
request,
|
||||||
|
"get-password-error",
|
||||||
|
"The password doesn't exist.",
|
||||||
|
[{"name": "token"}]
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
# Return OK and the password in JSON message
|
# Return OK and the password in JSON message
|
||||||
return jsonify(password=password)
|
return jsonify(password=password)
|
||||||
|
|
10
tests.py
10
tests.py
|
@ -239,7 +239,6 @@ class SnapPassRoutesTestCase(TestCase):
|
||||||
self.assertIsNone(snappass.get_password(key))
|
self.assertIsNone(snappass.get_password(key))
|
||||||
|
|
||||||
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:
|
|
||||||
rv = self.app.post(
|
rv = self.app.post(
|
||||||
'/api/v2/passwords',
|
'/api/v2/passwords',
|
||||||
headers={'Accept': 'application/json'},
|
headers={'Accept': 'application/json'},
|
||||||
|
@ -255,7 +254,6 @@ class SnapPassRoutesTestCase(TestCase):
|
||||||
self.assertEqual(bad_password['name'], '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:
|
|
||||||
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',
|
||||||
|
@ -272,8 +270,6 @@ class SnapPassRoutesTestCase(TestCase):
|
||||||
self.assertEqual(bad_ttl['name'], 'ttl')
|
self.assertEqual(bad_ttl['name'], 'ttl')
|
||||||
|
|
||||||
def test_set_password_api_v2_no_password_and_too_big_ttl(self):
|
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(
|
rv = self.app.post(
|
||||||
'/api/v2/passwords',
|
'/api/v2/passwords',
|
||||||
headers={'Accept': 'application/json'},
|
headers={'Accept': 'application/json'},
|
||||||
|
@ -291,7 +287,6 @@ class SnapPassRoutesTestCase(TestCase):
|
||||||
self.assertEqual(bad_ttl['name'], 'ttl')
|
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:
|
|
||||||
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',
|
||||||
|
@ -303,10 +298,9 @@ class SnapPassRoutesTestCase(TestCase):
|
||||||
key = unquote(json_content['token'])
|
key = unquote(json_content['token'])
|
||||||
|
|
||||||
rvc = self.app.head('/api/v2/passwords/' + quote(key))
|
rvc = self.app.head('/api/v2/passwords/' + quote(key))
|
||||||
self.assertEqual(rv.status_code, 200)
|
self.assertEqual(rvc.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:
|
|
||||||
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',
|
||||||
|
@ -321,7 +315,6 @@ class SnapPassRoutesTestCase(TestCase):
|
||||||
self.assertEqual(rvc.status_code, 404)
|
self.assertEqual(rvc.status_code, 404)
|
||||||
|
|
||||||
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:
|
|
||||||
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',
|
||||||
|
@ -340,7 +333,6 @@ class SnapPassRoutesTestCase(TestCase):
|
||||||
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:
|
|
||||||
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',
|
||||||
|
|
Loading…
Reference in a new issue