Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : master
---------------------------------------------------------------
commit cccc71d52ba190e1247429a02ad613db4fb108db
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Fri Nov 13 17:24:55 2015 +0100
[backend] handle_generate_gpg_key skips key creation when signing is disabled
---------------------------------------------------------------
backend/backend/actions.py | 11 +++++++++--
backend/tests/test_action.py | 15 +++++++++++++--
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/backend/backend/actions.py b/backend/backend/actions.py
index ac2ad78..c3cc4cc 100644
--- a/backend/backend/actions.py
+++ b/backend/backend/actions.py
@@ -215,12 +215,17 @@ class Action(object):
os.remove(log_path)
def handle_generate_gpg_key(self, result):
- self.log.debug("Action generate gpg key")
-
ext_data = json.loads(self.data["data"])
+ self.log.info("Action generate gpg key: {}".format(ext_data))
+
username = ext_data["username"]
projectname = ext_data["projectname"]
+ if self.opts.do_sign is False:
+ # skip key creation, most probably sign component is unused
+ result.result = ActionResult.SUCCESS
+ return
+
try:
create_user_keys(username, projectname, self.opts)
result.result = ActionResult.SUCCESS
@@ -257,6 +262,8 @@ class Action(object):
elif action_type == ActionType.GEN_GPG_KEY:
self.handle_generate_gpg_key(result)
+ self.log.info("Action result: {}".format(result))
+
if "result" in result:
if result.result == ActionResult.SUCCESS and \
not getattr(result, "job_ended_on", None):
diff --git a/backend/tests/test_action.py b/backend/tests/test_action.py
index 2b637e5..e06ed8d 100644
--- a/backend/tests/test_action.py
+++ b/backend/tests/test_action.py
@@ -50,7 +50,9 @@ class TestAction(object):
destdir=None,
frontend_base_url=None,
- results_baseurl=RESULTS_ROOT_URL
+ results_baseurl=RESULTS_ROOT_URL,
+
+ do_sign=True,
)
def teardown_method(self, method):
@@ -644,7 +646,6 @@ class TestAction(object):
test_action.run()
result_dict = mc_front_cb.update.call_args[0][0]["actions"][0]
-
assert result_dict["id"] == 11
assert result_dict["result"] == ActionResult.SUCCESS
@@ -660,3 +661,13 @@ class TestAction(object):
assert result_dict["id"] == 11
assert result_dict["result"] == ActionResult.FAILURE
+ # test, that key creation is skipped when signing is disabled
+ self.opts.do_sign = False
+ mc_front_cb.reset_mock()
+ mc_cuk.reset_mock()
+ test_action.run()
+
+ assert not mc_cuk.called
+ result_dict = mc_front_cb.update.call_args[0][0]["actions"][0]
+ assert result_dict["id"] == 11
+ assert result_dict["result"] == ActionResult.SUCCESS