2015-05-18 21:12:42 +03:00
|
|
|
var should = require('should'),
|
|
|
|
sinon = require('sinon'),
|
2016-10-11 11:36:00 +03:00
|
|
|
cacheControl = require('../../../server/middleware/cache-control');
|
2015-05-18 21:12:42 +03:00
|
|
|
|
|
|
|
describe('Middleware: cacheControl', function () {
|
|
|
|
var sandbox,
|
|
|
|
res;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
sandbox = sinon.sandbox.create();
|
|
|
|
|
|
|
|
res = {
|
|
|
|
set: sinon.spy()
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
sandbox.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('correctly sets the public profile headers', function (done) {
|
2016-10-11 11:36:00 +03:00
|
|
|
cacheControl('public')(null, res, function (a) {
|
2015-05-18 21:12:42 +03:00
|
|
|
should.not.exist(a);
|
2016-02-08 00:27:01 +03:00
|
|
|
res.set.calledOnce.should.be.true();
|
2015-05-18 21:12:42 +03:00
|
|
|
res.set.calledWith({'Cache-Control': 'public, max-age=0'});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('correctly sets the private profile headers', function (done) {
|
2016-10-11 11:36:00 +03:00
|
|
|
cacheControl('private')(null, res, function (a) {
|
2015-05-18 21:12:42 +03:00
|
|
|
should.not.exist(a);
|
2016-02-08 00:27:01 +03:00
|
|
|
res.set.calledOnce.should.be.true();
|
2015-05-18 21:12:42 +03:00
|
|
|
res.set.calledWith({
|
|
|
|
'Cache-Control':
|
|
|
|
'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0'
|
|
|
|
});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('will not set headers without a profile', function (done) {
|
2016-10-11 11:36:00 +03:00
|
|
|
cacheControl()(null, res, function (a) {
|
2015-05-18 21:12:42 +03:00
|
|
|
should.not.exist(a);
|
2016-02-08 00:27:01 +03:00
|
|
|
res.set.called.should.be.false();
|
2015-05-18 21:12:42 +03:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('will not get confused between serving public and private', function (done) {
|
2016-10-11 11:36:00 +03:00
|
|
|
var publicCC = cacheControl('public'),
|
|
|
|
privateCC = cacheControl('private');
|
2015-05-18 21:12:42 +03:00
|
|
|
|
2015-10-12 19:54:15 +03:00
|
|
|
publicCC(null, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.set.calledOnce.should.be.true();
|
2015-05-18 21:12:42 +03:00
|
|
|
res.set.calledWith({'Cache-Control': 'public, max-age=0'});
|
|
|
|
|
2015-10-12 19:54:15 +03:00
|
|
|
privateCC(null, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.set.calledTwice.should.be.true();
|
2015-05-18 21:12:42 +03:00
|
|
|
res.set.calledWith({
|
|
|
|
'Cache-Control':
|
|
|
|
'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0'
|
|
|
|
});
|
|
|
|
|
2015-10-12 19:54:15 +03:00
|
|
|
publicCC(null, res, function () {
|
2016-02-08 00:27:01 +03:00
|
|
|
res.set.calledThrice.should.be.true();
|
2015-05-18 21:12:42 +03:00
|
|
|
res.set.calledWith({'Cache-Control': 'public, max-age=0'});
|
|
|
|
|
2015-10-12 19:54:15 +03:00
|
|
|
privateCC(null, res, function () {
|
2015-05-18 21:12:42 +03:00
|
|
|
res.set.calledWith({
|
|
|
|
'Cache-Control': 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0'
|
|
|
|
});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2015-09-03 18:42:15 +03:00
|
|
|
});
|
2015-05-18 21:12:42 +03:00
|
|
|
|
2015-09-03 18:42:15 +03:00
|
|
|
it('will override public with private for private blogs', function (done) {
|
|
|
|
res.isPrivateBlog = true;
|
2016-10-11 11:36:00 +03:00
|
|
|
cacheControl('public')(null, res, function (a) {
|
2015-09-03 18:42:15 +03:00
|
|
|
should.not.exist(a);
|
2016-02-08 00:27:01 +03:00
|
|
|
res.set.calledOnce.should.be.true();
|
2015-09-03 18:42:15 +03:00
|
|
|
res.set.calledWith({
|
|
|
|
'Cache-Control':
|
|
|
|
'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0'
|
2015-05-18 21:12:42 +03:00
|
|
|
});
|
2015-09-03 18:42:15 +03:00
|
|
|
done();
|
2015-05-18 21:12:42 +03:00
|
|
|
});
|
2015-05-18 21:12:42 +03:00
|
|
|
});
|
|
|
|
});
|