mirror of
https://github.com/actions/runner-container-hooks.git
synced 2025-12-14 16:46:43 +00:00
Docker and K8s: Fix shell arguments when split by the runner (#115)
* Docker: Fix shell arguments when split by the runner * Add shlex to k8s hook as well
This commit is contained in:
@@ -40,21 +40,36 @@ describe('run script step', () => {
|
||||
definitions.runScriptStep.args.entryPoint = '/bin/bash'
|
||||
definitions.runScriptStep.args.entryPointArgs = [
|
||||
'-c',
|
||||
`if [[ ! $(env | grep "^PATH=") = "PATH=${definitions.runScriptStep.args.prependPath}:"* ]]; then exit 1; fi`
|
||||
`'if [[ ! $(env | grep "^PATH=") = "PATH=${definitions.runScriptStep.args.prependPath}:"* ]]; then exit 1; fi'`
|
||||
]
|
||||
await expect(
|
||||
runScriptStep(definitions.runScriptStep.args, prepareJobResponse.state)
|
||||
).resolves.not.toThrow()
|
||||
})
|
||||
|
||||
it("Should fix expansion and print correctly in container's stdout", async () => {
|
||||
const spy = jest.spyOn(process.stdout, 'write').mockImplementation()
|
||||
|
||||
definitions.runScriptStep.args.entryPoint = 'echo'
|
||||
definitions.runScriptStep.args.entryPointArgs = ['"Mona', 'the', `Octocat"`]
|
||||
await expect(
|
||||
runScriptStep(definitions.runScriptStep.args, prepareJobResponse.state)
|
||||
).resolves.not.toThrow()
|
||||
expect(spy).toHaveBeenCalledWith(
|
||||
expect.stringContaining('Mona the Octocat')
|
||||
)
|
||||
|
||||
spy.mockRestore()
|
||||
})
|
||||
|
||||
it('Should have path variable changed in container with prepend path string array', async () => {
|
||||
definitions.runScriptStep.args.prependPath = ['/some/other/path']
|
||||
definitions.runScriptStep.args.entryPoint = '/bin/bash'
|
||||
definitions.runScriptStep.args.entryPointArgs = [
|
||||
'-c',
|
||||
`if [[ ! $(env | grep "^PATH=") = "PATH=${definitions.runScriptStep.args.prependPath.join(
|
||||
`'if [[ ! $(env | grep "^PATH=") = "PATH=${definitions.runScriptStep.args.prependPath.join(
|
||||
':'
|
||||
)}:"* ]]; then exit 1; fi`
|
||||
)}:"* ]]; then exit 1; fi'`
|
||||
]
|
||||
await expect(
|
||||
runScriptStep(definitions.runScriptStep.args, prepareJobResponse.state)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { optionsWithDockerEnvs, sanitize } from '../src/utils'
|
||||
import { optionsWithDockerEnvs, sanitize, fixArgs } from '../src/utils'
|
||||
|
||||
describe('Utilities', () => {
|
||||
it('should return sanitized image name', () => {
|
||||
@@ -10,6 +10,37 @@ describe('Utilities', () => {
|
||||
expect(sanitize(validStr)).toBe(validStr)
|
||||
})
|
||||
|
||||
test.each([
|
||||
[['"Hello', 'World"'], ['Hello World']],
|
||||
[
|
||||
[
|
||||
'sh',
|
||||
'-c',
|
||||
`'[ $(cat /etc/*release* | grep -i -e "^ID=*alpine*" -c) != 0 ] || exit 1'`
|
||||
],
|
||||
[
|
||||
'sh',
|
||||
'-c',
|
||||
`[ $(cat /etc/*release* | grep -i -e "^ID=*alpine*" -c) != 0 ] || exit 1`
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'sh',
|
||||
'-c',
|
||||
`'[ $(cat /etc/*release* | grep -i -e '\\''^ID=*alpine*'\\'' -c) != 0 ] || exit 1'`
|
||||
],
|
||||
[
|
||||
'sh',
|
||||
'-c',
|
||||
`[ $(cat /etc/*release* | grep -i -e '^ID=*alpine*' -c) != 0 ] || exit 1`
|
||||
]
|
||||
]
|
||||
])('should fix split arguments(%p, %p)', (args, expected) => {
|
||||
const got = fixArgs(args)
|
||||
expect(got).toStrictEqual(expected)
|
||||
})
|
||||
|
||||
describe('with docker options', () => {
|
||||
it('should augment options with docker environment variables', () => {
|
||||
process.env.DOCKER_HOST = 'unix:///run/user/1001/docker.sock'
|
||||
|
||||
Reference in New Issue
Block a user