mirror of
https://github.com/laurivosandi/certidude
synced 2026-01-12 17:06:59 +00:00
tests: Fixes and better code coverage
This commit is contained in:
@@ -11,30 +11,28 @@ env = Environment(loader=FileSystemLoader(config.SCRIPT_DIR), trim_blocks=True)
|
||||
class ScriptResource():
|
||||
@whitelist_subject
|
||||
def on_get(self, req, resp, cn):
|
||||
try:
|
||||
path, buf, cert, attribs = authority.get_attributes(cn)
|
||||
except IOError:
|
||||
raise falcon.HTTPNotFound()
|
||||
else:
|
||||
script = config.SCRIPT_DEFAULT
|
||||
tags = []
|
||||
try:
|
||||
for tag in attribs.get("user").get("xdg").get("tags").split(","):
|
||||
if "=" in tag:
|
||||
k, v = tag.split("=", 1)
|
||||
else:
|
||||
k, v = "other", tag
|
||||
if k == "script":
|
||||
script = v
|
||||
tags.append(dict(id=tag, key=k, value=v))
|
||||
except AttributeError: # No tags
|
||||
pass
|
||||
path, buf, cert, attribs = authority.get_attributes(cn)
|
||||
# TODO: are keys unique?
|
||||
named_tags = {}
|
||||
other_tags = []
|
||||
|
||||
resp.set_header("Content-Type", "text/x-shellscript")
|
||||
resp.body = env.get_template(script).render(
|
||||
authority_name=const.FQDN,
|
||||
common_name=cn,
|
||||
tags=tags,
|
||||
attributes=attribs.get("user").get("machine"))
|
||||
logger.info("Served script %s for %s at %s" % (script, cn, req.context["remote_addr"]))
|
||||
try:
|
||||
for tag in attribs.get("user").get("xdg").get("tags").split(","):
|
||||
if "=" in tag:
|
||||
k, v = tag.split("=", 1)
|
||||
named_tags[k] = v
|
||||
else:
|
||||
other_tags.append(v)
|
||||
except AttributeError: # No tags
|
||||
pass
|
||||
|
||||
script = named_tags.get("script", config.SCRIPT_DEFAULT)
|
||||
resp.set_header("Content-Type", "text/x-shellscript")
|
||||
resp.body = env.get_template(script).render(
|
||||
authority_name=const.FQDN,
|
||||
common_name=cn,
|
||||
other_tags=other_tags,
|
||||
named_tags=named_tags,
|
||||
attributes=attribs.get("user").get("machine"))
|
||||
logger.info("Served script %s for %s at %s" % (script, cn, req.context["remote_addr"]))
|
||||
# TODO: Assert time is within reasonable range
|
||||
|
||||
Reference in New Issue
Block a user