Пример #1
0
def test_httpd_one_file_overwrites():
    httpd = HttpdConf(
        context_wrap(HTTPD_CONF_MORE, path='/etc/httpd/conf/httpd.conf'))
    result = HttpdConfAll([httpd])

    active_setting = result.get_active_setting('UserDir')
    assert active_setting.value == 'enable bob'
    assert active_setting.line == 'UserDir enable bob'
    assert active_setting.file_path == '/etc/httpd/conf/httpd.conf'
    assert active_setting.file_name == 'httpd.conf'

    setting_list = result.get_setting_list('UserDir')
    assert len(setting_list) == 2
    assert setting_list[0].value == 'disable'
    assert setting_list[0].line == 'UserDir disable'
    assert setting_list[0].file_path == '/etc/httpd/conf/httpd.conf'
    assert setting_list[0].file_name == 'httpd.conf'
    assert setting_list[0].section is None
    assert setting_list[1].value == 'enable bob'
    assert setting_list[1].line == 'UserDir enable bob'
    assert setting_list[1].file_path == '/etc/httpd/conf/httpd.conf'
    assert setting_list[1].file_name == 'httpd.conf'
    assert setting_list[1].section_name is None
Пример #2
0
def test_active_httpd():
    httpd1 = HttpdConf(
        context_wrap(HTTPD_CONF_1, path='/etc/httpd/conf/httpd.conf'))
    httpd2 = HttpdConf(
        context_wrap(HTTPD_CONF_2, path='/etc/httpd/conf.d/00-z.conf'))
    httpd3 = HttpdConf(
        context_wrap(HTTPD_CONF_3, path='/etc/httpd/conf.d/z-z.conf'))

    result = HttpdConfAll([httpd1, httpd2, httpd3])
    assert result.get_active_setting('MaxClients',
                                     section=('IfModule',
                                              'prefork.c'))[0].value == '512'
    assert result.get_active_setting(
        'MaxClients',
        section=('IfModule',
                 'prefork.c'))[0].file_path == '/etc/httpd/conf.d/z-z.conf'
    assert result.get_active_setting('ThreadsPerChild',
                                     section=('IfModule',
                                              'prefork.c'))[0].value == '16'
    assert result.get_active_setting(
        "MaxClients", ("IfModule", "prefork")) == [
            ParsedData(value='512',
                       line='MaxClients       512',
                       section='IfModule',
                       section_name='prefork.c',
                       file_name='z-z.conf',
                       file_path='/etc/httpd/conf.d/z-z.conf')
        ]
    assert result.get_active_setting('ServerLimit',
                                     section=('IfModule',
                                              'prefork.c'))[0].value == '256'
    assert result.get_active_setting(
        'JustForTest',
        section=('IfModule', 'prefork.c'))[-1].file_name == '00-z.conf'
    assert result.get_active_setting(
        'JustForTest_NoSec').line == 'JustForTest_NoSec "/var/www/cgi"'
