Skip to content

Commit e0880ce

Browse files
committed
test: add commit signing
1 parent 56b7a20 commit e0880ce

File tree

102 files changed

+167
-32
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+167
-32
lines changed

test/conftest.py

+7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def emptyrepo(tmp_path):
5353
with utils.TemporaryRepository('emptyrepo.zip', tmp_path) as path:
5454
yield pygit2.Repository(path)
5555

56+
5657
@pytest.fixture
5758
def encodingrepo(tmp_path):
5859
with utils.TemporaryRepository('encoding.zip', tmp_path) as path:
@@ -81,3 +82,9 @@ def testrepo_path(tmp_path):
8182
def testrepopacked(tmp_path):
8283
with utils.TemporaryRepository('testrepopacked.zip', tmp_path) as path:
8384
yield pygit2.Repository(path)
85+
86+
87+
@pytest.fixture
88+
def gpgsigned(tmp_path):
89+
with utils.TemporaryRepository('gpgsigned.git', tmp_path) as path:
90+
yield pygit2.Repository(path)

test/data/gpgsigned.git/HEAD

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/master

test/data/gpgsigned.git/HEAD_TRACKER

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: HEAD

test/data/gpgsigned.git/config

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = true
4+
bare = false
5+
logallrefupdates = true
6+
[remote "test"]
7+
url = git://github.com/libgit2/libgit2
8+
fetch = +refs/heads/*:refs/remotes/test/*

test/data/gpgsigned.git/index

9.99 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0000000000000000000000000000000000000000 099fabac3a9ea935598528c27f866e34089c2eff Patrick Steinhardt <[email protected]> 1442484463 +0200 branch: Created from HEAD
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
x��Q� P�9�^@��B!1F��'��J?���#�7��K��JhM�VE�,��.3���������uVsH�-;��U���,�M���P�Iɉ&�Ĕ׍�ס�K�O.2µո$8��N��ݗ��r��!�l�CTk�l�Ugf�0��s�ÓG(
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x��Q
2+
�0D��)��6�ͦ "xO���-�Fb��Eo��0 �Ǥ�,ske�[�Pn8R,EpD?�g�}�^3� ��<��G�hYK���8ЖDA��)���;g�ݧ���j�p�4����-������r���;�s�GA4ۺ=���(�in7�I�K�FE
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x��� 1E�Ni@��k2 "X�$�YW0Yc����Ås���z����MD��0��8!�����s� X��g�d�::@X0�P�w�"F/����R��Uz��m�ZZ�����V}|�/�o5����I�!�1z��:v��Uim}�/�>
2+
�F-
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

test/data/gpgsigned.git/objects/6f/d5c7dd2ab27b48c493023f794be09861e9045f

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
x��A�!D��}�G��Mr�\�m[F��1��1gȢ�(�G�Rr3�Co"�v�^hq�<7��A�Y{��"�&$�D�S�g��([B!�ΡwƳY��g���l$%E�������ֲ�'\d�_w-�[�k�'����1h���Z�t ��B��&;��:��A���"�m�%��V
Binary file not shown.

test/data/gpgsigned.git/objects/76/3d71aadf09a7951596c9746c024e7eece7c7af

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
x��Aj!��?0����09�o}�H�6�}��jUPP��Z&Y��� Aԛ��p��Fd��pz�[f�Y��P�qLJ.,Z�`�Ů�.�`�v� �q$�5+9�O�t��>�/�DE/龡W��*e��V�df1>�覭����ě��ʙF����T��h�k.i�^0�?P�R,
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
x+)JMU044b040031Qrut�ueX�l��mmA�m�̣�J}G�;U�T���������WRQ�`6���Kǥ�^/�-*|��W��3P�y��`%�E���\&g��|�0���{Ӎ1X
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

test/data/gpgsigned.git/objects/9f/d738e8f7967c078dceed8190330fc8648ee56a

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
x��[
2+
�0E��*f��դ "�W0��-�F�t�݁��pS[�Y��x�^
3+
D�b CLhut��}�8X*4Z��sY���U��A���X3�R�M��) s6輢M��រ�&Jm��;}�����<��\@����ޏpĀ�v�?��jۺL��?H�
Binary file not shown.

test/data/gpgsigned.git/objects/a4/a7dce85cf63874e984719f4fdd239f5145052f

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x��;j1D��md�����ǎ|M��3`��V{ >���Q����vL0I?�!�4�Z=�!�צ8�F���!r�sQ�y�9�]$D�&�l6A�>jFW�ҵ IKNi��Z�%�S���
2+
�� ������U~̽��>'��� �w��[��� ���DGڡ���Q-�M���>d���O����}�\�8g_Ш�oYr

test/data/gpgsigned.git/objects/a6/5fedf39aefe402d3bb6e24df4d4f5fe4547750

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
x��Q
2+
!@��s�B�Q"��� �ٱr������{<x����ƪ
3+
�Hl�JSer!�ZPTe*�j�U��Eo^��2�(���XS�€ED��O<Y��j$2�s_�&} ��,}��[~p�7~<��:� �����Z���p�?�1_��C0
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

test/data/gpgsigned.git/objects/b2/5fa35b38051e4ae45d4222e795f9df2e43f1d1

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x�A
2+
�0�a�9��I� ���p'�1�Ѷ�v\x{c���V�p�vW�g��ǎ0x�[ ]"g�#{rD�Cot ���N �U $��?9-p+1�^��Qx���9O\�C�� �m�'D{m�V��(+���l��,�
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
x��Kj1D��)z�UB��-0��uV9����<#������+�W<J���&8�/s��e���ȕKJ����S
2+
�Rv��{��Q��r��Y�QN$H\E����=6�X5���K Fr)�(�dC��Ά�����j�s�}���9�c-�w8�o�\�r��I���:
3+
l}F�W$Ds�ǣ��ٚOW�e�]V8-Ý��"U
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
x��Q
2+
�0D��)�ʦ�I<�'�lR+�Fj��Eo��0<x�h���a ���]ș��XUl�PF)�z�4y�,\r 'S��-mI4
3+
�Xh��&��F�}n+\���Y�-p|鷜oU�z;-��a��lt{��?�I�,:�o�R��cHK
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x�N[
2+
B!��U��z�ꁈ~�A8W�� 3�K-?�v�|�f&�R.]�6�1K�-p��%� ��d���&���S�6�;5�u�3��� �9 ΄h|��`U�h8gAk_j������y��Qor����#����ZR;�*�1*�j@ w���g��ǵ�|e��O�
Binary file not shown.
Binary file not shown.

test/data/gpgsigned.git/packed-refs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# pack-refs with: peeled sorted
2+
41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9 refs/heads/packed
3+
5b5b025afb0b4c913b4c338a42934a3863bf3644 refs/heads/packed-test
4+
b25fa35b38051e4ae45d4222e795f9df2e43f1d1 refs/tags/packed-tag
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a4a7dce85cf63874e984719f4fdd239f5145052f
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
144344043ba4d4a405da03de3844aa829ae8be0e
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
f9ed4af42472941da45a3ce44458455ed227a6be
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6fd5c7dd2ab27b48c493023f794be09861e9045f
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6b377958d8c6a4906e8573b53672a1a23a4e8ce6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
099fabac3a9ea935598528c27f866e34089c2eff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a38d028f71eaa590febb7d716b1ca32350cf70da
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4a202b346bb0fb0db7eff3cffeb3c70babbd2045
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
763d71aadf09a7951596c9746c024e7eece7c7af
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
e90810b8df3e80c413d903f631643c716887138d
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
099fabac3a9ea935598528c27f866e34089c2eff

test/data/gpgsigned.git/refs/symref

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/master
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7b4384978d2493e851f9cca7858815fac9b10980
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
b25fa35b38051e4ae45d4222e795f9df2e43f1d1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
b25fa35b38051e4ae45d4222e795f9df2e43f1d1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1385f264afb75a56a5bec74243be9b367ba4ca08
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
b25fa35b38051e4ae45d4222e795f9df2e43f1d1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/testrepo-worktree
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../..
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../testrepo-worktree/.git
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
099fabac3a9ea935598528c27f866e34089c2eff 099fabac3a9ea935598528c27f866e34089c2eff Patrick Steinhardt <[email protected]> 1442484463 +0200 checkout: moving from 099fabac3a9ea935598528c27f866e34089c2eff to testrepo-worktree

test/data/gpgsigned.zip

-16.4 KB
Binary file not shown.

test/test_commit_gpg.py

+98-32
Original file line numberDiff line numberDiff line change
@@ -22,49 +22,115 @@
2222
# along with this program; see the file COPYING. If not, write to
2323
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
2424
# Boston, MA 02110-1301, USA.
25+
from pygit2 import GIT_OBJ_COMMIT, Oid, Signature
2526

26-
import pygit2
27-
import pytest
27+
content = """\
28+
tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904
29+
parent 8496071c1b46c854b31185ea97743be6a8774479
30+
author Ben Burkert <[email protected]> 1358451456 -0800
31+
committer Ben Burkert <[email protected]> 1358451456 -0800
2832
29-
from . import utils
33+
a simple commit which works"""
3034

35+
gpgsig = """\
36+
-----BEGIN PGP SIGNATURE-----
37+
Version: GnuPG v1.4.12 (Darwin)
3138
32-
@pytest.fixture
33-
def repo(tmp_path):
34-
with utils.TemporaryRepository('gpgsigned.zip', tmp_path) as path:
35-
yield pygit2.Repository(path)
39+
iQIcBAABAgAGBQJQ+FMIAAoJEH+LfPdZDSs1e3EQAJMjhqjWF+WkGLHju7pTw2al
40+
o6IoMAhv0Z/LHlWhzBd9e7JeCnanRt12bAU7yvYp9+Z+z+dbwqLwDoFp8LVuigl8
41+
JGLcnwiUW3rSvhjdCp9irdb4+bhKUnKUzSdsR2CK4/hC0N2i/HOvMYX+BRsvqweq
42+
AsAkA6dAWh+gAfedrBUkCTGhlNYoetjdakWqlGL1TiKAefEZrtA1TpPkGn92vbLq
43+
SphFRUY9hVn1ZBWrT3hEpvAIcZag3rTOiRVT1X1flj8B2vGCEr3RrcwOIZikpdaW
44+
who/X3xh/DGbI2RbuxmmJpxxP/8dsVchRJJzBwG+yhwU/iN3MlV2c5D69tls/Dok
45+
6VbyU4lm/ae0y3yR83D9dUlkycOnmmlBAHKIZ9qUts9X7mWJf0+yy2QxJVpjaTGG
46+
cmnQKKPeNIhGJk2ENnnnzjEve7L7YJQF6itbx5VCOcsGh3Ocb3YR7DMdWjt7f8pu
47+
c6j+q1rP7EpE2afUN/geSlp5i3x8aXZPDj67jImbVCE/Q1X9voCtyzGJH7MXR0N9
48+
ZpRF8yzveRfMH8bwAJjSOGAFF5XkcR/RNY95o+J+QcgBLdX48h+ZdNmUf6jqlu3J
49+
7KmTXXQcOVpN6dD3CmRFsbjq+x6RHwa8u1iGn+oIkX908r97ckfB/kHKH7ZdXIJc
50+
cpxtDQQMGYFpXK/71stq
51+
=ozeK
52+
-----END PGP SIGNATURE-----"""
3653

54+
gpgsig_content = """\
55+
tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904
56+
parent 8496071c1b46c854b31185ea97743be6a8774479
57+
author Ben Burkert <[email protected]> 1358451456 -0800
58+
committer Ben Burkert <[email protected]> 1358451456 -0800
59+
gpgsig -----BEGIN PGP SIGNATURE-----
60+
Version: GnuPG v1.4.12 (Darwin)
61+
62+
iQIcBAABAgAGBQJQ+FMIAAoJEH+LfPdZDSs1e3EQAJMjhqjWF+WkGLHju7pTw2al
63+
o6IoMAhv0Z/LHlWhzBd9e7JeCnanRt12bAU7yvYp9+Z+z+dbwqLwDoFp8LVuigl8
64+
JGLcnwiUW3rSvhjdCp9irdb4+bhKUnKUzSdsR2CK4/hC0N2i/HOvMYX+BRsvqweq
65+
AsAkA6dAWh+gAfedrBUkCTGhlNYoetjdakWqlGL1TiKAefEZrtA1TpPkGn92vbLq
66+
SphFRUY9hVn1ZBWrT3hEpvAIcZag3rTOiRVT1X1flj8B2vGCEr3RrcwOIZikpdaW
67+
who/X3xh/DGbI2RbuxmmJpxxP/8dsVchRJJzBwG+yhwU/iN3MlV2c5D69tls/Dok
68+
6VbyU4lm/ae0y3yR83D9dUlkycOnmmlBAHKIZ9qUts9X7mWJf0+yy2QxJVpjaTGG
69+
cmnQKKPeNIhGJk2ENnnnzjEve7L7YJQF6itbx5VCOcsGh3Ocb3YR7DMdWjt7f8pu
70+
c6j+q1rP7EpE2afUN/geSlp5i3x8aXZPDj67jImbVCE/Q1X9voCtyzGJH7MXR0N9
71+
ZpRF8yzveRfMH8bwAJjSOGAFF5XkcR/RNY95o+J+QcgBLdX48h+ZdNmUf6jqlu3J
72+
7KmTXXQcOVpN6dD3CmRFsbjq+x6RHwa8u1iGn+oIkX908r97ckfB/kHKH7ZdXIJc
73+
cpxtDQQMGYFpXK/71stq
74+
=ozeK
75+
-----END PGP SIGNATURE-----
3776
38-
def test_get_gpg_signature_when_signed(repo):
39-
signed_hash = 'a00b212d5455ad8c4c1779f778c7d2a81bb5da23'
40-
expected_signature = (
41-
'-----BEGIN PGP SIGNATURE-----\n\n'
42-
'iQFGBAABCgAwFiEEQZu9JtePgJbDk7VC0+mlK74z13oFAlpzXykSHG1hcmtAbWFy\n'
43-
'a2FkYW1zLm1lAAoJENPppSu+M9d6FRoIAJXeQRRT1V47nnHITiel6426loYkeij7\n'
44-
'66doGNIyll95H92SwH4LAjPyEEByIG1VsA6NztzUoNgnEvAXI0iAz3LyI7N16M4b\n'
45-
'dPDkC72pp8tu280H5Qt5b2V5hmlKKSgtOS5iNhdU/FbWVS8MlHsqzQTZfoTdi6ch\n'
46-
'KWUsjzudVd3F/H/AU+1Jsxt8Iz/oK4T/puUQLnJZKjKlljGP994FA3JIpnZpZmbG\n'
47-
'FybYJEDXnng7uhx3Fz/Mo3KBJoQfAExTtaToY0n0hSjOe6GN9rEsRSMK3mWdysf2\n'
48-
'wOdtYMMcT16hG5tAwnD/myZ4rIIpyZJ/9mjymdUsj6UKf7D+vJuqfsI=\n=IyYy\n'
49-
'-----END PGP SIGNATURE-----'
50-
).encode('ascii')
77+
a simple commit which works"""
78+
# NOTE: ^^^ mind the gap (space must exist after GnuPG header) ^^^
5179

52-
expected_payload = (
53-
'tree c36c20831e43e5984c672a714661870b67ab1d95\nauthor Mark Adams '
54-
'<[email protected]> 1517510299 -0600\ncommitter Mark Adams <ma'
55-
'[email protected]> 1517510441 -0600\n\nMaking a GPG signed commi'
56-
't\n'
57-
).encode('ascii')
5880

59-
commit = repo.get(signed_hash)
60-
signature, payload = commit.gpg_signature
81+
def test_commit_signing(gpgsigned):
82+
repo = gpgsigned
83+
message = "a simple commit which works"
84+
author = Signature(
85+
name="Ben Burkert",
86+
87+
time=1358451456,
88+
offset=-480,
89+
)
90+
committer = Signature(
91+
name="Ben Burkert",
92+
93+
time=1358451456,
94+
offset=-480,
95+
)
96+
tree = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
97+
parents = ["8496071c1b46c854b31185ea97743be6a8774479"]
98+
99+
# create commit string
100+
commit = repo.create_commit_string(
101+
author, committer, message, tree, parents
102+
)
103+
assert commit == content
104+
105+
# create signed commit
106+
signed_oid = repo.create_commit_with_signature(content, gpgsig)
107+
signed_commit = repo.get(signed_oid)
108+
109+
# verify signed commit
110+
signature, payload = signed_commit.gpg_signature
111+
assert gpgsig == signature.decode("utf-8")
112+
assert content == payload.decode("utf-8")
113+
assert signed_commit.read_raw().decode("utf-8") == gpgsig_content
114+
115+
# perform sanity checks
116+
assert GIT_OBJ_COMMIT == signed_commit.type
117+
assert "6569fdf71dbd99081891154641869c537784a3ba" == signed_commit.hex
118+
assert signed_commit.message_encoding is None
119+
assert message == signed_commit.message
120+
assert 1358451456 == signed_commit.commit_time
121+
assert committer == signed_commit.committer
122+
assert author == signed_commit.author
123+
assert tree == signed_commit.tree.hex
124+
assert Oid(hex=tree) == signed_commit.tree_id
125+
assert 1 == len(signed_commit.parents)
126+
assert parents[0] == signed_commit.parents[0].hex
127+
assert Oid(hex=parents[0]) == signed_commit.parent_ids[0]
61128

62-
assert signature == expected_signature
63-
assert payload == expected_payload
64129

130+
def test_get_gpg_signature_when_unsigned(gpgsigned):
131+
unsigned_hash = "5b5b025afb0b4c913b4c338a42934a3863bf3644"
65132

66-
def test_get_gpg_signature_when_unsigned(repo):
67-
unsigned_hash = 'a84938d1d885e80dae24b86b06621cec47ff6edd'
133+
repo = gpgsigned
68134
commit = repo.get(unsigned_hash)
69135
signature, payload = commit.gpg_signature
70136

0 commit comments

Comments
 (0)