Skip to content

Commit

Permalink
feat(cookies): add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ealenn committed Jul 16, 2022
1 parent e345d59 commit 5c825d4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
1 change: 1 addition & 0 deletions docs/pages/configuration/feature-toggle.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This configuration is used to deactivate some elements in the response.
| ENABLE__HOST | application.enable.host | --enable:host | `true` |
| ENABLE__HTTP | application.enable.http | --enable:http | `true` |
| ENABLE__REQUEST | application.enable.request | --enable:request | `true` |
| ENABLE__COOKIES | application.enable.cookies | --enable:cookies | `true` |
| ENABLE__ENVIRONMENT | application.enable.environment | --enable:environment | `true` |
| ENABLE__FILE | application.enable.file | --enable:file | `true` |
| ENABLE__HEADER | application.enable.header | --enable:header | `true` |
27 changes: 9 additions & 18 deletions src/response/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,15 @@ const config = require('../nconf');

module.exports = (req) => {
if (config.get('enable:request')) {
if (config.get('enable:cookies')) {
return {
params: req.params,
query: req.query,
cookies: req.cookies,
body: req.body,
headers: req.headers
}
} else {
delete req.headers["cookie"];
return {
params: req.params,
query: req.query,
body: req.body,
headers: req.headers
}
}
const isCookiesEnabled = config.get('enable:cookies');
return {
params: req.params,
query: req.query,
cookies: isCookiesEnabled ? req.cookies : [],
body: req.body,
headers: req.headers
};
} else {
return undefined
return undefined
}
}
25 changes: 24 additions & 1 deletion test/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,27 @@ describe('Request with Cookies', function () {
})
.expect(200, done);
});
});
});

describe('Request with Cookies but disabled in configuration', function () {
var server;
beforeEach(function () {
require('../src/nconf').set('enable:cookies', false);
server = require('../src/app');
});
afterEach(function () {
require('../src/nconf').set('enable:cookies', true);
server.close();
});

it('GET', function test(done) {
request(server)
.get('/')
.set('Cookie', ['testOne=valueOne;testTwo=valueTwo'])
.send()
.expect(function (res) {
assert.deepEqual(res.body.request.cookies, []);
})
.expect(200, done);
});
});

0 comments on commit 5c825d4

Please sign in to comment.