Skip to content

Commit

Permalink
update current user info during sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Allie Crevier committed Aug 13, 2020
1 parent 2545d16 commit 6e6865f
Show file tree
Hide file tree
Showing 17 changed files with 3,067 additions and 8,339 deletions.
15 changes: 9 additions & 6 deletions securedrop_client/api_jobs/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from sqlalchemy.orm.session import Session

from securedrop_client.api_jobs.base import ApiJob
from securedrop_client.storage import get_remote_data, update_local_storage
from securedrop_client.storage import get_remote_data, update_and_get_user, update_local_storage

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -37,8 +37,11 @@ def call_api(self, api_client: API, session: Session) -> Any:
# This timeout is used for 3 different requests: `get_sources`, `get_all_submissions`, and
# `get_all_replies`
api_client.default_request_timeout = 60
remote_sources, remote_submissions, remote_replies = get_remote_data(api_client)

update_local_storage(
session, remote_sources, remote_submissions, remote_replies, self.data_dir
)
sources, submissions, replies = get_remote_data(api_client)

update_local_storage(session, sources, submissions, replies, self.data_dir)
user = api_client.get_current_user()
if "uuid" in user and "username" in user and "first_name" in user and "last_name" in user:
update_and_get_user(
user["uuid"], user["username"], user["first_name"], user["last_name"], session,
)
34 changes: 31 additions & 3 deletions tests/api_jobs/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,37 @@ def test_MetadataSyncJob_success(mocker, homedir, session, session_maker):
"securedrop_client.api_jobs.sync.get_remote_data", return_value=([mock_source], [], [])
)

api_client = mocker.MagicMock()
api_client.default_request_timeout = mocker.MagicMock()
api_client.default_request_timeout = mocker.MagicMock()
user = factory.User(uuid="mock1", username="mock1", firstname="mock1", lastname="mock1")
session.add(user)

api_client = mocker.patch("securedrop_client.logic.sdclientapi.API")

user = {"uuid": "mock1", "username": "mock1", "first_name": "mock1", "last_name": "mock1"}
mocker.patch.object(api_client, "get_current_user", return_value=user)

job.call_api(api_client, session)

assert mock_get_remote_data.call_count == 1


def test_MetadataSyncJob_success_current_user_name_change(mocker, homedir, session, session_maker):
job = MetadataSyncJob(homedir)

mock_source = factory.RemoteSource(
key={"type": "PGP", "public": PUB_KEY, "fingerprint": "123456ABC"}
)

mock_get_remote_data = mocker.patch(
"securedrop_client.api_jobs.sync.get_remote_data", return_value=([mock_source], [], [])
)

user = factory.User(uuid="mock1", username="mock1", firstname="mock1", lastname="mock1")
session.add(user)

api_client = mocker.patch("securedrop_client.logic.sdclientapi.API")

user = {"uuid": "mock2", "username": "mock2", "first_name": "mock2", "last_name": "mock2"}
mocker.patch.object(api_client, "get_current_user", return_value=user)

job.call_api(api_client, session)

Expand Down
812 changes: 389 additions & 423 deletions tests/functional/cassettes/test_delete_source_and_their_docs.yaml

Large diffs are not rendered by default.

1,622 changes: 277 additions & 1,345 deletions tests/functional/cassettes/test_download_file.yaml

Large diffs are not rendered by default.

1,622 changes: 277 additions & 1,345 deletions tests/functional/cassettes/test_export_dialog.yaml

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions tests/functional/cassettes/test_login_as_journalist.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
interactions:
- request:
body: '{"username": "journalist", "passphrase": "correct horse battery staple
profanity oil chewy", "one_time_code": "493941"}'
profanity oil chewy", "one_time_code": "123456"}'
headers:
Accept:
- '*/*'
Expand All @@ -17,16 +17,17 @@ interactions:
uri: http://localhost:8081/api/v1/token
response:
body:
string: "{\n \"expiration\": \"2020-02-17T21:45:20.569829Z\", \n \"journalist_first_name\":
null, \n \"journalist_last_name\": null, \n \"journalist_uuid\": \"1eff0bb5-289b-4105-b3c1-ec93d5704db6\",
\n \"token\": \"eyJhbGciOiJIUzI1NiIsImlhdCI6MTU4MTk0NzEyMCwiZXhwIjoxNTgxOTc1OTIwfQ.eyJpZCI6MX0.4h6pPAy4bl58Yc5Gim1LVdhvTYELvMfIWoZPlBR2ZZI\"\n}\n"
string: "{\n \"expiration\": \"2020-08-14T06:49:16.951787Z\", \n \"journalist_first_name\"\
: \"\", \n \"journalist_last_name\": \"\", \n \"journalist_uuid\": \"a93d176e-676c-4f1c-b0d4-8f9ca8bd0989\"\
, \n \"token\": \"eyJhbGciOiJIUzI1NiIsImlhdCI6MTU5NzM1ODk1NiwiZXhwIjoxNTk3Mzg3NzU2fQ.eyJpZCI6MX0.N4AOTJABrxZXPWC2owcyqJ-pkv3xxPKvhkpbM5-7etU\"\
\n}\n"
headers:
Content-Length:
- '317'
- '313'
Content-Type:
- application/json
Date:
- Mon, 17 Feb 2020 13:45:20 GMT
- Thu, 13 Aug 2020 22:49:16 GMT
Server:
- Werkzeug/0.16.0 Python/3.5.2
status:
Expand Down
1,056 changes: 174 additions & 882 deletions tests/functional/cassettes/test_login_from_offline.yaml

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions tests/functional/cassettes/test_logout_as_journalist.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
interactions:
- request:
body: '{"username": "journalist", "passphrase": "correct horse battery staple
profanity oil chewy", "one_time_code": "994892"}'
profanity oil chewy", "one_time_code": "123456"}'
headers:
Accept:
- '*/*'
Expand All @@ -17,16 +17,17 @@ interactions:
uri: http://localhost:8081/api/v1/token
response:
body:
string: "{\n \"expiration\": \"2020-02-20T22:11:20.428580Z\", \n \"journalist_first_name\":
null, \n \"journalist_last_name\": null, \n \"journalist_uuid\": \"29c7756e-c0f9-4316-b42f-a0af9e20adb0\",
\n \"token\": \"eyJpYXQiOjE1ODIyMDc4ODAsImV4cCI6MTU4MjIzNjY4MCwiYWxnIjoiSFMyNTYifQ.eyJpZCI6MX0.GX36N5A-cyf6bdvalil5_gRa9MnDgIZU_z4NgV8Vzcc\"\n}\n"
string: "{\n \"expiration\": \"2020-08-14T06:47:49.899445Z\", \n \"journalist_first_name\"\
: \"\", \n \"journalist_last_name\": \"\", \n \"journalist_uuid\": \"a93d176e-676c-4f1c-b0d4-8f9ca8bd0989\"\
, \n \"token\": \"eyJhbGciOiJIUzI1NiIsImlhdCI6MTU5NzM1ODg2OSwiZXhwIjoxNTk3Mzg3NjY5fQ.eyJpZCI6MX0.84SIK6fc1hEH9BsJfRuchlYkYWxsNVCEmFqktyy2JUY\"\
\n}\n"
headers:
Content-Length:
- '317'
- '313'
Content-Type:
- application/json
Date:
- Thu, 20 Feb 2020 14:11:20 GMT
- Thu, 13 Aug 2020 22:47:49 GMT
Server:
- Werkzeug/0.16.0 Python/3.5.2
status:
Expand Down
Loading

0 comments on commit 6e6865f

Please sign in to comment.