Пример #3
0
def test_httpd_splits():
    httpd1 = HttpdConf(
        context_wrap(HTTPD_CONF_MAIN_1, path='/etc/httpd/conf/httpd.conf'))
    httpd2 = HttpdConf(
        context_wrap(HTTPD_CONF_FILE_1, path='/etc/httpd/conf.d/00-a.conf'))
    httpd3 = HttpdConf(
        context_wrap(HTTPD_CONF_FILE_2, path='/etc/httpd/conf.d/01-b.conf'))
    result = HttpdConfAll([httpd1, httpd2, httpd3])
    assert result.get_active_setting('ServerRoot').value == '/home/skontar/www'
    assert result.get_active_setting(
        'ServerRoot').line == 'ServerRoot "/home/skontar/www"'
    assert result.get_active_setting('ServerRoot').file_name == '01-b.conf'
    assert result.get_active_setting(
        'ServerRoot').file_path == '/etc/httpd/conf.d/01-b.conf'
    assert result.get_active_setting('Listen').value == '8080'
    assert result.get_active_setting('Listen').line == 'Listen 8080'
    assert result.get_active_setting('Listen').file_name == '00-a.conf'
    assert result.get_active_setting(
        'Listen').file_path == '/etc/httpd/conf.d/00-a.conf'

    httpd1 = HttpdConf(
        context_wrap(HTTPD_CONF_MAIN_2, path='/etc/httpd/conf/httpd.conf'))
    httpd2 = HttpdConf(
        context_wrap(HTTPD_CONF_FILE_1, path='/etc/httpd/conf.d/00-a.conf'))
    httpd3 = HttpdConf(
        context_wrap(HTTPD_CONF_FILE_2, path='/etc/httpd/conf.d/01-b.conf'))

    result = HttpdConfAll([httpd1, httpd2, httpd3])
    assert result.get_active_setting('ServerRoot').value == '/etc/httpd'
    assert result.get_active_setting(
        'ServerRoot').line == 'ServerRoot "/etc/httpd"'
    assert result.get_active_setting('ServerRoot').file_name == 'httpd.conf'
    assert result.get_active_setting(
        'ServerRoot').file_path == '/etc/httpd/conf/httpd.conf'
    assert result.get_active_setting('Listen').value == '80'
    assert result.get_active_setting('Listen').line == 'Listen 80'
    assert result.get_active_setting('Listen').file_name == 'httpd.conf'
    assert result.get_active_setting(
        'Listen').file_path == '/etc/httpd/conf/httpd.conf'

    httpd1 = HttpdConf(
        context_wrap(HTTPD_CONF_MAIN_3, path='/etc/httpd/conf/httpd.conf'))
    httpd2 = HttpdConf(
        context_wrap(HTTPD_CONF_FILE_1, path='/etc/httpd/conf.d/00-a.conf'))
    httpd3 = HttpdConf(
        context_wrap(HTTPD_CONF_FILE_2, path='/etc/httpd/conf.d/01-b.conf'))

    result = HttpdConfAll([httpd1, httpd2, httpd3])
    assert result.get_active_setting('ServerRoot').value == '/home/skontar/www'
    assert result.get_active_setting(
        'ServerRoot').line == 'ServerRoot "/home/skontar/www"'
    assert result.get_active_setting('ServerRoot').file_name == '01-b.conf'
    assert result.get_active_setting(
        'ServerRoot').file_path == '/etc/httpd/conf.d/01-b.conf'
    assert result.get_active_setting('Listen').value == '80'
    assert result.get_active_setting('Listen').line == 'Listen 80'
    assert result.get_active_setting('Listen').file_name == 'httpd.conf'
    assert result.get_active_setting(
        'Listen').file_path == '/etc/httpd/conf/httpd.conf'

    # Test is data from inactive configs are also stored
    assert [a.file_name for a in result.config_data
            ] == ['httpd.conf', '00-a.conf', '01-b.conf', 'httpd.conf']
    assert result.config_data[1].file_name == '00-a.conf'
    assert result.config_data[1].file_path == '/etc/httpd/conf.d/00-a.conf'
    assert result.config_data[1].full_data_dict['Listen'][0].value == '8080'
    assert result.config_data[1].full_data_dict['Listen'][
        0].line == 'Listen 8080'
