New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mock-fs

Package Overview
Dependencies
Maintainers
1
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mock-fs - npm Package Compare versions

Comparing version 3.6.0 to 3.7.0

6

changelog.md
# Change Log
## 3.7.0
* Add support for `fs.access()` and `fs.accessSync()` (thanks @shyiko, see [#78][#78] and [#80][#80]).
## 3.6.0

@@ -111,1 +115,3 @@

[#75]: https://github.com/tschaub/mock-fs/pull/75
[#78]: https://github.com/tschaub/mock-fs/pull/78
[#80]: https://github.com/tschaub/mock-fs/pull/80

@@ -832,2 +832,32 @@ 'use strict';

/**
* Tests user permissions.
* @param {string} filepath Path.
* @param {number} mode Mode.
* @param {function(Error)} callback Callback (optional).
*/
Binding.prototype.access = function(filepath, mode, callback) {
maybeCallback(callback, this, function() {
var item = this._system.getItem(filepath);
if (!item) {
throw new FSError('ENOENT', filepath);
}
if (mode && process.getuid && process.getgid) {
var itemMode = item.getMode();
if (item.getUid() === process.getuid()) {
if ((itemMode & (mode * 64)) !== mode * 64) {
throw new FSError('EACCES', filepath);
}
} else if (item.getGid() === process.getgid()) {
if ((itemMode & (mode * 8)) !== mode * 8) {
throw new FSError('EACCES', filepath);
}
} else {
if ((itemMode & mode) !== mode) {
throw new FSError('EACCES', filepath);
}
}
}
});
};

@@ -834,0 +864,0 @@ /**

2

package.json
{
"name": "mock-fs",
"description": "A configurable mock file system. You know, for testing.",
"version": "3.6.0",
"version": "3.7.0",
"main": "lib/index.js",

@@ -6,0 +6,0 @@ "homepage": "https://github.com/tschaub/mock-fs",

@@ -201,3 +201,3 @@ # `mock-fs`

The following [`fs` functions](http://nodejs.org/api/fs.html) are overridden: `fs.ReadStream`, `fs.Stats`, `fs.WriteStream`, `fs.appendFile`, `fs.appendFileSync`, `fs.chmod`, `fs.chmodSync`, `fs.chown`, `fs.chownSync`, `fs.close`, `fs.closeSync`, `fs.createReadStream`, `fs.createWriteStream`, `fs.exists`, `fs.existsSync`, `fs.fchmod`, `fs.fchmodSync`, `fs.fchown`, `fs.fchownSync`, `fs.fdatasync`, `fs.fdatasyncSync`, `fs.fstat`, `fs.fstatSync`, `fs.fsync`, `fs.fsyncSync`, `fs.ftruncate`, `fs.ftruncateSync`, `fs.futimes`, `fs.futimesSync`, `fs.lchmod`, `fs.lchmodSync`, `fs.lchown`, `fs.lchownSync`, `fs.link`, `fs.linkSync`, `fs.lstatSync`, `fs.lstat`, `fs.mkdir`, `fs.mkdirSync`, `fs.open`, `fs.openSync`, `fs.read`, `fs.readSync`, `fs.readFile`, `fs.readFileSync`, `fs.readdir`, `fs.readdirSync`, `fs.readlink`, `fs.readlinkSync`, `fs.realpath`, `fs.realpathSync`, `fs.rename`, `fs.renameSync`, `fs.rmdir`, `fs.rmdirSync`, `fs.stat`, `fs.statSync`, `fs.symlink`, `fs.symlinkSync`, `fs.truncate`, `fs.truncateSync`, `fs.unlink`, `fs.unlinkSync`, `fs.utimes`, `fs.utimesSync`, `fs.write`, `fs.writeSync`, `fs.writeFile`, and `fs.writeFileSync`.
The following [`fs` functions](http://nodejs.org/api/fs.html) are overridden: `fs.ReadStream`, `fs.Stats`, `fs.WriteStream`, `fs.access`, `fs.accessSync`, `fs.appendFile`, `fs.appendFileSync`, `fs.chmod`, `fs.chmodSync`, `fs.chown`, `fs.chownSync`, `fs.close`, `fs.closeSync`, `fs.createReadStream`, `fs.createWriteStream`, `fs.exists`, `fs.existsSync`, `fs.fchmod`, `fs.fchmodSync`, `fs.fchown`, `fs.fchownSync`, `fs.fdatasync`, `fs.fdatasyncSync`, `fs.fstat`, `fs.fstatSync`, `fs.fsync`, `fs.fsyncSync`, `fs.ftruncate`, `fs.ftruncateSync`, `fs.futimes`, `fs.futimesSync`, `fs.lchmod`, `fs.lchmodSync`, `fs.lchown`, `fs.lchownSync`, `fs.link`, `fs.linkSync`, `fs.lstatSync`, `fs.lstat`, `fs.mkdir`, `fs.mkdirSync`, `fs.open`, `fs.openSync`, `fs.read`, `fs.readSync`, `fs.readFile`, `fs.readFileSync`, `fs.readdir`, `fs.readdirSync`, `fs.readlink`, `fs.readlinkSync`, `fs.realpath`, `fs.realpathSync`, `fs.rename`, `fs.renameSync`, `fs.rmdir`, `fs.rmdirSync`, `fs.stat`, `fs.statSync`, `fs.symlink`, `fs.symlinkSync`, `fs.truncate`, `fs.truncateSync`, `fs.unlink`, `fs.unlinkSync`, `fs.utimes`, `fs.utimesSync`, `fs.write`, `fs.writeSync`, `fs.writeFile`, and `fs.writeFileSync`.

@@ -204,0 +204,0 @@ Mock `fs.Stats` objects have the following properties: `dev`, `ino`, `nlink`, `mode`, `size`, `rdev`, `blksize`, `blocks`, `atime`, `ctime`, `mtime`, `birthtime`, `uid`, and `gid`. In addition, all of the `is*()` method are provided (e.g. `isDirectory()`, `isFile()`, et al.).

@@ -1261,2 +1261,53 @@ /* eslint-env mocha */

describe('#access()', function() {
it('works if file exists', function() {
var binding = new Binding(system);
var pathname = path.join('mock-dir', 'one-link.txt');
binding.access(pathname);
});
if (process.getuid && process.getgid) {
it('fails in case of insufficient user permissions', function() {
var binding = new Binding(system);
var item = system.getItem(path.join('mock-dir', 'one.txt'));
item.setMode(parseInt('0077', 8));
assert.throws(function() {
binding.access(path.join('mock-dir', 'one.txt'), 1);
}, /EACCES/);
});
it('fails in case of insufficient group permissions', function() {
var binding = new Binding(system);
var item = system.getItem(path.join('mock-dir', 'one.txt'));
item.setUid(process.getuid() + 1);
item.setMode(parseInt('0707', 8));
assert.throws(function() {
binding.access(path.join('mock-dir', 'one.txt'), 2);
}, /EACCES/);
});
it('fails in case of insufficient permissions', function() {
var binding = new Binding(system);
var item = system.getItem(path.join('mock-dir', 'one.txt'));
item.setUid(process.getuid() + 1);
item.setGid(process.getgid() + 1);
item.setMode(parseInt('0771', 8));
assert.throws(function() {
binding.access(path.join('mock-dir', 'one.txt'), 5);
}, /EACCES/);
});
}
it('fails for bogus paths', function() {
var binding = new Binding(system);
assert.throws(function() {
binding.access(path.join('mock-dir', 'bogus'));
}, /ENOENT/);
});
});
});

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc