(t *testing.T)
| 239 | } |
| 240 | |
| 241 | func 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 |
| 254 | USER root |
| 255 | RUN useradd --create-home pickme |
| 256 | USER pickme |
| 257 | FROM a AS other |
| 258 | USER root |
| 259 | RUN useradd --create-home notme |
| 260 | USER notme |
| 261 | FROM 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 | |
| 282 | func TestUidGid(t *testing.T) { |
| 283 | t.Parallel() |
nothing calls this directly
no test coverage detected