From 17a9214307250b5fd2769385c73b723d55a26dab Mon Sep 17 00:00:00 2001 From: Carlos Martín Nieto Date: Wed, 15 Oct 2014 15:43:02 +0200 Subject: Update to libgit2 master The option to ignore the server's certificate has been removed, replaced witha callback for the user to perform their own checking. Remote.Fetch() now performs opportunistic updates and takes a list of refspecs to use as the active set for a particular fetch. --- remote_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'remote_test.go') diff --git a/remote_test.go b/remote_test.go index 7cef1ec..8021f71 100644 --- a/remote_test.go +++ b/remote_test.go @@ -1,6 +1,8 @@ package git import ( + "fmt" + "crypto/x509" "os" "testing" ) @@ -45,3 +47,35 @@ func TestListRemotes(t *testing.T) { compareStringList(t, expected, actual) } + + +func assertHostname(cert *x509.Certificate, valid bool, hostname string, t *testing.T) int { + fmt.Println("hostname", hostname) + if hostname != "github.com" { + t.Fatal("Hostname does not match") + return ErrUser + } + + return 0 +} + +func TestCertificateCheck(t *testing.T) { + repo := createTestRepo(t) + defer os.RemoveAll(repo.Workdir()) + defer repo.Free() + + remote, err := repo.CreateRemote("origin", "https://github.com/libgit2/TestGitRepository") + checkFatal(t, err) + + callbacks := RemoteCallbacks{ + CertificateCheckCallback: func (cert *x509.Certificate, valid bool, hostname string) int { + return assertHostname(cert, valid, hostname, t) + }, + } + + err = remote.SetCallbacks(&callbacks) + checkFatal(t, err) + err = remote.Fetch([]string{}, nil, "") + checkFatal(t, err) + fmt.Println("after Fetch()") +} -- cgit v1.2.3