-
Notifications
You must be signed in to change notification settings - Fork 696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Download unread/ all selected sources #1467
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
import os | ||
|
||
from cStringIO import StringIO | ||
import unittest | ||
import zipfile | ||
import mock | ||
import time | ||
import datetime | ||
|
||
from flask_testing import TestCase | ||
from flask import url_for, escape | ||
from flask_testing import TestCase | ||
import mock | ||
import os | ||
import time | ||
import unittest | ||
import zipfile | ||
|
||
# Set environment variable so config.py uses a test environment | ||
os.environ['SECUREDROP_ENV'] = 'test' | ||
import config | ||
|
||
import common | ||
import config | ||
import crypto_util | ||
import journalist | ||
import common | ||
from db import (db_session, Source, Submission, Journalist, Reply, | ||
InvalidPasswordLength) | ||
from db import (db_session, InvalidPasswordLength, Journalist, Reply, Source, | ||
Submission) | ||
|
||
|
||
class TestJournalist(TestCase): | ||
|
@@ -28,7 +28,7 @@ def create_app(self): | |
return journalist.app | ||
|
||
def add_source_and_submissions(self): | ||
sid = 'EQZGCJBRGISGOTC2NZVWG6LILJBHEV3CINNEWSCLLFTUWZJPKJFECLS2NZ4G4U3QOZCFKTTPNZMVIWDCJBBHMUDBGFHXCQ3R' | ||
sid = crypto_util.hash_codename(crypto_util.genrandomid()) | ||
codename = crypto_util.display_id() | ||
crypto_util.genkeypair(sid, codename) | ||
source = Source(sid, codename) | ||
|
@@ -367,7 +367,8 @@ def test_admin_authorization_for_posts(self): | |
|
||
def test_user_authorization_for_gets(self): | ||
urls = [url_for('index'), url_for('col', sid='1'), | ||
url_for('doc', sid='1', fn='1'), url_for('edit_account')] | ||
url_for('download_single_submission', sid='1', fn='1'), | ||
url_for('edit_account')] | ||
|
||
for url in urls: | ||
res = self.client.get(url) | ||
|
@@ -511,22 +512,115 @@ def test_delete_source_deletes_docs_on_disk(self): | |
dir_source_docs = os.path.join(config.STORE_DIR, source.filesystem_id) | ||
self.assertFalse(os.path.exists(dir_source_docs)) | ||
|
||
def test_bulk_download(self): | ||
source, files = self.add_source_and_submissions() | ||
def test_download_selected_from_source(self): | ||
sid = 'EQZGCJBRGISGOTC2NZVWG6LILJBHEV3CINNEWSCLLFTUWZJPKJFECLS2NZ4G4U3QOZCFKTTPNZMVIWDCJBBHMUDBGFHXCQ3R' | ||
source = Source(sid, crypto_util.display_id()) | ||
db_session.add(source) | ||
db_session.commit() | ||
files = ['1-abc1-msg.gpg', '2-abc2-msg.gpg', '3-abc3-msg.gpg', '4-abc4-msg.gpg'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can adapt |
||
selected_files = files[:2] | ||
unselected_files = files[2:] | ||
common.setup_test_docs(sid, files) | ||
|
||
self._login_user() | ||
rv = self.client.post('/bulk', data=dict( | ||
action='download', | ||
sid=source.filesystem_id, | ||
doc_names_selected=files | ||
)) | ||
rv = self.client.post('/bulk', | ||
data=dict(action='download', sid=sid, | ||
doc_names_selected=selected_files)) | ||
|
||
self.assertEqual(rv.status_code, 200) | ||
self.assertEqual(rv.content_type, 'application/zip') | ||
self.assertTrue(zipfile.is_zipfile(StringIO(rv.data))) | ||
self.assertTrue(zipfile.ZipFile(StringIO(rv.data)).getinfo( | ||
os.path.join(source.journalist_filename, files[0]) | ||
)) | ||
|
||
for file in selected_files: | ||
self.assertTrue( | ||
zipfile.ZipFile(StringIO(rv.data)).getinfo( | ||
os.path.join(source.journalist_filename, file)) | ||
) | ||
|
||
for file in unselected_files: | ||
try: | ||
zipfile.ZipFile(StringIO(rv.data)).getinfo( | ||
os.path.join(source.journalist_filename, file)) | ||
except KeyError: | ||
pass | ||
else: | ||
self.assertTrue(False) | ||
|
||
def _setup_two_sources(self): | ||
# Add two sources to the database | ||
self.sid = crypto_util.hash_codename(crypto_util.genrandomid()) | ||
self.sid2 = crypto_util.hash_codename(crypto_util.genrandomid()) | ||
self.source = Source(self.sid, crypto_util.display_id()) | ||
self.source2 = Source(self.sid2, crypto_util.display_id()) | ||
db_session.add(self.source) | ||
db_session.add(self.source2) | ||
db_session.commit() | ||
|
||
# The sources have made two submissions each, both being messages | ||
self.files = ['1-s1-msg.gpg', '2-s1-msg.gpg'] | ||
common.setup_test_docs(self.sid, self.files) | ||
self.files2 = ['1-s2-msg.gpg', '2-s2-msg.gpg'] | ||
common.setup_test_docs(self.sid2, self.files2) | ||
|
||
# Mark the first message for each of the two sources read | ||
for fn in (self.files[0], self.files2[0]): | ||
s = Submission.query.filter(Submission.filename == fn).one() | ||
s.downloaded = True | ||
db_session.commit() | ||
|
||
|
||
|
||
def test_download_unread_selected_sources(self): | ||
self._setup_two_sources() | ||
self._login_user() | ||
resp = self.client.post('/col/process', | ||
data=dict(action='download-unread', | ||
cols_selected=[self.sid, self.sid2])) | ||
|
||
self.assertEqual(resp.status_code, 200) | ||
self.assertEqual(resp.content_type, 'application/zip') | ||
self.assertTrue(zipfile.is_zipfile(StringIO(resp.data))) | ||
|
||
for file in (self.files[1], self.files2[1]): | ||
self.assertTrue( | ||
zipfile.ZipFile(StringIO(resp.data)).getinfo( | ||
os.path.join('unread', file)) | ||
) | ||
|
||
for file in (self.files[0], self.files2[0]): | ||
try: | ||
zipfile.ZipFile(StringIO(resp.data)).getinfo( | ||
os.path.join('unread', file)) | ||
except KeyError: | ||
pass | ||
else: | ||
self.assertTrue(False) | ||
|
||
def test_download_all_selected_sources(self): | ||
self._setup_two_sources() | ||
self._login_user() | ||
resp = self.client.post('/col/process', | ||
data=dict(action='download-all', | ||
cols_selected=[self.sid2])) | ||
|
||
self.assertEqual(resp.status_code, 200) | ||
self.assertEqual(resp.content_type, 'application/zip') | ||
self.assertTrue(zipfile.is_zipfile(StringIO(resp.data))) | ||
|
||
for file in self.files2: | ||
self.assertTrue( | ||
zipfile.ZipFile(StringIO(resp.data)).getinfo( | ||
os.path.join('all', file)) | ||
) | ||
|
||
for file in self.files: | ||
try: | ||
zipfile.ZipFile(StringIO(resp.data)).getinfo( | ||
os.path.join('all', file)) | ||
except KeyError: | ||
pass | ||
else: | ||
self.assertTrue(False) | ||
|
||
def test_max_password_length(self): | ||
"""Creating a Journalist with a password that is greater than the | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call on changing these icons!