| |
@@ -12,6 +12,7 @@
|
| |
from copr_backend.sign import (
|
| |
get_pubkey, _sign_one, sign_rpms_in_dir, create_user_keys,
|
| |
gpg_hashtype_for_chroot,
|
| |
+ call_sign_bin,
|
| |
)
|
| |
|
| |
STDOUT = "stdout"
|
| |
@@ -19,6 +20,7 @@
|
| |
|
| |
|
| |
class TestSign(object):
|
| |
+ # pylint: disable=too-many-public-methods
|
| |
|
| |
def setup_method(self, method):
|
| |
self.username = "foo"
|
| |
@@ -70,8 +72,9 @@
|
| |
get_pubkey(self.username, self.projectname, MagicMock())
|
| |
|
| |
|
| |
+ @mock.patch("copr_backend.sign.time.sleep")
|
| |
@mock.patch("copr_backend.sign.Popen")
|
| |
- def test_get_pubkey_unknown_key(self, mc_popen):
|
| |
+ def test_get_pubkey_unknown_key(self, mc_popen, _sleep):
|
| |
mc_handle = MagicMock()
|
| |
mc_handle.communicate.return_value = (STDOUT, "unknown key: foobar")
|
| |
mc_handle.returncode = 1
|
| |
@@ -82,8 +85,9 @@
|
| |
|
| |
assert "There are no gpg keys for user foo in keyring" in str(err)
|
| |
|
| |
+ @mock.patch("copr_backend.sign.time.sleep")
|
| |
@mock.patch("copr_backend.sign.Popen")
|
| |
- def test_get_pubkey_unknown_error(self, mc_popen):
|
| |
+ def test_get_pubkey_unknown_error(self, mc_popen, _sleep):
|
| |
mc_handle = MagicMock()
|
| |
mc_handle.communicate.return_value = (STDOUT, STDERR)
|
| |
mc_handle.returncode = 1
|
| |
@@ -134,8 +138,9 @@
|
| |
with pytest.raises(CoprSignError):
|
| |
_sign_one(fake_path, self.usermail, "sha256", MagicMock())
|
| |
|
| |
+ @mock.patch("copr_backend.sign.time.sleep")
|
| |
@mock.patch("copr_backend.sign.Popen")
|
| |
- def test_sign_one_cmd_erro(self, mc_popen):
|
| |
+ def test_sign_one_cmd_erro(self, mc_popen, _sleep):
|
| |
mc_handle = MagicMock()
|
| |
mc_handle.communicate.return_value = (STDOUT, STDERR)
|
| |
mc_handle.returncode = 1
|
| |
@@ -145,6 +150,21 @@
|
| |
with pytest.raises(CoprSignError):
|
| |
_sign_one(fake_path, self.usermail, "sha256", MagicMock())
|
| |
|
| |
+ @staticmethod
|
| |
+ @mock.patch("copr_backend.sign.time.sleep")
|
| |
+ @mock.patch("copr_backend.sign.Popen")
|
| |
+ def test_call_sign_bin_repeatedly(mc_popen, _sleep):
|
| |
+ """
|
| |
+ Test that we attempt to run /bin/sign multiple times if it returns
|
| |
+ non-zero exit status
|
| |
+ """
|
| |
+ mc_handle = MagicMock()
|
| |
+ mc_handle.communicate.return_value = (STDOUT, STDERR)
|
| |
+ mc_handle.returncode = 1
|
| |
+ mc_popen.return_value = mc_handle
|
| |
+ call_sign_bin(cmd=[], log=MagicMock())
|
| |
+ assert mc_popen.call_count == 3
|
| |
+
|
| |
@mock.patch("copr_backend.sign.SafeRequest.send")
|
| |
def test_create_user_keys(self, mc_request):
|
| |
mc_request.return_value.status_code = 200
|
| |
@@ -153,7 +173,7 @@
|
| |
assert mc_request.called
|
| |
expected_call = mock.call(
|
| |
url="http://example.com/gen_key",
|
| |
- data='{"name_real": "foo_bar", "name_email": "foo_bar@copr.fedorahosted.org"}',
|
| |
+ data={"name_real": "foo_bar", "name_email": "foo#bar@copr.fedorahosted.org"},
|
| |
method="post"
|
| |
)
|
| |
assert mc_request.call_args == expected_call
|
| |
@@ -168,7 +188,7 @@
|
| |
|
| |
|
| |
@mock.patch("copr_backend.sign.SafeRequest.send")
|
| |
- def test_create_user_keys(self, mc_request):
|
| |
+ def test_create_user_keys_err(self, mc_request):
|
| |
for code in [400, 401, 404, 500, 599]:
|
| |
mc_request.return_value.status_code = code
|
| |
mc_request.return_value.content = "error: {}".format(code)
|
| |
Also, I am fixing the signing in docker-compose that currently doesn't work. I don't like the fix very much, so if you understand why it doesn't work, please let me know