Skip to content

Commit

Permalink
safer icon retrieval (#3592)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhizor authored May 25, 2021
1 parent 024ccc9 commit 43b13eb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static DestinationDefinitionRead buildDestinationDefinitionRead(StandardDestinat
.dockerImageTag(standardDestinationDefinition.getDockerImageTag())
.documentationUrl(new URI(standardDestinationDefinition.getDocumentationUrl()))
.icon(loadIcon(standardDestinationDefinition.getIcon()));
} catch (URISyntaxException | NullPointerException | IOException e) {
} catch (URISyntaxException | NullPointerException e) {
throw new KnownException(500, "Unable to process retrieved latest destination definitions list", e);
}
}
Expand Down Expand Up @@ -161,8 +161,12 @@ public DestinationDefinitionRead updateDestinationDefinition(DestinationDefiniti
return buildDestinationDefinitionRead(newDestination);
}

public static String loadIcon(String name) throws IOException {
return name == null ? null : MoreResources.readResource("icons/" + name);
public static String loadIcon(String name) {
try {
return name == null ? null : MoreResources.readResource("icons/" + name);
} catch (IOException e) {
return null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static SourceDefinitionRead buildSourceDefinitionRead(StandardSourceDefinition s
.dockerImageTag(standardSourceDefinition.getDockerImageTag())
.documentationUrl(new URI(standardSourceDefinition.getDocumentationUrl()))
.icon(loadIcon(standardSourceDefinition.getIcon()));
} catch (URISyntaxException | NullPointerException | IOException e) {
} catch (URISyntaxException | NullPointerException e) {
throw new KnownException(500, "Unable to process retrieved latest source definitions list", e);
}
}
Expand Down Expand Up @@ -158,8 +158,12 @@ public SourceDefinitionRead updateSourceDefinition(SourceDefinitionUpdate source
return buildSourceDefinitionRead(newSource);
}

public static String loadIcon(String name) throws IOException {
return name == null ? null : MoreResources.readResource("icons/" + name);
public static String loadIcon(String name) {
try {
return name == null ? null : MoreResources.readResource("icons/" + name);
} catch (IOException e) {
return null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ void testListDestinations() throws JsonValidationException, IOException, URISynt
.dockerRepository(destination.getDockerRepository())
.dockerImageTag(destination.getDockerImageTag())
.documentationUrl(new URI(destination.getDocumentationUrl()))
.icon(loadIcon(destination.getIcon()));
.icon(DestinationDefinitionsHandler.loadIcon(destination.getIcon()));

final DestinationDefinitionRead expectedDestinationDefinitionRead2 = new DestinationDefinitionRead()
.destinationDefinitionId(destination2.getDestinationDefinitionId())
.name(destination2.getName())
.dockerRepository(destination2.getDockerRepository())
.dockerImageTag(destination2.getDockerImageTag())
.documentationUrl(new URI(destination2.getDocumentationUrl()))
.icon(loadIcon(destination2.getIcon()));
.icon(DestinationDefinitionsHandler.loadIcon(destination2.getIcon()));

final DestinationDefinitionReadList actualDestinationDefinitionReadList = destinationHandler.listDestinationDefinitions();

Expand All @@ -131,7 +131,7 @@ void testGetDestination() throws JsonValidationException, ConfigNotFoundExceptio
.dockerRepository(destination.getDockerRepository())
.dockerImageTag(destination.getDockerImageTag())
.documentationUrl(new URI(destination.getDocumentationUrl()))
.icon(loadIcon(destination.getIcon()));
.icon(DestinationDefinitionsHandler.loadIcon(destination.getIcon()));

final DestinationDefinitionIdRequestBody destinationDefinitionIdRequestBody = new DestinationDefinitionIdRequestBody()
.destinationDefinitionId(destination.getDestinationDefinitionId());
Expand Down Expand Up @@ -159,7 +159,7 @@ void testCreateDestinationDefinition() throws URISyntaxException, IOException, J
.dockerImageTag(destination.getDockerImageTag())
.documentationUrl(new URI(destination.getDocumentationUrl()))
.destinationDefinitionId(destination.getDestinationDefinitionId())
.icon(loadIcon(destination.getIcon()));
.icon(DestinationDefinitionsHandler.loadIcon(destination.getIcon()));

final DestinationDefinitionRead actualRead = destinationHandler.createDestinationDefinition(create);

Expand Down Expand Up @@ -212,12 +212,4 @@ void testHttpTimeout() throws IOException, InterruptedException {

}

private static String loadIcon(String name) {
try {
return DestinationDefinitionsHandler.loadIcon(name);
} catch (IOException e) {
return "Error";
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ void testListSourceDefinitions() throws JsonValidationException, IOException, UR
.dockerRepository(source.getDockerRepository())
.dockerImageTag(source.getDockerImageTag())
.documentationUrl(new URI(source.getDocumentationUrl()))
.icon(loadIcon(source.getIcon()));
.icon(SourceDefinitionsHandler.loadIcon(source.getIcon()));

SourceDefinitionRead expectedSourceDefinitionRead2 = new SourceDefinitionRead()
.sourceDefinitionId(source2.getSourceDefinitionId())
.name(source2.getName())
.dockerRepository(source.getDockerRepository())
.dockerImageTag(source.getDockerImageTag())
.documentationUrl(new URI(source.getDocumentationUrl()))
.icon(loadIcon(source.getIcon()));
.icon(SourceDefinitionsHandler.loadIcon(source.getIcon()));

final SourceDefinitionReadList actualSourceDefinitionReadList = sourceHandler.listSourceDefinitions();

Expand All @@ -133,7 +133,7 @@ void testGetSourceDefinition() throws JsonValidationException, ConfigNotFoundExc
.dockerRepository(source.getDockerRepository())
.dockerImageTag(source.getDockerImageTag())
.documentationUrl(new URI(source.getDocumentationUrl()))
.icon(loadIcon(source.getIcon()));
.icon(SourceDefinitionsHandler.loadIcon(source.getIcon()));

final SourceDefinitionIdRequestBody sourceDefinitionIdRequestBody =
new SourceDefinitionIdRequestBody().sourceDefinitionId(source.getSourceDefinitionId());
Expand Down Expand Up @@ -161,7 +161,7 @@ void testCreateSourceDefinition() throws URISyntaxException, IOException, JsonVa
.dockerImageTag(source.getDockerImageTag())
.documentationUrl(new URI(source.getDocumentationUrl()))
.sourceDefinitionId(source.getSourceDefinitionId())
.icon(loadIcon(source.getIcon()));
.icon(SourceDefinitionsHandler.loadIcon(source.getIcon()));

final SourceDefinitionRead actualRead = sourceHandler.createSourceDefinition(create);

Expand Down Expand Up @@ -215,20 +215,12 @@ void testHttpTimeout() throws IOException, InterruptedException {
@Test
@DisplayName("Icon should contain data")
void testIconHoldsData() {
final String icon = loadIcon(source.getIcon());
final String icon = SourceDefinitionsHandler.loadIcon(source.getIcon());
assertNotNull(icon);
assert (icon.length() > 3000);
assert (icon.length() < 6000);
}

}

private static String loadIcon(String name) {
try {
return SourceDefinitionsHandler.loadIcon(name);
} catch (IOException e) {
return "Error";
}
}

}

0 comments on commit 43b13eb

Please sign in to comment.