diff --git a/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabAuthorizingFileContentProvider.java b/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabAuthorizingFileContentProvider.java index 1137407b94..86241a46c8 100644 --- a/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabAuthorizingFileContentProvider.java +++ b/wsmaster/che-core-api-factory-gitlab/src/main/java/org/eclipse/che/api/factory/server/gitlab/GitlabAuthorizingFileContentProvider.java @@ -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; diff --git a/wsmaster/che-core-api-factory-gitlab/src/test/java/org/eclipse/che/api/factory/server/gitlab/GitlabAuthorizingFileContentProviderTest.java b/wsmaster/che-core-api-factory-gitlab/src/test/java/org/eclipse/che/api/factory/server/gitlab/GitlabAuthorizingFileContentProviderTest.java index 0ba01840d0..796223a47f 100644 --- a/wsmaster/che-core-api-factory-gitlab/src/test/java/org/eclipse/che/api/factory/server/gitlab/GitlabAuthorizingFileContentProviderTest.java +++ b/wsmaster/che-core-api-factory-gitlab/src/test/java/org/eclipse/che/api/factory/server/gitlab/GitlabAuthorizingFileContentProviderTest.java @@ -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; @@ -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"); + } }