Skip to content

Commit

Permalink
Use getProviderUrl() instead of getHostName() when generating gitlab …
Browse files Browse the repository at this point in the history
…url parameter (#738)
  • Loading branch information
vinokurig authored Nov 13, 2024
1 parent b99673b commit be7243d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class GitlabAuthorizingFileContentProvider extends AuthorizingFileContentProvide
@Override
protected boolean isPublicRepository(GitlabUrl remoteFactoryUrl) {
try {
urlFetcher.fetch(remoteFactoryUrl.getHostName() + '/' + remoteFactoryUrl.getSubGroups());
urlFetcher.fetch(remoteFactoryUrl.getProviderUrl() + '/' + remoteFactoryUrl.getSubGroups());
return true;
} catch (IOException e) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.io.FileNotFoundException;
import org.eclipse.che.api.factory.server.scm.PersonalAccessToken;
import org.eclipse.che.api.factory.server.scm.PersonalAccessTokenManager;
import org.eclipse.che.api.factory.server.scm.exception.UnknownScmProviderException;
import org.eclipse.che.api.workspace.server.devfile.FileContentProvider;
import org.eclipse.che.api.workspace.server.devfile.URLFetcher;
import org.mockito.Mock;
Expand Down Expand Up @@ -59,4 +61,23 @@ public void shouldPreserveAbsolutePaths() throws Exception {
fileContentProvider.fetchContent(url);
verify(urlFetcher).fetch(eq(url), eq("Bearer my-token"));
}

@Test(expectedExceptions = FileNotFoundException.class)
public void shouldThrowFileNotFoundException() throws Exception {
// given
URLFetcher urlFetcher = Mockito.mock(URLFetcher.class);
when(urlFetcher.fetch(
eq(
"https://gitlab.com/api/v4/projects/eclipse%2Fche/repository/files/devfile.yaml/raw?ref=HEAD")))
.thenThrow(new FileNotFoundException());
when(urlFetcher.fetch(eq("https://gitlab.com/eclipse/che"))).thenReturn("content");
when(personalAccessTokenManager.getAndStore(anyString()))
.thenThrow(new UnknownScmProviderException("", ""));
GitlabUrl gitlabUrl = new GitlabUrl().withHostName("gitlab.com").withSubGroups("eclipse/che");
FileContentProvider fileContentProvider =
new GitlabAuthorizingFileContentProvider(gitlabUrl, urlFetcher, personalAccessTokenManager);

// when
fileContentProvider.fetchContent("devfile.yaml");
}
}

0 comments on commit be7243d

Please sign in to comment.