MCPcopy Create free account
hub / github.com/github/gh-aw / TestBuildDockerCommandWithExpandableVars

Function TestBuildDockerCommandWithExpandableVars

pkg/workflow/shell_test.go:200–281  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

198}
199
200func TestBuildDockerCommandWithExpandableVars(t *testing.T) {
201 tests := []struct {
202 name string
203 input string
204 expected string
205 }{
206 {
207 name: "simple command without variables",
208 input: "docker run hello",
209 expected: "'docker run hello'",
210 },
211 {
212 name: "command with single GITHUB_WORKSPACE",
213 input: "docker run -v ${GITHUB_WORKSPACE}:${GITHUB_WORKSPACE}",
214 expected: "'docker run -v '\"${GITHUB_WORKSPACE}\"':'\"${GITHUB_WORKSPACE}\"''",
215 },
216 {
217 name: "command with GITHUB_WORKSPACE at the start",
218 input: "${GITHUB_WORKSPACE}/file",
219 expected: "''\"${GITHUB_WORKSPACE}\"'/file'",
220 },
221 {
222 name: "command with GITHUB_WORKSPACE at the end",
223 input: "path/to/${GITHUB_WORKSPACE}",
224 expected: "'path/to/'\"${GITHUB_WORKSPACE}\"''",
225 },
226 {
227 name: "command with multiple GITHUB_WORKSPACE references",
228 input: "${GITHUB_WORKSPACE}/src:${GITHUB_WORKSPACE}/dst",
229 expected: "''\"${GITHUB_WORKSPACE}\"'/src:'\"${GITHUB_WORKSPACE}\"'/dst'",
230 },
231 {
232 name: "command with GITHUB_WORKSPACE and single quote",
233 input: "it's in ${GITHUB_WORKSPACE}",
234 expected: "'it'\\''s in '\"${GITHUB_WORKSPACE}\"''",
235 },
236 {
237 name: "complex docker command",
238 input: "docker run -v ${GITHUB_WORKSPACE}:${GITHUB_WORKSPACE}:rw image",
239 expected: "'docker run -v '\"${GITHUB_WORKSPACE}\"':'\"${GITHUB_WORKSPACE}\"':rw image'",
240 },
241 {
242 name: "command with spaces and no variables",
243 input: "docker run hello world",
244 expected: "'docker run hello world'",
245 },
246 {
247 name: "empty command",
248 input: "",
249 expected: "",
250 },
251 {
252 name: "injection attempt in GITHUB_WORKSPACE context",
253 input: "${GITHUB_WORKSPACE}; rm -rf /",
254 expected: "''\"${GITHUB_WORKSPACE}\"'; rm -rf /'",
255 },
256 {
257 name: "multiple different variables",

Callers

nothing calls this directly

Calls 3

RunMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected