Exemple #1
0
func TestCertFromSSLCAInfoEnv(t *testing.T) {

	tempfile, err := ioutil.TempFile("", "testcert")
	assert.Equal(t, nil, err, "Error creating temp cert file")
	defer os.Remove(tempfile.Name())

	_, err = tempfile.WriteString(testCert)
	assert.Equal(t, nil, err, "Error writing temp cert file")
	tempfile.Close()

	oldEnv := Config.envVars
	defer func() {
		Config.envVars = oldEnv
	}()

	Config.envVars = map[string]string{"GIT_SSL_CAINFO": tempfile.Name()}

	// Should match any host at all
	pool := getRootCAsForHost("git-lfs.local")
	assert.NotEqual(t, (*x509.CertPool)(nil), pool)
	pool = getRootCAsForHost("wronghost.com")
	assert.NotEqual(t, (*x509.CertPool)(nil), pool)
	pool = getRootCAsForHost("notthisone.com:8888")
	assert.NotEqual(t, (*x509.CertPool)(nil), pool)

}
Exemple #2
0
func TestCertFromSSLCAPathEnv(t *testing.T) {

	tempdir, err := ioutil.TempDir("", "testcertdir")
	assert.Equal(t, nil, err, "Error creating temp cert dir")
	defer os.RemoveAll(tempdir)

	err = ioutil.WriteFile(filepath.Join(tempdir, "cert1.pem"), []byte(testCert), 0644)
	assert.Equal(t, nil, err, "Error creating cert file")

	oldEnv := Config.envVars
	defer func() {
		Config.envVars = oldEnv
	}()

	Config.envVars = map[string]string{"GIT_SSL_CAPATH": tempdir}

	// Should match any host at all
	pool := getRootCAsForHost("git-lfs.local")
	assert.NotEqual(t, (*x509.CertPool)(nil), pool)
	pool = getRootCAsForHost("wronghost.com")
	assert.NotEqual(t, (*x509.CertPool)(nil), pool)
	pool = getRootCAsForHost("notthisone.com:8888")
	assert.NotEqual(t, (*x509.CertPool)(nil), pool)

}
Exemple #3
0
func TestNtlmHeaderParseInvalid(t *testing.T) {
	res := http.Response{}
	res.Header = make(map[string][]string)
	res.Header.Add("Www-Authenticate", base64.StdEncoding.EncodeToString([]byte("NTLM I am a moose")))
	_, err := parseChallengeResponse(&res)
	assert.NotEqual(t, err, nil)
}
Exemple #4
0
func TestResolveEmptyCurrentRef(t *testing.T) {
	repo := test.NewRepo(t)
	repo.Pushd()
	defer func() {
		repo.Popd()
		repo.Cleanup()
	}()

	_, err := CurrentRef()
	assert.NotEqual(t, nil, err)
}
Exemple #5
0
func TestCertFromSSLCAInfoConfig(t *testing.T) {

	tempfile, err := ioutil.TempFile("", "testcert")
	assert.Equal(t, nil, err, "Error creating temp cert file")
	defer os.Remove(tempfile.Name())

	_, err = tempfile.WriteString(testCert)
	assert.Equal(t, nil, err, "Error writing temp cert file")
	tempfile.Close()

	oldGitConfig := Config.gitConfig
	defer func() {
		Config.gitConfig = oldGitConfig
	}()

	Config.gitConfig = map[string]string{"http.https://git-lfs.local/.sslcainfo": tempfile.Name()}

	// Should match
	pool := getRootCAsForHost("git-lfs.local")
	assert.NotEqual(t, (*x509.CertPool)(nil), pool)

	// Shouldn't match
	pool = getRootCAsForHost("wronghost.com")
	assert.Equal(t, (*x509.CertPool)(nil), pool)

	// Ports have to match
	pool = getRootCAsForHost("git-lfs.local:8443")
	assert.Equal(t, (*x509.CertPool)(nil), pool)

	// Now use global sslcainfo
	Config.gitConfig = map[string]string{"http.sslcainfo": tempfile.Name()}

	// Should match anything
	pool = getRootCAsForHost("git-lfs.local")
	assert.NotEqual(t, (*x509.CertPool)(nil), pool)
	pool = getRootCAsForHost("wronghost.com")
	assert.NotEqual(t, (*x509.CertPool)(nil), pool)
	pool = getRootCAsForHost("git-lfs.local:8443")
	assert.NotEqual(t, (*x509.CertPool)(nil), pool)

}
Exemple #6
0
func TestNtlmClientSessionBadCreds(t *testing.T) {

	//Make sure to clear ntlmSession so test order doesn't matter.
	Config.ntlmSession = nil

	creds := Creds{"username": "******", "password": "******"}
	_, err := Config.ntlmClientSession(creds)
	assert.NotEqual(t, err, nil)

	//clean up
	Config.ntlmSession = nil
}
Exemple #7
0
func TestSortExtensionsDuplicatePriority(t *testing.T) {
	m := map[string]Extension{
		"foo": Extension{
			"foo",
			"foo-clean %f",
			"foo-smudge %f",
			0,
		},
		"bar": Extension{
			"bar",
			"bar-clean %f",
			"bar-smudge %f",
			0,
		},
	}

	sorted, err := SortExtensions(m)

	assert.NotEqual(t, err, nil)
	assert.Equal(t, len(sorted), 0)
}