MCPcopy Create free account
hub / github.com/coder/envbuilder / TestSetupRepoAuth

Function TestSetupRepoAuth

git/git_test.go:353–525  ·  view source on GitHub ↗

nolint:paralleltest // t.Setenv for SSH_AUTH_SOCK

(t *testing.T)

Source from the content-addressed store, hash-verified

351
352// nolint:paralleltest // t.Setenv for SSH_AUTH_SOCK
353func TestSetupRepoAuth(t *testing.T) {
354 t.Setenv("SSH_AUTH_SOCK", "")
355 t.Run("Empty", func(t *testing.T) {
356 opts := &options.Options{}
357 auth := git.SetupRepoAuth(t.Logf, opts)
358 require.Nil(t, auth)
359 })
360
361 t.Run("HTTP/NoAuth", func(t *testing.T) {
362 opts := &options.Options{
363 GitURL: "http://host.tld/repo",
364 }
365 auth := git.SetupRepoAuth(t.Logf, opts)
366 require.Nil(t, auth)
367 })
368
369 t.Run("HTTP/BasicAuth", func(t *testing.T) {
370 opts := &options.Options{
371 GitURL: "http://host.tld/repo",
372 GitUsername: "user",
373 GitPassword: "pass",
374 }
375 auth := git.SetupRepoAuth(t.Logf, opts)
376 ba, ok := auth.(*githttp.BasicAuth)
377 require.True(t, ok)
378 require.Equal(t, opts.GitUsername, ba.Username)
379 require.Equal(t, opts.GitPassword, ba.Password)
380 })
381
382 t.Run("HTTPS/BasicAuth", func(t *testing.T) {
383 opts := &options.Options{
384 GitURL: "https://host.tld/repo",
385 GitUsername: "user",
386 GitPassword: "pass",
387 }
388 auth := git.SetupRepoAuth(t.Logf, opts)
389 ba, ok := auth.(*githttp.BasicAuth)
390 require.True(t, ok)
391 require.Equal(t, opts.GitUsername, ba.Username)
392 require.Equal(t, opts.GitPassword, ba.Password)
393 })
394
395 t.Run("SSH/WithScheme", func(t *testing.T) {
396 kPath := writeTestPrivateKey(t)
397 opts := &options.Options{
398 GitURL: "ssh://host.tld/repo",
399 GitSSHPrivateKeyPath: kPath,
400 }
401 auth := git.SetupRepoAuth(t.Logf, opts)
402 _, ok := auth.(*gitssh.PublicKeys)
403 require.True(t, ok)
404 })
405
406 t.Run("SSH/NoScheme", func(t *testing.T) {
407 kPath := writeTestPrivateKey(t)
408 opts := &options.Options{
409 GitURL: "git@host.tld:repo/path",
410 GitSSHPrivateKeyPath: kPath,

Callers

nothing calls this directly

Calls 3

SetupRepoAuthFunction · 0.92
writeTestPrivateKeyFunction · 0.85

Tested by

no test coverage detected