As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Commit 922bb8ff authored by Will Chandler's avatar Will Chandler
Browse files

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.
parent 2941910e
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -408,17 +408,33 @@ func TestGitUploadPackSuccess(t *testing.T) {
ensureGitalyRepository(t)
client := runSSHD(t, successAPI(t))
session, err := client.NewSession()
require.NoError(t, err)
defer session.Close()
output, err := session.Output(fmt.Sprintf("git-upload-pack %s", testRepo))
stdin, err := session.StdinPipe()
require.NoError(t, err)
outputLines := strings.Split(string(output), "\n")
stdout, err := session.StdoutPipe()
require.NoError(t, err)
reader := bufio.NewReader(stdout)
err = session.Start(fmt.Sprintf("git-upload-pack %s", testRepo))
require.NoError(t, err)
require.Regexp(t, "^[0-9a-f]{44} HEAD.+", outputLines[0])
line, err := reader.ReadString('\n')
require.NoError(t, err)
require.Regexp(t, "^[0-9a-f]{44} HEAD.+", line)
// Gracefully close connection
_, err = fmt.Fprintln(stdin, "0000")
require.NoError(t, err)
output, err := io.ReadAll(stdout)
require.NoError(t, err)
outputLines := strings.Split(string(output), "\n")
for i := 1; i < (len(outputLines) - 1); i++ {
require.Regexp(t, "^[0-9a-f]{44} refs/(heads|tags)/[^ ]+", outputLines[i])
Loading
Loading
@@ -436,11 +452,29 @@ func TestGitUploadArchiveSuccess(t *testing.T) {
require.NoError(t, err)
defer session.Close()
output, err := session.Output(fmt.Sprintf("git-upload-archive %s", testRepo))
stdin, err := session.StdinPipe()
require.NoError(t, err)
outputLines := strings.Split(string(output), "\n")
stdout, err := session.StdoutPipe()
require.NoError(t, err)
reader := bufio.NewReader(stdout)
err = session.Start(fmt.Sprintf("git-upload-archive %s", testRepo))
require.NoError(t, err)
_, err = fmt.Fprintln(stdin, "0012argument HEAD\n0000")
line, err := reader.ReadString('\n')
require.Equal(t, "0008ACK\n", line)
require.NoError(t, err)
// Gracefully close connection
_, err = fmt.Fprintln(stdin, "0000")
require.NoError(t, err)
output, err := io.ReadAll(stdout)
require.NoError(t, err)
require.Equal(t, "0008ACK", outputLines[0])
require.Regexp(t, "^0000", outputLines[1])
require.Equal(t, []byte("0000"), output[len(output)-4:])
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment