Exemple #1
0
def test_maximum_length_handling_ascii():
    # Test that id secrets can be up to 56 characters long.
    longest_id_secret = "m" * idencoding.MAXIMUM_ID_SECRET_LENGTH
    helper = idencoding.IdEncodingHelper(id_secret=longest_id_secret)
    helper.encode_id(1)

    # Test that security helper will catch if the id secret is too long.
    threw_exception = False
    longer_id_secret = "m" * (idencoding.MAXIMUM_ID_SECRET_LENGTH + 1)
    try:
        idencoding.IdEncodingHelper(id_secret=longer_id_secret)
    except Exception:
        threw_exception = True

    assert threw_exception

    # Test that different kinds produce different keys even when id secret
    # is very long.
    e11 = helper.encode_id(1, kind="moo")
    e12 = helper.encode_id(1, kind="moo2")

    assert e11 != e12

    # Test that long kinds are rejected because it uses up "too much" randomness
    # from id_secret values. This isn't a strict requirement up but lets just enforce
    # the best practice.
    assertion_error_raised = False
    try:
        helper.encode_id(1, kind="this is a really long kind")
    except AssertionError:
        assertion_error_raised = True

    assert assertion_error_raised
Exemple #2
0
    def __init__(self, **kwargs):
        super().__init__()
        self[BasicApp] = self
        log.debug("python path is: %s", ", ".join(sys.path))
        self.name = "reports"
        # Read config file and check for errors
        self.config = config.Configuration(**kwargs)
        self.config.check()
        configure_logging(self.config)
        self.application_stack = application_stack_instance()
        # Determine the database url
        if self.config.database_connection:
            db_url = self.config.database_connection
        else:
            db_url = "sqlite:///%s?isolation_level=IMMEDIATE" % self.config.database
        # Setup the database engine and ORM
        self.model = galaxy.model.mapping.init(
            self.config.file_path,
            db_url,
            self.config.database_engine_options,
            create_tables=True)
        if not self.config.database_connection:
            self.targets_mysql = False
        else:
            self.targets_mysql = 'mysql' in self.config.database_connection
        # Security helper
        self.security = idencoding.IdEncodingHelper(
            id_secret=self.config.id_secret)

        self._register_singleton(idencoding.IdEncodingHelper, self.security)
        self._register_singleton(SharedModelMapping, self.model)

        # used for cachebusting -- refactor this into a *SINGLE* UniverseApplication base.
        self.server_starttime = int(time.time())
Exemple #3
0
 def setUp(self):
     self.security = idencoding.IdEncodingHelper(
         id_secret='changethisinproductiontoo')
     self.history_id = os.environ.get('GALAXY_TEST_HISTORY_ID', None)
     self.host, self.port, self.url = target_url_parts()
     self.test_data_resolver = TestDataResolver()
     self.keepOutdir = setup_keep_outdir()
Exemple #4
0
 def __init__(self, **kwargs):
     log.debug("python path is: %s", ", ".join(sys.path))
     self.name = "coralsnp_reports"
     # Read config file and check for errors
     self.config = config.Configuration(**kwargs)
     self.config.check()
     config.configure_logging(self.config)
     self.application_stack = application_stack_instance()
     # Determine the database url
     if self.config.database_connection:
         db_url = self.config.database_connection
     else:
         db_url = "postgresql://*****:*****@localhost/stag"
     # Setup the database engine and ORM
     self.model = galaxy.model.corals.mapping.init(
         db_url, self.config.database_engine_options)
     if not self.config.database_connection:
         self.targets_mysql = False
     else:
         self.targets_mysql = 'mysql' in self.config.database_connection
     # Security helper
     self.security = idencoding.IdEncodingHelper(
         id_secret=self.config.id_secret)
     # used for cachebusting -- refactor this into a *SINGLE* UniverseApplication base.
     self.server_starttime = int(time.time())
Exemple #5
0
 def __init__(self, **kwd):
     log.debug("python path is: %s", ", ".join(sys.path))
     self.name = "tool_shed"
     # Read the tool_shed.ini configuration file and check for errors.
     self.config = config.Configuration(**kwd)
     self.config.check()
     configure_logging(self.config)
     self.application_stack = application_stack_instance()
     # Initialize the  Galaxy datatypes registry.
     self.datatypes_registry = galaxy.datatypes.registry.Registry()
     self.datatypes_registry.load_datatypes(self.config.root,
                                            self.config.datatypes_config)
     # Initialize the Tool Shed repository_types registry.
     self.repository_types_registry = tool_shed.repository_types.registry.Registry(
     )
     # Initialize the RepositoryGridFilterManager.
     self.repository_grid_filter_manager = RepositoryGridFilterManager()
     # Determine the Tool Shed database connection string.
     if self.config.database_connection:
         db_url = self.config.database_connection
     else:
         db_url = "sqlite:///%s?isolation_level=IMMEDIATE" % self.config.database
     # Initialize the Tool Shed database and check for appropriate schema version.
     from galaxy.webapps.tool_shed.model.migrate.check import create_or_verify_database
     create_or_verify_database(db_url, self.config.database_engine_options)
     # Set up the Tool Shed database engine and ORM.
     from galaxy.webapps.tool_shed.model import mapping
     self.model = mapping.init(self.config.file_path, db_url,
                               self.config.database_engine_options)
     self.security = idencoding.IdEncodingHelper(
         id_secret=self.config.id_secret)
     # initialize the Tool Shed tag handler.
     self.tag_handler = CommunityTagHandler(self)
     # Initialize the Tool Shed tool data tables.  Never pass a configuration file here
     # because the Tool Shed should always have an empty dictionary!
     self.tool_data_tables = galaxy.tools.data.ToolDataTableManager(
         self.config.tool_data_path)
     self.genome_builds = GenomeBuilds(self)
     from galaxy import auth
     self.auth_manager = auth.AuthManager(self)
     # Citation manager needed to load tools.
     from galaxy.managers.citations import CitationsManager
     self.citations_manager = CitationsManager(self)
     # The Tool Shed makes no use of a Galaxy toolbox, but this attribute is still required.
     self.toolbox = tools.ToolBox([], self.config.tool_path, self)
     # Initialize the Tool Shed security agent.
     self.security_agent = self.model.security_agent
     # The Tool Shed makes no use of a quota, but this attribute is still required.
     self.quota_agent = galaxy.quota.NoQuotaAgent(self.model)
     # Initialize the baseline Tool Shed statistics component.
     self.shed_counter = self.model.shed_counter
     # Let the Tool Shed's HgwebConfigManager know where the hgweb.config file is located.
     self.hgweb_config_manager = self.model.hgweb_config_manager
     self.hgweb_config_manager.hgweb_config_dir = self.config.hgweb_config_dir
     # Initialize the repository registry.
     self.repository_registry = tool_shed.repository_registry.Registry(self)
     #  used for cachebusting -- refactor this into a *SINGLE* UniverseApplication base.
     self.server_starttime = int(time.time())
     log.debug("Tool shed hgweb.config file is: %s",
               self.hgweb_config_manager.hgweb_config)
Exemple #6
0
    def __init__(self, root=None, **kwargs):
        Bunch.__init__(self, **kwargs)
        if not root:
            root = tempfile.mkdtemp()
            self._remove_root = True
        else:
            self._remove_root = False
        self.security = idencoding.IdEncodingHelper(
            id_secret='6e46ed6483a833c100e68cc3f1d0dd76')
        self.database_connection = kwargs.get('database_connection',
                                              "sqlite:///:memory:")
        self.use_remote_user = kwargs.get('use_remote_user', False)
        self.data_dir = os.path.join(root, 'database')
        self.file_path = os.path.join(self.data_dir, 'files')
        self.jobs_directory = os.path.join(self.data_dir, 'jobs_directory')
        self.new_file_path = os.path.join(self.data_dir, 'tmp')
        self.tool_data_path = os.path.join(root, 'tool-data')
        self.tool_dependency_dir = None
        self.metadata_strategy = 'legacy'

        self.object_store_config_file = ''
        self.object_store = 'disk'
        self.object_store_check_old_style = False
        self.object_store_cache_path = '/tmp/cache'
        self.umask = os.umask(0o77)
        self.gid = os.getgid()

        self.user_activation_on = False
        self.new_user_dataset_access_role_default_private = False

        self.expose_dataset_path = True
        self.allow_user_dataset_purge = True
        self.enable_old_display_applications = True
        self.redact_username_in_logs = False
        self.auth_config_file = "config/auth_conf.xml.sample"
        self.error_email_to = "*****@*****.**"
        self.password_expiration_period = 0

        self.umask = 0o77

        # Compliance related config
        self.redact_email_in_job_name = False

        # Follow two required by GenomeBuilds
        self.len_file_path = os.path.join('tool-data', 'shared', 'ucsc',
                                          'chrom')
        self.builds_file_path = os.path.join('tool-data', 'shared', 'ucsc',
                                             'builds.txt.sample')

        self.preserve_python_environment = "always"
        self.enable_beta_gdpr = False
        self.legacy_eager_objectstore_initialization = True

        self.version_major = "19.09"

        # set by MockDir
        self.root = root

        self.config_file = None
