-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve permissions support (#1059)
* test: Add tests for permissions * feat: Add permissions implementations to Volume * fix: Side effects test pollution in chmod() test * fix: Improper handling of O_EXCL in openFile() * fix: No longer check execute permission on files in mkdirp While files are not a permitted place to create subdirectories in, the proper error should be ENOTDIR, not EACCES * test: Add tests for recursive mkdir * test: Add tests for chmodSync * fix: No longer require permissions to chmod * test: Add more extensive tests for mkdir recursive mode * refactor: Inline tree walking * chore: cleanup * style: Run prettier * test: Improve testing for missing permissions on intermediate directories * chore: cleanup * style: run prettier * fix: utimes should not require permissions
- Loading branch information
1 parent
764ab58
commit 575a76b
Showing
28 changed files
with
1,208 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { create } from '../util'; | ||
|
||
describe('chmodSync', () => { | ||
it('should be able to chmod files and directories owned by the UID regardless of their permissions', () => { | ||
const perms = [ | ||
0o777, // rwx | ||
0o666, // rw | ||
0o555, // rx | ||
0o444, // r | ||
0o333, // wx | ||
0o222, // w | ||
0o111, // x | ||
0o000, // none | ||
]; | ||
// Check for directories | ||
perms.forEach(perm => { | ||
const vol = create({}); | ||
vol.mkdirSync('/foo', { mode: perm }); | ||
expect(() => { | ||
vol.chmodSync('/foo', 0o777); | ||
}).not.toThrow(); | ||
}); | ||
// Check for files | ||
perms.forEach(perm => { | ||
const vol = create({ '/foo': 'foo' }); | ||
expect(() => { | ||
vol.chmodSync('/foo', 0o777); | ||
}).not.toThrow(); | ||
}); | ||
}); | ||
|
||
it('should chmod the target of a symlink, not the symlink itself', () => { | ||
const vol = create({ '/target': 'contents' }); | ||
vol.symlinkSync('/target', '/link'); | ||
const expectedLink = vol.lstatSync('/link').mode; | ||
const expectedTarget = vol.statSync('/target').mode & ~0o777; | ||
vol.chmodSync('/link', 0); | ||
|
||
expect(vol.lstatSync('/link').mode).toEqual(expectedLink); | ||
expect(vol.statSync('/target').mode).toEqual(expectedTarget); | ||
}); | ||
|
||
it.skip('should throw EPERM when trying to chmod targets not owned by the uid', () => { | ||
const uid = process.getuid() + 1; | ||
// Check for directories | ||
const vol = create({}); | ||
vol.mkdirSync('/foo'); | ||
vol.chownSync('/foo', uid, process.getgid()); | ||
expect(() => { | ||
vol.chmodSync('/foo', 0o777); | ||
}).toThrow(/PERM/); | ||
}); | ||
|
||
it("should throw ENOENT when target doesn't exist", () => { | ||
const vol = create({}); | ||
expect(() => { | ||
vol.chmodSync('/foo', 0o777); | ||
}).toThrow(/ENOENT/); | ||
}); | ||
|
||
it('should throw EACCES when containing directory has insufficient permissions', () => { | ||
const vol = create({ '/foo/test': 'test' }); | ||
vol.chmodSync('/foo', 0o666); // rw | ||
expect(() => { | ||
vol.chmodSync('/foo/test', 0o777); | ||
}).toThrow(/EACCES/); | ||
}); | ||
|
||
it('should throw EACCES when intermediate directory has insufficient permissions', () => { | ||
const vol = create({ '/foo/test': 'test' }); | ||
vol.chmodSync('/', 0o666); // rw | ||
expect(() => { | ||
vol.chmodSync('/foo/test', 0o777); | ||
}).toThrow(/EACCES/); | ||
}); | ||
}); |
Oops, something went wrong.