summaryrefslogtreecommitdiff
path: root/remote_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'remote_test.go')
-rw-r--r--remote_test.go34
1 files changed, 34 insertions, 0 deletions
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()")
+}