diff --git a/src/playwright/install.sh b/src/playwright/install.sh index 61696d8..b335aac 100644 --- a/src/playwright/install.sh +++ b/src/playwright/install.sh @@ -1,3 +1,12 @@ #!/bin/bash -npx playwright install --with-deps ${BROWSERS} +set -e + +# Install Playwright browsers +# If _REMOTE_USER is set and not root, install as that user +# Otherwise install as root (test scenarios) +if [ -n "${_REMOTE_USER}" ] && [ "${_REMOTE_USER}" != "root" ] && id -u "${_REMOTE_USER}" > /dev/null 2>&1; then + su "${_REMOTE_USER}" -c "npx playwright install --with-deps ${BROWSERS}" +else + npx playwright install --with-deps ${BROWSERS} +fi diff --git a/test/playwright/scenarios.json b/test/playwright/scenarios.json index c66658a..e238e9f 100644 --- a/test/playwright/scenarios.json +++ b/test/playwright/scenarios.json @@ -14,5 +14,13 @@ "browsers": "firefox chromium" } } + }, + "test_user_install": { + "image": "ubuntu:focal", + "features": { + "playwright": { + "browsers": "chromium" + } + } } } \ No newline at end of file diff --git a/test/playwright/test_user_install.sh b/test/playwright/test_user_install.sh new file mode 100755 index 0000000..0061254 --- /dev/null +++ b/test/playwright/test_user_install.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +set -e + +source dev-container-features-test-lib + +# Test that Playwright is installed +check "Playwright is available" npx playwright --version + +# Check that browsers are installed in user's home directory (not root) +CURRENT_USER=$(whoami) +USER_HOME=$(eval echo ~${CURRENT_USER}) + +# Verify browser cache exists in the user's home directory +check "Browser cache in user home" test -d "${USER_HOME}/.cache/ms-playwright" + +# Verify the cache directory is owned by the current user +check "Browser cache owned by user" bash -c "[ \"\$(stat -c '%U' ${USER_HOME}/.cache/ms-playwright)\" = \"${CURRENT_USER}\" ]" + +# Verify browsers are not installed in root directory (if we're not root) +if [ "${CURRENT_USER}" != "root" ]; then + check "Browser cache not in root" bash -c "! test -d /root/.cache/ms-playwright || [ \"\$(ls -A /root/.cache/ms-playwright 2>/dev/null | wc -l)\" = \"0\" ]" +fi + +# Test that browsers can be listed (validates installation) +check "Can list browsers" npx playwright install --list + +# Verify the user can run playwright commands without permission issues +check "User can run playwright" bash -c 'npx playwright --help | grep -q "Usage"' + +reportResults \ No newline at end of file