Skip to content

Commit 5c2963a

Browse files
committed
Do not validate Bitbucket Server by Api request
1 parent e3c3c88 commit 5c2963a

File tree

2 files changed

+3
-45
lines changed

2 files changed

+3
-45
lines changed

wsmaster/che-core-api-factory-bitbucket-server/src/main/java/org/eclipse/che/api/factory/server/bitbucket/BitbucketServerURLParser.java

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012-2024 Red Hat, Inc.
2+
* Copyright (c) 2012-2025 Red Hat, Inc.
33
* This program and the accompanying materials are made
44
* available under the terms of the Eclipse Public License 2.0
55
* which is available at https://www.eclipse.org/legal/epl-2.0/
@@ -30,14 +30,11 @@
3030
import org.eclipse.che.api.factory.server.scm.PersonalAccessTokenManager;
3131
import org.eclipse.che.api.factory.server.scm.exception.ScmCommunicationException;
3232
import org.eclipse.che.api.factory.server.scm.exception.ScmConfigurationPersistenceException;
33-
import org.eclipse.che.api.factory.server.scm.exception.ScmItemNotFoundException;
34-
import org.eclipse.che.api.factory.server.scm.exception.ScmUnauthorizedException;
3533
import org.eclipse.che.api.factory.server.urlfactory.DevfileFilenamesProvider;
3634
import org.eclipse.che.commons.annotation.Nullable;
3735
import org.eclipse.che.commons.env.EnvironmentContext;
3836
import org.eclipse.che.commons.lang.StringUtils;
3937
import org.eclipse.che.security.oauth.OAuthAPI;
40-
import org.eclipse.che.security.oauth1.BitbucketServerOAuthAuthenticator;
4138

4239
/**
4340
* Parser of String Bitbucket Server URLs and provide {@link BitbucketServerUrl} objects.
@@ -112,31 +109,10 @@ public boolean isValid(@NotNull String url) {
112109
return
113110
// If Bitbucket server URL is not configured try to find it in a manually added user namespace
114111
// token.
115-
isUserTokenPresent(url)
116-
// Try to call an API request to see if the URL matches Bitbucket.
117-
|| isApiRequestRelevant(url);
112+
isUserTokenPresent(url);
118113
}
119114
}
120115

121-
private boolean isApiRequestRelevant(String repositoryUrl) {
122-
try {
123-
HttpBitbucketServerApiClient bitbucketServerApiClient =
124-
new HttpBitbucketServerApiClient(
125-
getServerUrl(repositoryUrl),
126-
new BitbucketServerOAuthAuthenticator("", "", "", ""),
127-
oAuthAPI,
128-
"");
129-
// If the user request catches the unauthorised error, it means that the provided url
130-
// belongs to Bitbucket.
131-
bitbucketServerApiClient.getUser();
132-
} catch (ScmItemNotFoundException | ScmCommunicationException e) {
133-
return false;
134-
} catch (ScmUnauthorizedException e) {
135-
return true;
136-
}
137-
return false;
138-
}
139-
140116
private String getServerUrl(String repositoryUrl) {
141117
if (repositoryUrl.startsWith("ssh://git@")) {
142118
String substring = repositoryUrl.substring(10);

wsmaster/che-core-api-factory-bitbucket-server/src/test/java/org/eclipse/che/api/factory/server/bitbucket/BitbucketServerURLParserTest.java

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012-2024 Red Hat, Inc.
2+
* Copyright (c) 2012-2025 Red Hat, Inc.
33
* This program and the accompanying materials are made
44
* available under the terms of the Eclipse Public License 2.0
55
* which is available at https://www.eclipse.org/legal/epl-2.0/
@@ -109,24 +109,6 @@ public void shouldThrowExceptionWhenURLDintMatchAnyConfiguredServer() {
109109
bitbucketURLParser.parse("https://github.com/org/repo");
110110
}
111111

112-
@Test
113-
public void shouldValidateUrlByApiRequest() {
114-
// given
115-
bitbucketURLParser =
116-
new BitbucketServerURLParser(
117-
null, devfileFilenamesProvider, oAuthAPI, mock(PersonalAccessTokenManager.class));
118-
String url = wireMockServer.url("/users/user/repos/repo");
119-
stubFor(
120-
get(urlEqualTo("/plugins/servlet/applinks/whoami"))
121-
.willReturn(aResponse().withStatus(401)));
122-
123-
// when
124-
boolean result = bitbucketURLParser.isValid(url);
125-
126-
// then
127-
assertTrue(result);
128-
}
129-
130112
@Test
131113
public void shouldNotValidateUrlByApiRequest() {
132114
// given

0 commit comments

Comments
 (0)