From f7e979eaa23042c80309087653c197abdd405045 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Thu, 28 Jan 2021 14:30:20 -0800 Subject: [PATCH] Don't include the region param in authorizedRequest if it's already in the URL --- ui/app/services/token.js | 2 +- ui/tests/unit/services/token-test.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ui/app/services/token.js b/ui/app/services/token.js index 78d43feb1a70..3f9663968b47 100644 --- a/ui/app/services/token.js +++ b/ui/app/services/token.js @@ -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 && region.indexOf('region=') === -1) { url = addParams(url, { region }); } } diff --git a/ui/tests/unit/services/token-test.js b/ui/tests/unit/services/token-test.js index 5bc72437ae9f..edf1bc266621 100644 --- a/ui/tests/unit/services/token-test.js +++ b/ui/tests/unit/services/token-test.js @@ -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®ion=already-here'); + assert.equal( + this.server.handledRequests.pop().url, + '/path?query=param®ion=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();