File: root-user.js

package info (click to toggle)
node-yarnpkg 1.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 92,980 kB
  • sloc: sh: 323; makefile: 19
file content (24 lines) | stat: -rw-r--r-- 590 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* @flow */

import {isRootUser, isFakeRoot} from '../../src/util/root-user.js';

test('isRootUser', () => {
  expect(isRootUser(null)).toBe(false);
  expect(isRootUser(1001)).toBe(false);
  expect(isRootUser(0)).toBe(true);
});

test('isFakeRoot', () => {
  const hasFakerootPreviously = 'FAKEROOTKEY' in process.env;
  const oldValue = process.env.FAKEROOTKEY;
  delete process.env.FAKEROOTKEY;

  expect(isFakeRoot()).toBe(false);

  process.env.FAKEROOTKEY = '15574641';
  expect(isFakeRoot()).toBe(true);

  if (hasFakerootPreviously) {
    process.env.FAKEROOTKEY = oldValue;
  }
});