@Test void testUploadAppMissingRequiredConfigFile() throws IOException { InputStream zipData = AppManagerServiceImplTest.class.getResourceAsStream("/valid-app.zip"); String fileName = "app.zip"; String tmpDirName = "apps_tmp" + File.separator + "extracted_app.zip"; doReturn(tempDir).when(fileStore).getFileUnchecked(tmpDirName); doReturn(indexFile) .when(fileStore) .getFileUnchecked(tmpDirName + File.separator + "index.html"); when(indexFile.exists()).thenReturn(true); doReturn(configFile) .when(fileStore) .getFileUnchecked(tmpDirName + File.separator + "config.json"); Exception exception = assertThrows( AppArchiveMissingFilesException.class, () -> appManagerServiceImpl.uploadApp(zipData, fileName, "app")); assertThat(exception.getMessage()).containsPattern("missingFromArchive:\\[config.json\\]"); }
@Override public String uploadApp(InputStream zipData, String zipFileName, String formFieldName) throws IOException { String tempFilesDir = "extracted_" + zipFileName; String tempAppDirectoryName = APPS_TMP_DIR + separator + tempFilesDir; fileStore.createDirectory(tempAppDirectoryName); try { ZipFileUtil.unzip(zipData, fileStore.getFileUnchecked(tempAppDirectoryName)); } catch (UnzipException unzipException) { fileStore.delete(tempAppDirectoryName); throw new InvalidAppArchiveException(formFieldName, unzipException); } List<String> missingRequiredFilesList = buildMissingRequiredFiles(tempAppDirectoryName); if (!missingRequiredFilesList.isEmpty()) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new AppArchiveMissingFilesException(missingRequiredFilesList); } return tempAppDirectoryName; }
AppManagerServiceImpl implements AppManagerService { @Override public String uploadApp(InputStream zipData, String zipFileName, String formFieldName) throws IOException { String tempFilesDir = "extracted_" + zipFileName; String tempAppDirectoryName = APPS_TMP_DIR + separator + tempFilesDir; fileStore.createDirectory(tempAppDirectoryName); try { ZipFileUtil.unzip(zipData, fileStore.getFileUnchecked(tempAppDirectoryName)); } catch (UnzipException unzipException) { fileStore.delete(tempAppDirectoryName); throw new InvalidAppArchiveException(formFieldName, unzipException); } List<String> missingRequiredFilesList = buildMissingRequiredFiles(tempAppDirectoryName); if (!missingRequiredFilesList.isEmpty()) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new AppArchiveMissingFilesException(missingRequiredFilesList); } return tempAppDirectoryName; } }
AppManagerServiceImpl implements AppManagerService { @Override public String uploadApp(InputStream zipData, String zipFileName, String formFieldName) throws IOException { String tempFilesDir = "extracted_" + zipFileName; String tempAppDirectoryName = APPS_TMP_DIR + separator + tempFilesDir; fileStore.createDirectory(tempAppDirectoryName); try { ZipFileUtil.unzip(zipData, fileStore.getFileUnchecked(tempAppDirectoryName)); } catch (UnzipException unzipException) { fileStore.delete(tempAppDirectoryName); throw new InvalidAppArchiveException(formFieldName, unzipException); } List<String> missingRequiredFilesList = buildMissingRequiredFiles(tempAppDirectoryName); if (!missingRequiredFilesList.isEmpty()) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new AppArchiveMissingFilesException(missingRequiredFilesList); } return tempAppDirectoryName; } AppManagerServiceImpl(
      AppFactory appFactory,
      DataService dataService,
      FileStore fileStore,
      Gson gson,
      PluginFactory pluginFactory); }
AppManagerServiceImpl implements AppManagerService { @Override public String uploadApp(InputStream zipData, String zipFileName, String formFieldName) throws IOException { String tempFilesDir = "extracted_" + zipFileName; String tempAppDirectoryName = APPS_TMP_DIR + separator + tempFilesDir; fileStore.createDirectory(tempAppDirectoryName); try { ZipFileUtil.unzip(zipData, fileStore.getFileUnchecked(tempAppDirectoryName)); } catch (UnzipException unzipException) { fileStore.delete(tempAppDirectoryName); throw new InvalidAppArchiveException(formFieldName, unzipException); } List<String> missingRequiredFilesList = buildMissingRequiredFiles(tempAppDirectoryName); if (!missingRequiredFilesList.isEmpty()) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new AppArchiveMissingFilesException(missingRequiredFilesList); } return tempAppDirectoryName; } AppManagerServiceImpl(
      AppFactory appFactory,
      DataService dataService,
      FileStore fileStore,
      Gson gson,
      PluginFactory pluginFactory); @Override List<AppResponse> getApps(); @Override AppResponse getAppByName(String appName); @Override @Transactional void activateApp(App app); @Override @Transactional void deactivateApp(App app); @Override @Transactional void deleteApp(String id); @Override String uploadApp(InputStream zipData, String zipFileName, String formFieldName); @Override AppConfig checkAndObtainConfig(String tempDir, String configContent); @Override @Transactional void configureApp(AppConfig appConfig, String htmlTemplate); @Override String extractFileContent(String appDir, String fileName); }
AppManagerServiceImpl implements AppManagerService { @Override public String uploadApp(InputStream zipData, String zipFileName, String formFieldName) throws IOException { String tempFilesDir = "extracted_" + zipFileName; String tempAppDirectoryName = APPS_TMP_DIR + separator + tempFilesDir; fileStore.createDirectory(tempAppDirectoryName); try { ZipFileUtil.unzip(zipData, fileStore.getFileUnchecked(tempAppDirectoryName)); } catch (UnzipException unzipException) { fileStore.delete(tempAppDirectoryName); throw new InvalidAppArchiveException(formFieldName, unzipException); } List<String> missingRequiredFilesList = buildMissingRequiredFiles(tempAppDirectoryName); if (!missingRequiredFilesList.isEmpty()) { fileStore.deleteDirectory(APPS_TMP_DIR); throw new AppArchiveMissingFilesException(missingRequiredFilesList); } return tempAppDirectoryName; } AppManagerServiceImpl(
      AppFactory appFactory,
      DataService dataService,
      FileStore fileStore,
      Gson gson,
      PluginFactory pluginFactory); @Override List<AppResponse> getApps(); @Override AppResponse getAppByName(String appName); @Override @Transactional void activateApp(App app); @Override @Transactional void deactivateApp(App app); @Override @Transactional void deleteApp(String id); @Override String uploadApp(InputStream zipData, String zipFileName, String formFieldName); @Override AppConfig checkAndObtainConfig(String tempDir, String configContent); @Override @Transactional void configureApp(AppConfig appConfig, String htmlTemplate); @Override String extractFileContent(String appDir, String fileName); static final String APPS_DIR; static final String ZIP_INDEX_FILE; static final String ZIP_CONFIG_FILE; static final String APP_PLUGIN_ROOT; }