Skip to content

Commit c7a165a

Browse files
erikkempermanphated
authored andcommitted
Build: Check mode of not-owned.txt & avoid repeated notices (#232)
1 parent 28d3ba0 commit c7a165a

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ node_js:
88
- '0.10'
99
before_script:
1010
- find test -type d -exec chmod g+s {} \;
11-
- sudo chown root test/fixtures/not-owned/
1211
- sudo chown root test/fixtures/not-owned/not-owned.txt
12+
- sudo chmod 666 test/fixtures/not-owned/not-owned.txt
1313
after_script:
1414
- npm run coveralls

test/not-owned.js

+27-7
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,38 @@ var clean = cleanup();
2323

2424
describe('.dest() on not owned files', function() {
2525

26-
var dirStats = fs.statSync(notOwnedBase);
2726
var fileStats = fs.statSync(notOwnedPath);
2827

2928
beforeEach(clean);
3029
afterEach(clean);
3130

31+
var seenActions = false;
32+
33+
function needsAction() {
34+
var problems = [];
35+
var actions = [];
36+
if (fileStats.uid !== 0) {
37+
problems.push('Test files not owned by root.');
38+
actions.push(' sudo chown root ' + notOwnedPath);
39+
}
40+
if ((fileStats.mode & parseInt('022', 8)) !== parseInt('022', 8)) {
41+
problems.push('Test files not readable/writable by non-owners.');
42+
actions.push(' sudo chmod 666 ' + notOwnedPath);
43+
}
44+
if (actions.length > 0) {
45+
if (!seenActions) {
46+
console.log(problems.join('\n'));
47+
console.log('Please run the following commands and try again:');
48+
console.log(actions.join('\n'));
49+
seenActions = true;
50+
}
51+
return true;
52+
}
53+
return false;
54+
}
55+
3256
it('does not error if mtime is different', function(done) {
33-
if (dirStats.uid !== 0 || fileStats.uid !== 0) {
34-
console.log('Test files not owned by root.');
35-
console.log('Please chown ' + notOwnedBase + ' and ' + notOwnedPath + ' and try again.');
57+
if (needsAction()) {
3658
this.skip();
3759
return;
3860
}
@@ -62,9 +84,7 @@ describe('.dest() on not owned files', function() {
6284
});
6385

6486
it('does not error if mode is different', function(done) {
65-
if (dirStats.uid !== 0 || fileStats.uid !== 0) {
66-
console.log('Test files not owned by root.');
67-
console.log('Please chown ' + notOwnedBase + ' and ' + notOwnedPath + ' and try again.');
87+
if (needsAction()) {
6888
this.skip();
6989
return;
7090
}

0 commit comments

Comments
 (0)