Skip to content

Commit

Permalink
feat: add certificate_check callback to ls_remotes
Browse files Browse the repository at this point in the history
Fixes: #1262

Signed-off-by: Kevin Valk <[email protected]>
  • Loading branch information
kevinvalk committed Nov 21, 2024
1 parent eba710e commit 4a50299
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions pygit2/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ def git_remote_callbacks(payload):
# Plug callbacks
cdata.credentials = C._credentials_cb
cdata.update_tips = C._update_tips_cb
cdata.certificate_check = C._certificate_check_cb
# Payload
handle = ffi.new_handle(payload)
cdata.payload = handle
Expand Down
30 changes: 30 additions & 0 deletions test/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,36 @@ def update_tips(self, name, old, new):
assert callbacks.i > 0


@utils.requires_network
def test_ls_remotes_certificate_check():
url = 'https://github.com/pygit2/empty.git'

class MyCallbacks(pygit2.RemoteCallbacks):
def __init__(self):
self.i = 0

def certificate_check(self, certificate, valid, host):
self.i += 1

assert certificate is None
assert valid is True
assert host == b'github.com'
return True

# We create an in-memory repository
git = pygit2.Repository()
remote = git.remotes.create_anonymous(url)

callbacks = MyCallbacks()
refs = remote.ls_remotes(callbacks=callbacks)

# Sanity check that we indeed got some refs.
assert len(refs) > 0

# Make sure our certificate_check callback triggered.
assert callbacks.i > 0


@pytest.fixture
def origin(tmp_path):
with utils.TemporaryRepository('barerepo.zip', tmp_path) as path:
Expand Down

0 comments on commit 4a50299

Please sign in to comment.