Skip to content

Commit

Permalink
Merge pull request certbot#806 from letsencrypt/apache_include_quotes
Browse files Browse the repository at this point in the history
Apache include quotes
  • Loading branch information
bmw committed Sep 22, 2015
2 parents 8780798 + d4d71a7 commit 5ee88f0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions letsencrypt-apache/letsencrypt_apache/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ def find_dir(self, directive, arg=None, start=None, exclude=True):
Directives should be in the form of a case insensitive regex currently
.. todo:: arg should probably be a list
.. todo:: arg search currently only supports direct matching. It does
not handle the case of variables or quoted arguments. This should
be adapted to use a generic search for the directive and then do a
case-insensitive self.get_arg filter
Note: Augeas is inherently case sensitive while Apache is case
insensitive. Augeas 1.0 allows case insensitive regexes like
Expand Down Expand Up @@ -315,6 +319,14 @@ def get_arg(self, match):
"""
value = self.aug.get(match)

# No need to strip quotes for variables, as apache2ctl already does this
# but we do need to strip quotes for all normal arguments.

# Note: normal argument may be a quoted variable
# e.g. strip now, not later
value = value.strip("'\"")

variables = ApacheParser.arg_var_interpreter.findall(value)

for var in variables:
Expand Down Expand Up @@ -390,6 +402,9 @@ def _get_include_path(self, arg):
# logger.error("Error: Invalid regexp characters in %s", arg)
# return []

# Remove beginning and ending quotes
arg = arg.strip("'\"")

# Standardize the include argument based on server root
if not arg.startswith("/"):
# Normpath will condense ../
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def setup_variables(self):
"COMPLEX": "",
"tls_port": "1234",
"fnmatch_filename": "test_fnmatch.conf",
"tls_port_str": "1234"
}
)

Expand All @@ -49,6 +50,12 @@ def test_basic_variable_parsing(self):
self.assertEqual(len(matches), 1)
self.assertEqual(self.parser.get_arg(matches[0]), "1234")

def test_basic_variable_parsing_quotes(self):
matches = self.parser.find_dir("TestVariablePortStr")

self.assertEqual(len(matches), 1)
self.assertEqual(self.parser.get_arg(matches[0]), "1234")

def test_invalid_variable_parsing(self):
del self.parser.variables["tls_port"]

Expand Down Expand Up @@ -89,6 +96,7 @@ def verify_fnmatch(self, arg, hit=True):
else:
self.assertFalse(self.parser.find_dir("FNMATCH_DIRECTIVE"))

# NOTE: Only run one test per function otherwise you will have inf recursion
def test_include(self):
self.verify_fnmatch("test_fnmatch.?onf")

Expand All @@ -101,6 +109,12 @@ def test_include_fullpath(self):
def test_include_fullpath_trailing_slash(self):
self.verify_fnmatch(self.config_path + "//")

def test_include_single_quotes(self):
self.verify_fnmatch("'" + self.config_path + "'")

def test_include_double_quotes(self):
self.verify_fnmatch('"' + self.config_path + '"')

def test_include_variable(self):
self.verify_fnmatch("../complex_parsing/${fnmatch_filename}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ IncludeOptional sites-enabled/*.conf
Define COMPLEX

Define tls_port 1234
Define tls_port_str "1234"

Define fnmatch_filename test_fnmatch.conf


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
TestVariablePort ${tls_port}
TestVariablePortStr "${tls_port_str}"

LoadModule status_module modules/mod_status.so

Expand Down

0 comments on commit 5ee88f0

Please sign in to comment.