Exemplo n.º 1
0
def test_get_apache_ip_directive_upgrade_file_22(mock_glob, mock_osaccess,
                                                 mock_ospath):
    """Test we get the expected directive value for Apache 2.2
       when using the upgrade file filename"""

    config = utils.get_config('%s/apache_setup.cfg' % utils.get_data_path())
    gen = ServiceAccessGeneratorApache('%s/ip_data.cfg' %
                                       utils.get_data_path())
    gen.set_config_values(config)
    ip_directive = gen._get_apache_ip_directive()

    assert ip_directive == 'Allow from'
Exemplo n.º 2
0
def test_get_apache_ip_directive_apachectl_call_24(mock_ospopen, mock_osaccess,
                                                   mock_ospath):
    """Test we get the expected directive value for Apache 2.4
       when 'apachctl' is called"""

    config = utils.get_config('%s/apache_setup.cfg' % utils.get_data_path())
    gen = ServiceAccessGeneratorApache('%s/ip_data.cfg' %
                                       utils.get_data_path())
    gen.set_config_values(config)
    ip_directive = gen._get_apache_ip_directive()

    assert ip_directive == 'Require ip'
Exemplo n.º 3
0
def test_get_apache_ip_directive_apachectl_call_24(
        mock_ospopen,
        mock_osaccess,
        mock_ospath):
    """Test we get the expected directive value for Apache 2.4
       when 'apachctl' is called"""

    config = utils.get_config('%s/apache_setup.cfg' % utils.get_data_path())
    gen = ServiceAccessGeneratorApache(
        '%s/ip_data.cfg' % utils.get_data_path()
    )
    gen.set_config_values(config)
    ip_directive = gen._get_apache_ip_directive()

    assert ip_directive == 'Require ip'
Exemplo n.º 4
0
def test_get_apache_ip_directive_upgrade_file_24(
        mock_glob,
        mock_osaccess,
        mock_ospath):
    """Test we get the expected directive value for Apache 2.4
       when using the upgrade file filename"""

    config = utils.get_config('%s/apache_setup.cfg' % utils.get_data_path())
    gen = ServiceAccessGeneratorApache(
        '%s/ip_data.cfg' % utils.get_data_path()
    )
    gen.set_config_values(config)
    ip_directive = gen._get_apache_ip_directive()

    assert ip_directive == 'Require ip'
Exemplo n.º 5
0
def test_update_config_v24_large_IP_set(
        mock_glob,
        mock_osaccess,
        mock_ospath_apache,
        mock_ospath_base):
    """Test we get the expected modifications in the config file"""

    utils.create_test_tmpdir()
    utils.copy_to_testdir('%s/apache-vhost.cfg' % utils.get_data_path())
    config = utils.get_config('%s/apache_setup.cfg' % utils.get_data_path())
    ip_config = utils.get_config('%s/ip_data.cfg' % utils.get_data_path())
    large_ip_set = '192.168.1.0/24,' * 400
    large_ip_set += '192.168.1.0/24'
    ip_config.set('region3', 'public-ips', large_ip_set)
    large_ip_data = open('%s/large_ip_data.cfg' % utils.get_test_tmpdir(), 'w')
    ip_config.write(large_ip_data)
    large_ip_data.close()

    gen = ServiceAccessGeneratorApache(
        '%s/large_ip_data.cfg' % utils.get_test_tmpdir()
    )
    gen.set_config_values(config)
    with pytest.raises(ServiceAccessGeneratorServiceRestartError) as excinfo:
        gen.update_config()

    # Load the reference result data
    ref_result_file = (
        '%s/apache-vhost-24-large-ip-set.cfg'
        % utils.get_reference_result_path()
    )
    ref_result = open(ref_result_file).read()

    # Load the generated result
    gen_result_file = (
        '%s/apache-vhost.cfg' % utils.get_test_tmpdir()
    )
    gen_result = open(gen_result_file).read()

    if ref_result == gen_result:
        # success
        utils.remove_test_tmpdir()
    else:
        msg = 'Test failed, not removing test directory '
        msg += '"%s" to aid debugging ' % utils.get_test_tmpdir()
        assert False, msg
