|
4 | 4 | package integration |
5 | 5 |
|
6 | 6 | import ( |
7 | | - "bytes" |
8 | 7 | "encoding/hex" |
9 | 8 | "fmt" |
10 | 9 | "io" |
@@ -112,7 +111,7 @@ func testGitGeneral(t *testing.T, u *url.URL) { |
112 | 111 | t.Run("CreateUserKey", doAPICreateUserKey(sshContext, "test-key", keyFile, func(t *testing.T, key api.PublicKey) { |
113 | 112 | keyID = key.ID |
114 | 113 | })) |
115 | | - assert.Greater(t, keyID, int64(0)) |
| 114 | + assert.NotZero(t, keyID) |
116 | 115 |
|
117 | 116 | // Setup remote link |
118 | 117 | // TODO: get url from api |
@@ -144,26 +143,22 @@ func testGitGeneral(t *testing.T, u *url.URL) { |
144 | 143 | }) |
145 | 144 | } |
146 | 145 |
|
147 | | -func doLFSUploadTest(ctx APITestContext, keyID int64) func(*testing.T) { |
| 146 | +func doLFSUploadTest(_ APITestContext, keyID int64) func(*testing.T) { |
148 | 147 | return func(t *testing.T) { |
149 | | - // This is set in withKeyFile and ensure correctly |
150 | | - sshCommand := os.Getenv("GIT_SSH_COMMAND") |
151 | | - |
152 | | - // We really have to split on the arguments and pass them individually. |
153 | | - sshOptions, err := shellquote.Split(sshCommand) |
154 | | - assert.NoError(t, err) |
155 | | - |
156 | | - sshOptions = append(sshOptions, "-p "+strconv.Itoa(setting.SSH.ListenPort), "git@"+setting.SSH.ListenHost) |
157 | | - // user2's key upload lfs file to user5/repo4 |
158 | | - sshOptions = append(sshOptions, "git-lfs-authenticate", "user5/repo4.git", "upload") |
159 | | - |
160 | | - cmd := exec.CommandContext(t.Context(), sshOptions[0], sshOptions[1:]...) |
161 | | - stderr := bytes.Buffer{} |
162 | | - cmd.Stderr = &stderr |
163 | | - err = cmd.Run() |
| 148 | + sshCommand := os.Getenv("GIT_SSH_COMMAND") // it is set in withKeyFile and ensure correctly |
| 149 | + sshCmdParts, err := shellquote.Split(sshCommand) // and parse the ssh command to construct some mocked arguments |
| 150 | + require.NoError(t, err) |
164 | 151 |
|
165 | | - assert.ErrorContains(t, err, "exit status 1") |
166 | | - assert.Contains(t, stderr.String(), fmt.Sprintf("User: 2:user2 with Key: %d:test-key is not authorized to write to user5/repo4.", keyID)) |
| 152 | + t.Run("User2AccessUser5Repo4", func(t *testing.T) { |
| 153 | + sshCmdParts = append(sshCmdParts, |
| 154 | + "-p", strconv.Itoa(setting.SSH.ListenPort), "git@"+setting.SSH.ListenHost, |
| 155 | + "git-lfs-authenticate", "user5/repo4.git", "upload", // user2's key upload lfs file to user5/repo4 |
| 156 | + ) |
| 157 | + cmd := exec.CommandContext(t.Context(), sshCmdParts[0], sshCmdParts[1:]...) |
| 158 | + out, err := cmd.Output() |
| 159 | + assert.ErrorContains(t, err, "exit status 1") |
| 160 | + assert.Contains(t, string(out), fmt.Sprintf("User: 2:user2 with Key: %d:test-key is not authorized to write to user5/repo4.", keyID)) |
| 161 | + }) |
167 | 162 | } |
168 | 163 | } |
169 | 164 |
|
|
0 commit comments