1
- # Copyright 2010-2021 The pygit2 contributors
1
+ # Copyright 2010-2022 The pygit2 contributors
2
2
#
3
3
# This file is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License, version 2,
31
31
author Ben Burkert <[email protected] > 1358451456 -0800
32
32
committer Ben Burkert <[email protected] > 1358451456 -0800
33
33
34
- a simple commit which works"""
34
+ a simple commit which works\
35
+ """
35
36
36
37
gpgsig = """\
37
38
-----BEGIN PGP SIGNATURE-----
50
51
7KmTXXQcOVpN6dD3CmRFsbjq+x6RHwa8u1iGn+oIkX908r97ckfB/kHKH7ZdXIJc
51
52
cpxtDQQMGYFpXK/71stq
52
53
=ozeK
53
- -----END PGP SIGNATURE-----"""
54
+ -----END PGP SIGNATURE-----\
55
+ """
54
56
55
57
gpgsig_content = """\
56
58
tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904
75
77
=ozeK
76
78
-----END PGP SIGNATURE-----
77
79
78
- a simple commit which works"""
80
+ a simple commit which works\
81
+ """
79
82
# NOTE: ^^^ mind the gap (space must exist after GnuPG header) ^^^
83
+ # XXX: seems macos wants the space while linux does not
80
84
81
85
82
86
def test_commit_signing (gpgsigned ):
@@ -103,36 +107,36 @@ def test_commit_signing(gpgsigned):
103
107
)
104
108
assert commit == content
105
109
106
- # create signed commit
107
- signed_oid = repo .create_commit_with_signature (content , gpgsig )
108
- signed_commit = repo .get (signed_oid )
110
+ # create/retrieve signed commit
111
+ oid = repo .create_commit_with_signature (content , gpgsig )
112
+ commit = repo .get (oid )
113
+ signature , payload = commit .gpg_signature
109
114
110
- # verify signed commit
111
- signature , payload = signed_commit .gpg_signature
112
- assert gpgsig == signature .decode ("utf-8" )
115
+ # validate signed commit
113
116
assert content == payload .decode ("utf-8" )
114
- assert signed_commit .read_raw ().decode ("utf-8" ) == gpgsig_content
117
+ assert gpgsig == signature .decode ("utf-8" )
118
+ assert gpgsig_content == commit .read_raw ().decode ("utf-8" )
115
119
116
120
# perform sanity checks
117
- assert GIT_OBJ_COMMIT == signed_commit .type
118
- assert "6569fdf71dbd99081891154641869c537784a3ba" == signed_commit .hex
119
- assert signed_commit .message_encoding is None
120
- assert message == signed_commit .message
121
- assert 1358451456 == signed_commit .commit_time
122
- assert committer == signed_commit .committer
123
- assert author == signed_commit .author
124
- assert tree == signed_commit .tree .hex
125
- assert Oid (hex = tree ) == signed_commit .tree_id
126
- assert 1 == len (signed_commit .parents )
127
- assert parents [0 ] == signed_commit .parents [0 ].hex
128
- assert Oid (hex = parents [0 ]) == signed_commit .parent_ids [0 ]
121
+ assert GIT_OBJ_COMMIT == commit .type
122
+ assert "6569fdf71dbd99081891154641869c537784a3ba" == commit .hex
123
+ assert commit .message_encoding is None
124
+ assert message == commit .message
125
+ assert 1358451456 == commit .commit_time
126
+ assert committer == commit .committer
127
+ assert author == commit .author
128
+ assert tree == commit .tree .hex
129
+ assert Oid (hex = tree ) == commit .tree_id
130
+ assert 1 == len (commit .parents )
131
+ assert parents [0 ] == commit .parents [0 ].hex
132
+ assert Oid (hex = parents [0 ]) == commit .parent_ids [0 ]
129
133
130
134
131
135
def test_get_gpg_signature_when_unsigned (gpgsigned ):
132
- unsigned_hash = "5b5b025afb0b4c913b4c338a42934a3863bf3644"
136
+ unhash = "5b5b025afb0b4c913b4c338a42934a3863bf3644"
133
137
134
138
repo = gpgsigned
135
- commit = repo .get (unsigned_hash )
139
+ commit = repo .get (unhash )
136
140
signature , payload = commit .gpg_signature
137
141
138
142
assert signature is None
0 commit comments