|
|
@@ -1,7 +1,7 @@
|
|
|
/* eslint-disable arrow-body-style */
|
|
|
|
|
|
describe('safeRedirect', () => {
|
|
|
- let safeRedirect;
|
|
|
+ let registerSafeRedirect;
|
|
|
|
|
|
const whitelistOfHosts = [
|
|
|
'white1.example.com:8080',
|
|
|
@@ -9,7 +9,7 @@ describe('safeRedirect', () => {
|
|
|
];
|
|
|
|
|
|
beforeEach(async(done) => {
|
|
|
- safeRedirect = require('@server/middleware/safe-redirect')(whitelistOfHosts);
|
|
|
+ registerSafeRedirect = require('@server/middleware/safe-redirect')(whitelistOfHosts);
|
|
|
done();
|
|
|
});
|
|
|
|
|
|
@@ -26,7 +26,7 @@ describe('safeRedirect', () => {
|
|
|
const next = jest.fn();
|
|
|
|
|
|
test('redirects to \'/\' because specified url causes open redirect vulnerability', () => {
|
|
|
- safeRedirect(req, res, next);
|
|
|
+ registerSafeRedirect(req, res, next);
|
|
|
|
|
|
const result = res.safeRedirect('//evil.example.com');
|
|
|
|
|
|
@@ -39,7 +39,7 @@ describe('safeRedirect', () => {
|
|
|
});
|
|
|
|
|
|
test('redirects to \'/\' because specified host without port is not in whitelist', () => {
|
|
|
- safeRedirect(req, res, next);
|
|
|
+ registerSafeRedirect(req, res, next);
|
|
|
|
|
|
const result = res.safeRedirect('http://white1.example.com/path/to/page');
|
|
|
|
|
|
@@ -52,7 +52,7 @@ describe('safeRedirect', () => {
|
|
|
});
|
|
|
|
|
|
test('redirects to the specified local url', () => {
|
|
|
- safeRedirect(req, res, next);
|
|
|
+ registerSafeRedirect(req, res, next);
|
|
|
|
|
|
const result = res.safeRedirect('/path/to/page');
|
|
|
|
|
|
@@ -65,7 +65,7 @@ describe('safeRedirect', () => {
|
|
|
});
|
|
|
|
|
|
test('redirects to the specified local url (fqdn)', () => {
|
|
|
- safeRedirect(req, res, next);
|
|
|
+ registerSafeRedirect(req, res, next);
|
|
|
|
|
|
const result = res.safeRedirect('http://example.com/path/to/page');
|
|
|
|
|
|
@@ -78,7 +78,7 @@ describe('safeRedirect', () => {
|
|
|
});
|
|
|
|
|
|
test('redirects to the specified whitelisted url (white1.example.com:8080)', () => {
|
|
|
- safeRedirect(req, res, next);
|
|
|
+ registerSafeRedirect(req, res, next);
|
|
|
|
|
|
const result = res.safeRedirect('http://white1.example.com:8080/path/to/page');
|
|
|
|
|
|
@@ -91,7 +91,7 @@ describe('safeRedirect', () => {
|
|
|
});
|
|
|
|
|
|
test('redirects to the specified whitelisted url (white2.example.com:8080)', () => {
|
|
|
- safeRedirect(req, res, next);
|
|
|
+ registerSafeRedirect(req, res, next);
|
|
|
|
|
|
const result = res.safeRedirect('http://white2.example.com:8080/path/to/page');
|
|
|
|