Skip to content

Commit

Permalink
fixup! Support raw devfile urls without yaml extension
Browse files Browse the repository at this point in the history
  • Loading branch information
vinokurig committed May 13, 2024
1 parent ba0faa9 commit 63b0172
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static org.eclipse.che.api.factory.server.FactoryResolverPriority.HIGHEST;
import static org.eclipse.che.api.factory.shared.Constants.URL_PARAMETER_NAME;

import com.fasterxml.jackson.databind.JsonNode;
import jakarta.validation.constraints.NotNull;
import java.io.IOException;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -75,12 +76,10 @@ public boolean accept(Map<String, String> factoryParameters) {
private boolean containsDevfile(String requestURL) {
try {
String fetch = urlFetcher.fetch(requestURL);
devfileParser.parseYaml(fetch);
return true;
} catch (IOException e) {
JsonNode parsedYaml = devfileParser.parseYamlRaw(fetch);
return !parsedYaml.isEmpty();
} catch (IOException | DevfileFormatException e) {
return false;
} catch (DevfileFormatException e) {
return !e.getMessage().startsWith("Cannot construct instance of");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;

import com.fasterxml.jackson.databind.JsonNode;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -40,7 +41,6 @@
import org.eclipse.che.api.workspace.server.devfile.DevfileVersionDetector;
import org.eclipse.che.api.workspace.server.devfile.URLFetcher;
import org.eclipse.che.api.workspace.server.devfile.URLFileContentProvider;
import org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException;
import org.eclipse.che.api.workspace.server.devfile.validator.ComponentIntegrityValidator;
import org.eclipse.che.api.workspace.server.devfile.validator.ComponentIntegrityValidator.NoopComponentIntegrityValidator;
import org.eclipse.che.api.workspace.server.devfile.validator.DevfileIntegrityValidator;
Expand Down Expand Up @@ -170,12 +170,13 @@ public void shouldAcceptRawDevfileUrl(String url) {
}

@Test
public void shouldAcceptRawDevfileUrlWithUnrecognizedDevfile() throws Exception {
public void shouldAcceptRawDevfileUrlWithYaml() throws Exception {
// given
JsonNode jsonNode = mock(JsonNode.class);
String url = "https://host/path/devfile";
when(urlFetcher.fetch(eq(url))).thenReturn(DEVFILE);
when(devfileParser.parseYaml(eq(DEVFILE)))
.thenThrow(new DevfileFormatException("Unrecognized field \"schemaVersion\""));
when(devfileParser.parseYamlRaw(eq(DEVFILE))).thenReturn(jsonNode);
when(jsonNode.isEmpty()).thenReturn(false);

// when
boolean result =
Expand All @@ -188,10 +189,11 @@ public void shouldAcceptRawDevfileUrlWithUnrecognizedDevfile() throws Exception
@Test
public void shouldNotAcceptPublicGitRepositoryUrl() throws Exception {
// given
JsonNode jsonNode = mock(JsonNode.class);
String gitRepositoryUrl = "https://host/user/repo.git";
when(urlFetcher.fetch(eq(gitRepositoryUrl))).thenReturn("unsupported content");
when(devfileParser.parseYaml(eq("unsupported content")))
.thenThrow(new DevfileFormatException("Cannot construct instance of ..."));
when(devfileParser.parseYamlRaw(eq("unsupported content"))).thenReturn(jsonNode);
when(jsonNode.isEmpty()).thenReturn(true);

// when
boolean result =
Expand Down

0 comments on commit 63b0172

Please sign in to comment.