Пример #4
0
def test_shadowing():
    httpd1 = HttpdConf(
        context_wrap(HTTPD_CONF_SHADOWTEST_1,
                     path='/etc/httpd/conf/httpd.conf'))
    httpd2 = HttpdConf(
        context_wrap(HTTPD_CONF_SHADOWTEST_2,
                     path='/etc/httpd/conf.d/00-z.conf'))
    httpd3 = HttpdConf(
        context_wrap(HTTPD_CONF_SHADOWTEST_3,
                     path='/etc/httpd/conf.d/z-z.conf'))

    result = HttpdConfAll([httpd1, httpd2, httpd3])

    # get_setting_list returns ALL matching data

    assert result.get_setting_list('Foo') == [
        ParsedData('1A', 'Foo 1A', None, None, 'httpd.conf',
                   '/etc/httpd/conf/httpd.conf'),
        ParsedData('1B', 'Foo 1B', None, None, 'httpd.conf',
                   '/etc/httpd/conf/httpd.conf'),
        ParsedData('1C', 'Foo 1C', None, None, 'httpd.conf',
                   '/etc/httpd/conf/httpd.conf'),
        ParsedData('2A', 'Foo 2A', None, None, '00-z.conf',
                   '/etc/httpd/conf.d/00-z.conf'),
        ParsedData('2B', 'Foo 2B', None, None, '00-z.conf',
                   '/etc/httpd/conf.d/00-z.conf'),
        ParsedData('2C', 'Foo 2C', None, None, '00-z.conf',
                   '/etc/httpd/conf.d/00-z.conf'),
        ParsedData('3A', 'Foo 3A', None, None, 'z-z.conf',
                   '/etc/httpd/conf.d/z-z.conf'),
        ParsedData('3B', 'Foo 3B', None, None, 'z-z.conf',
                   '/etc/httpd/conf.d/z-z.conf'),
        ParsedData('3C', 'Foo 3C', None, None, 'z-z.conf',
                   '/etc/httpd/conf.d/z-z.conf'),
    ]
    assert result.get_setting_list(
        'Bar', section=('IfModule', 'prefork.c')) == [
            {
                ('IfModule', 'prefork.c'): [
                    ParsedData('1A', 'Bar 1A', 'IfModule', 'prefork.c',
                               'httpd.conf', '/etc/httpd/conf/httpd.conf'),
                    ParsedData('1B', 'Bar 1B', 'IfModule', 'prefork.c',
                               'httpd.conf', '/etc/httpd/conf/httpd.conf'),
                    ParsedData('1C', 'Bar 1C', 'IfModule', 'prefork.c',
                               'httpd.conf', '/etc/httpd/conf/httpd.conf'),
                    ParsedData('3A', 'Bar 3A', 'IfModule', 'prefork.c',
                               'z-z.conf', '/etc/httpd/conf.d/z-z.conf'),
                    ParsedData('3B', 'Bar 3B', 'IfModule', 'prefork.c',
                               'z-z.conf', '/etc/httpd/conf.d/z-z.conf'),
                    ParsedData('3C', 'Bar 3C', 'IfModule', 'prefork.c',
                               'z-z.conf', '/etc/httpd/conf.d/z-z.conf'),
                ],
            },
            {
                ('IfModule', 'ASDF.prefork.c.ASDF'): [
                    ParsedData('2A', 'Bar 2A', 'IfModule',
                               'ASDF.prefork.c.ASDF', '00-z.conf',
                               '/etc/httpd/conf.d/00-z.conf'),
                    ParsedData('2B', 'Bar 2B', 'IfModule',
                               'ASDF.prefork.c.ASDF', '00-z.conf',
                               '/etc/httpd/conf.d/00-z.conf'),
                    ParsedData('2C', 'Bar 2C', 'IfModule',
                               'ASDF.prefork.c.ASDF', '00-z.conf',
                               '/etc/httpd/conf.d/00-z.conf'),
                ],
            },
        ]
    assert result.get_setting_list('Bar') == []

    # get_active_setting returns the last value

    assert result.get_active_setting('Foo') == ('3C', 'Foo 3C', None, None,
                                                'z-z.conf',
                                                '/etc/httpd/conf.d/z-z.conf')
    assert result.get_active_setting(
        'Bar', section=('IfModule', 'prefork.c')) == [
            ('3C', 'Bar 3C', 'IfModule', 'prefork.c', 'z-z.conf',
             '/etc/httpd/conf.d/z-z.conf'),
            ('2C', 'Bar 2C', 'IfModule', 'ASDF.prefork.c.ASDF', '00-z.conf',
             '/etc/httpd/conf.d/00-z.conf'),
        ]
    assert result.get_active_setting('Bar') is None
