| Server IP : 34.87.99.72 / Your IP : 216.73.217.31 Web Server : Apache/2.4.46 (Unix) OpenSSL/1.1.1n System : Linux zlock-bitnami-lamp-prod-v2-vm 4.19.0-16-cloud-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64 User : bitnami ( 1000) PHP Version : 7.4.18 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /opt/bitnami/nami/node_modules/chai-fs/lib/assertions/ |
Upload File : |
module.exports = function (chai, utils) {
var Assertion = chai.Assertion;
var flag = utils.flag;
var assert = chai.assert;
var fs = require('fs');
var BitMask = require('bit-mask');
// ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
//
// implemented but disabled until I find a good cross-platform way to implement and test this
//
// ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
/* jshint -W026 */
return;
//-------------------------------------------------------------------------------------------------------------
function statPermissionXNix(file, permission) {
var stat = fs.statSync(file);
var mask = new BitMask.OwnershipMask(stat.mode);
var ret = mask.hasPermission('world', permission);
ret = ret || (process.gid === stat.gid && mask.hasPermission('group', permission));
ret = ret || (process.uid === stat.uid && mask.hasPermission('user', permission));
return ret;
}
function canReadFile(file) {
// BEH!
if (process.platform === 'win32') {
return true;
}
if (process.platform === 'darwin' || process.platform === 'linux') {
return statPermissionXNix(file, 'read');
}
return false;
}
function canWriteFile(file) {
// BEH!
if (process.platform === 'win32') {
return true;
}
if (process.platform === 'darwin' || process.platform === 'linux') {
return statPermissionXNix(file, 'write');
}
return false;
}
function canExecuteFile(file) {
// BEH!
if (process.platform === 'win32') {
return true;
}
if (process.platform === 'darwin' || process.platform === 'linux') {
return statPermissionXNix(file, 'execute');
}
return false;
}
//-------------------------------------------------------------------------------------------------------------
Assertion.addMethod('readable', function (msg) {
var preMsg = '';
if (msg) {
flag(this, 'message', msg);
preMsg = msg + ': ';
}
var obj = this._obj;
new chai.Assertion(obj, preMsg + 'value').is.a('string');
new chai.Assertion(obj, preMsg + 'value').to.be.a.path();
var pass = canReadFile(obj);
this.assert(
pass
, "expected #{this} to be readable"
, "expected #{this} not to be readable"
);
});
assert.pathReadable = function (val, msg) {
new chai.Assertion(val).to.be.readable(msg);
};
assert.notPathReadable = function (val, msg) {
new chai.Assertion(val).to.not.be.readable(msg);
};
//-------------------------------------------------------------------------------------------------------------
Assertion.addMethod('writable', function (msg) {
var preMsg = '';
if (msg) {
flag(this, 'message', msg);
preMsg = msg + ': ';
}
var obj = this._obj;
new chai.Assertion(obj, preMsg + 'value').is.a('string');
new chai.Assertion(obj, preMsg + 'value').to.be.a.path();
var pass = canWriteFile(obj);
this.assert(
pass
, "expected #{this} to be writable"
, "expected #{this} not to be writable"
);
});
assert.pathWritable = function (val, msg) {
new chai.Assertion(val).to.be.writable(msg);
};
assert.notPathWritable = function (val, msg) {
new chai.Assertion(val).to.not.be.writable(msg);
};
//-------------------------------------------------------------------------------------------------------------
Assertion.addMethod('executable', function (msg) {
var preMsg = '';
if (msg) {
flag(this, 'message', msg);
preMsg = msg + ': ';
}
var obj = this._obj;
new chai.Assertion(obj, preMsg + 'value').is.a('string');
new chai.Assertion(obj, preMsg + 'value').to.be.a.path();
var pass = canExecuteFile(obj);
this.assert(
pass
, "expected #{this} to be executable"
, "expected #{this} not to be executable"
);
});
assert.pathExecutable = function (val, msg) {
new chai.Assertion(val).to.be.executable(msg);
};
assert.notPathExecutable = function (val, msg) {
new chai.Assertion(val).to.not.be.executable(msg);
};
};