Exemple #7
0
def test_maximum_length_handling_nonascii():
    longest_id_secret = "◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎"
    helper = idencoding.IdEncodingHelper(id_secret=longest_id_secret)
    helper.encode_id(1)

    # Test that security helper will catch if the id secret is too long.
    threw_exception = False
    longer_id_secret = "◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎"
    try:
        idencoding.IdEncodingHelper(id_secret=longer_id_secret)
    except Exception:
        threw_exception = True

    assert threw_exception

    # Test that different kinds produce different keys even when id secret
    # is very long.
    e11 = helper.encode_id(1, kind="moo")
    e12 = helper.encode_id(1, kind="moo2")

    assert e11 != e12
Exemple #8
0
import galaxy.config
from galaxy.security import idencoding
from galaxy.util.script import app_properties_from_args, populate_config_args

parser = argparse.ArgumentParser()
populate_config_args(parser)
parser.add_argument('-e', '--encode-id', dest='encode_id', help='Encode an ID')
parser.add_argument('-d', '--decode-id', dest='decode_id', help='Decode an ID')
parser.add_argument('--hda', dest='hda_id', help='Display HistoryDatasetAssociation info')
parser.add_argument('--ldda', dest='ldda_id', help='Display LibraryDatasetDatasetAssociation info')
args = parser.parse_args()

app_properties = app_properties_from_args(args)
config = galaxy.config.Configuration(**app_properties)
helper = idencoding.IdEncodingHelper(id_secret=app_properties.get('id_secret'))
model = galaxy.config.init_models_from_config(config)

if args.encode_id:
    print('Encoded "{}": {}'.format(args.encode_id, helper.encode_id(args.encode_id)))

if args.decode_id:
    print('Decoded "{}": {}'.format(args.decode_id, helper.decode_id(args.decode_id)))

if args.hda_id:
    try:
        hda_id = int(args.hda_id)
    except Exception:
        hda_id = int(helper.decode_id(args.hda_id))
    hda = model.context.current.query(model.HistoryDatasetAssociation).get(hda_id)
    print(f'HDA "{hda.id}" is Dataset "{hda.dataset.id}" at: {hda.file_name}')
Exemple #9
0
 def __init__(self, **kwargs):
     self.name = kwargs.get('name', 'galaxy')
     self.security = idencoding.IdEncodingHelper(
         id_secret='6e46ed6483a833c100e68cc3f1d0dd76')
Exemple #10
0
from galaxy.security import idencoding

test_helper_1 = idencoding.IdEncodingHelper(id_secret="secu1")
test_helper_2 = idencoding.IdEncodingHelper(id_secret="secu2")


def test_maximum_length_handling_ascii():
    # Test that id secrets can be up to 56 characters long.
    longest_id_secret = "m" * idencoding.MAXIMUM_ID_SECRET_LENGTH
    helper = idencoding.IdEncodingHelper(id_secret=longest_id_secret)
    helper.encode_id(1)

    # Test that security helper will catch if the id secret is too long.
    threw_exception = False
    longer_id_secret = "m" * (idencoding.MAXIMUM_ID_SECRET_LENGTH + 1)
    try:
        idencoding.IdEncodingHelper(id_secret=longer_id_secret)
    except Exception:
        threw_exception = True

    assert threw_exception

    # Test that different kinds produce different keys even when id secret
    # is very long.
    e11 = helper.encode_id(1, kind="moo")
    e12 = helper.encode_id(1, kind="moo2")

    assert e11 != e12

    # Test that long kinds are rejected because it uses up "too much" randomness
    # from id_secret values. This isn't a strict requirement up but lets just enforce
Exemple #11
0
 def __init__(self, **kwd) -> None:
     super().__init__()
     self[BasicApp] = self
     log.debug("python path is: %s", ", ".join(sys.path))
     self.name = "tool_shed"
     # will be overwritten when building WSGI app
     self.is_webapp = False
     # Read the tool_shed.ini configuration file and check for errors.
     self.config: Any = config.Configuration(**kwd)
     self.config.check()
     configure_logging(self.config)
     self.application_stack = application_stack_instance()
     # Initialize the  Galaxy datatypes registry.
     self.datatypes_registry = galaxy.datatypes.registry.Registry()
     self.datatypes_registry.load_datatypes(self.config.root,
                                            self.config.datatypes_config)
     # Initialize the Tool Shed repository_types registry.
     self.repository_types_registry = tool_shed.repository_types.registry.Registry(
     )
     # Initialize the RepositoryGridFilterManager.
     self.repository_grid_filter_manager = RepositoryGridFilterManager()
     # Determine the Tool Shed database connection string.
     if self.config.database_connection:
         db_url = self.config.database_connection
     else:
         db_url = f"sqlite:///{self.config.database}?isolation_level=IMMEDIATE"
     # Initialize the Tool Shed database and check for appropriate schema version.
     from tool_shed.webapp.model.migrate.check import create_or_verify_database
     create_or_verify_database(db_url, self.config.database_engine_options)
     # Set up the Tool Shed database engine and ORM.
     from tool_shed.webapp.model import mapping
     model: mapping.ToolShedModelMapping = mapping.init(
         self.config.file_path, db_url, self.config.database_engine_options)
     self.model = model
     self.security = idencoding.IdEncodingHelper(
         id_secret=self.config.id_secret)
     self._register_singleton(idencoding.IdEncodingHelper, self.security)
     self._register_singleton(SharedModelMapping, model)
     self._register_singleton(mapping.ToolShedModelMapping, model)
     self._register_singleton(scoped_session, self.model.context)
     self._register_singleton(UserManager, UserManager)
     # initialize the Tool Shed tag handler.
     self.tag_handler = CommunityTagHandler(self)
     # Initialize the Tool Shed tool data tables.  Never pass a configuration file here
     # because the Tool Shed should always have an empty dictionary!
     self.tool_data_tables = galaxy.tools.data.ToolDataTableManager(
         self.config.tool_data_path)
     self.genome_builds = GenomeBuilds(self)
     self.auth_manager = self._register_singleton(
         auth.AuthManager, auth.AuthManager(self.config))
     # Citation manager needed to load tools.
     self.citations_manager = self._register_singleton(
         CitationsManager, CitationsManager(self))
     self.use_tool_dependency_resolution = False
     # Initialize the Tool Shed security agent.
     self.security_agent = model.security_agent
     # The Tool Shed makes no use of a quota, but this attribute is still required.
     self.quota_agent = self._register_singleton(QuotaAgent, NoQuotaAgent())
     # Initialize the baseline Tool Shed statistics component.
     self.shed_counter = model.shed_counter
     # Let the Tool Shed's HgwebConfigManager know where the hgweb.config file is located.
     self.hgweb_config_manager = hgweb_config_manager
     self.hgweb_config_manager.hgweb_config_dir = self.config.hgweb_config_dir
     # Initialize the repository registry.
     self.repository_registry = tool_shed.repository_registry.Registry(self)
     #  used for cachebusting -- refactor this into a *SINGLE* UniverseApplication base.
     self.server_starttime = int(time.time())
     log.debug("Tool shed hgweb.config file is: %s",
               self.hgweb_config_manager.hgweb_config)