From 4d21c1f71336b8ec24fdc1591a6a2711cba4050b Mon Sep 17 00:00:00 2001 From: Bastian Doetsch Date: Thu, 7 Apr 2022 12:33:00 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20enforce=20lower=20and=20u?= =?UTF-8?q?pper=20file=20size=20limit=20when=20triggering=20analysis=20[RO?= =?UTF-8?q?AD-799][ROAD-814]=20(#37)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: check for min and max file size when triggering analysis [ROAD-799] also bump upload tries to 10 --- CHANGELOG.md | 4 ++++ build.gradle | 2 +- .../javaclient/core/AnalysisDataBase.java | 3 ++- .../javaclient/core/DeepCodeUtilsBase.java | 2 +- .../requests/GetAnalysisRequest.java | 2 +- .../javaclient/core/AnalysisDataTest.java | 23 ++++++++++++++++--- 6 files changed, 29 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d12650..c1cbc8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [2.3.1] - 2022-04 +- fix: adjust max file size to the correct size of 1MB (previously: 4000 bytes) +- chore: update upload attemps to 10 + ## [2.3.0] - 2022-03 - fix: make 5 consequent attempts to getAnalysis during polling if operation does not succeed with 404 - fix: make 5 attempts to re-upload files if operation does not succeed diff --git a/build.gradle b/build.gradle index a167485..f1e2030 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { group = "io.snyk.code.sdk" archivesBaseName = "snyk-code-client" -version = "2.3.0" +version = "2.3.1" repositories { mavenLocal() diff --git a/src/main/java/ai/deepcode/javaclient/core/AnalysisDataBase.java b/src/main/java/ai/deepcode/javaclient/core/AnalysisDataBase.java index 425063e..feec390 100644 --- a/src/main/java/ai/deepcode/javaclient/core/AnalysisDataBase.java +++ b/src/main/java/ai/deepcode/javaclient/core/AnalysisDataBase.java @@ -36,6 +36,7 @@ public abstract class AnalysisDataBase { public static final String COMPLETE = "COMPLETE"; + public static final int MAX_FILE_SIZE = 1024 * 1024; private final PlatformDependentUtilsBase pdUtils; private final HashContentUtilsBase hashContentUtils; private final DeepCodeParamsBase deepCodeParams; @@ -411,7 +412,7 @@ private boolean uploadFilesStep( } else if (missingFiles.isEmpty()) { dcLogger.logInfo("No missingFiles to Upload"); } else { - final int attempts = 5; + final int attempts = 10; int counter = 0; while (!missingFiles.isEmpty() && counter < attempts) { if (counter > 0) { diff --git a/src/main/java/ai/deepcode/javaclient/core/DeepCodeUtilsBase.java b/src/main/java/ai/deepcode/javaclient/core/DeepCodeUtilsBase.java index 3eefa51..c7c5731 100644 --- a/src/main/java/ai/deepcode/javaclient/core/DeepCodeUtilsBase.java +++ b/src/main/java/ai/deepcode/javaclient/core/DeepCodeUtilsBase.java @@ -70,7 +70,7 @@ public List getAllSupportedFilesInProject( protected abstract Collection allProjectFiles(@NotNull Object project); - private static final long MAX_FILE_SIZE = 4000000; // ~ 4MB in bytes + private static final long MAX_FILE_SIZE = 1024*1024; // 1MB in bytes public boolean isSupportedFileFormat(@NotNull Object file) { // DCLogger.getInstance().info("isSupportedFileFormat started for " + psiFile.getName()); diff --git a/src/main/java/ai/deepcode/javaclient/requests/GetAnalysisRequest.java b/src/main/java/ai/deepcode/javaclient/requests/GetAnalysisRequest.java index 86638e7..a338b92 100644 --- a/src/main/java/ai/deepcode/javaclient/requests/GetAnalysisRequest.java +++ b/src/main/java/ai/deepcode/javaclient/requests/GetAnalysisRequest.java @@ -16,7 +16,7 @@ public class GetAnalysisRequest { * @param severity * @param shard uniq String (hash) per Project to optimize jobs on backend (run on the same worker to reuse caches) * @param ideProductName specific IDE - * @param orgDisplayName client’s snyk organization name + * @param orgDisplayName clients snyk organization name * @param prioritized * @param legacy */ diff --git a/src/test/java/ai/deepcode/javaclient/core/AnalysisDataTest.java b/src/test/java/ai/deepcode/javaclient/core/AnalysisDataTest.java index 4dca31b..171639e 100644 --- a/src/test/java/ai/deepcode/javaclient/core/AnalysisDataTest.java +++ b/src/test/java/ai/deepcode/javaclient/core/AnalysisDataTest.java @@ -15,6 +15,9 @@ import org.jetbrains.annotations.NotNull; import org.junit.Test; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; import java.util.Arrays; import java.util.Collections; import java.util.LinkedList; @@ -38,6 +41,16 @@ public class AnalysisDataTest { public @NotNull String getProjectName(@NotNull Object project) { return project.toString(); } + + @Override + public @NotNull String getFileName(@NotNull Object file) { + return "testFileName"; + } + + @Override + public long getFileSize(@NotNull Object file) { + return getFileName(file).length(); + } }; final DCLoggerBase dcLogger = new LoggerMock(); @@ -77,7 +90,7 @@ private static class RestApiMockWithBrokenFileUpload extends DeepCodeRestApiMock // make 5 attempts to re-upload files if operation does not succeed @Test - public void reupload_files_if_initial_upload_does_not_succeed() { + public void reupload_files_if_initial_upload_does_not_succeed() throws IOException { final int[] reUploadCounter = {0}; restApi = new RestApiMockWithBrokenFileUpload() { @Override @@ -94,9 +107,13 @@ public void reupload_files_if_initial_upload_does_not_succeed() { final String project = "Project1"; final String progress = "Progress Indicator"; - analysisData.updateCachedResultsForFiles(project, Collections.singleton("File"), progress); + File file = File.createTempFile("analysisDataTest","tmp"); + file.deleteOnExit(); + Files.writeString(file.toPath(), "testtestest"); + + analysisData.updateCachedResultsForFiles(project, Collections.singleton(file), progress); - assertEquals("Should be made 5 attempts to re-upload files if operation does not succeed", 5, reUploadCounter[0]); + assertEquals("Should have made 10 attempts to re-upload files if operation does not succeed", 10, reUploadCounter[0]); } // do not try to getAnalysis if `upload files` is not succeed (i.e. `missingFiles` is not empty after uploads)