A mock directory set with 0555 mode should fail to write with EACCES error when attempting to write to a new file in that directory.
Actual
You can successfully write a new file.
Steps to Reproduce
This test shows the steps to reproduce.
'use strict';
const helper = require('../helper');
const fs = require('fs');
const mock = require('../../lib/index');
const assert = helper.assert;
describe('testing directory write permissions', function() {
beforeEach(function() {
mock({
'mod/444': mock.directory({mode: 0o444}),
'mod/555': mock.directory({mode: 0o555})
});
});
afterEach(mock.restore);
it('generates EACCES for W_OK and 555', function(done) {
fs.access('mod/555', fs.W_OK, function(err) {
assert.instanceOf(err, Error);
assert.equal(err.code, 'EACCES');
done();
});
});
it('fails to write to dir with 0444 mode', function(done) {
fs.writeFile('mod/444/should-fail', 'bar', 'utf8', function(err) {
assert.instanceOf(err, Error);
assert.equal(err.code, 'EACCES');
done();
});
});
it('fails to write to dir with 0555 mode', function(done) {
fs.writeFile('mod/555/should-fail', 'bar', 'utf8', function(err) {
if (err) {
assert.instanceOf(err, Error);
assert.equal(err.code, 'EACCES');
return done(err);
} else {
const val = fs.readFileSync('mod/555/should-fail');
assert.fail(`did not throw EACCES error - file contents: ${val}`);
done();
}
});
});
});
The output of the test
1) testing directory write permissions
fails to write to dir with 0555 mode:
Uncaught AssertionError: did not throw EACCES error - file contents: bar
at /Users/winston/dev/github/tschaub/mock-fs/test/lib/555.spec.js:42:16
at FSReqCallback.oncomplete (fs.js:155:23)
at /Users/winston/dev/github/tschaub/mock-fs/lib/binding.js:88:9
at processTicksAndRejections (internal/process/task_queues.js:79:11)
Expected
A mock directory set with
0555
mode should fail to write withEACCES
error when attempting to write to a new file in that directory.Actual
You can successfully write a new file.
Steps to Reproduce
This test shows the steps to reproduce.
The output of the test