Пример #5
0
def test_active_httpd_nest_1():
    httpd1 = HttpdConf(
        context_wrap(HTTPD_CONF_NEST_1, path='/etc/httpd/conf/httpd.conf'))
    httpd2 = HttpdConf(
        context_wrap(HTTPD_CONF_NEST_2, path='/etc/httpd/conf.d/00-z.conf'))
    result = HttpdConfAll([httpd1, httpd2])
    assert result.get_setting_list('Order1', ('FilesMatch', 'php')) == []
    assert result.get_setting_list('Order', ('FilesMatch', 'pdf')) == []
    php_fm_order = result.get_setting_list('Order',
                                           section=('FilesMatch', 'php'))
    assert {
        ('FilesMatch', '".php[45]?$"'):
        [('allow,deny', 'Order allow,deny', 'FilesMatch', '".php[45]?$"',
          '00-z.conf', '/etc/httpd/conf.d/00-z.conf'),
         ('deny,allow', 'Order deny,allow', 'FilesMatch', '".php[45]?$"',
          '00-z.conf', '/etc/httpd/conf.d/00-z.conf')]
    } in php_fm_order
    assert {
        ('FilesMatch', '".php[45]"'):
        [('allow,deny', 'Order allow,deny', 'FilesMatch', '".php[45]"',
          'httpd.conf', '/etc/httpd/conf/httpd.conf'),
         ('deny,allow', 'Order deny,allow', 'FilesMatch', '".php[45]"',
          '00-z.conf', '/etc/httpd/conf.d/00-z.conf')],
    } in php_fm_order
    assert {
        ('FilesMatch', '".php[45]?$"'):
        [('allow,deny', 'Order allow,deny', 'FilesMatch', '".php[45]?$"',
          'httpd.conf', '/etc/httpd/conf/httpd.conf'),
         ('deny,allow', 'Order deny,allow', 'FilesMatch', '".php[45]?$"',
          'httpd.conf', '/etc/httpd/conf/httpd.conf')]
    } in php_fm_order
    re_im = result.get_setting_list('RewriteEngine', 'IfModule')
    assert {
        ('IfModule', 'mod_rewrite.c'):
        [('On', 'RewriteEngine On', 'IfModule', 'mod_rewrite.c', 'httpd.conf',
          '/etc/httpd/conf/httpd.conf'),
         ('Off', 'RewriteEngine Off', 'IfModule', 'mod_rewrite.c',
          'httpd.conf', '/etc/httpd/conf/httpd.conf')]
    } in re_im
    assert {
        ('IfModule', 'mod_rewrite.c'):
        [('Off', 'RewriteEngine Off', 'IfModule', 'mod_rewrite.c',
          'httpd.conf', '/etc/httpd/conf/httpd.conf'),
         ('On', 'RewriteEngine On', 'IfModule', 'mod_rewrite.c', '00-z.conf',
          '/etc/httpd/conf.d/00-z.conf')]
    } in re_im
    assert sorted(result.get_setting_list('EnableSendfile')) == sorted([
        ('off', 'EnableSendfile off', None, None, '00-z.conf',
         '/etc/httpd/conf.d/00-z.conf'),
        ('on', 'EnableSendfile on', None, None, 'httpd.conf',
         '/etc/httpd/conf/httpd.conf')
    ])
    assert result.get_setting_list('LogLevel') == [
        ('warn', 'LogLevel warn', None, None, 'httpd.conf',
         '/etc/httpd/conf/httpd.conf')
    ]
    assert result.get_setting_list('LogLevel1') == []

    assert result.get_active_setting('Order1', ('FilesMatch', 'php')) == []
    assert result.get_active_setting('Order', ('FilesMatch', 'pdf')) == []
    assert len(result.get_active_setting('Order',
                                         ('FilesMatch', '.php[45]?$'))) == 2
    assert len(result.get_active_setting('Order', ('FilesMatch', ))) == 4
    assert len(result.get_active_setting('Order',
                                         ('FilesMatch', '.php[45]'))) == 3
    assert sorted(
        result.get_active_setting(
            'Order', section=('FilesMatch', 'php'))) == sorted([
                ('deny,allow', 'Order deny,allow', 'FilesMatch',
                 '".php[45]?$"', '00-z.conf', '/etc/httpd/conf.d/00-z.conf'),
                ('deny,allow', 'Order deny,allow', 'FilesMatch', '".php[45]"',
                 '00-z.conf', '/etc/httpd/conf.d/00-z.conf'),
                ('deny,allow', 'Order deny,allow', 'FilesMatch',
                 '".php[45]?$"', 'httpd.conf', '/etc/httpd/conf/httpd.conf')
            ])
    assert sorted(
        result.get_active_setting(
            'RewriteEngine', section='IfModule')) == sorted([
                ('Off', 'RewriteEngine Off', 'IfModule', 'mod_rewrite.c',
                 'httpd.conf', '/etc/httpd/conf/httpd.conf'),
                ('On', 'RewriteEngine On', 'IfModule', 'mod_rewrite.c',
                 '00-z.conf', '/etc/httpd/conf.d/00-z.conf')
            ])
    assert result.get_active_setting(
        'EnableSendfile').line == 'EnableSendfile on'
    assert result.get_active_setting('Deny', ('FilesMatch', 'test')) == []
    assert result.get_active_setting(
        'Allow', ('FilesMatch', 'test'))[0].value == 'from all'
    assert result.get_active_setting('Deny', section=('IfModule', )) == []
    assert result.get_active_setting('MaxClients',
                                     section=('IfModule', 'prefork')) == []
    assert result.get_active_setting(
        'RewriteRule',
        section=('IfModule',
                 'mod_rewrite.c'))[0].line == "RewriteRule .* /index.php"
    assert result.get_active_setting("DocumentRoot").value == '/var/www/html'
    assert result.get_active_setting('RewriteRule',
                                     section=('IfModule', 'mod_rewrite.c',
                                              'invalid_test')) == []
    assert result.get_active_setting('LogLevel') == (
        'warn', 'LogLevel warn', None, None, 'httpd.conf',
        '/etc/httpd/conf/httpd.conf')
    assert result.get_active_setting('LogLevel1') is None