Skip to content

Commit 1c85086

Browse files
committed
test(e2e): add GPG forwarding with SSH signing format test (#731)
Validates that workspace starts successfully when GPG agent forwarding is enabled and the host has gpg.format=ssh with an SSH signing key. This is the exact scenario reported in issue #731.
1 parent c449387 commit 1c85086

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

e2e/tests/ssh/ssh.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,65 @@ var _ = ginkgo.Describe("devpod ssh test suite", ginkgo.Label("ssh"), ginkgo.Ord
107107
// framework.ExpectNoError(err)
108108
// })
109109

110+
ginkgo.It(
111+
"should start workspace with GPG forwarding when host uses SSH signing format",
112+
ginkgo.Label("gpg"),
113+
ginkgo.SpecTimeout(5*time.Minute),
114+
func(ctx ginkgo.SpecContext) {
115+
if runtime.GOOS == osWindows {
116+
ginkgo.Skip("skipping on windows")
117+
}
118+
119+
tempDir, err := framework.CopyToTempDir("tests/ssh/testdata/gpg-forwarding")
120+
framework.ExpectNoError(err)
121+
122+
f := framework.NewDefaultFramework(initialDir + "/bin")
123+
_ = f.DevPodProviderAdd(ctx, "docker")
124+
err = f.DevPodProviderUse(ctx, "docker")
125+
framework.ExpectNoError(err)
126+
127+
ginkgo.DeferCleanup(func(cleanupCtx context.Context) {
128+
_ = f.DevPodWorkspaceDelete(cleanupCtx, tempDir)
129+
framework.CleanupTempDir(initialDir, tempDir)
130+
})
131+
132+
// Configure host git to use SSH signing format with an SSH key,
133+
// simulating the reporter's setup from issue #731.
134+
sshKeyDir, err := os.MkdirTemp("", "devpod-gpg-ssh-test")
135+
framework.ExpectNoError(err)
136+
defer func() { _ = os.RemoveAll(sshKeyDir) }()
137+
138+
keyPath := filepath.Join(sshKeyDir, "id_ed25519")
139+
// #nosec G204 -- test command with controlled arguments
140+
err = exec.Command(
141+
"ssh-keygen", "-t", "ed25519", "-f", keyPath, "-N", "", "-q",
142+
).Run()
143+
framework.ExpectNoError(err)
144+
145+
// Create a temporary gitconfig with SSH signing format
146+
gitConfigDir := ginkgo.GinkgoT().TempDir()
147+
gitConfigPath := filepath.Join(gitConfigDir, ".gitconfig")
148+
gitConfigContent := "[gpg]\n\tformat = ssh\n[user]\n\tsigningKey = " +
149+
keyPath + ".pub\n\tname = Test\n\temail = test@test.com\n"
150+
err = os.WriteFile(gitConfigPath, []byte(gitConfigContent), 0o600)
151+
framework.ExpectNoError(err)
152+
ginkgo.GinkgoT().Setenv("GIT_CONFIG_GLOBAL", gitConfigPath)
153+
154+
// Start workspace with GPG agent forwarding enabled.
155+
// Before the fix, this would fail because setup-gpg would try
156+
// to use the SSH key path as a GPG key and crash.
157+
err = f.DevPodUp(ctx, tempDir, "--gpg-agent-forwarding")
158+
framework.ExpectNoError(err)
159+
160+
// Verify SSH server is running and reachable
161+
devpodSSHDeadline := time.Now().Add(20 * time.Second)
162+
devpodSSHCtx, cancelSSH := context.WithDeadline(ctx, devpodSSHDeadline)
163+
defer cancelSSH()
164+
err = f.DevPodSSHEchoTestString(devpodSSHCtx, tempDir)
165+
framework.ExpectNoError(err)
166+
},
167+
)
168+
110169
ginkgo.It(
111170
"should set up git SSH signature helper and sign a commit",
112171
ginkgo.SpecTimeout(7*time.Minute),

0 commit comments

Comments
 (0)