MCPcopy Create free account
hub / github.com/coder/envbuilder / TestUserFromMultistage

Function TestUserFromMultistage

integration/integration_test.go:241–280  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

239}
240
241func TestUserFromMultistage(t *testing.T) {
242 t.Parallel()
243
244 // Ensures that a Git repository with a devcontainer.json is cloned and built.
245 srv := gittest.CreateGitServer(t, gittest.Options{
246 Files: map[string]string{
247 "devcontainer.json": `{
248 "name": "Test",
249 "build": {
250 "dockerfile": "Dockerfile"
251 },
252 }`,
253 "Dockerfile": fmt.Sprintf(`FROM %s AS a
254USER root
255RUN useradd --create-home pickme
256USER pickme
257FROM a AS other
258USER root
259RUN useradd --create-home notme
260USER notme
261FROM a AS b`, testImageUbuntu),
262 },
263 })
264 ctr, err := runEnvbuilder(t, runOpts{env: []string{
265 envbuilderEnv("GIT_URL", srv.URL),
266 }})
267 require.NoError(t, err)
268
269 // Check that envbuilder started command as user.
270 // Since envbuilder starts as root, probe for up to 10 seconds.
271 for i := 0; i < 10; i++ {
272 out := execContainer(t, ctr, "ps aux | awk '/^pickme * 1 / {print $1}' | sort -u")
273 got := strings.TrimSpace(out)
274 if got == "pickme" {
275 return
276 }
277 time.Sleep(time.Second)
278 }
279 require.Fail(t, "expected pid 1 to be running as pickme")
280}
281
282func TestUidGid(t *testing.T) {
283 t.Parallel()

Callers

nothing calls this directly

Calls 4

CreateGitServerFunction · 0.92
runEnvbuilderFunction · 0.85
envbuilderEnvFunction · 0.85
execContainerFunction · 0.85

Tested by

no test coverage detected