Exemple #1
0
    def test_modsec(self):
        vhost = """<VirtualHost *:80>
  ServerName www.example.com
  SecRuleEngine off
</VirtualHost>"""
        result = vh.from_string(vhost, 'test_sec1')
        for name, params in result.items():
            self.assertTrue(params['modsec_disable_vhost'])

        vhost = """<VirtualHost *:80>
  ServerName www.example.com
  SecRequestBodyLimit 1024000
  SecRuleRemoveById 1 2 "9000-9010"
</VirtualHost>"""
        result = vh.from_string(vhost, 'test_sec2')
        for name, params in result.items():
            self.assertEqual(params['modsec_body_limit'], 1024000)
            self.assertEqual(params['modsec_disable_ids'], ['1', '2', '9000-9010'])
Exemple #2
0
    def test_headers(self):
        vhost = """<VirtualHost *:80>
  ServerName www.example.com
  Header Set X-Robots-Tag "noindex, noarchive, nosnippet"
</VirtualHost>"""
        result = vh.from_string(vhost, 'test_headers')
        for name, params in result.items():
            self.assertEqual(params['headers'],
                             ['Set X-Robots-Tag "noindex, noarchive, nosnippet"'])
Exemple #3
0
    def test_php(self):
        vhost = """<VirtualHost *:80>
  ServerName www.example.com
  php_value include_path ".:/path/with spaces"
  php_admin_flag engine on
</VirtualHost>"""
        result = vh.from_string(vhost, 'test_php')
        for name, params in result.items():
            self.assertEqual(params['php_values'],
                             {'include_path': '".:/path/with spaces"'})
            self.assertEqual(params['php_admin_flags'], {'engine': 'on'})
Exemple #4
0
    def test_redirect(self):
        vhost = """<VirtualHost *:80>
  ServerName www.example.com
  Redirect permanent "/one" "http://example.com/two"
  Redirect 303 "/three" "http://example.com/other"
</VirtualHost>"""
        result = vh.from_string(vhost, 'test_redirect')
        for name, params in result.items():
            self.assertEqual(params['redirect_status'], ['permanent', '303'])
            self.assertEqual(params['redirect_source'], ['/one', '/three'])
            self.assertEqual(params['redirect_dest'],
                             ['http://example.com/two', 'http://example.com/other'])
Exemple #5
0
    def test_addhandler(self):
        vhost = """<VirtualHost *:80>
  ServerName www.example.com
  <Directory "/var/www/html">
    AddHandler php-script .php .php5
  </Directory>
</VirtualHost>"""
        result = vh.from_string(vhost, 'test_addhandler')
        expected = [{'extensions': ['.php', '.php5'], 'handler': 'php-script'}]
        for name, params in result.items():
            self.assertIn('directories', params)
            drt = params['directories'][0]
            self.assertEqual(drt['path'], '/var/www/html')
            self.assertEqual(drt['provider'], 'directory')
            self.assertEqual(drt['addhandlers'], expected)
Exemple #6
0
    def test_itk(self):
        vhost = """<VirtualHost *:80>
  ServerName www.example.com
  AssignUserId www-user www-group
  MaxClientsVHost 50
  NiceValue -10
  LimitUIDRange 1000 2000
</VirtualHost>"""
        result = vh.from_string(vhost, 'test_itk')
        expected = {'user'           : 'www-user',
                    'group'          : 'www-group',
                    'maxclientvhost' : 50,
                    'nice'           : -10,
                    'limituidrange'  : '1000 2000'}
        for name, params in result.items():
            self.assertIn('itk', params)
            self.assertEqual(params['itk'], expected)
