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
  • Loading branch information
vinokurig committed Nov 11, 2024
1 parent d0a37de commit 0456dcc
Show file tree
Hide file tree
Showing 2 changed files with 20 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,10 +15,14 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.io.FileNotFoundException;
import java.io.IOException;
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.eclipse.che.api.workspace.server.devfile.exception.DevfileException;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.testng.MockitoTestNGListener;
Expand Down Expand Up @@ -59,4 +63,19 @@ 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 0456dcc

Please sign in to comment.