fixup! Support raw devfile urls without yaml extension

pull/683/head
ivinokur 2024-05-09 18:01:27 +03:00
parent ec3ee70f50
commit ba0faa9784
2 changed files with 20 additions and 2 deletions

View File

@ -77,7 +77,9 @@ public class RawDevfileUrlFactoryParameterResolver extends BaseFactoryParameterR
String fetch = urlFetcher.fetch(requestURL);
devfileParser.parseYaml(fetch);
return true;
} catch (IOException | DevfileFormatException e) {
} catch (IOException e) {
return false;
} catch (DevfileFormatException e) {
return !e.getMessage().startsWith("Cannot construct instance of");
}
}

View File

@ -30,6 +30,7 @@ import static org.testng.Assert.fail;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.che.api.core.BadRequestException;
@ -185,7 +186,7 @@ public class RawDevfileUrlFactoryParameterResolverTest {
}
@Test
public void shouldNotAcceptGitRepositoryUrl() throws Exception {
public void shouldNotAcceptPublicGitRepositoryUrl() throws Exception {
// given
String gitRepositoryUrl = "https://host/user/repo.git";
when(urlFetcher.fetch(eq(gitRepositoryUrl))).thenReturn("unsupported content");
@ -201,6 +202,21 @@ public class RawDevfileUrlFactoryParameterResolverTest {
assertFalse(result);
}
@Test
public void shouldNotAcceptPrivateGitRepositoryUrl() throws Exception {
// given
String gitRepositoryUrl = "https://host/user/private-repo.git";
when(urlFetcher.fetch(eq(gitRepositoryUrl))).thenThrow(new FileNotFoundException());
// when
boolean result =
rawDevfileUrlFactoryParameterResolver.accept(
singletonMap(URL_PARAMETER_NAME, gitRepositoryUrl));
// then
assertFalse(result);
}
@DataProvider(name = "invalidURLsProvider")
private Object[][] invalidUrlsProvider() {
return new Object[][] {