MCPcopy Index your code
hub / github.com/ddev/ddev / TestSSHAuth

Function TestSSHAuth

pkg/ddevapp/ssh_auth_test.go:23–139  ·  view source on GitHub ↗

TestSSHAuth tests basic SSH authentication

(t *testing.T)

Source from the content-addressed store, hash-verified

21
22// TestSSHAuth tests basic SSH authentication
23func TestSSHAuth(t *testing.T) {
24 if dockerutil.IsColima() {
25 t.Skip("Skipping on Colima")
26 }
27 assert := asrt.New(t)
28 origDir, _ := os.Getwd()
29 app := &ddevapp.DdevApp{}
30
31 runTime := util.TimeTrackC(t.Name())
32
33 // Add a docker-compose service that has SSH server and mounted authorized_keys
34 site := TestSites[0]
35 // If running this with GOTEST_SHORT we have to create the directory, tarball etc.
36 if site.Dir == "" || !fileutil.FileExists(site.Dir) {
37 err := site.Prepare()
38 if err != nil {
39 t.Fatalf("Prepare() failed on TestSite.Prepare() site=%s, err=%v", site.Name, err)
40 }
41 }
42
43 testcommon.ClearDockerEnv()
44
45 err := app.Init(site.Dir)
46 require.NoError(t, err, "app.Init() failed on site %s in dir %s, err=%v", site.Name, site.Dir, err)
47 t.Cleanup(func() {
48 err = app.Stop(true, false)
49 assert.NoError(err)
50 err = os.Chdir(origDir)
51 assert.NoError(err)
52 _ = os.RemoveAll(app.GetConfigPath(".ssh"))
53 _ = os.RemoveAll(app.GetConfigPath("docker-compose.sshserver.yaml"))
54 })
55 srcDdev := filepath.Join(origDir, "testdata", t.Name(), ".ddev")
56 err = fileutil.CopyDir(filepath.Join(srcDdev, ".ssh"), app.GetConfigPath(".ssh"))
57 require.NoError(t, err)
58 err = util.Chmod(app.GetConfigPath(".ssh"), 0700)
59 require.NoError(t, err)
60 err = util.Chmod(app.GetConfigPath(".ssh/authorized_keys"), 0600)
61 require.NoError(t, err)
62 err = util.Chmod(app.GetConfigPath(".ssh/id_rsa"), 0600)
63 require.NoError(t, err)
64 err = fileutil.CopyFile(filepath.Join(srcDdev, "docker-compose.sshserver.yaml"), app.GetConfigPath("docker-compose.sshserver.yaml"))
65 require.NoError(t, err)
66
67 // Start with the testsite stopped (and everything stopped)
68 err = app.Stop(true, false)
69 assert.NoError(err)
70
71 // Make absolutely sure the ssh-agent is created from scratch.
72 err = ddevapp.RemoveSSHAgentContainer()
73 require.NoError(t, err)
74
75 err = app.Start()
76 require.NoError(t, err)
77
78 err = app.EnsureSSHAgentContainer()
79 require.NoError(t, err)
80

Callers

nothing calls this directly

Calls 15

InitMethod · 0.95
StopMethod · 0.95
GetConfigPathMethod · 0.95
StartMethod · 0.95
ExecMethod · 0.95
IsColimaFunction · 0.92
TimeTrackCFunction · 0.92
FileExistsFunction · 0.92
ClearDockerEnvFunction · 0.92
CopyDirFunction · 0.92
ChmodFunction · 0.92

Tested by

no test coverage detected