This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
tstatic/tests/server.test.ts

125 lines
4.4 KiB
TypeScript
Raw Normal View History

2017-02-19 18:19:45 +00:00
import { expect } from 'chai';
import { runServer } from './helpers';
2017-02-19 19:01:53 +00:00
import * as fs from 'fs';
2017-02-19 22:01:43 +00:00
import * as path from 'path';
2017-07-08 12:14:20 +01:00
import { Options } from '../src/types';
2017-02-19 18:19:45 +00:00
2017-07-08 12:14:20 +01:00
const PKG = require('../package.json');
2017-02-19 18:19:45 +00:00
describe('Server', function () {
it('Should be usable', function (done) {
runServer({
allowed_ips: [],
basicAuth: [],
dirList: false,
serveDir: 'site/',
opbeat: false,
open: false
}, '/index.html', function (response : any) {
expect(response.status).to.equal(200);
expect(response.url).to.include('/index.html');
done();
});
});
2017-02-19 19:01:53 +00:00
describe('index route', function () {
2017-02-19 22:01:43 +00:00
const body = fs.readFileSync(path.join(__dirname, '..', 'site', 'index.html')).toString();
2017-02-19 19:01:53 +00:00
['', '/', '/index.html'].forEach(function (path : string) {
it('should render ' + path, function (done) {
runServer({
allowed_ips: [],
basicAuth: [],
dirList: false,
serveDir: 'site/',
opbeat: false,
open: false
}, path, function (response : any) {
expect(response.status).to.equal(200);
2017-02-19 21:53:06 +00:00
expect(response.text()).to.eventually.equal(body).notify(done);
2017-02-19 19:01:53 +00:00
});
});
});
});
2017-07-08 12:14:20 +01:00
describe('secure headers', function () {
const SERVER_SETTINGS = {
allowed_ips: [],
basicAuth: [],
dirList: false,
serveDir: 'site/',
opbeat: false,
open: false
} as Options;
it('Should have no powered by header', function (done) {
runServer(SERVER_SETTINGS, '/index.html', function (response : any) {
expect(response.status).to.equal(200);
expect(response.headers.get('x-powered-by')).to.contain('tstatic');
expect(response.headers.get('x-powered-by')).to.contain(PKG.version);
done();
});
});
it('Should have xss block header', function (done) {
runServer(SERVER_SETTINGS, '/index.html', function (response : any) {
expect(response.status).to.equal(200);
expect(response.headers.get('x-xss-protection')).to.equal('1; mode=block');
done();
});
});
it('Should block iframes', function (done) {
runServer(SERVER_SETTINGS, '/index.html', function (response : any) {
expect(response.status).to.equal(200);
expect(response.headers.get('x-frame-options')).to.equal('SAMEORIGIN');
done();
});
});
it('Should have expect-ct header', function (done) {
runServer(SERVER_SETTINGS, '/index.html', function (response : any) {
expect(response.status).to.equal(200);
expect(response.headers.get('expect-ct')).to.equal('max-age=1000');
done();
});
});
it('Should block DNS prefetch', function (done) {
runServer(SERVER_SETTINGS, '/index.html', function (response : any) {
expect(response.status).to.equal(200);
expect(response.headers.get('x-dns-prefetch-control')).to.equal('off');
done();
});
});
it('Should block open on IE', function (done) {
runServer(SERVER_SETTINGS, '/index.html', function (response : any) {
expect(response.status).to.equal(200);
expect(response.headers.get('x-download-options')).to.equal('noopen');
done();
});
});
it('Should block cache', function (done) {
runServer(SERVER_SETTINGS, '/index.html', function (response : any) {
expect(response.status).to.equal(200);
expect(response.headers.get('cache-control')).to.contain('no-store');
expect(response.headers.get('cache-control')).to.contain('no-cache');
expect(response.headers.get('pragma')).to.contain('no-cache');
expect(response.headers.get('surrogate-control')).to.contain('no-store');
expect(response.headers.get('expires')).to.contain(0);
done();
});
});
it('Should block cache', function (done) {
runServer(SERVER_SETTINGS, '/index.html', function (response : any) {
expect(response.status).to.equal(200);
expect(response.headers.get('referrer-policy')).to.contain('same-origin');
done();
});
});
});
2017-02-19 18:19:45 +00:00
});