Skip to content

Commit 4a50299

Browse files
committed
feat: add certificate_check callback to ls_remotes
Fixes: #1262 Signed-off-by: Kevin Valk <[email protected]>
1 parent eba710e commit 4a50299

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

pygit2/callbacks.py

+1
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ def git_remote_callbacks(payload):
391391
# Plug callbacks
392392
cdata.credentials = C._credentials_cb
393393
cdata.update_tips = C._update_tips_cb
394+
cdata.certificate_check = C._certificate_check_cb
394395
# Payload
395396
handle = ffi.new_handle(payload)
396397
cdata.payload = handle

test/test_remote.py

+30
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,36 @@ def update_tips(self, name, old, new):
296296
assert callbacks.i > 0
297297

298298

299+
@utils.requires_network
300+
def test_ls_remotes_certificate_check():
301+
url = 'https://github.com/pygit2/empty.git'
302+
303+
class MyCallbacks(pygit2.RemoteCallbacks):
304+
def __init__(self):
305+
self.i = 0
306+
307+
def certificate_check(self, certificate, valid, host):
308+
self.i += 1
309+
310+
assert certificate is None
311+
assert valid is True
312+
assert host == b'github.com'
313+
return True
314+
315+
# We create an in-memory repository
316+
git = pygit2.Repository()
317+
remote = git.remotes.create_anonymous(url)
318+
319+
callbacks = MyCallbacks()
320+
refs = remote.ls_remotes(callbacks=callbacks)
321+
322+
# Sanity check that we indeed got some refs.
323+
assert len(refs) > 0
324+
325+
# Make sure our certificate_check callback triggered.
326+
assert callbacks.i > 0
327+
328+
299329
@pytest.fixture
300330
def origin(tmp_path):
301331
with utils.TemporaryRepository('barerepo.zip', tmp_path) as path:

0 commit comments

Comments
 (0)