Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion server/src/main/java/org/eclipse/openvsx/ExtensionProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,9 @@ private String tryGetAssetPath(String type) {
return null;
}

public @Nullable TempFile getIcon(ExtensionVersion extVersion) throws IOException {
public @Nullable String getIconPath() {
var iconPath = tryGetAssetPath(ExtensionQueryResult.ExtensionFile.FILE_ICON);

if (StringUtils.isEmpty(iconPath)) {
loadPackageJson();
var iconPathNode = packageJson.get("icon");
Expand All @@ -489,6 +490,15 @@ private String tryGetAssetPath(String type) {
iconPath = "extension/" + iconPath;
}

return iconPath;
}

public @Nullable TempFile getIcon(ExtensionVersion extVersion) throws IOException {
var iconPath = getIconPath();
if (iconPath == null) {
return null;
}

var entryFile = ArchiveUtil.readEntry(zipFile, iconPath);
if (entryFile == null) {
throw new ErrorResultException("Icon " + entryNotFoundMessage(iconPath));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
package org.eclipse.openvsx.publish;

import java.io.IOException;
import java.nio.file.Path;
import java.time.LocalDateTime;
import java.util.List;
import java.util.function.Consumer;
Expand Down Expand Up @@ -65,7 +64,7 @@ public class PublishExtensionVersionHandler {
private final ExtensionControlService extensionControl;
private final ExtensionScanService scanService;

private final Predicate<Path> unsupportedIconExtensions;
private final Predicate<String> unsupportedIconExtensions;

public PublishExtensionVersionHandler(
PublishingConfig config,
Expand Down Expand Up @@ -95,7 +94,7 @@ public PublishExtensionVersionHandler(
return false;
}

var fileExtension = FilenameUtils.getExtension(path.toString());
var fileExtension = FilenameUtils.getExtension(path);
return config.getUnsupportedIconFormats().stream().anyMatch(ext -> ext.equalsIgnoreCase(fileExtension));
};
}
Expand All @@ -115,15 +114,15 @@ public ExtensionVersion createExtensionVersion(ExtensionProcessor processor, Per
.map(id -> parseExtensionId(id, "extensionDependencies"))
.toList();

if(!parsedDependencies.isEmpty()) {
if (!parsedDependencies.isEmpty()) {
checkDependencies(parsedDependencies);
}
bundledExtensions.forEach(id -> parseExtensionId(id, "extensionPack"));
}

extVersion.setDependencies(dependencies);
extVersion.setBundledExtensions(bundledExtensions);
if(integrityService.isEnabled()) {
if (integrityService.isEnabled()) {
extVersion.setSignatureKeyPair(repositories.findActiveKeyPair());
}

Expand Down Expand Up @@ -178,7 +177,8 @@ private ExtensionVersion createExtensionVersion(ExtensionProcessor processor, Us
extVersion.setExtension(extension);

validateLicense(processor, extVersion);
validateIcon(processor, extVersion);
validateIcon(processor);
validateFileResources(processor, extVersion);
validateMetadata(extVersion);
entityManager.persist(extVersion);
return extVersion;
Expand Down Expand Up @@ -221,13 +221,22 @@ private void checkLicense(ExtensionVersion extVersion, TempFile licenseFile) {
}
}

private void validateIcon(ExtensionProcessor processor, ExtensionVersion extVersion) {
try (var iconFile = processor.getIcon(extVersion)) {
if (iconFile != null && unsupportedIconExtensions.test(iconFile.getPath())) {
throw new ErrorResultException("This extension cannot be accepted as it uses an unsupported icon format.");
}
} catch (IOException e) {
throw new ServerErrorException("Failed to read icon file", e);
private void validateIcon(ExtensionProcessor processor) {
var iconPath = processor.getIconPath();
if (iconPath != null && unsupportedIconExtensions.test(iconPath)) {
throw new ErrorResultException("This extension cannot be accepted as it uses an unsupported icon format.");
}
}

private void validateFileResources(ExtensionProcessor processor, ExtensionVersion extVersion) {
try {
// Validate that all file resources are readable/accessible during synchronous publishing
// to avoid failing during async publishing and report errors directly back to publishers.
// This creates unnecessary temp files, however these are usually small and thus it is
// acceptable in this case.
processor.getFileResources(extVersion, _ -> {});
} catch (ErrorResultException exc) {
throw new ErrorResultException("Validation failed: " + exc.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.nio.file.Path;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
Expand All @@ -35,7 +34,6 @@
import org.eclipse.openvsx.repositories.RepositoryService;
import org.eclipse.openvsx.scanning.ExtensionScanService;
import org.eclipse.openvsx.util.ErrorResultException;
import org.eclipse.openvsx.util.TempFile;
import org.jobrunr.scheduling.JobRequestScheduler;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -207,7 +205,7 @@ private ExtensionVersion mockExtensionVersion(String namespace, String name, Str
when(processor.getExtensionName()).thenReturn(name);
when(processor.getVersion()).thenReturn(version);
if (iconPath != null) {
when(processor.getIcon(ArgumentMatchers.any())).thenReturn(new TempFile(Path.of(iconPath)));
when(processor.getIconPath()).thenReturn(iconPath);
}

var ev = new ExtensionVersion();
Expand Down
Loading