Beispiel #1
0
def test_validate_celery_config_request_logs_dir_misconfigured(file_type, access, error, tmpdir):
    cachito_request_file_logs_dir = tmpdir.join("logs")
    cachito_bundles_dir = tmpdir.join("bundles")
    cachito_bundles_dir.mkdir()
    cachito_sources_dir = tmpdir.join("sources")
    cachito_sources_dir.mkdir()
    if file_type == "file":
        cachito_request_file_logs_dir.write("")
    elif file_type == "dir":
        cachito_request_file_logs_dir.mkdir()
    elif file_type is None:
        # Skip creating the file or directory altogether
        pass
    else:
        raise ValueError(f"Bad file_type {file_type}")

    if not access:
        if os.getuid() == 0:
            pytest.skip("Cannot restrict the root user from writing to any file")
        cachito_request_file_logs_dir.chmod(mode=0o555)

    celery_app = celery.Celery()
    celery_app.conf.cachito_api_url = "http://localhost:8080/api/v1/"
    celery_app.conf.cachito_bundles_dir = cachito_bundles_dir
    celery_app.conf.cachito_sources_dir = cachito_sources_dir
    celery_app.conf.cachito_default_environment_variables = {}
    celery_app.conf.cachito_request_file_logs_dir = cachito_request_file_logs_dir
    error = error.format(logs_dir=cachito_request_file_logs_dir)
    with pytest.raises(ConfigError, match=error):
        validate_celery_config(celery_app.conf)
Beispiel #2
0
def test_validate_celery_config(mock_isdir):
    celery_app = celery.Celery()
    celery_app.conf.cachito_archives_dir = '/tmp/some-path'
    celery_app.conf.cachito_shared_dir = '/tmp/some-other-path'
    celery_app.conf.cachito_api_url = 'http://cachito-api/api/v1/'
    validate_celery_config(celery_app.conf)
    assert mock_isdir.call_count == 2
    mock_isdir.assert_any_call(celery_app.conf.cachito_shared_dir)
    mock_isdir.assert_any_call(celery_app.conf.cachito_archives_dir)
Beispiel #3
0
def test_validate_celery_config(mock_isdir):
    celery_app = celery.Celery()
    celery_app.conf.cachito_api_url = "http://cachito-api/api/v1/"
    celery_app.conf.cachito_bundles_dir = "/tmp/some-path/bundles"
    celery_app.conf.cachito_default_environment_variables = {}
    celery_app.conf.cachito_sources_dir = "/tmp/some-path/sources"
    celery_app.conf.cachito_nexus_hoster_username = "******"
    celery_app.conf.cachito_nexus_hoster_password = "******"
    validate_celery_config(celery_app.conf)
    mock_isdir.assert_any_call(celery_app.conf.cachito_bundles_dir)
    mock_isdir.assert_any_call(celery_app.conf.cachito_sources_dir)
Beispiel #4
0
def test_validate_celery_config_failure_default_env_vars(mock_isdir, default_env_vars, expected):
    celery_app = celery.Celery()
    celery_app.conf.cachito_api_url = "http://cachito-api/api/v1/"
    celery_app.conf.cachito_bundles_dir = "/tmp/some-path/bundles"
    celery_app.conf.cachito_default_environment_variables = default_env_vars
    celery_app.conf.cachito_sources_dir = "/tmp/some-path/sources"
    celery_app.conf.cachito_nexus_hoster_username = "******"
    celery_app.conf.cachito_nexus_hoster_password = "******"

    with pytest.raises(ConfigError, match=expected):
        validate_celery_config(celery_app.conf)
Beispiel #5
0
def test_validate_celery_config_invalid_nexus_hoster_config(
        mock_isdir, hoster_username, hoster_password):
    celery_app = celery.Celery()
    celery_app.conf.cachito_api_url = "http://cachito-api/api/v1/"
    celery_app.conf.cachito_bundles_dir = "/tmp/some-path/bundles"
    celery_app.conf.cachito_sources_dir = "/tmp/some-path/sources"
    celery_app.conf.cachito_nexus_hoster_username = hoster_username
    celery_app.conf.cachito_nexus_hoster_password = hoster_password
    expected = (
        'If "cachito_nexus_hoster_username" or "cachito_nexus_hoster_password" is set, '
        "the other must also be set")
    with pytest.raises(ConfigError, match=expected):
        validate_celery_config(celery_app.conf)
Beispiel #6
0
def test_validate_celery_config_failure(mock_isdir, bundles_dir, sources_dir):
    celery_app = celery.Celery()
    celery_app.conf.cachito_sources_dir = "/tmp/some-path/sources"

    if bundles_dir:
        celery_app.conf.cachito_bundles_dir = "/tmp/some-path/bundles"
        dir_name = "cachito_sources_dir"
    elif sources_dir:
        celery_app.conf.cachito_sources_dir = "/tmp/some-path/sources"
        dir_name = "cachito_bundles_dir"

    setattr(celery_app.conf, dir_name, None)
    expected = f'The configuration "{dir_name}" must be set to an existing directory'
    with pytest.raises(ConfigError, match=expected):
        validate_celery_config(celery_app.conf)
Beispiel #7
0
def test_validate_celery_config_missing_cert(mock_isdir, auth_type, has_cert, auth_cert):
    celery_app = celery.Celery()
    celery_app.conf.cachito_api_url = "http://cachito-api/api/v1/"
    celery_app.conf.cachito_default_environment_variables = {}
    celery_app.conf.cachito_bundles_dir = "/tmp/some-path/bundles"
    celery_app.conf.cachito_sources_dir = "/tmp/some-path/sources"
    celery_app.conf.cachito_auth_type = auth_type
    if has_cert:
        celery_app.conf.cachito_auth_cert = auth_cert

    if (has_cert and auth_cert) or auth_type != "cert":
        validate_celery_config(celery_app.conf)
    else:
        expected = 'cachito_auth_cert configuration must be set for "cert" authentication'
        with pytest.raises(ConfigError, match=expected):
            validate_celery_config(celery_app.conf)
Beispiel #8
0
def test_validate_celery_config_failure():
    celery_app = celery.Celery()
    celery_app.conf.cachito_archives_dir = None
    expected = 'The configuration "cachito_archives_dir" must be set to an existing directory'
    with pytest.raises(ConfigError, match=expected):
        validate_celery_config(celery_app.conf)