mirror of
https://github.com/actions/runner-container-hooks.git
synced 2025-12-14 16:46:43 +00:00
added tests around user volume mounts for prepare job
This commit is contained in:
@@ -52,7 +52,10 @@ export function containerVolumes(
|
|||||||
'Volume mounts outside of the work folder are not supported'
|
'Volume mounts outside of the work folder are not supported'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
sourceVolumePath = userVolume.sourceVolumePath.slice(workspacePath.length)
|
// sourcec volume path should be relative path
|
||||||
|
sourceVolumePath = userVolume.sourceVolumePath.slice(
|
||||||
|
workspacePath.length + 1
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
sourceVolumePath = userVolume.sourceVolumePath
|
sourceVolumePath = userVolume.sourceVolumePath
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,4 +40,32 @@ describe('Prepare job', () => {
|
|||||||
const content = fs.readFileSync(prepareJobOutputFilePath)
|
const content = fs.readFileSync(prepareJobOutputFilePath)
|
||||||
expect(() => JSON.parse(content.toString())).not.toThrow()
|
expect(() => JSON.parse(content.toString())).not.toThrow()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should prepare job with absolute path for userVolumeMount', async () => {
|
||||||
|
prepareJobData.args.container.userMountVolumes.forEach(v => {
|
||||||
|
if (!path.isAbsolute(v.sourceVolumePath)) {
|
||||||
|
v.sourceVolumePath = path.join(
|
||||||
|
process.env.GITHUB_WORKSPACE as string,
|
||||||
|
v.sourceVolumePath
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
await expect(
|
||||||
|
prepareJob(prepareJobData.args, prepareJobOutputFilePath)
|
||||||
|
).resolves.not.toThrow()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should throw an exception if the user volume mount is absolute path outside of GITHUB_WORKSPACE', async () => {
|
||||||
|
prepareJobData.args.container.userMountVolumes.forEach(v => {
|
||||||
|
if (!path.isAbsolute(v.sourceVolumePath)) {
|
||||||
|
v.sourceVolumePath = path.join(
|
||||||
|
'/path/outside/of/github-workspace',
|
||||||
|
v.sourceVolumePath
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
await expect(
|
||||||
|
prepareJob(prepareJobData.args, prepareJobOutputFilePath)
|
||||||
|
).rejects.toThrow()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user