Exemplo n.º 6
0
def test_update_config_v24(mock_glob, mock_osaccess, mock_ospath_apache,
                           mock_ospath_base):
    """Test we get the expected modifications in the config file"""

    utils.create_test_tmpdir()
    utils.copy_to_testdir('%s/apache-vhost.cfg' % utils.get_data_path())
    config = utils.get_config('%s/apache_setup.cfg' % utils.get_data_path())
    gen = ServiceAccessGeneratorApache('%s/ip_data.cfg' %
                                       utils.get_data_path())
    gen.set_config_values(config)
    with pytest.raises(ServiceAccessGeneratorServiceRestartError) as excinfo:
        gen.update_config()

    # Load the reference result data
    ref_result_file = ('%s/apache-vhost-24.cfg' %
                       utils.get_reference_result_path())
    ref_result = open(ref_result_file).read()

    # Load the generated result
    gen_result_file = ('%s/apache-vhost.cfg' % utils.get_test_tmpdir())
    gen_result = open(gen_result_file).read()

    if ref_result == gen_result:
        # success
        utils.remove_test_tmpdir()
    else:
        msg = 'Test failed, not removing test directory '
        msg += '"%s" to aid debugging ' % utils.get_test_tmpdir()
        assert False, msg
Exemplo n.º 7
0
def test_update_config_v24(
        mock_glob,
        mock_osaccess,
        mock_ospath_apache,
        mock_ospath_base):
    """Test we get the expected modifications in the config file"""

    utils.create_test_tmpdir()
    utils.copy_to_testdir('%s/apache-vhost.cfg' % utils.get_data_path())
    config = utils.get_config('%s/apache_setup.cfg' % utils.get_data_path())
    gen = ServiceAccessGeneratorApache(
        '%s/ip_data.cfg' % utils.get_data_path()
    )
    gen.set_config_values(config)
    with pytest.raises(ServiceAccessGeneratorServiceRestartError) as excinfo:
        gen.update_config()

    # Load the reference result data
    ref_result_file = (
        '%s/apache-vhost-24.cfg' % utils.get_reference_result_path()
    )
    ref_result = open(ref_result_file).read()

    # Load the generated result
    gen_result_file = (
        '%s/apache-vhost.cfg' % utils.get_test_tmpdir()
    )
    gen_result = open(gen_result_file).read()

    if ref_result == gen_result:
        # success
        utils.remove_test_tmpdir()
    else:
        msg = 'Test failed, not removing test directory '
        msg += '"%s" to aid debugging ' % utils.get_test_tmpdir()
        assert False, msg
Exemplo n.º 8
0
def test_update_config_v24_large_IP_set(
        mock_glob,
        mock_osaccess,
        mock_ospath_apache,
        mock_ospath_base):
    """Test we get the expected modifications in the config file"""

    utils.create_test_tmpdir()
    utils.copy_to_testdir('%s/apache-vhost_24.cfg' % utils.get_data_path())
    config = utils.get_config('%s/apache_setup_24.cfg' % utils.get_data_path())
    ip_config = utils.get_config('%s/ip_data.cfg' % utils.get_data_path())
    large_ip_set = '192.168.1.0/24,' * 400
    large_ip_set += '192.168.1.0/24'
    ip_config.set('region3', 'public-ips', large_ip_set)
    large_ip_data = open('%s/large_ip_data.cfg' % utils.get_test_tmpdir(), 'w')
    ip_config.write(large_ip_data)
    large_ip_data.close()

    gen = ServiceAccessGeneratorApache(
        '%s/large_ip_data.cfg' % utils.get_test_tmpdir()
    )
    gen.set_config_values(config)
    with pytest.raises(ServiceAccessGeneratorServiceRestartError) as excinfo:
        gen.update_config()

    # Load the reference result data
    ref_result_file = (
        '%s/apache-vhost-24-large-ip-set.cfg'
        % utils.get_reference_result_path()
    )
    ref_result = open(ref_result_file).read()

    # Load the generated result
    gen_result_file = (
        '%s/apache-vhost_24.cfg' % utils.get_test_tmpdir()
    )
    gen_result = open(gen_result_file).read()

    if ref_result == gen_result:
        # success
        utils.remove_test_tmpdir()
    else:
        msg = 'Test failed, not removing test directory '
        msg += '"%s" to aid debugging ' % utils.get_test_tmpdir()
        assert False, msg