-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #881 from scidsg/always-require-pgp
Remove REQUIRE_PGP env var and instead always require PGP
- Loading branch information
Showing
8 changed files
with
61 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ | |
from hushline.db import db | ||
from hushline.model import Message, OrganizationSetting, User, Username | ||
|
||
pgp_message_sig = "-----BEGIN PGP MESSAGE-----\n\n" | ||
|
||
|
||
def get_captcha_from_session(client: FlaskClient, username: str) -> str: | ||
# Simulate loading the profile page to generate and retrieve the CAPTCHA from the session | ||
|
@@ -20,6 +22,7 @@ def get_captcha_from_session(client: FlaskClient, username: str) -> str: | |
return captcha_answer | ||
|
||
|
||
@pytest.mark.usefixtures("_pgp_user") | ||
def test_profile_header(client: FlaskClient, user: User) -> None: | ||
assert ( | ||
db.session.scalars( | ||
|
@@ -53,6 +56,7 @@ def test_profile_header(client: FlaskClient, user: User) -> None: | |
|
||
|
||
@pytest.mark.usefixtures("_authenticated_user") | ||
@pytest.mark.usefixtures("_pgp_user") | ||
def test_profile_submit_message(client: FlaskClient, user: User) -> None: | ||
msg_content = "This is a test message." | ||
|
||
|
@@ -71,16 +75,17 @@ def test_profile_submit_message(client: FlaskClient, user: User) -> None: | |
message = db.session.scalars( | ||
db.select(Message).filter_by(username_id=user.primary_username.id) | ||
).one() | ||
assert message.content == msg_content | ||
assert pgp_message_sig in message.content | ||
|
||
response = client.get( | ||
url_for("inbox", username=user.primary_username.username), follow_redirects=True | ||
) | ||
assert response.status_code == 200 | ||
assert msg_content in response.text, response.text | ||
assert pgp_message_sig in response.text, response.text | ||
|
||
|
||
@pytest.mark.usefixtures("_authenticated_user") | ||
@pytest.mark.usefixtures("_pgp_user") | ||
def test_profile_submit_message_to_alias( | ||
client: FlaskClient, user: User, user_alias: Username | ||
) -> None: | ||
|
@@ -99,18 +104,18 @@ def test_profile_submit_message_to_alias( | |
assert "Message submitted successfully." in response.text | ||
|
||
message = db.session.scalars(db.select(Message).filter_by(username_id=user_alias.id)).one() | ||
assert message.content == msg_content | ||
assert pgp_message_sig in message.content | ||
|
||
response = client.get(url_for("inbox", username=user_alias.username), follow_redirects=True) | ||
assert response.status_code == 200 | ||
assert msg_content in response.text, response.text | ||
assert pgp_message_sig in response.text, response.text | ||
|
||
|
||
@pytest.mark.usefixtures("_authenticated_user") | ||
@pytest.mark.usefixtures("_pgp_user") | ||
def test_profile_submit_message_with_contact_method(client: FlaskClient, user: User) -> None: | ||
message_content = "This is a test message." | ||
contact_method = "[email protected]" | ||
expected_content = f"Contact Method: {contact_method}\n\n{message_content}" | ||
|
||
response = client.post( | ||
url_for("profile", username=user.primary_username.username), | ||
|
@@ -128,31 +133,29 @@ def test_profile_submit_message_with_contact_method(client: FlaskClient, user: U | |
message = db.session.scalars( | ||
db.select(Message).filter_by(username_id=user.primary_username.id) | ||
).one() | ||
assert message.content == expected_content | ||
assert pgp_message_sig in message.content | ||
|
||
response = client.get( | ||
url_for("inbox", username=user.primary_username.username), follow_redirects=True | ||
) | ||
assert response.status_code == 200 | ||
assert expected_content in response.text | ||
assert pgp_message_sig in response.text | ||
|
||
|
||
@pytest.mark.usefixtures("_authenticated_user") | ||
def test_profile_pgp_required(client: FlaskClient, app: Flask, user: User) -> None: | ||
app.config["REQUIRE_PGP"] = True | ||
|
||
response = client.get(url_for("profile", username=user.primary_username.username)) | ||
assert response.status_code == 200 | ||
assert "Sending messages is disabled" in response.text | ||
|
||
user.pgp_key = "test_pgp_key" | ||
assert 'id="messageForm"' in response.text | ||
assert "You can't send encrypted messages to this user through Hush Line" not in response.text | ||
|
||
user.pgp_key = None | ||
db.session.commit() | ||
|
||
response = client.get(url_for("profile", username=user.primary_username.username)) | ||
assert response.status_code == 200 | ||
|
||
assert 'id="messageForm"' in response.text | ||
assert "You can't send encrypted messages to this user through Hush Line" not in response.text | ||
assert "Sending messages is disabled" in response.text | ||
|
||
|
||
@pytest.mark.usefixtures("_authenticated_user") | ||
|
@@ -190,6 +193,7 @@ def test_profile_extra_fields(client: FlaskClient, app: Flask, user: User) -> No | |
|
||
|
||
@pytest.mark.usefixtures("_authenticated_user") | ||
@pytest.mark.usefixtures("_pgp_user") | ||
def test_profile_submit_message_with_invalid_captcha(client: FlaskClient, user: User) -> None: | ||
message_content = "This is a test message." | ||
contact_method = "[email protected]" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters