Comparing version 2.1.0 to 2.1.1
@@ -208,3 +208,11 @@ // Load modules | ||
if (err) { | ||
return callback(Boom.notFound()); | ||
if (err.code === 'ENOENT') { | ||
return callback(Boom.notFound()); | ||
} | ||
if (err.code === 'EACCES' || err.code === 'EPERM') { | ||
return callback(Boom.forbidden()); | ||
} | ||
return callback(Boom.wrap(err, null, 'failed to open file')); | ||
} | ||
@@ -211,0 +219,0 @@ |
{ | ||
"name": "inert", | ||
"description": "Static file and directory handlers plugin for hapi.js", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"repository": "git://github.com/hapijs/inert", | ||
@@ -6,0 +6,0 @@ "main": "index", |
@@ -939,2 +939,80 @@ // Load modules | ||
it('returns error when open fails unexpectedly', function (done) { | ||
var filename = Hoek.uniqueFilename(Os.tmpDir()) + '.package.json'; | ||
Fs.writeFileSync(filename, 'data'); | ||
var orig = Fs.open; | ||
Fs.open = function () { // can return EMFILE error | ||
Fs.open = orig; | ||
var callback = arguments[arguments.length - 1]; | ||
callback(new Error('failed')); | ||
}; | ||
var server = provisionServer(); | ||
server.route({ method: 'GET', path: '/', handler: { file: filename } }); | ||
server.inject('/', function (res) { | ||
expect(res.statusCode).to.equal(500); | ||
done(); | ||
}); | ||
}); | ||
it('returns a 403 when missing file read permission', function (done) { | ||
var filename = Hoek.uniqueFilename(Os.tmpDir()) + '.package.json'; | ||
Fs.writeFileSync(filename, 'data'); | ||
var fd; | ||
if (process.platform === 'win32') { | ||
// make a permissionless file by unlinking an open file | ||
fd = Fs.openSync(filename, 'r'); | ||
Fs.unlinkSync(filename); | ||
} else { | ||
Fs.chmodSync(filename, 0); | ||
} | ||
var server = provisionServer(); | ||
server.route({ method: 'GET', path: '/', handler: { file: filename } }); | ||
server.inject('/', function (res1) { | ||
var orig = Fs.open; | ||
Fs.open = function (path, mode, callback) { // fake alternate permission error | ||
Fs.open = orig; | ||
return Fs.open(path, mode, function(err, fd) { | ||
if (err) { | ||
if (err.code === 'EACCES') { | ||
err.code = 'EPERM'; | ||
err.errno = -1; | ||
} else if (err.code === 'EPERM') { | ||
err.code = 'EPERM'; | ||
err.errno = -13; | ||
} | ||
} | ||
return callback(err, fd); | ||
}); | ||
}; | ||
server.inject('/', function (res2) { | ||
// cleanup | ||
if (typeof fd === 'number') { | ||
Fs.closeSync(fd); | ||
} else { | ||
Fs.unlinkSync(filename); | ||
} | ||
expect(res1.statusCode).to.equal(403); | ||
expect(res2.statusCode).to.equal(403); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe('response range', function () { | ||
@@ -941,0 +1019,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
363482
1743