testing out the validateAndMask() function, with console.log's...

This commit is contained in:
Stephen Ward 2018-09-23 13:49:00 -04:00
parent fd3de6be2c
commit add00ce563
3 changed files with 51 additions and 9 deletions

28
package-lock.json generated
View File

@ -3278,12 +3278,14 @@
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
@ -3298,17 +3300,20 @@
"code-point-at": { "code-point-at": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.2",
@ -3425,7 +3430,8 @@
"inherits": { "inherits": {
"version": "2.0.3", "version": "2.0.3",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.5",
@ -3437,6 +3443,7 @@
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"number-is-nan": "^1.0.0" "number-is-nan": "^1.0.0"
} }
@ -3451,6 +3458,7 @@
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
@ -3458,12 +3466,14 @@
"minimist": { "minimist": {
"version": "0.0.8", "version": "0.0.8",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"minipass": { "minipass": {
"version": "2.2.4", "version": "2.2.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"safe-buffer": "^5.1.1", "safe-buffer": "^5.1.1",
"yallist": "^3.0.0" "yallist": "^3.0.0"
@ -3482,6 +3492,7 @@
"version": "0.5.1", "version": "0.5.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
} }
@ -3562,7 +3573,8 @@
"number-is-nan": { "number-is-nan": {
"version": "1.0.1", "version": "1.0.1",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"object-assign": { "object-assign": {
"version": "4.1.1", "version": "4.1.1",
@ -3574,6 +3586,7 @@
"version": "1.4.0", "version": "1.4.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
@ -3695,6 +3708,7 @@
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"code-point-at": "^1.0.0", "code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",

View File

@ -1623,8 +1623,16 @@ function open(fs, context, path, flags, mode, callback) {
* callback = makeCallback(callback); * callback = makeCallback(callback);
* } * }
*/ */
if (arguments.length == 5){
callback = arguments[arguments.length - 1]; callback = arguments[arguments.length - 1];
}
else {
//need to test this validateAndMakeMode
console.log("open'd mode: " + mode)
mode = validateAndMaskMode(mode, FULL_READ_WRITE_EXEC_PERMISSIONS, callback);
console.log("mask'd mode: " + mode)
}
if(!pathCheck(path, callback)) return; if(!pathCheck(path, callback)) return;
function check_result(error, fileNode) { function check_result(error, fileNode) {
@ -1913,12 +1921,15 @@ function isUint32(value) {
// Validator for mode_t (the S_* constants). Valid numbers or octal strings // Validator for mode_t (the S_* constants). Valid numbers or octal strings
// will be masked with 0o777 to be consistent with the behavior in POSIX APIs. // will be masked with 0o777 to be consistent with the behavior in POSIX APIs.
function validateAndMaskMode(value, def, callback) { function validateAndMaskMode(value, def, callback) {
console.log("Passed in mode: " + value)
if(typeof def === 'function') { if(typeof def === 'function') {
callback = def; callback = def;
def = undefined; def = undefined;
} }
if (isUint32(value)) { if (isUint32(value)) {
let newMode = value & FULL_READ_WRITE_EXEC_PERMISSIONS;
console.log("Masked mode: " + newMode)
return value & FULL_READ_WRITE_EXEC_PERMISSIONS; return value & FULL_READ_WRITE_EXEC_PERMISSIONS;
} }
@ -1939,6 +1950,7 @@ function validateAndMaskMode(value, def, callback) {
return false; return false;
} }
var parsed = parseInt(value, 8); var parsed = parseInt(value, 8);
console.log("Parsed + Masekd mode: " + parsed & FULL_READ_WRITE_EXEC_PERMISSIONS)
return parsed & FULL_READ_WRITE_EXEC_PERMISSIONS; return parsed & FULL_READ_WRITE_EXEC_PERMISSIONS;
} }

View File

@ -106,6 +106,22 @@ describe('fs.open', function() {
}); });
}); });
it('should create a new file when flagged for write, and set the mode', function(done) {
var fs = util.fs();
fs.open('/myfile', 'w', 644, function(error) {
if(error) throw error;
fs.stat('/myfile', function(error, result) {
expect(error).not.to.exist;
expect(result).to.exist;
expect(result.type).to.equal('FILE');
expect(result.mode).to.exist;
expect(result.mode).to.equal(33188)
done();
});
});
});
/** /**
* This test is currently correct per our code, but incorrect according to the spec. * This test is currently correct per our code, but incorrect according to the spec.
* When we fix https://github.com/filerjs/filer/issues/314 we'll have to update this. * When we fix https://github.com/filerjs/filer/issues/314 we'll have to update this.