Skip to content

Commit

Permalink
chore: add dotfiles test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed May 25, 2020
1 parent 5953004 commit 07c65ac
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function lookup(filepath, enc) {
return CACHE[filepath] = {
data: filedata,
size: stats.size,
type: mime.getType(full)
type: mime.getType(full) || ''
};
}

Expand Down
61 changes: 61 additions & 0 deletions tests/sirv.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,64 @@ single('should use custom fallback when `single` is a string', async () => {
});

single.run();

// ---

const dotfiles = suite('dotfiles');

dotfiles('should reject hidden files (dotfiles) by default', async () => {
let server = utils.http();

try {
await server.send('GET', '/.hello').catch(err => {
assert.is(err.statusCode, 404);
});

await server.send('GET', '/foo/.world').catch(err => {
assert.is(err.statusCode, 404);
});
} finally {
server.close();
}
});

dotfiles('should treat dotfiles with fallback during `single` mode', async () => {
let server = utils.http({ single: true });

try {
let res1 = await server.send('GET', '/.hello');
await utils.matches(res1, 200, 'index.html', 'utf8');

let res2 = await server.send('GET', '/foo/.world');
await utils.matches(res2, 200, 'index.html', 'utf8');
} finally {
server.close();
}
});

dotfiles.only('should always allow access to ".well-known" directory contents', async () => {
let server = utils.http();

try {
let res = await server.send('GET', '/.well-known/example');
await utils.matches(res, 200, '.well-known/example', 'utf8');
} finally {
server.close();
}
});

dotfiles('should allow requests to hidden files only when enabled', async () => {
let server = utils.http({ dotfiles: true });

try {
let res1 = await server.send('GET', '/.hello');
await utils.matches(res1, 200, '.hello', 'utf8');

let res2 = await server.send('GET', '/foo/.world');
await utils.matches(res2, 200, 'foo/.world', 'utf8');
} finally {
server.close();
}
});

dotfiles.run();

0 comments on commit 07c65ac

Please sign in to comment.