Skip to content

Commit 3ff3d3f

Browse files
committed
feat: add certificate_check callback to ls_remotes
Fixes: #1262 Signed-off-by: Kevin Valk <kevin@codean.io>
1 parent eba710e commit 3ff3d3f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

pygit2/callbacks.py

Lines changed: 1 addition & 0 deletions
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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,35 @@ def update_tips(self, name, old, new):
295295
remote.fetch(callbacks=callbacks)
296296
assert callbacks.i > 0
297297

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

299328
@pytest.fixture
300329
def origin(tmp_path):

0 commit comments

Comments
 (0)