@@ -23,16 +23,38 @@ var clean = cleanup();
23
23
24
24
describe ( '.dest() on not owned files' , function ( ) {
25
25
26
- var dirStats = fs . statSync ( notOwnedBase ) ;
27
26
var fileStats = fs . statSync ( notOwnedPath ) ;
28
27
29
28
beforeEach ( clean ) ;
30
29
afterEach ( clean ) ;
31
30
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
+
32
56
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 ( ) ) {
36
58
this . skip ( ) ;
37
59
return ;
38
60
}
@@ -62,9 +84,7 @@ describe('.dest() on not owned files', function() {
62
84
} ) ;
63
85
64
86
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 ( ) ) {
68
88
this . skip ( ) ;
69
89
return ;
70
90
}
0 commit comments