Use BaseUrlBehavior when fetching OAuth config
Change-Id: I2a845758ef7671089c52672f80d8f43779eabb01
diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-gapi-auth.js b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-gapi-auth.js
index 2f60268..f4e66a3 100644
--- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-gapi-auth.js
+++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-gapi-auth.js
@@ -159,7 +159,8 @@
};
GrGapiAuth.prototype._getOAuthConfig = function() {
- const authConfigURL = '/accounts/self/oauthconfig';
+ const baseUrl = Gerrit.BaseUrlBehavior.getBaseUrl();
+ const authConfigURL = baseUrl + '/accounts/self/oauthconfig';
const opts = {
headers: new Headers({Accept: 'application/json'}),
credentials: 'same-origin',
diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-gapi-auth_test.html b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-gapi-auth_test.html
index 3890fd6..70cdd83 100644
--- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-gapi-auth_test.html
+++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-gapi-auth_test.html
@@ -21,6 +21,7 @@
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<script src="../../../bower_components/web-component-tester/browser.js"></script>
<link rel="import" href="../../../test/common-test-setup.html"/>
+<link rel="import" href="../../../behaviors/base-url-behavior/base-url-behavior.html">
<script src="gr-gapi-auth.js"></script>
@@ -42,7 +43,7 @@
authorize: sandbox.stub(),
},
};
- sandbox.stub(window, 'fetch').returns(Promise.resolve());
+ sandbox.stub(window, 'fetch').returns(Promise.resolve({ok: true}));
});
teardown(() => {
@@ -158,7 +159,6 @@
test('_getOAuthConfig', () => {
const config = {};
- fetch.returns(Promise.resolve({ok: true}));
sandbox.stub(auth, '_getResponseObject').returns(config);
return auth._getOAuthConfig().then(c => {
const [url, options] = fetch.lastCall.args;
@@ -169,6 +169,15 @@
});
});
+ test('BaseUrlBehavior', () => {
+ sandbox.stub(Gerrit.BaseUrlBehavior, 'getBaseUrl').returns('http://foo');
+ sandbox.stub(auth, '_getResponseObject').returns({});
+ return auth._getOAuthConfig().then(c => {
+ const [url] = fetch.lastCall.args;
+ assert.equal(url, 'http://foo/accounts/self/oauthconfig');
+ });
+ });
+
suite('faster gerrit cors', () => {
setup(() => {
window.FASTER_GERRIT_CORS = true;
diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.html b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.html
index 6149abe..753c26e 100644
--- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.html
+++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.html
@@ -17,6 +17,7 @@
<link rel="import" href="../../../behaviors/gr-path-list-behavior/gr-path-list-behavior.html">
<link rel="import" href="../../../behaviors/rest-client-behavior/rest-client-behavior.html">
<link rel="import" href="../../../bower_components/polymer/polymer.html">
+<link rel="import" href="../../../behaviors/base-url-behavior/base-url-behavior.html">
<!-- NB: es6-promise Needed for IE11 and fetch polyfill support, see Issue 4308 -->
<script src="../../../bower_components/es6-promise/dist/es6-promise.min.js"></script>
<script src="../../../bower_components/fetch/fetch.js"></script>