mirror of
https://github.com/certbot/certbot.git
synced 2026-06-03 22:08:07 -04: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:
parent
f050fcfa58
commit
f83a77d8ad
7 changed files with 50 additions and 46 deletions
|
|
@ -36,7 +36,7 @@ class NginxConfiguratorTest(util.NginxTest):
|
|||
names = self.config.get_all_names()
|
||||
self.assertEqual(names, set(
|
||||
["*.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",
|
||||
"example.*", "www.example.org", "myhost"]))
|
||||
|
||||
|
|
@ -70,7 +70,7 @@ class NginxConfiguratorTest(util.NginxTest):
|
|||
parsed[0])
|
||||
|
||||
def test_choose_vhost(self):
|
||||
localhost_conf = set(['localhost'])
|
||||
localhost_conf = set(['localhost', '~^(www\.)?(example|bar)\.'])
|
||||
server_conf = set(['somename', 'another.alias', 'alias'])
|
||||
example_conf = set(['.example.com', 'example.*'])
|
||||
foo_conf = set(['*.www.foo.com', '*.www.example.com'])
|
||||
|
|
@ -81,8 +81,10 @@ class NginxConfiguratorTest(util.NginxTest):
|
|||
'example.com.uk.test': example_conf,
|
||||
'www.example.com': example_conf,
|
||||
'test.www.example.com': foo_conf,
|
||||
'abc.www.foo.com': foo_conf}
|
||||
bad_results = ['www.foo.com', 'example', '69.255.225.155']
|
||||
'abc.www.foo.com': foo_conf,
|
||||
'www.bar.co.uk': localhost_conf}
|
||||
bad_results = ['www.foo.com', 'example', 't.www.bar.co',
|
||||
'69.255.225.155']
|
||||
|
||||
for name in results:
|
||||
self.assertEqual(results[name],
|
||||
|
|
@ -134,7 +136,7 @@ class NginxConfiguratorTest(util.NginxTest):
|
|||
['ssl_certificate_key', '/etc/nginx/key.pem'],
|
||||
['include',
|
||||
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):
|
||||
nginx_conf = self.config.parser.abs_path('nginx.conf')
|
||||
|
|
|
|||
|
|
@ -63,21 +63,22 @@ class TestRawNginxParser(unittest.TestCase):
|
|||
self.assertEqual(
|
||||
parsed,
|
||||
[['user', 'www-data'],
|
||||
[['server'], [
|
||||
['listen', '*:80 default_server ssl'],
|
||||
['server_name', '*.www.foo.com *.www.example.com'],
|
||||
['root', '/home/ubuntu/sites/foo/'],
|
||||
[['location', '/status'], [
|
||||
['check_status'],
|
||||
[['types'], [['image/jpeg', 'jpg']]],
|
||||
]],
|
||||
[['location', '~', 'case_sensitive\.php$'], [
|
||||
['hoge', 'hoge']
|
||||
]],
|
||||
[['location', '~*', 'case_insensitive\.php$'], []],
|
||||
[['location', '=', 'exact_match\.php$'], []],
|
||||
[['location', '^~', 'ignore_regex\.php$'], []],
|
||||
]]]
|
||||
[['http'],
|
||||
[[['server'], [
|
||||
['listen', '*:80 default_server ssl'],
|
||||
['server_name', '*.www.foo.com *.www.example.com'],
|
||||
['root', '/home/ubuntu/sites/foo/'],
|
||||
[['location', '/status'], [
|
||||
[['types'], [['image/jpeg', 'jpg']]],
|
||||
]],
|
||||
[['location', '~', 'case_sensitive\.php$'], [
|
||||
['index', 'index.php'],
|
||||
['root', '/var/root'],
|
||||
]],
|
||||
[['location', '~*', 'case_insensitive\.php$'], []],
|
||||
[['location', '=', 'exact_match\.php$'], []],
|
||||
[['location', '^~', 'ignore_regex\.php$'], []]
|
||||
]]]]]
|
||||
)
|
||||
|
||||
def test_dump_as_file(self):
|
||||
|
|
|
|||
|
|
@ -84,7 +84,9 @@ class NginxParserTest(util.NginxTest):
|
|||
|
||||
vhost1 = VirtualHost(parser.abs_path('nginx.conf'),
|
||||
[Addr('', '8080', False, False)],
|
||||
False, True, set(['localhost']), [])
|
||||
False, True, set(['localhost',
|
||||
'~^(www\.)?(example|bar)\.']),
|
||||
[])
|
||||
vhost2 = VirtualHost(parser.abs_path('nginx.conf'),
|
||||
[Addr('somename', '8080', False, False),
|
||||
Addr('', '8000', False, False)],
|
||||
|
|
@ -118,7 +120,8 @@ class NginxParserTest(util.NginxTest):
|
|||
def test_add_server_directives(self):
|
||||
parser = NginxParser(self.config_path, self.ssl_options)
|
||||
parser.add_server_directives(parser.abs_path('nginx.conf'),
|
||||
set(['localhost']),
|
||||
set(['localhost',
|
||||
'~^(www\.)?(example|bar)\.']),
|
||||
[['foo', 'bar'], ['ssl_certificate',
|
||||
'/etc/ssl/cert.pem']])
|
||||
r = re.compile('foo bar;\n\s+ssl_certificate /etc/ssl/cert.pem')
|
||||
|
|
|
|||
|
|
@ -1,23 +1,25 @@
|
|||
# a test nginx conf
|
||||
user www-data;
|
||||
|
||||
server {
|
||||
listen *:80 default_server ssl;
|
||||
server_name *.www.foo.com *.www.example.com;
|
||||
root /home/ubuntu/sites/foo/;
|
||||
http {
|
||||
server {
|
||||
listen *:80 default_server ssl;
|
||||
server_name *.www.foo.com *.www.example.com;
|
||||
root /home/ubuntu/sites/foo/;
|
||||
|
||||
location /status {
|
||||
check_status;
|
||||
types {
|
||||
image/jpeg jpg;
|
||||
location /status {
|
||||
types {
|
||||
image/jpeg jpg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
location ~ case_sensitive\.php$ {
|
||||
hoge hoge;
|
||||
}
|
||||
location ~* case_insensitive\.php$ {}
|
||||
location = exact_match\.php$ {}
|
||||
location ^~ ignore_regex\.php$ {}
|
||||
location ~ case_sensitive\.php$ {
|
||||
index index.php;
|
||||
root /var/root;
|
||||
}
|
||||
location ~* case_insensitive\.php$ {}
|
||||
location = exact_match\.php$ {}
|
||||
location ^~ ignore_regex\.php$ {}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
0
letsencrypt/client/plugins/nginx/tests/testdata/mime.types
vendored
Normal file
0
letsencrypt/client/plugins/nginx/tests/testdata/mime.types
vendored
Normal file
|
|
@ -18,6 +18,7 @@ include foo.conf;
|
|||
|
||||
http {
|
||||
include mime.types;
|
||||
include sites-enabled/*;
|
||||
default_type application/octet-stream;
|
||||
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
|
|
@ -30,13 +31,13 @@ http {
|
|||
tcp_nopush on;
|
||||
|
||||
keepalive_timeout 0;
|
||||
keepalive_timeout 65;
|
||||
|
||||
gzip on;
|
||||
|
||||
server {
|
||||
listen 8080;
|
||||
server_name localhost;
|
||||
server_name ~^(www\.)?(example|bar)\.;
|
||||
|
||||
charset koi8-r;
|
||||
|
||||
|
|
@ -68,7 +69,6 @@ http {
|
|||
fastcgi_pass 127.0.0.1:9000;
|
||||
fastcgi_index index.php;
|
||||
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
|
||||
include fastcgi_params;
|
||||
}
|
||||
|
||||
# deny access to .htaccess files, if Nginx's document root
|
||||
|
|
@ -115,7 +115,5 @@ http {
|
|||
# }
|
||||
#}
|
||||
|
||||
include conf.d/test.conf;
|
||||
include sites-enabled/*;
|
||||
|
||||
#include conf.d/test.conf;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ events {
|
|||
include foo.conf;
|
||||
http {
|
||||
include mime.types;
|
||||
include sites-enabled/*;
|
||||
default_type application/octet-stream;
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
|
|
@ -18,12 +19,12 @@ http {
|
|||
sendfile on;
|
||||
tcp_nopush on;
|
||||
keepalive_timeout 0;
|
||||
keepalive_timeout 65;
|
||||
gzip on;
|
||||
|
||||
server {
|
||||
listen 8080;
|
||||
server_name localhost;
|
||||
server_name ~^(www\.)?(example|bar)\.;
|
||||
charset koi8-r;
|
||||
access_log logs/host.access.log main;
|
||||
|
||||
|
|
@ -47,7 +48,6 @@ http {
|
|||
fastcgi_pass 127.0.0.1:9000;
|
||||
fastcgi_index index.php;
|
||||
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
|
||||
include fastcgi_params;
|
||||
}
|
||||
|
||||
location ~ /\.ht {
|
||||
|
|
@ -65,8 +65,6 @@ http {
|
|||
index index.html index.htm;
|
||||
}
|
||||
}
|
||||
include conf.d/test.conf;
|
||||
include sites-enabled/*;
|
||||
|
||||
server {
|
||||
listen 443 ssl;
|
||||
|
|
|
|||
Loading…
Reference in a new issue