aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilippe Perrin <philippe.perrin@sonarsource.com>2020-12-16 10:48:58 +0100
committersonartech <sonartech@sonarsource.com>2021-01-11 20:20:39 +0000
commit78ad25f06a00e099d277e26b634aaa593f5026ed (patch)
treee4bb7a0ed5a84d993069d9cdc01a7b6a642e8201
parent6789a2ec09f916b67bb34400f332570d2ca26b94 (diff)
downloadsonarqube-78ad25f06a00e099d277e26b634aaa593f5026ed.tar.gz
sonarqube-78ad25f06a00e099d277e26b634aaa593f5026ed.zip
SONAR-14212 Remove obsolete Sonar-Version HTTP header
-rw-r--r--server/sonar-web/src/main/js/app/components/extensions/legacy/__tests__/request-legacy-test.ts13
-rw-r--r--server/sonar-web/src/main/js/app/components/extensions/legacy/request-legacy.ts34
-rw-r--r--server/sonar-webserver/src/main/java/org/sonar/server/platform/web/WebServiceFilter.java5
-rw-r--r--server/sonar-webserver/src/test/java/org/sonar/server/platform/web/WebServiceFilterTest.java19
4 files changed, 11 insertions, 60 deletions
diff --git a/server/sonar-web/src/main/js/app/components/extensions/legacy/__tests__/request-legacy-test.ts b/server/sonar-web/src/main/js/app/components/extensions/legacy/__tests__/request-legacy-test.ts
index 55995d1f138..8fed4500317 100644
--- a/server/sonar-web/src/main/js/app/components/extensions/legacy/__tests__/request-legacy-test.ts
+++ b/server/sonar-web/src/main/js/app/components/extensions/legacy/__tests__/request-legacy-test.ts
@@ -189,19 +189,6 @@ describe('checkStatus', () => {
});
});
- it('should reload the page when version is changing', async () => {
- const reload = jest.fn();
- delete window.location;
- (window as any).location = { reload };
-
- await checkStatus(mockResponse({ 'Sonar-Version': '6.7' }));
- expect(reload).not.toBeCalled();
- await checkStatus(mockResponse({ 'Sonar-Version': '6.7' }));
- expect(reload).not.toBeCalled();
- checkStatus(mockResponse({ 'Sonar-Version': '7.9' }));
- expect(reload).toBeCalled();
- });
-
function mockResponse(headers: T.Dict<string> = {}, status = 200): any {
return {
headers: { get: (prop: string) => headers[prop] },
diff --git a/server/sonar-web/src/main/js/app/components/extensions/legacy/request-legacy.ts b/server/sonar-web/src/main/js/app/components/extensions/legacy/request-legacy.ts
index 7122e3dbb21..f39f74fd801 100644
--- a/server/sonar-web/src/main/js/app/components/extensions/legacy/request-legacy.ts
+++ b/server/sonar-web/src/main/js/app/components/extensions/legacy/request-legacy.ts
@@ -34,9 +34,6 @@ import { getBaseUrl } from '../../../../helpers/system';
Do not use these functions, but rather the ones from sonar-ui-common/helpers/request.ts
*/
-/** Current application version. Can be changed if a newer version is deployed. */
-let currentApplicationVersion: string | undefined;
-
function getCSRFTokenName(): string {
return 'X-XSRF-TOKEN';
}
@@ -155,34 +152,19 @@ function corsRequest(url: string, mode: RequestMode = 'cors'): Request {
return request;
}
-function checkApplicationVersion(response: Response): boolean {
- const version = response.headers.get('Sonar-Version');
- if (version) {
- if (currentApplicationVersion && currentApplicationVersion !== version) {
- window.location.reload();
- return false;
- } else {
- currentApplicationVersion = version;
- }
- }
- return true;
-}
-
/**
* Check that response status is ok
*/
function checkStatus(response: Response): Promise<Response> {
return new Promise((resolve, reject) => {
- if (checkApplicationVersion(response)) {
- if (response.status === 401) {
- import('sonar-ui-common/helpers/handleRequiredAuthentication')
- .then(i => i.default())
- .then(reject, reject);
- } else if (response.status >= 200 && response.status < 300) {
- resolve(response);
- } else {
- reject({ response });
- }
+ if (response.status === 401) {
+ import('sonar-ui-common/helpers/handleRequiredAuthentication')
+ .then(i => i.default())
+ .then(reject, reject);
+ } else if (response.status >= 200 && response.status < 300) {
+ resolve(response);
+ } else {
+ reject({ response });
}
});
}
diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/web/WebServiceFilter.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/web/WebServiceFilter.java
index b75718b7f72..91225b72daa 100644
--- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/web/WebServiceFilter.java
+++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/web/WebServiceFilter.java
@@ -51,9 +51,8 @@ public class WebServiceFilter extends ServletFilter {
private final WebServiceEngine webServiceEngine;
private final Set<String> includeUrls;
private final Set<String> excludeUrls;
- private final SonarRuntime runtime;
- public WebServiceFilter(WebServiceEngine webServiceEngine, SonarRuntime runtime) {
+ public WebServiceFilter(WebServiceEngine webServiceEngine) {
this.webServiceEngine = webServiceEngine;
this.includeUrls = concat(
Stream.of("/api/*"),
@@ -67,7 +66,6 @@ public class WebServiceFilter extends ServletFilter {
.filter(action -> action.handler() instanceof ServletFilterHandler)
.map(toPath()))
.collect(MoreCollectors.toSet());
- this.runtime = runtime;
}
@Override
@@ -84,7 +82,6 @@ public class WebServiceFilter extends ServletFilter {
HttpServletResponse response = (HttpServletResponse) servletResponse;
ServletRequest wsRequest = new ServletRequest(request);
ServletResponse wsResponse = new ServletResponse(response);
- wsResponse.setHeader("Sonar-Version", runtime.getApiVersion().toString());
webServiceEngine.execute(wsRequest, wsResponse);
}
diff --git a/server/sonar-webserver/src/test/java/org/sonar/server/platform/web/WebServiceFilterTest.java b/server/sonar-webserver/src/test/java/org/sonar/server/platform/web/WebServiceFilterTest.java
index 79cc7e545d0..29b55e8b373 100644
--- a/server/sonar-webserver/src/test/java/org/sonar/server/platform/web/WebServiceFilterTest.java
+++ b/server/sonar-webserver/src/test/java/org/sonar/server/platform/web/WebServiceFilterTest.java
@@ -29,15 +29,10 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.SonarEdition;
-import org.sonar.api.SonarQubeSide;
-import org.sonar.api.SonarRuntime;
-import org.sonar.api.internal.SonarRuntimeImpl;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.RequestHandler;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
-import org.sonar.api.utils.Version;
import org.sonar.server.ws.ServletFilterHandler;
import org.sonar.server.ws.WebServiceEngine;
@@ -61,7 +56,6 @@ public class WebServiceFilterTest {
private HttpServletResponse response = mock(HttpServletResponse.class);
private FilterChain chain = mock(FilterChain.class);
private ServletOutputStream responseOutput = mock(ServletOutputStream.class);
- private SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse(RUNTIME_VERSION), SonarQubeSide.SERVER, SonarEdition.COMMUNITY);
private WebServiceFilter underTest;
@Before
@@ -111,22 +105,13 @@ public class WebServiceFilterTest {
@Test
public void execute_ws() {
- underTest = new WebServiceFilter(webServiceEngine, runtime);
+ underTest = new WebServiceFilter(webServiceEngine);
underTest.doFilter(request, response, chain);
verify(webServiceEngine).execute(any(), any());
}
- @Test
- public void add_version_to_response_headers() {
- underTest = new WebServiceFilter(webServiceEngine, runtime);
-
- underTest.doFilter(request, response, chain);
-
- verify(response).setHeader("Sonar-Version", RUNTIME_VERSION);
- }
-
private void initWebServiceEngine(WsUrl... wsUrls) {
List<WebService.Controller> controllers = new ArrayList<>();
@@ -147,7 +132,7 @@ public class WebServiceFilterTest {
controllers.add(wsController);
}
when(webServiceEngine.controllers()).thenReturn(controllers);
- underTest = new WebServiceFilter(webServiceEngine, runtime);
+ underTest = new WebServiceFilter(webServiceEngine);
}
static final class WsUrl {