|
| 1 | +# Copyright 2010-2020 The pygit2 contributors |
| 2 | +# |
| 3 | +# This file is free software; you can redistribute it and/or modify |
| 4 | +# it under the terms of the GNU General Public License, version 2, |
| 5 | +# as published by the Free Software Foundation. |
| 6 | +# |
| 7 | +# In addition to the permissions in the GNU General Public License, |
| 8 | +# the authors give you unlimited permission to link the compiled |
| 9 | +# version of this file into combinations with other programs, |
| 10 | +# and to distribute those combinations without any restriction |
| 11 | +# coming from the use of this file. (The General Public License |
| 12 | +# restrictions do apply in other respects; for example, they cover |
| 13 | +# modification of the file, and distribution when not linked into |
| 14 | +# a combined executable.) |
| 15 | +# |
| 16 | +# This file is distributed in the hope that it will be useful, but |
| 17 | +# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | +# General Public License for more details. |
| 20 | +# |
| 21 | +# You should have received a copy of the GNU General Public License |
| 22 | +# along with this program; see the file COPYING. If not, write to |
| 23 | +# the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
| 24 | +# Boston, MA 02110-1301, USA. |
| 25 | + |
| 26 | +import pygit2 |
| 27 | +import pytest |
| 28 | + |
| 29 | +from . import utils |
| 30 | + |
| 31 | + |
| 32 | +@pytest.fixture(scope='module') |
| 33 | +def repo(): |
| 34 | + repo_spec = 'tar', 'gpgsigned' |
| 35 | + with utils.TemporaryRepository(repo_spec) as path: |
| 36 | + yield pygit2.Repository(path) |
| 37 | + |
| 38 | + |
| 39 | +def test_get_gpg_signature_when_signed(repo): |
| 40 | + signed_hash = 'a00b212d5455ad8c4c1779f778c7d2a81bb5da23' |
| 41 | + expected_signature = ( |
| 42 | + '-----BEGIN PGP SIGNATURE-----\n\n' |
| 43 | + 'iQFGBAABCgAwFiEEQZu9JtePgJbDk7VC0+mlK74z13oFAlpzXykSHG1hcmtAbWFy\n' |
| 44 | + 'a2FkYW1zLm1lAAoJENPppSu+M9d6FRoIAJXeQRRT1V47nnHITiel6426loYkeij7\n' |
| 45 | + '66doGNIyll95H92SwH4LAjPyEEByIG1VsA6NztzUoNgnEvAXI0iAz3LyI7N16M4b\n' |
| 46 | + 'dPDkC72pp8tu280H5Qt5b2V5hmlKKSgtOS5iNhdU/FbWVS8MlHsqzQTZfoTdi6ch\n' |
| 47 | + 'KWUsjzudVd3F/H/AU+1Jsxt8Iz/oK4T/puUQLnJZKjKlljGP994FA3JIpnZpZmbG\n' |
| 48 | + 'FybYJEDXnng7uhx3Fz/Mo3KBJoQfAExTtaToY0n0hSjOe6GN9rEsRSMK3mWdysf2\n' |
| 49 | + 'wOdtYMMcT16hG5tAwnD/myZ4rIIpyZJ/9mjymdUsj6UKf7D+vJuqfsI=\n=IyYy\n' |
| 50 | + '-----END PGP SIGNATURE-----' |
| 51 | + ).encode('ascii') |
| 52 | + |
| 53 | + expected_payload = ( |
| 54 | + 'tree c36c20831e43e5984c672a714661870b67ab1d95\nauthor Mark Adams ' |
| 55 | + '<madams@atlassian.com> 1517510299 -0600\ncommitter Mark Adams <ma' |
| 56 | + 'dams@atlassian.com> 1517510441 -0600\n\nMaking a GPG signed commi' |
| 57 | + 't\n' |
| 58 | + ).encode('ascii') |
| 59 | + |
| 60 | + commit = repo.get(signed_hash) |
| 61 | + signature, payload = commit.gpg_signature |
| 62 | + |
| 63 | + assert signature == expected_signature |
| 64 | + assert payload == expected_payload |
| 65 | + |
| 66 | + |
| 67 | +def test_get_gpg_signature_when_unsigned(repo): |
| 68 | + unsigned_hash = 'a84938d1d885e80dae24b86b06621cec47ff6edd' |
| 69 | + commit = repo.get(unsigned_hash) |
| 70 | + signature, payload = commit.gpg_signature |
| 71 | + |
| 72 | + assert signature is None |
| 73 | + assert payload is None |
0 commit comments