def test_has_valid_gpg_signature_call_Release(self): """ Test _has_valid_gpg_signature call with a detached GPG signature (Release + Release.gpg). :return: """ repo = DpkgRepo("http://dummy/url/Release") response = FakeRequests().conf( content=b"dummy content", url="http://dummy/url/Release", ) mock_popen = MagicMock() mock_popen().returncode = 0 with patch("spacewalk.common.repo.subprocess.Popen", mock_popen): assert repo._has_valid_gpg_signature(response) mock_popen.assert_called_once gpg_args = mock_popen.call_args[0][0] assert gpg_args[0] == "gpg" assert gpg_args[1] == "--verify" assert gpg_args[2] == "--homedir" assert gpg_args[3] == "/var/lib/spacewalk/gpgdir" assert gpg_args[4].beginswith("/tmp/") assert gpg_args[5].beginswith("/tmp/")
def test_has_valid_gpg_signature_returns_false_if_gpg_verify_fails(self): """ Test _has_valid_gpg_signature returns False if gpg --verify returns non-zero. :return: """ repo = DpkgRepo("http://dummy/url/InRelease") response = FakeRequests().conf( content=b"dummy content", url="http://dummy/url/InRelease", ) mock_popen = MagicMock() mock_popen().returncode = 1 with patch("spacewalk.common.repo.subprocess.Popen", mock_popen): assert not repo._has_valid_gpg_signature(response)
def test_has_valid_gpg_signature_call_InRelease(self): """ Test _has_valid_gpg_signature call with an embedded GPG signature (InRelease). :return: """ repo = DpkgRepo("http://dummy/url/InRelease") response = FakeRequests().conf( content=b"dummy content", url="http://dummy/url/InRelease", ) mock_popen = MagicMock() mock_communicate = MagicMock() mock_popen().communicate = mock_communicate mock_popen().returncode = 0 with patch("spacewalk.common.repo.subprocess.Popen", mock_popen): assert repo._has_valid_gpg_signature(response) mock_communicate.assert_called_once_with(b"dummy content")