libgit2 / pygit2

Python bindings for libgit2
https://www.pygit2.org/
Other
1.59k stars 383 forks source link

test_keypair_from_memory errors #1070

Closed kapilt closed 1 year ago

kapilt commented 3 years ago

using pygit2 1.5, i was trying a script to do a checkout with keypair from memory but its consistently erroring out on invalid cred type.

from pathlib import Path
import pygit2
import getpass

def main():
    keypair = pygit2.KeypairFromMemory( 
        "git", 
        str(Path('~/.ssh/id_ed25519.pub').expanduser().read_text()), 
        str(Path('~/.ssh/id_ed25519').expanduser().read_text()), 
        "") 

    pygit2.clone_repository(
        'ssh://git@github.com/pygit2/empty', 'empty',
        callbacks=pygit2.RemoteCallbacks(credentials=keypair))

if __name__ == '__main__':
    main()

trying out the pygit2 test suite from a git checkout, also shows an error when using ssh key pair from memory

test/test_credentials.py:121:                                                                                                                         [8/1910]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../.pyenv/versions/3.9.1/envs/stackql-3.9/lib/python3.9/site-packages/pygit2/__init__.py:222: in clone_repository
    payload.check_error(err)                                                   
../../.pyenv/versions/3.9.1/envs/stackql-3.9/lib/python3.9/site-packages/pygit2/callbacks.py:91: in check_error
    raise self._stored_exception
../../.pyenv/versions/3.9.1/envs/stackql-3.9/lib/python3.9/site-packages/pygit2/callbacks.py:331: in wrapper
    return f(*args)
../../.pyenv/versions/3.9.1/envs/stackql-3.9/lib/python3.9/site-packages/pygit2/callbacks.py:376: in _credentials_cb
    ccred = get_credentials(credentials, url, username, allowed)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

fn = <pygit2.credentials.KeypairFromMemory object at 0x7fd5380ac7f0>, url = <cdata 'char *' 0x56050e3e0a40>, username = <cdata 'char *' 0x56050e4c7830>
allowed = 6

    def get_credentials(fn, url, username, allowed):                                                                                                          
        """Call fn and return the credentials object.
        """                                                                                                                                                   
        url_str = maybe_string(url)                                                                                                                           
        username_str = maybe_string(username)

        creds = fn(url_str, username_str, allowed)

        credential_type = getattr(creds, 'credential_type', None)
        credential_tuple = getattr(creds, 'credential_tuple', None)
        if not credential_type or not credential_tuple:
            raise TypeError("credential does not implement interface")

        cred_type = credential_type

        if not (allowed & cred_type):
>           raise TypeError("invalid credential type")
E           TypeError: invalid credential type

specifically allowed is 6 and cred_type is 64. its unclear why the cred type for in memory key pair is different then ssh key (cred_type 2) for this check against the remote allowed auth types.

its also unclear why this passes in ci, my host is 20.04, using the manywheels release so libgit2 1.1 with libssh 1.9 statically linked.

emirot commented 3 years ago

@kapilt Did you find the reason?

jdavid commented 1 year ago

Try with the latest release v1.11.1 which includes openssl 1.1