Skip to content

Commit

Permalink
fix(authentication): correctly extract the requested url from headers (
Browse files Browse the repository at this point in the history
  • Loading branch information
ghusse authored and Guillaume Gautreau committed Nov 26, 2020
1 parent c089afd commit d97e2c7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/services/request-analyser.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const url = require('url');

class RequestAnalyzerService {
/**
* @private @static
Expand Down Expand Up @@ -27,7 +29,9 @@ class RequestAnalyzerService {
|| (isForwarded
? undefined
: RequestAnalyzerService._extractPortFromHost(request.headers.host));
const path = request.url;

const parsedUrl = url.parse(request.originalUrl);
const path = parsedUrl.pathname;

return `${protocol}://${hostname}${port ? `:${port}` : ''}${path}`;
}
Expand Down
8 changes: 4 additions & 4 deletions test/services/request-analyzer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('requestAnalyzerService', () => {
},
protocol: 'http',
hostname: 'localhost.com',
url: '/forest/authentication',
originalUrl: '/forest/authentication?foo=bar&hello=world',
};

const result = service.extractOriginalUrlWithoutQuery(request);
Expand All @@ -32,7 +32,7 @@ describe('requestAnalyzerService', () => {
},
protocol: 'http',
hostname: 'localhost.com',
url: '/forest/authentication',
originalUrl: '/forest/authentication?foo=bar&hello=world',
};

const result = service.extractOriginalUrlWithoutQuery(request);
Expand All @@ -54,7 +54,7 @@ describe('requestAnalyzerService', () => {
},
protocol: 'http',
hostname: 'localhost.com',
url: '/forest/authentication',
originalUrl: '/forest/authentication?foo=bar&hello=world',
};

const result = service.extractOriginalUrlWithoutQuery(request);
Expand All @@ -75,7 +75,7 @@ describe('requestAnalyzerService', () => {
},
protocol: 'http',
hostname: 'localhost.com',
url: '/forest/authentication',
originalUrl: '/forest/authentication?foo=bar&hello=world',
};

const result = service.extractOriginalUrlWithoutQuery(request);
Expand Down

0 comments on commit d97e2c7

Please sign in to comment.