diff --git a/ui/desktop/CHANGELOG.md b/ui/desktop/CHANGELOG.md index 34bb51bf9..5726e86f2 100644 --- a/ui/desktop/CHANGELOG.md +++ b/ui/desktop/CHANGELOG.md @@ -6,7 +6,8 @@ Canonical reference for changes, improvements, and bugfixes for Boundary Desktop ### Bug Fixes -- ui: Trigger zoom-in menu option on keyboard shortcut. ([PR](https://github.com/hashicorp/boundary-ui/pull/505)) +- Trigger zoom-in menu option on keyboard shortcut. ([PR](https://github.com/hashicorp/boundary-ui/pull/505)) +- Boundary Desktop will accept origins with or without trailing slashes. ([PR](https://github.com/hashicorp/boundary-ui/pull/519)) ## v1.0.0-beta [CLI 0.1.8] (2021.03.10) diff --git a/ui/desktop/app/services/origin.js b/ui/desktop/app/services/origin.js index a5c1f3a0e..9ca0895f2 100644 --- a/ui/desktop/app/services/origin.js +++ b/ui/desktop/app/services/origin.js @@ -63,6 +63,10 @@ export default class OriginService extends Service { typeof origin === 'string' ); try { + // Silently drop trailing slashes if present. + // This is important since API paths that will be appended to the origin + // will include preceeding slashes already. + origin = origin.replace(/\/*$/, ''); this.adapter.host = origin; this.rendererOrigin = origin; if (origin !== (await this.mainOrigin)) { diff --git a/ui/desktop/tests/unit/services/origin-test.js b/ui/desktop/tests/unit/services/origin-test.js index 4d8703cf6..cc6cdfa69 100644 --- a/ui/desktop/tests/unit/services/origin-test.js +++ b/ui/desktop/tests/unit/services/origin-test.js @@ -24,4 +24,15 @@ module('Unit | Service | origin', function (hooks) { assert.equal(service.adapter.host, window.location.origin); }); }); + + test('drops trailing slashes from origin on setOrigin', async function (assert) { + assert.expect(4); + sinon.stub(ipcService, 'invoke'); + await service.setOrigin(`${window.location.origin}/`); + assert.equal(service.rendererOrigin, window.location.origin); + assert.equal(service.adapter.host, window.location.origin); + await service.setOrigin(`${window.location.origin}//////`); + assert.equal(service.rendererOrigin, window.location.origin); + assert.equal(service.adapter.host, window.location.origin); + }); });