Skip to content

Commit

Permalink
fix: use process.geteuid and catch uid errors in file util (#17488)
Browse files Browse the repository at this point in the history
Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
  • Loading branch information
flotwig and jennifer-shehane committed Jul 30, 2021
1 parent 13f792c commit 209efa4
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 3 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
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

4 comments on commit 209efa4

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 209efa4 Jul 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/8.1.1/circle-develop-209efa433d5dfe3efbaf141c231faea3fe44785c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 209efa4 Jul 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/8.1.1/appveyor-develop-209efa433d5dfe3efbaf141c231faea3fe44785c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 209efa4 Jul 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/8.1.1/appveyor-develop-209efa433d5dfe3efbaf141c231faea3fe44785c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 209efa4 Jul 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/8.1.1/circle-develop-209efa433d5dfe3efbaf141c231faea3fe44785c/cypress.tgz

Please sign in to comment.