@Test public void when_checksum_is_correct_but_not_valid_zipfile_throws_404() { when(mockedChecksumService.hasCorrectChecksum(eq("mychecksum"), any())).thenReturn(true); when(mockedZipSupport.isZipFile(any())).thenReturn(false); expectedException.expect(NotAcceptableException.class); serviceToTest.uploadSourceCode(PROJECT1, randomUuid, file, "mychecksum"); }
@UseCaseUserUploadsSourceCode(@Step(number = 2, name = "Try to find project annd upload sourcecode as zipfile", description = "When project is found and user has access and job is initializing the sourcecode file will be uploaded")) public void uploadSourceCode(String projectId, UUID jobUUID, MultipartFile file, String checkSum) { assertion.isValidProjectId(projectId); assertion.isValidJobUUID(jobUUID); notNull(file, "file may not be null!"); String traceLogID = logSanitizer.sanitize(UUIDTraceLogID.traceLogID(jobUUID),-1); auditLogService.log("Wants to upload source code to project {}, {}", logSanitizer.sanitize(projectId, 30) ,traceLogID); assertService.assertUserHasAccessToProject(projectId); assertJobFoundAndStillInitializing(projectId, jobUUID); JobStorage jobStorage = storageService.getJobStorage(projectId, jobUUID); Path tmpFile = null; try { try { tmpFile = Files.createTempFile("sechub_schedule_upload_tmp", null); file.transferTo(tmpFile); } catch (IOException e) { LOG.error("Was not able to create temp file of zipped sources!", e); throw new SecHubRuntimeException("Was not able to create temp file"); } assertValidZipFile(tmpFile); assertCheckSumCorrect(checkSum, tmpFile); try { jobStorage.store(SOURCECODE_ZIP, file.getInputStream()); } catch (IOException e) { LOG.error("Was not able to store zipped sources! {}", traceLogID, e); throw new SecHubRuntimeException("Was not able to upload sources"); } LOG.info("uploaded sourcecode for {}", traceLogID); } finally { if (tmpFile != null && Files.exists(tmpFile)) { try { Files.delete(tmpFile); } catch (IOException e) { LOG.error("Was not able delete former temp file for zipped sources! {}",traceLogID, e); } } } }
SchedulerUploadService { @UseCaseUserUploadsSourceCode(@Step(number = 2, name = "Try to find project annd upload sourcecode as zipfile", description = "When project is found and user has access and job is initializing the sourcecode file will be uploaded")) public void uploadSourceCode(String projectId, UUID jobUUID, MultipartFile file, String checkSum) { assertion.isValidProjectId(projectId); assertion.isValidJobUUID(jobUUID); notNull(file, "file may not be null!"); String traceLogID = logSanitizer.sanitize(UUIDTraceLogID.traceLogID(jobUUID),-1); auditLogService.log("Wants to upload source code to project {}, {}", logSanitizer.sanitize(projectId, 30) ,traceLogID); assertService.assertUserHasAccessToProject(projectId); assertJobFoundAndStillInitializing(projectId, jobUUID); JobStorage jobStorage = storageService.getJobStorage(projectId, jobUUID); Path tmpFile = null; try { try { tmpFile = Files.createTempFile("sechub_schedule_upload_tmp", null); file.transferTo(tmpFile); } catch (IOException e) { LOG.error("Was not able to create temp file of zipped sources!", e); throw new SecHubRuntimeException("Was not able to create temp file"); } assertValidZipFile(tmpFile); assertCheckSumCorrect(checkSum, tmpFile); try { jobStorage.store(SOURCECODE_ZIP, file.getInputStream()); } catch (IOException e) { LOG.error("Was not able to store zipped sources! {}", traceLogID, e); throw new SecHubRuntimeException("Was not able to upload sources"); } LOG.info("uploaded sourcecode for {}", traceLogID); } finally { if (tmpFile != null && Files.exists(tmpFile)) { try { Files.delete(tmpFile); } catch (IOException e) { LOG.error("Was not able delete former temp file for zipped sources! {}",traceLogID, e); } } } } }
SchedulerUploadService { @UseCaseUserUploadsSourceCode(@Step(number = 2, name = "Try to find project annd upload sourcecode as zipfile", description = "When project is found and user has access and job is initializing the sourcecode file will be uploaded")) public void uploadSourceCode(String projectId, UUID jobUUID, MultipartFile file, String checkSum) { assertion.isValidProjectId(projectId); assertion.isValidJobUUID(jobUUID); notNull(file, "file may not be null!"); String traceLogID = logSanitizer.sanitize(UUIDTraceLogID.traceLogID(jobUUID),-1); auditLogService.log("Wants to upload source code to project {}, {}", logSanitizer.sanitize(projectId, 30) ,traceLogID); assertService.assertUserHasAccessToProject(projectId); assertJobFoundAndStillInitializing(projectId, jobUUID); JobStorage jobStorage = storageService.getJobStorage(projectId, jobUUID); Path tmpFile = null; try { try { tmpFile = Files.createTempFile("sechub_schedule_upload_tmp", null); file.transferTo(tmpFile); } catch (IOException e) { LOG.error("Was not able to create temp file of zipped sources!", e); throw new SecHubRuntimeException("Was not able to create temp file"); } assertValidZipFile(tmpFile); assertCheckSumCorrect(checkSum, tmpFile); try { jobStorage.store(SOURCECODE_ZIP, file.getInputStream()); } catch (IOException e) { LOG.error("Was not able to store zipped sources! {}", traceLogID, e); throw new SecHubRuntimeException("Was not able to upload sources"); } LOG.info("uploaded sourcecode for {}", traceLogID); } finally { if (tmpFile != null && Files.exists(tmpFile)) { try { Files.delete(tmpFile); } catch (IOException e) { LOG.error("Was not able delete former temp file for zipped sources! {}",traceLogID, e); } } } }  }
SchedulerUploadService { @UseCaseUserUploadsSourceCode(@Step(number = 2, name = "Try to find project annd upload sourcecode as zipfile", description = "When project is found and user has access and job is initializing the sourcecode file will be uploaded")) public void uploadSourceCode(String projectId, UUID jobUUID, MultipartFile file, String checkSum) { assertion.isValidProjectId(projectId); assertion.isValidJobUUID(jobUUID); notNull(file, "file may not be null!"); String traceLogID = logSanitizer.sanitize(UUIDTraceLogID.traceLogID(jobUUID),-1); auditLogService.log("Wants to upload source code to project {}, {}", logSanitizer.sanitize(projectId, 30) ,traceLogID); assertService.assertUserHasAccessToProject(projectId); assertJobFoundAndStillInitializing(projectId, jobUUID); JobStorage jobStorage = storageService.getJobStorage(projectId, jobUUID); Path tmpFile = null; try { try { tmpFile = Files.createTempFile("sechub_schedule_upload_tmp", null); file.transferTo(tmpFile); } catch (IOException e) { LOG.error("Was not able to create temp file of zipped sources!", e); throw new SecHubRuntimeException("Was not able to create temp file"); } assertValidZipFile(tmpFile); assertCheckSumCorrect(checkSum, tmpFile); try { jobStorage.store(SOURCECODE_ZIP, file.getInputStream()); } catch (IOException e) { LOG.error("Was not able to store zipped sources! {}", traceLogID, e); throw new SecHubRuntimeException("Was not able to upload sources"); } LOG.info("uploaded sourcecode for {}", traceLogID); } finally { if (tmpFile != null && Files.exists(tmpFile)) { try { Files.delete(tmpFile); } catch (IOException e) { LOG.error("Was not able delete former temp file for zipped sources! {}",traceLogID, e); } } } }  @UseCaseUserUploadsSourceCode(@Step(number = 2, name = "Try to find project annd upload sourcecode as zipfile", description = "When project is found and user has access and job is initializing the sourcecode file will be uploaded")) void uploadSourceCode(String projectId, UUID jobUUID, MultipartFile file, String checkSum); }
SchedulerUploadService { @UseCaseUserUploadsSourceCode(@Step(number = 2, name = "Try to find project annd upload sourcecode as zipfile", description = "When project is found and user has access and job is initializing the sourcecode file will be uploaded")) public void uploadSourceCode(String projectId, UUID jobUUID, MultipartFile file, String checkSum) { assertion.isValidProjectId(projectId); assertion.isValidJobUUID(jobUUID); notNull(file, "file may not be null!"); String traceLogID = logSanitizer.sanitize(UUIDTraceLogID.traceLogID(jobUUID),-1); auditLogService.log("Wants to upload source code to project {}, {}", logSanitizer.sanitize(projectId, 30) ,traceLogID); assertService.assertUserHasAccessToProject(projectId); assertJobFoundAndStillInitializing(projectId, jobUUID); JobStorage jobStorage = storageService.getJobStorage(projectId, jobUUID); Path tmpFile = null; try { try { tmpFile = Files.createTempFile("sechub_schedule_upload_tmp", null); file.transferTo(tmpFile); } catch (IOException e) { LOG.error("Was not able to create temp file of zipped sources!", e); throw new SecHubRuntimeException("Was not able to create temp file"); } assertValidZipFile(tmpFile); assertCheckSumCorrect(checkSum, tmpFile); try { jobStorage.store(SOURCECODE_ZIP, file.getInputStream()); } catch (IOException e) { LOG.error("Was not able to store zipped sources! {}", traceLogID, e); throw new SecHubRuntimeException("Was not able to upload sources"); } LOG.info("uploaded sourcecode for {}", traceLogID); } finally { if (tmpFile != null && Files.exists(tmpFile)) { try { Files.delete(tmpFile); } catch (IOException e) { LOG.error("Was not able delete former temp file for zipped sources! {}",traceLogID, e); } } } }  @UseCaseUserUploadsSourceCode(@Step(number = 2, name = "Try to find project annd upload sourcecode as zipfile", description = "When project is found and user has access and job is initializing the sourcecode file will be uploaded")) void uploadSourceCode(String projectId, UUID jobUUID, MultipartFile file, String checkSum);  }