Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add 'static' plugin tests of 404s for #1382 #1391

Merged
merged 1 commit into from Jun 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions test/plugins/static.test.js
Expand Up @@ -232,6 +232,37 @@ describe('static resource plugin', function () {
testNoAppendPath(done, false, '.tmp', null, true);
});

it('static responds 404 for missing file', function (done) {
var p = '/public/no-such-file.json';
var tmpPath = path.join(process.cwd(), '.tmp');

SERVER.get(new RegExp('/public/.*'),
restify.plugins.serveStatic({directory: tmpPath}));

CLIENT.get(p, function (err, req, res, obj) {
assert.ok(err);
assert.strictEqual(err.statusCode, 404);
assert.strictEqual(err.restCode, 'ResourceNotFound');
done();
});
});

it('GH-1382 static responds 404 for missing file with percent-codes',
function (done) {
var p = '/public/no-%22such-file.json';
var tmpPath = path.join(process.cwd(), '.tmp');

SERVER.get(new RegExp('/public/.*'),
restify.plugins.serveStatic({directory: tmpPath}));

CLIENT.get(p, function (err, req, res, obj) {
assert.ok(err);
assert.equal(err.statusCode, 404);
assert.equal(err.restCode, 'ResourceNotFound');
done();
});
});

// To ensure this will always get properly restored (even in case of a test
// failure) we do it here.
var originalCreateReadStream = fs.createReadStream;
Expand Down