|
9 | 9 | "path/filepath" |
10 | 10 | "runtime" |
11 | 11 | "strconv" |
| 12 | + "strings" |
12 | 13 | "time" |
13 | 14 |
|
14 | 15 | "github.com/onsi/ginkgo/v2" |
@@ -104,6 +105,81 @@ var _ = ginkgo.Describe("devpod ssh test suite", ginkgo.Label("ssh"), ginkgo.Ord |
104 | 105 | // framework.ExpectNoError(err) |
105 | 106 | // }) |
106 | 107 |
|
| 108 | + ginkgo.It( |
| 109 | + "should set up git SSH signature helper in workspace", |
| 110 | + func(ctx context.Context) { |
| 111 | + if runtime.GOOS == "windows" { |
| 112 | + ginkgo.Skip("skipping on windows") |
| 113 | + } |
| 114 | + |
| 115 | + tempDir, err := framework.CopyToTempDir("tests/ssh/testdata/ssh-signing") |
| 116 | + framework.ExpectNoError(err) |
| 117 | + |
| 118 | + f := framework.NewDefaultFramework(initialDir + "/bin") |
| 119 | + _ = f.DevPodProviderAdd(ctx, "docker") |
| 120 | + err = f.DevPodProviderUse(ctx, "docker") |
| 121 | + framework.ExpectNoError(err) |
| 122 | + |
| 123 | + ginkgo.DeferCleanup(func(cleanupCtx context.Context) { |
| 124 | + _ = f.DevPodWorkspaceDelete(cleanupCtx, tempDir) |
| 125 | + framework.CleanupTempDir(initialDir, tempDir) |
| 126 | + }) |
| 127 | + |
| 128 | + // Generate a temporary SSH key for signing |
| 129 | + sshKeyDir, err := os.MkdirTemp("", "devpod-ssh-signing-test") |
| 130 | + framework.ExpectNoError(err) |
| 131 | + defer func() { _ = os.RemoveAll(sshKeyDir) }() |
| 132 | + |
| 133 | + keyPath := filepath.Join(sshKeyDir, "id_ed25519") |
| 134 | + // #nosec G204 -- test command with controlled arguments |
| 135 | + err = exec.Command( |
| 136 | + "ssh-keygen", "-t", "ed25519", "-f", keyPath, "-N", "", "-q", |
| 137 | + ).Run() |
| 138 | + framework.ExpectNoError(err) |
| 139 | + |
| 140 | + // Start workspace with git-ssh-signing-key flag |
| 141 | + devpodUpCtx, cancel := context.WithTimeout(ctx, 5*time.Minute) |
| 142 | + defer cancel() |
| 143 | + err = f.DevPodUp(devpodUpCtx, tempDir, |
| 144 | + "--git-ssh-signing-key", keyPath+".pub", |
| 145 | + ) |
| 146 | + framework.ExpectNoError(err) |
| 147 | + |
| 148 | + sshCtx, cancelSSH := context.WithTimeout(ctx, 20*time.Second) |
| 149 | + defer cancelSSH() |
| 150 | + |
| 151 | + // Verify the helper script was installed |
| 152 | + out, err := f.DevPodSSH(sshCtx, tempDir, |
| 153 | + "test -x /usr/local/bin/devpod-ssh-signature && echo EXISTS", |
| 154 | + ) |
| 155 | + framework.ExpectNoError(err) |
| 156 | + gomega.Expect(strings.TrimSpace(out)).To( |
| 157 | + gomega.Equal("EXISTS"), |
| 158 | + "devpod-ssh-signature helper script should be installed and executable", |
| 159 | + ) |
| 160 | + |
| 161 | + // Verify git config has the SSH signing program set |
| 162 | + out, err = f.DevPodSSH(sshCtx, tempDir, |
| 163 | + "git config --global gpg.ssh.program", |
| 164 | + ) |
| 165 | + framework.ExpectNoError(err) |
| 166 | + gomega.Expect(strings.TrimSpace(out)).To( |
| 167 | + gomega.Equal("devpod-ssh-signature"), |
| 168 | + "git gpg.ssh.program should be set to devpod-ssh-signature", |
| 169 | + ) |
| 170 | + |
| 171 | + // Verify git config has gpg format set to ssh |
| 172 | + out, err = f.DevPodSSH(sshCtx, tempDir, |
| 173 | + "git config --global gpg.format", |
| 174 | + ) |
| 175 | + framework.ExpectNoError(err) |
| 176 | + gomega.Expect(strings.TrimSpace(out)).To( |
| 177 | + gomega.Equal("ssh"), |
| 178 | + "git gpg.format should be set to ssh", |
| 179 | + ) |
| 180 | + }, |
| 181 | + ) |
| 182 | + |
107 | 183 | ginkgo.It( |
108 | 184 | "should start a new workspace with a docker provider (default) and forward a port into it", |
109 | 185 | func(ctx context.Context) { |
|
0 commit comments