Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into disallow-cross-user-access
Browse files Browse the repository at this point in the history
  • Loading branch information
bartfeenstra committed Nov 27, 2017
2 parents a8c1340 + 1f2ca6b commit ff6994e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tk/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@


class Process:

PROGRESS = 'PROGRESS'

def __init__(self, session, sourcebox_url, sourcebox_account_name, sourcebox_user_name, sourcebox_password):
# Values are 2-tuples (user_name: str, result: str).
self._processes = {}
Expand All @@ -28,7 +31,7 @@ def _process_queue_worker(self, queue):

def submit(self, user_name, document):
process_id = str(uuid.uuid4())
self._processes[process_id] = (user_name, 'PROGRESS')
self._processes[process_id] = (user_name, self.PROGRESS)
self._session.post(self._sourcebox_url, data={
'account': self._sourcebox_account_name,
'username': self._sourcebox_user_name,
Expand All @@ -51,4 +54,7 @@ def _handler(session, response):
def retrieve(self, process_id):
if process_id not in self._processes:
return None
return self._processes[process_id]
process = self._processes[process_id]
if self.PROGRESS != process[1]:
del self._processes[process_id]
return process
10 changes: 10 additions & 0 deletions tk/tests/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ def testSuccessWithProcessedDocument(self, m):
# ideal as it could lead to random test failures, but it is
# unavoidable without additional tools.
sleep(6)
headers = {
'Accept': 'text/xml',
}
query = {
'access_token': self._flask_app.auth.grant_access_token(user_name),
}
response = self._flask_app_client.get('/retrieve/%s' % process_id,
headers={
'Accept': 'text/xml',
Expand All @@ -268,6 +274,10 @@ def testSuccessWithProcessedDocument(self, m):
self.assertEquals(response.status_code, 200)
self.assertEquals(response.get_data(as_text=True), PROFILE)

# Confirm the results are no longer available, in order to keep memory consumption reasonable.
response = self._flask_app_client.get('/retrieve/%s' % process_id, headers=headers, query_string=query)
self.assertEquals(response.status_code, 404)

@requests_mock.mock()
def testSuccessWithSomeoneElsesDocument(self, m):
my_user_name = 'User Foo'
Expand Down

0 comments on commit ff6994e

Please sign in to comment.