Skip to content

Commit

Permalink
fix: use process.geteuid and catch uid errors in file util
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed Jul 26, 2021
1 parent 69d2da1 commit 5dffac0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
15 changes: 14 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,20 @@
"rules": {
"prefer-spread": "off",
"prefer-rest-params": "off",
"no-useless-constructor": "off"
"no-useless-constructor": "off",
"no-restricted-properties": [
"error",
{
"object": "process",
"property": "geteuid",
"message": "process.geteuid() will throw on Windows. Do not use it unless you catch any potential errors."
},
{
"object": "os",
"property": "userInfo",
"message": "os.userInfo() will throw when there is not an `/etc/passwd` entry for the current user (like when running with --user 12345 in Docker). Do not use it unless you catch any potential errors."
}
]
},
"settings": {
"react": {
Expand Down
5 changes: 1 addition & 4 deletions packages/server/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
{
"extends": [
"plugin:@cypress/dev/tests"
"../../.eslintrc.json"
],
"parser": "@typescript-eslint/parser",
"env": {
"cypress/globals": true
},
"plugins": [
"cypress"
]
Expand Down
13 changes: 12 additions & 1 deletion packages/server/lib/util/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ const { default: pQueue } = require('p-queue')
const DEBOUNCE_LIMIT = 1000
const LOCK_TIMEOUT = 2000

function getUid () {
try {
// eslint-disable-next-line no-restricted-properties
return process.geteuid()
} catch (err) {
// process.geteuid() can fail, return a constant
// @see https://github.com/cypress-io/cypress/issues/17415
return 1
}
}

class File {
constructor (options = {}) {
if (!options.path) {
Expand All @@ -23,7 +34,7 @@ class File {

// If multiple users write to a specific directory is os.tmpdir, permission errors can arise.
// Instead, we make a user specific directory with os.tmpdir.
this._lockFileDir = path.join(os.tmpdir(), `cypress-${os.userInfo().uid}`)
this._lockFileDir = path.join(os.tmpdir(), `cypress-${getUid()()}`)
this._lockFilePath = path.join(this._lockFileDir, `${md5(this.path)}.lock`)

this._queue = new pQueue({ concurrency: 1 })
Expand Down
1 change: 1 addition & 0 deletions scripts/run-docker-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ echo "You should be able to edit files locally"
echo "but execute the code in the container"

docker run -v $PWD:/home/person/cypress \
--user 12345 \
-w /home/person/cypress${WORKING_DIR:-} \
-it $name \
/bin/bash

0 comments on commit 5dffac0

Please sign in to comment.