Return empty credentials from bitbucket URL with username (#466)
Override the getCredentials() method in the BitbucketUrl class to intercept bitbucket URL with username e.g. https://user@bitbucket.org/eclipse/che. Return empty credentials for such urls.pull/469/head
parent
be757ec5a6
commit
5a04496ded
|
|
@ -87,6 +87,7 @@ public class AzureDevOpsURLParser {
|
|||
// - https://<credentials>@<host>/<organization>/<project>/_git/<repoName>
|
||||
// For the first case we need to remove the `organization` from the url to distinguish it from
|
||||
// `credentials`
|
||||
// TODO: return empty credentials like the BitBucketUrl
|
||||
String organizationCanIgnore = matcher.group("organizationCanIgnore");
|
||||
if (!isNullOrEmpty(organization) && organization.equals(organizationCanIgnore)) {
|
||||
url = url.replace(organizationCanIgnore + "@", "");
|
||||
|
|
|
|||
|
|
@ -147,6 +147,17 @@ public class BitbucketUrl extends DefaultFactoryUrl {
|
|||
return "https://" + HOSTNAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getCredentials() {
|
||||
// Bitbucket repository URL may contain username e.g.
|
||||
// https://<username>@bitbucket.org/<workspace_ID>/<repo_name>.git. If username is present, it
|
||||
// can not be used as credentials. Moreover, we skip credentials for Bitbucket repository URl at
|
||||
// all, because we do not support credentials in a repository URL. We only support credentials
|
||||
// in a devfile URL, which is handled by the DefaultFactoryUrl class.
|
||||
// Todo: add a new abstraction for divfile URL to be able to retrieve credentials separately.
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides location to the repository part of the full bitbucket URL.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import static org.mockito.Mockito.lenient;
|
|||
import static org.mockito.Mockito.when;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
|
|
@ -63,6 +64,14 @@ public class BitbucketUrlTest {
|
|||
assertEquals(iterator.next().location(), "https://bitbucket.org/eclipse/che/raw/HEAD/foo.bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnEmptyCredentials() {
|
||||
// when
|
||||
BitbucketUrl url = this.bitbucketURLParser.parse("https://user@bitbucket.org/eclipse/che");
|
||||
// then
|
||||
assertTrue(url.getCredentials().isEmpty());
|
||||
}
|
||||
|
||||
/** Check the original repository */
|
||||
@Test
|
||||
public void checkRepositoryLocation() {
|
||||
|
|
|
|||
|
|
@ -66,6 +66,10 @@ public class DefaultFactoryUrl implements RemoteFactoryUrl {
|
|||
return null;
|
||||
}
|
||||
|
||||
public URL getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getCredentials() {
|
||||
if (url == null || isNullOrEmpty(url.getUserInfo())) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue