Skip to content

Commit

Permalink
Start adding tests for nginx configurator
Browse files Browse the repository at this point in the history
  • Loading branch information
yan committed Apr 18, 2015
1 parent d2588de commit 154db5a
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 213 deletions.
12 changes: 6 additions & 6 deletions letsencrypt/client/plugins/nginx/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def prepare(self):

# Set Version
if self.version is None:
self.version = self._get_version()
self.version = self.get_version()

# Get all of the available vhosts
self.vhosts = self.parser.get_vhosts()
Expand Down Expand Up @@ -214,7 +214,7 @@ def _get_ranked_matches(self, target_name):
matches.append({'vhost': vhost,
'name': name,
'rank': 6 if vhost.ssl else 7})
return sorted(matches, key=lambda x: x['rank'], reverse=True)
return sorted(matches, key=lambda x: x['rank'])

def get_all_names(self):
"""Returns all names found in the Nginx Configuration.
Expand Down Expand Up @@ -303,7 +303,7 @@ def enhance(self, domain, enhancement, options=None):
try:
return self._enhance_func[enhancement](
self.choose_vhost(domain), options)
except ValueError:
except (KeyError, ValueError):
raise errors.LetsEncryptConfiguratorError(
"Unsupported enhancement: {}".format(enhancement))
except errors.LetsEncryptConfiguratorError:
Expand Down Expand Up @@ -360,7 +360,7 @@ def _verify_setup(self):
le_util.make_or_verify_dir(self.config.work_dir, 0o755, uid)
le_util.make_or_verify_dir(self.config.backup_dir, 0o755, uid)

def _get_version(self):
def get_version(self):
"""Return version of Nginx Server.
Version is returned as tuple. (ie. 2.4.7 = (2, 4, 7))
Expand Down Expand Up @@ -440,11 +440,11 @@ def save(self, title=None, temporary=False):
self.reverter.add_to_checkpoint(save_files,
self.save_notes)

# Don't override original files for now.
self.parser.filedump('le')
self.parser.filedump(ext='')
if title and not temporary:
self.reverter.finalize_checkpoint(title)

# Refresh the vhosts
self.vhosts = self.parser.get_vhosts()

return True
Expand Down
5 changes: 3 additions & 2 deletions letsencrypt/client/plugins/nginx/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,19 @@ def _get_servernames(self, names):
names = re.sub(whitespace_re, ' ', names)
return names.split(' ')

def _parse_files(self, filepath):
def _parse_files(self, filepath, override=False):
"""Parse files from a glob
:param str filepath: Nginx config file path
:param bool override: Whether to parse a file that has been parsed
:returns: list of parsed tree structures
:rtype: list
"""
files = glob.glob(filepath)
trees = []
for f in files:
if f in self.parsed:
if f in self.parsed and not override:
continue
try:
with open(f) as fo:
Expand Down
Loading

0 comments on commit 154db5a

Please sign in to comment.