|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import * as assert from 'assert'; |
| 7 | +import { shellExec, output } from './testUtils'; |
| 8 | +import { dockerExecFunction } from '../spec-shutdown/dockerUtils'; |
| 9 | +import { plainExec } from '../spec-common/commonUtils'; |
| 10 | +import { launch } from '../spec-common/shellServer'; |
| 11 | +import { getHomeFolder, getUserFromPasswdDB } from '../spec-common/injectHeadless'; |
| 12 | + |
| 13 | +describe('getHomeFolder', function () { |
| 14 | + this.timeout('20s'); |
| 15 | + |
| 16 | + it(`should ignore non-writeable HOME`, async () => { |
| 17 | + const res = await shellExec(`docker run -d mcr.microsoft.com/devcontainers/base:latest sleep inf`); |
| 18 | + const containerId = res.stdout.trim(); |
| 19 | + |
| 20 | + const vscodeShellServer = await launchShellServer(containerId, 'vscode'); |
| 21 | + const vscodeUser = await getUserFromPasswdDB(vscodeShellServer, 'vscode'); |
| 22 | + assert.ok(vscodeUser); |
| 23 | + |
| 24 | + assert.strictEqual(await getHomeFolder(vscodeShellServer, {}, vscodeUser), '/home/vscode'); |
| 25 | + assert.strictEqual(await getHomeFolder(vscodeShellServer, { HOME: '/root' }, vscodeUser), '/home/vscode'); |
| 26 | + assert.strictEqual(await getHomeFolder(vscodeShellServer, { HOME: '/home/vscode' }, vscodeUser), '/home/vscode'); |
| 27 | + assert.strictEqual(await getHomeFolder(vscodeShellServer, { HOME: '/home/vscode/foo' }, vscodeUser), '/home/vscode/foo'); |
| 28 | + |
| 29 | + const rootServer = await launchShellServer(containerId, 'root'); |
| 30 | + const rootUser = await getUserFromPasswdDB(rootServer, 'root'); |
| 31 | + assert.ok(rootUser); |
| 32 | + |
| 33 | + assert.strictEqual(await getHomeFolder(rootServer, {}, rootUser), '/root'); |
| 34 | + assert.strictEqual(await getHomeFolder(rootServer, { HOME: '/home/vscode' }, rootUser), '/home/vscode'); |
| 35 | + }); |
| 36 | + |
| 37 | + async function launchShellServer(containerId: string, username: string) { |
| 38 | + const exec = dockerExecFunction({ |
| 39 | + exec: plainExec(undefined), |
| 40 | + cmd: 'docker', |
| 41 | + env: {}, |
| 42 | + output, |
| 43 | + }, containerId, username); |
| 44 | + return launch(exec, output); |
| 45 | + } |
| 46 | +}); |
0 commit comments