Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 825842c

Browse filesBrowse files
sam-githubItalo A. Casas
authored andcommitted
test: getgroups() may contain duplicate GIDs
Some systems may have multiple group names with the same group ID, in which case getgroups() returns duplicate values, where `id -G` will filter the duplicates. Unique and sort the arrays so they can be compared. PR-URL: #10389 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
1 parent c6618df commit 825842c
Copy full SHA for 825842c

File tree

Expand file treeCollapse file tree

1 file changed

+11
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-5
lines changed
Open diff view settings
Collapse file
+11-5Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
'use strict';
22
const common = require('../common');
3-
const assert = require('assert');
4-
const exec = require('child_process').exec;
3+
4+
// Check `id -G` and `process.getgroups()` return same groups.
55

66
if (common.isOSX) {
77
common.skip('Output of `id -G` is unreliable on Darwin.');
88
return;
99
}
10+
const assert = require('assert');
11+
const exec = require('child_process').exec;
1012

1113
if (typeof process.getgroups === 'function') {
12-
const groups = process.getgroups();
14+
const groups = unique(process.getgroups());
1315
assert(Array.isArray(groups));
1416
assert(groups.length > 0);
1517
exec('id -G', function(err, stdout) {
1618
assert.ifError(err);
17-
const real_groups = stdout.match(/\d+/g).map(Number);
18-
assert.strictEqual(groups.length, real_groups.length);
19+
const real_groups = unique(stdout.match(/\d+/g).map(Number));
20+
assert.deepStrictEqual(groups, real_groups);
1921
check(groups, real_groups);
2022
check(real_groups, groups);
2123
});
@@ -24,3 +26,7 @@ if (typeof process.getgroups === 'function') {
2426
function check(a, b) {
2527
for (let i = 0; i < a.length; ++i) assert.notStrictEqual(b.indexOf(a[i]), -1);
2628
}
29+
30+
function unique(groups) {
31+
return [...new Set(groups)].sort();
32+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.