Skip to content

Commit

Permalink
Add test for length validation
Browse files Browse the repository at this point in the history
  • Loading branch information
smallwat3r committed Sep 12, 2023
1 parent ec7fcd3 commit 232fbe6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion shhh/api/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _secret_validator(secret: str) -> None:
max_length = app.config["SHHH_SECRET_MAX_LENGTH"]
if len(secret) > max_length:
raise ValidationError(f"The secret should not exceed {max_length} "
"characters")
"characters.")


class WriteRequest(Schema):
Expand Down
1 change: 1 addition & 0 deletions shhh/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class TestConfig(DefaultConfig):
SQLALCHEMY_DATABASE_URI = "sqlite://"

SHHH_HOST = "http://test.test"
SHHH_SECRET_MAX_LENGTH = 20
SHHH_DB_LIVENESS_RETRY_COUNT = 1
SHHH_DB_LIVENESS_SLEEP_INTERVAL = 0.1

Expand Down
11 changes: 11 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ def test_api_post_weak_passphrase(app, post_payload, passphrase):
"characters, with 1 number and 1 uppercase.")


def test_api_post_secret_too_long(app, post_payload):
post_payload["secret"] = "MoreThan20Characters!"
with app.test_request_context(), app.test_client() as test_client:
response = test_client.post(url_for("api.secret"), json=post_payload)
assert response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY
data = response.get_json()
assert data["response"]["status"] == Status.ERROR
assert data["response"]["details"] == ("The secret should not exceed "
"20 characters.")


def test_api_get_wrong_passphrase(app, secret):
with app.test_request_context(), app.test_client() as test_client:
response = test_client.get(
Expand Down

0 comments on commit 232fbe6

Please sign in to comment.