Don't include the region param in authorizedRequest if it's already in the URL

This commit is contained in:
Michael Lange 2021-01-28 14:30:20 -08:00
parent d44e0772f7
commit f487562955
2 changed files with 12 additions and 1 deletions

View File

@ -94,7 +94,7 @@ export default class TokenService extends Service {
authorizedRequest(url, options) {
if (this.get('system.shouldIncludeRegion')) {
const region = this.get('system.activeRegion');
if (region) {
if (region && url.indexOf('region=') === -1) {
url = addParams(url, { region });
}
}

View File

@ -50,6 +50,17 @@ module('Unit | Service | Token', function(hooks) {
);
});
test('authorizedRequest does not include the region param when the region param is already in the URL', function(assert) {
const token = this.subject();
token.authorizedRequest('/path?query=param&region=already-here');
assert.equal(
this.server.handledRequests.pop().url,
'/path?query=param&region=already-here',
'The region param that is already in the URL takes precedence over the region in the service'
);
});
test('authorizedRawRequest bypasses adding the region param', function(assert) {
const token = this.subject();