mirror of
https://github.com/certbot/certbot.git
synced 2026-08-02 16:12:09 +02:00
Add regex servername test, correct conf syntax
Running the configtest (nginx -c -t /path/to/nginx.conf) should now say "The configuration file /path/to/nginx.conf syntax is ok"
This commit is contained in:
@@ -36,7 +36,7 @@ class NginxConfiguratorTest(util.NginxTest):
|
|||||||
names = self.config.get_all_names()
|
names = self.config.get_all_names()
|
||||||
self.assertEqual(names, set(
|
self.assertEqual(names, set(
|
||||||
["*.www.foo.com", "somename", "another.alias",
|
["*.www.foo.com", "somename", "another.alias",
|
||||||
"alias", "localhost", ".example.com",
|
"alias", "localhost", ".example.com", "~^(www\.)?(example|bar)\.",
|
||||||
"155.225.50.69.nephoscale.net", "*.www.example.com",
|
"155.225.50.69.nephoscale.net", "*.www.example.com",
|
||||||
"example.*", "www.example.org", "myhost"]))
|
"example.*", "www.example.org", "myhost"]))
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ class NginxConfiguratorTest(util.NginxTest):
|
|||||||
parsed[0])
|
parsed[0])
|
||||||
|
|
||||||
def test_choose_vhost(self):
|
def test_choose_vhost(self):
|
||||||
localhost_conf = set(['localhost'])
|
localhost_conf = set(['localhost', '~^(www\.)?(example|bar)\.'])
|
||||||
server_conf = set(['somename', 'another.alias', 'alias'])
|
server_conf = set(['somename', 'another.alias', 'alias'])
|
||||||
example_conf = set(['.example.com', 'example.*'])
|
example_conf = set(['.example.com', 'example.*'])
|
||||||
foo_conf = set(['*.www.foo.com', '*.www.example.com'])
|
foo_conf = set(['*.www.foo.com', '*.www.example.com'])
|
||||||
@@ -81,8 +81,10 @@ class NginxConfiguratorTest(util.NginxTest):
|
|||||||
'example.com.uk.test': example_conf,
|
'example.com.uk.test': example_conf,
|
||||||
'www.example.com': example_conf,
|
'www.example.com': example_conf,
|
||||||
'test.www.example.com': foo_conf,
|
'test.www.example.com': foo_conf,
|
||||||
'abc.www.foo.com': foo_conf}
|
'abc.www.foo.com': foo_conf,
|
||||||
bad_results = ['www.foo.com', 'example', '69.255.225.155']
|
'www.bar.co.uk': localhost_conf}
|
||||||
|
bad_results = ['www.foo.com', 'example', 't.www.bar.co',
|
||||||
|
'69.255.225.155']
|
||||||
|
|
||||||
for name in results:
|
for name in results:
|
||||||
self.assertEqual(results[name],
|
self.assertEqual(results[name],
|
||||||
@@ -134,7 +136,7 @@ class NginxConfiguratorTest(util.NginxTest):
|
|||||||
['ssl_certificate_key', '/etc/nginx/key.pem'],
|
['ssl_certificate_key', '/etc/nginx/key.pem'],
|
||||||
['include',
|
['include',
|
||||||
self.config.parser.loc["ssl_options"]]]],
|
self.config.parser.loc["ssl_options"]]]],
|
||||||
self.config.parser.parsed[nginx_conf][-1][-1][-3])
|
self.config.parser.parsed[nginx_conf][-1][-1][-1])
|
||||||
|
|
||||||
def test_get_all_certs_keys(self):
|
def test_get_all_certs_keys(self):
|
||||||
nginx_conf = self.config.parser.abs_path('nginx.conf')
|
nginx_conf = self.config.parser.abs_path('nginx.conf')
|
||||||
|
|||||||
@@ -63,21 +63,22 @@ class TestRawNginxParser(unittest.TestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
parsed,
|
parsed,
|
||||||
[['user', 'www-data'],
|
[['user', 'www-data'],
|
||||||
[['server'], [
|
[['http'],
|
||||||
['listen', '*:80 default_server ssl'],
|
[[['server'], [
|
||||||
['server_name', '*.www.foo.com *.www.example.com'],
|
['listen', '*:80 default_server ssl'],
|
||||||
['root', '/home/ubuntu/sites/foo/'],
|
['server_name', '*.www.foo.com *.www.example.com'],
|
||||||
[['location', '/status'], [
|
['root', '/home/ubuntu/sites/foo/'],
|
||||||
['check_status'],
|
[['location', '/status'], [
|
||||||
[['types'], [['image/jpeg', 'jpg']]],
|
[['types'], [['image/jpeg', 'jpg']]],
|
||||||
]],
|
]],
|
||||||
[['location', '~', 'case_sensitive\.php$'], [
|
[['location', '~', 'case_sensitive\.php$'], [
|
||||||
['hoge', 'hoge']
|
['index', 'index.php'],
|
||||||
]],
|
['root', '/var/root'],
|
||||||
[['location', '~*', 'case_insensitive\.php$'], []],
|
]],
|
||||||
[['location', '=', 'exact_match\.php$'], []],
|
[['location', '~*', 'case_insensitive\.php$'], []],
|
||||||
[['location', '^~', 'ignore_regex\.php$'], []],
|
[['location', '=', 'exact_match\.php$'], []],
|
||||||
]]]
|
[['location', '^~', 'ignore_regex\.php$'], []]
|
||||||
|
]]]]]
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_dump_as_file(self):
|
def test_dump_as_file(self):
|
||||||
|
|||||||
@@ -84,7 +84,9 @@ class NginxParserTest(util.NginxTest):
|
|||||||
|
|
||||||
vhost1 = VirtualHost(parser.abs_path('nginx.conf'),
|
vhost1 = VirtualHost(parser.abs_path('nginx.conf'),
|
||||||
[Addr('', '8080', False, False)],
|
[Addr('', '8080', False, False)],
|
||||||
False, True, set(['localhost']), [])
|
False, True, set(['localhost',
|
||||||
|
'~^(www\.)?(example|bar)\.']),
|
||||||
|
[])
|
||||||
vhost2 = VirtualHost(parser.abs_path('nginx.conf'),
|
vhost2 = VirtualHost(parser.abs_path('nginx.conf'),
|
||||||
[Addr('somename', '8080', False, False),
|
[Addr('somename', '8080', False, False),
|
||||||
Addr('', '8000', False, False)],
|
Addr('', '8000', False, False)],
|
||||||
@@ -118,7 +120,8 @@ class NginxParserTest(util.NginxTest):
|
|||||||
def test_add_server_directives(self):
|
def test_add_server_directives(self):
|
||||||
parser = NginxParser(self.config_path, self.ssl_options)
|
parser = NginxParser(self.config_path, self.ssl_options)
|
||||||
parser.add_server_directives(parser.abs_path('nginx.conf'),
|
parser.add_server_directives(parser.abs_path('nginx.conf'),
|
||||||
set(['localhost']),
|
set(['localhost',
|
||||||
|
'~^(www\.)?(example|bar)\.']),
|
||||||
[['foo', 'bar'], ['ssl_certificate',
|
[['foo', 'bar'], ['ssl_certificate',
|
||||||
'/etc/ssl/cert.pem']])
|
'/etc/ssl/cert.pem']])
|
||||||
r = re.compile('foo bar;\n\s+ssl_certificate /etc/ssl/cert.pem')
|
r = re.compile('foo bar;\n\s+ssl_certificate /etc/ssl/cert.pem')
|
||||||
|
|||||||
+17
-15
@@ -1,23 +1,25 @@
|
|||||||
# a test nginx conf
|
# a test nginx conf
|
||||||
user www-data;
|
user www-data;
|
||||||
|
|
||||||
server {
|
http {
|
||||||
listen *:80 default_server ssl;
|
server {
|
||||||
server_name *.www.foo.com *.www.example.com;
|
listen *:80 default_server ssl;
|
||||||
root /home/ubuntu/sites/foo/;
|
server_name *.www.foo.com *.www.example.com;
|
||||||
|
root /home/ubuntu/sites/foo/;
|
||||||
|
|
||||||
location /status {
|
location /status {
|
||||||
check_status;
|
types {
|
||||||
types {
|
image/jpeg jpg;
|
||||||
image/jpeg jpg;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
location ~ case_sensitive\.php$ {
|
location ~ case_sensitive\.php$ {
|
||||||
hoge hoge;
|
index index.php;
|
||||||
}
|
root /var/root;
|
||||||
location ~* case_insensitive\.php$ {}
|
}
|
||||||
location = exact_match\.php$ {}
|
location ~* case_insensitive\.php$ {}
|
||||||
location ^~ ignore_regex\.php$ {}
|
location = exact_match\.php$ {}
|
||||||
|
location ^~ ignore_regex\.php$ {}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ include foo.conf;
|
|||||||
|
|
||||||
http {
|
http {
|
||||||
include mime.types;
|
include mime.types;
|
||||||
|
include sites-enabled/*;
|
||||||
default_type application/octet-stream;
|
default_type application/octet-stream;
|
||||||
|
|
||||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||||
@@ -30,13 +31,13 @@ http {
|
|||||||
tcp_nopush on;
|
tcp_nopush on;
|
||||||
|
|
||||||
keepalive_timeout 0;
|
keepalive_timeout 0;
|
||||||
keepalive_timeout 65;
|
|
||||||
|
|
||||||
gzip on;
|
gzip on;
|
||||||
|
|
||||||
server {
|
server {
|
||||||
listen 8080;
|
listen 8080;
|
||||||
server_name localhost;
|
server_name localhost;
|
||||||
|
server_name ~^(www\.)?(example|bar)\.;
|
||||||
|
|
||||||
charset koi8-r;
|
charset koi8-r;
|
||||||
|
|
||||||
@@ -68,7 +69,6 @@ http {
|
|||||||
fastcgi_pass 127.0.0.1:9000;
|
fastcgi_pass 127.0.0.1:9000;
|
||||||
fastcgi_index index.php;
|
fastcgi_index index.php;
|
||||||
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
|
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
|
||||||
include fastcgi_params;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# deny access to .htaccess files, if Nginx's document root
|
# deny access to .htaccess files, if Nginx's document root
|
||||||
@@ -115,7 +115,5 @@ http {
|
|||||||
# }
|
# }
|
||||||
#}
|
#}
|
||||||
|
|
||||||
include conf.d/test.conf;
|
#include conf.d/test.conf;
|
||||||
include sites-enabled/*;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ events {
|
|||||||
include foo.conf;
|
include foo.conf;
|
||||||
http {
|
http {
|
||||||
include mime.types;
|
include mime.types;
|
||||||
|
include sites-enabled/*;
|
||||||
default_type application/octet-stream;
|
default_type application/octet-stream;
|
||||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||||
'$status $body_bytes_sent "$http_referer" '
|
'$status $body_bytes_sent "$http_referer" '
|
||||||
@@ -18,12 +19,12 @@ http {
|
|||||||
sendfile on;
|
sendfile on;
|
||||||
tcp_nopush on;
|
tcp_nopush on;
|
||||||
keepalive_timeout 0;
|
keepalive_timeout 0;
|
||||||
keepalive_timeout 65;
|
|
||||||
gzip on;
|
gzip on;
|
||||||
|
|
||||||
server {
|
server {
|
||||||
listen 8080;
|
listen 8080;
|
||||||
server_name localhost;
|
server_name localhost;
|
||||||
|
server_name ~^(www\.)?(example|bar)\.;
|
||||||
charset koi8-r;
|
charset koi8-r;
|
||||||
access_log logs/host.access.log main;
|
access_log logs/host.access.log main;
|
||||||
|
|
||||||
@@ -47,7 +48,6 @@ http {
|
|||||||
fastcgi_pass 127.0.0.1:9000;
|
fastcgi_pass 127.0.0.1:9000;
|
||||||
fastcgi_index index.php;
|
fastcgi_index index.php;
|
||||||
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
|
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
|
||||||
include fastcgi_params;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
location ~ /\.ht {
|
location ~ /\.ht {
|
||||||
@@ -65,8 +65,6 @@ http {
|
|||||||
index index.html index.htm;
|
index index.html index.htm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
include conf.d/test.conf;
|
|
||||||
include sites-enabled/*;
|
|
||||||
|
|
||||||
server {
|
server {
|
||||||
listen 443 ssl;
|
listen 443 ssl;
|
||||||
|
|||||||
Reference in New Issue
Block a user