Exemple #7
0
    def test_auth(self):
        vhost = """<VirtualHost *:80>
  ServerName www.example.com
  <Location "/private/">
    AuthType Digest
    AuthName "private area"
    AuthDigestDomain "/private/" "http://www.example.com/private2/"
    AuthDigestProvider file
    AuthUserFile "/web/auth/.digest_pw"
    Require valid-user
  </Location>
</VirtualHost>"""
        result = vh.from_string(vhost, 'test_auth')
        for name, params in result.items():
            drt = params['directories'][0]
            self.assertEqual(drt['provider'], 'location')
            self.assertEqual(drt['auth_type'], 'Digest')
            self.assertEqual(drt['auth_name'], 'private area')
            self.assertEqual(drt['auth_digest_domain'],
                             ['/private/', 'http://www.example.com/private2/'])
            self.assertEqual(drt['auth_digest_provider'], 'file')
            self.assertEqual(drt['auth_user_file'], '/web/auth/.digest_pw')
            self.assertEqual(drt['auth_require'], 'valid-user')
Exemple #8
0
    def test_quotes(self):
        # The ssl_cert param should not have quotes as they are
        # added by apache::vhost
        vhost = """<VirtualHost *:443>
  ServerName www.example.com
  SSLEngine on
  SSLCertificateFile "/path/to/cert file"
</VirtualHost>"""
        expected = '/path/to/cert file'
        result = vh.from_string(vhost, 'test_quotes1')
        for name, params in result.items():
            self.assertTrue(params['ssl'])
            self.assertEqual(params['ssl_cert'], expected)

        # With single quotes
        vhost = """<VirtualHost *:443>
  ServerName www.example.com
  SSLEngine on
  SSLCertificateFile '/path/to/cert file'
</VirtualHost>"""
        expected = '/path/to/cert file'
        result = vh.from_string(vhost, 'test_quotes2')
        for name, params in result.items():
            self.assertTrue(params['ssl'])
            self.assertEqual(params['ssl_cert'], expected)

        # And backticks
        vhost = """<VirtualHost *:443>
  ServerName www.example.com
  SSLEngine on
  SSLCertificateFile `/path/to/cert file`
</VirtualHost>"""
        expected = '/path/to/cert file'
        result = vh.from_string(vhost, 'test_quotes3')
        for name, params in result.items():
            self.assertTrue(params['ssl'])
            self.assertEqual(params['ssl_cert'], expected)

        # In this case, apache::vhost does not add the quotes around
        # the value of passenger_app_root, so they should be added
        # here.
        vhost = """<VirtualHost *:80>
  ServerName www.example.com
  PassengerAppRoot "/path/to/passenger root"
</VirtualHost>"""
        expected = '"/path/to/passenger root"'
        result = vh.from_string(vhost, 'test_quotes4')
        for name, params in result.items():
            self.assertEqual(params['passenger_app_root'], expected)

        # The quotes should be stripped and readded to the second
        # argument, but the third argument won't get them readded
        # because it doesn't contain a character that would force the
        # argument to be in quotes (backslash). Also, pyparsing seems
        # to have a problem keeping the backslash, when parsing a
        # quoted string.
        vhost = """<VirtualHost *:80>
  ServerName www.example.com
  SetEnvIf Request_URI "\.gif$" object_is_image=gif
</VirtualHost>"""
        expected = [r'Request_URI "\.gif$" object_is_image=gif']
        result = vh.from_string(vhost, 'test_quotes5')
        for name, params in result.items():
            self.assertEqual(params['setenvif'], expected)

        # Test escaped quotes
        vhost = """<VirtualHost *:80>
  ServerName www.example.com
  CustomLog /var/log/apache2/access_log "%h %l %u %t \\"%r\\" %>s %b"
</VirtualHost>"""
        result = vh.from_string(vhost, 'test_quotes6')
        for name, params in result.items():
            self.assertTrue(params['access_log'])
            self.assertEqual(params['access_log_file'], 'access_log')
            self.assertEqual(params['logroot'], '/var/log/apache2')
            self.assertEqual(params['access_log_format'], r'"%h %l %u %t \"%r\" %>s %b"')