Skip to content

Commit 922bb8f

Browse files
author
Will Chandler
committed
Send full git request/response in SSHD tests
Before 9deaf47f1ecb00f0f36d18ee4a0fb1576f5a0efe, Gitaly would return success for `SSHUploadPack` and `SSHUploadArchive` regardless of the exit code of the `git upload-pack|archive` process. As a result, the gitlab-sshd acceptance tests could rely on no errors being returned from Gitaly. Currently these tests send the minimum request needed to start a session, causing the server git process to fail as the `0000` flush packet to end the session is never sent. This commit fixes the tests by sending the full request/response needed for a successful git operation.
1 parent 2941910 commit 922bb8f

File tree

1 file changed

+42
-8
lines changed

1 file changed

+42
-8
lines changed

cmd/gitlab-sshd/acceptance_test.go

+42-8
Original file line numberDiff line numberDiff line change
@@ -408,17 +408,33 @@ func TestGitUploadPackSuccess(t *testing.T) {
408408
ensureGitalyRepository(t)
409409

410410
client := runSSHD(t, successAPI(t))
411-
412411
session, err := client.NewSession()
413412
require.NoError(t, err)
414413
defer session.Close()
415414

416-
output, err := session.Output(fmt.Sprintf("git-upload-pack %s", testRepo))
415+
stdin, err := session.StdinPipe()
417416
require.NoError(t, err)
418417

419-
outputLines := strings.Split(string(output), "\n")
418+
stdout, err := session.StdoutPipe()
419+
require.NoError(t, err)
420+
421+
reader := bufio.NewReader(stdout)
422+
423+
err = session.Start(fmt.Sprintf("git-upload-pack %s", testRepo))
424+
require.NoError(t, err)
420425

421-
require.Regexp(t, "^[0-9a-f]{44} HEAD.+", outputLines[0])
426+
line, err := reader.ReadString('\n')
427+
require.NoError(t, err)
428+
require.Regexp(t, "^[0-9a-f]{44} HEAD.+", line)
429+
430+
// Gracefully close connection
431+
_, err = fmt.Fprintln(stdin, "0000")
432+
require.NoError(t, err)
433+
434+
output, err := io.ReadAll(stdout)
435+
require.NoError(t, err)
436+
437+
outputLines := strings.Split(string(output), "\n")
422438

423439
for i := 1; i < (len(outputLines) - 1); i++ {
424440
require.Regexp(t, "^[0-9a-f]{44} refs/(heads|tags)/[^ ]+", outputLines[i])
@@ -436,11 +452,29 @@ func TestGitUploadArchiveSuccess(t *testing.T) {
436452
require.NoError(t, err)
437453
defer session.Close()
438454

439-
output, err := session.Output(fmt.Sprintf("git-upload-archive %s", testRepo))
455+
stdin, err := session.StdinPipe()
440456
require.NoError(t, err)
441457

442-
outputLines := strings.Split(string(output), "\n")
458+
stdout, err := session.StdoutPipe()
459+
require.NoError(t, err)
460+
461+
reader := bufio.NewReader(stdout)
462+
463+
err = session.Start(fmt.Sprintf("git-upload-archive %s", testRepo))
464+
require.NoError(t, err)
465+
466+
_, err = fmt.Fprintln(stdin, "0012argument HEAD\n0000")
467+
468+
line, err := reader.ReadString('\n')
469+
require.Equal(t, "0008ACK\n", line)
470+
require.NoError(t, err)
471+
472+
// Gracefully close connection
473+
_, err = fmt.Fprintln(stdin, "0000")
474+
require.NoError(t, err)
475+
476+
output, err := io.ReadAll(stdout)
477+
require.NoError(t, err)
443478

444-
require.Equal(t, "0008ACK", outputLines[0])
445-
require.Regexp(t, "^0000", outputLines[1])
479+
require.Equal(t, []byte("0000"), output[len(output)-4:])
446480
}

0 commit comments

Comments
 (0)