Skip to content

Commit

Permalink
Configuration tests for the last few upload enhancements.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Aug 11, 2017
1 parent 14ae1ff commit 345219a
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 0 deletions.
Binary file added test-data/1.sam.gz
Binary file not shown.
Binary file added test-data/bad.html.gz
Binary file not shown.
Binary file added test-data/random-file
Binary file not shown.
1 change: 1 addition & 0 deletions test/functional/tools/sample_datatypes_conf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
<datatype extension="vcf" type="galaxy.datatypes.tabular:Vcf" display_in_upload="true"/>
<datatype extension="bgzip" type="galaxy.datatypes.binary:Binary" subclass="true" />
<datatype extension="vcf_bgzip" type="galaxy.datatypes.tabular:VcfGz" type_extension="bgzip" subclass="true" display_in_upload="true"/>
<datatype extension="html" type="galaxy.datatypes.text:Html" mimetype="text/html"/>
</registration>
</datatypes>
112 changes: 112 additions & 0 deletions test/integration/test_check_upload_content_configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
"""Integration tests for check_upload_content configuraiton option."""

from base import integration_util
from base.populators import DatasetPopulator


class BaseCheckUploadContentConfigurationTestCase(integration_util.IntegrationTestCase):

framework_tool_and_types = True

def setUp(self):
super(BaseCheckUploadContentConfigurationTestCase, self).setUp()
self.dataset_populator = DatasetPopulator(self.galaxy_interactor)
self.history_id = self.dataset_populator.new_history()


class NonAdminsCannotPasteFilePathTestCase(BaseCheckUploadContentConfigurationTestCase):

@classmethod
def handle_galaxy_config_kwds(cls, config):
config["allow_path_paste"] = True

def test(self):
payload = self.dataset_populator.upload_payload(
self.history_id, 'file:///Users/john/workspace/galaxy/test-data/1.RData', ext="binary"
)
create_response = self._post( "tools", data=payload )
# Ideally this would be 403 but the tool API endpoint isn't using
# the newer API decorator that handles those details.
assert create_response.status_code >= 400


class AdminsCanPasteFilePathsTestCase(BaseCheckUploadContentConfigurationTestCase):

require_admin_user = True

@classmethod
def handle_galaxy_config_kwds(cls, config):
config["allow_path_paste"] = True

def test(self):
payload = self.dataset_populator.upload_payload(
self.history_id, 'file:///Users/john/workspace/galaxy/test-data/random-file',
)
create_response = self._post( "tools", data=payload )
# Ideally this would be 403 but the tool API endpoint isn't using
# the newer API decorator that handles those details.
assert create_response.status_code == 200


class DefaultBinaryContentFiltersTestCase(BaseCheckUploadContentConfigurationTestCase):

require_admin_user = True

@classmethod
def handle_galaxy_config_kwds(cls, config):
config["allow_path_paste"] = True

def test_random_binary_allowed(self):
dataset = self.dataset_populator.new_dataset(
self.history_id, 'file:///Users/john/workspace/galaxy/test-data/random-file', file_type="auto", wait=True
)
dataset = self.dataset_populator.get_history_dataset_details(self.history_id, dataset=dataset)
assert dataset["file_ext"] == "data", dataset

def test_gzipped_html_content_blocked_by_default(self):
dataset = self.dataset_populator.new_dataset(
self.history_id, 'file:///Users/john/workspace/galaxy/test-data/bad.html.gz', file_type="auto", wait=True
)
dataset = self.dataset_populator.get_history_dataset_details(self.history_id, dataset=dataset)
assert dataset["file_size"] == 0


class DisableContentCheckingTestCase(BaseCheckUploadContentConfigurationTestCase):

require_admin_user = True

@classmethod
def handle_galaxy_config_kwds(cls, config):
config["allow_path_paste"] = True
config["check_upload_content"] = False

def test_gzipped_html_content_now_allowed(self):
self.dataset_populator.new_dataset(
self.history_id, 'file:///Users/john/workspace/galaxy/test-data/bad.html.gz', file_type="auto", wait=True
)
dataset = self.dataset_populator.get_history_dataset_details(self.history_id, dataset=dataset)
# Same file was empty above!
assert dataset["file_size"] != 0


class AutoDecompressTestCase(BaseCheckUploadContentConfigurationTestCase):

require_admin_user = True

@classmethod
def handle_galaxy_config_kwds(cls, config):
config["allow_path_paste"] = True

def test_auto_decompress_off(self):
dataset = self.dataset_populator.new_dataset(
self.history_id, 'file:///Users/john/workspace/galaxy/test-data/1.sam.gz', file_type="auto", auto_decompress=False, wait=True
)
dataset = self.dataset_populator.get_history_dataset_details(self.history_id, dataset=dataset)
assert dataset["file_ext"] == "data", dataset

def test_auto_decompress_on(self):
dataset = self.dataset_populator.new_dataset(
self.history_id, 'file:///Users/john/workspace/galaxy/test-data/1.sam.gz', file_type="auto", wait=True
)
dataset = self.dataset_populator.get_history_dataset_details(self.history_id, dataset=dataset)
assert dataset["file_ext"] == "sam", dataset

0 comments on commit 345219a

Please sign in to comment.