Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use process.geteuid and catch uid errors in file util #17488

Merged
merged 7 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions cli/test/lib/tasks/verify_spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-restricted-properties */
require('../../spec_helper')

const path = require('path')
Expand Down
1 change: 1 addition & 0 deletions packages/electron/lib/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fs = Promise.promisifyAll(fs)
* If running as root on Linux, no-sandbox must be passed or Chrome will not start
*/
const isSandboxNeeded = () => {
// eslint-disable-next-line no-restricted-properties
return (os.platform() === 'linux') && (process.geteuid() === 0)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/server/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": [
"plugin:@cypress/dev/tests"
"../../.eslintrc.json"
],
"parser": "@typescript-eslint/parser",
"env": {
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 packages/server/test/e2e/2_cookies_spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-restricted-properties */
import dayjs from 'dayjs'
import parser from 'cookie-parser'
import e2e from '../support/helpers/e2e'
Expand Down
1 change: 1 addition & 0 deletions packages/server/test/integration/cypress_spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-restricted-properties */
require('../spec_helper')

const R = require('ramda')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-restricted-properties */
const fs = require('fs')
const { expect } = require('chai')

Expand Down