@Test public void warningExistsTest() { Map<String, List<SecurityWarning>> securityWarnings = new HashMap<>(); SecurityWarning scriptlerWarning = new SecurityWarning("SECURITY", "security warning", "scriptler", "url"); scriptlerWarning.addSecurityVersion("", "",".*"); securityWarnings.put("scriptler", singletonList(scriptlerWarning)); SecurityWarning lockableResourceWarning1 = new SecurityWarning("SECURITY", "security warning1", "lockable-resources", "url"); lockableResourceWarning1.addSecurityVersion("", "1.59", "1[.][0-9](|[.-].*)|1[.][12345][0-9](|[.-].*)"); SecurityWarning lockableResourceWarning2 = new SecurityWarning("SECURITY", "security warning2", "lockable-resources", "url"); lockableResourceWarning2.addSecurityVersion("", "2.2", "1[.].*|2[.][012](|[.-].*)"); securityWarnings.put("lockable-resources", Arrays.asList(lockableResourceWarning1, lockableResourceWarning2)); SecurityWarning cucumberReports = new SecurityWarning("SECURITY", "security warning", "cucumber-reports", "url"); cucumberReports.addSecurityVersion("1.3.0", "2.5.1", "(1[.][34]|2[.][012345])(|[.-].*)"); securityWarnings.put("cucumber-reports", singletonList(cucumberReports)); SecurityWarning sshAgentsWarning = new SecurityWarning("SECURITY", "security warning", "ssh-slaves", "url"); sshAgentsWarning.addSecurityVersion("", "1.14", "0[.].*|1[.][0-9](|[.-].*)|1[.]1[01234](|[.-].*)"); securityWarnings.put("ssh-slaves", singletonList(sshAgentsWarning)); pm.setAllSecurityWarnings(securityWarnings); Plugin scriptler = new Plugin("scriptler", "1.2", null, null); Plugin lockableResource = new Plugin("lockable-resources", "1.60", null, null); Plugin lockableResource2 = new Plugin("lockable-resources", "2.3.0", null, null); Plugin cucumberReports1 = new Plugin("cucumber-reports", "1.2.1", null, null); Plugin cucumberReports2 = new Plugin("cucumber-reports", "1.4.1", null, null); Plugin sshAgents1 = new Plugin("ssh-slaves", "0.9", null, null); Plugin sshAgents2 = new Plugin("ssh-slaves", "9.2", null, null); assertThat(pm.warningExists(scriptler)).isTrue(); assertThat(pm.warningExists(lockableResource)).isTrue(); assertThat(pm.warningExists(lockableResource2)).isFalse(); assertThat(pm.warningExists(cucumberReports1)).isFalse(); assertThat(pm.warningExists(cucumberReports2)).isTrue(); assertThat(pm.warningExists(sshAgents1)).isTrue(); assertThat(pm.warningExists(sshAgents2)).isFalse(); }
public boolean warningExists(Plugin plugin) { String pluginName = plugin.getName(); List<SecurityWarning> securityWarnings = new ArrayList<>(); if (allSecurityWarnings.containsKey(pluginName)) { for (SecurityWarning securityWarning : allSecurityWarnings.get(pluginName)) { for (SecurityWarning.SecurityVersion effectedVersion : securityWarning.getSecurityVersions()) { Matcher m = effectedVersion.getPattern().matcher(plugin.getVersion().toString()); if (m.matches()) { securityWarnings.add(securityWarning); } } } } plugin.setSecurityWarnings(securityWarnings); return !securityWarnings.isEmpty(); }
PluginManager { public boolean warningExists(Plugin plugin) { String pluginName = plugin.getName(); List<SecurityWarning> securityWarnings = new ArrayList<>(); if (allSecurityWarnings.containsKey(pluginName)) { for (SecurityWarning securityWarning : allSecurityWarnings.get(pluginName)) { for (SecurityWarning.SecurityVersion effectedVersion : securityWarning.getSecurityVersions()) { Matcher m = effectedVersion.getPattern().matcher(plugin.getVersion().toString()); if (m.matches()) { securityWarnings.add(securityWarning); } } } } plugin.setSecurityWarnings(securityWarnings); return !securityWarnings.isEmpty(); } }
PluginManager { public boolean warningExists(Plugin plugin) { String pluginName = plugin.getName(); List<SecurityWarning> securityWarnings = new ArrayList<>(); if (allSecurityWarnings.containsKey(pluginName)) { for (SecurityWarning securityWarning : allSecurityWarnings.get(pluginName)) { for (SecurityWarning.SecurityVersion effectedVersion : securityWarning.getSecurityVersions()) { Matcher m = effectedVersion.getPattern().matcher(plugin.getVersion().toString()); if (m.matches()) { securityWarnings.add(securityWarning); } } } } plugin.setSecurityWarnings(securityWarnings); return !securityWarnings.isEmpty(); } @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "we want the user to be able to specify a path")  PluginManager(Config cfg); }
PluginManager { public boolean warningExists(Plugin plugin) { String pluginName = plugin.getName(); List<SecurityWarning> securityWarnings = new ArrayList<>(); if (allSecurityWarnings.containsKey(pluginName)) { for (SecurityWarning securityWarning : allSecurityWarnings.get(pluginName)) { for (SecurityWarning.SecurityVersion effectedVersion : securityWarning.getSecurityVersions()) { Matcher m = effectedVersion.getPattern().matcher(plugin.getVersion().toString()); if (m.matches()) { securityWarnings.add(securityWarning); } } } } plugin.setSecurityWarnings(securityWarnings); return !securityWarnings.isEmpty(); } @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "we want the user to be able to specify a path")  PluginManager(Config cfg); void start(); void start(boolean downloadUc); List<Plugin> findPluginsToDownload(Map<String, Plugin> requestedPlugins); Map<String, Plugin> findEffectivePlugins(List<Plugin> pluginsToBeDownloaded); void listPlugins(); void logPlugins(String description, List<Plugin> plugins); Map<String, List<SecurityWarning>> getSecurityWarnings(); void showAllSecurityWarnings(); void showSpecificSecurityWarnings(List<Plugin> plugins); List<Plugin> getLatestVersionsOfPlugins(List<Plugin> plugins); boolean warningExists(Plugin plugin); void checkVersionCompatibility(VersionNumber jenkinsVersion, List<Plugin> pluginsToBeDownloaded); void downloadPlugins(List<Plugin> plugins); Map<String, Plugin> findPluginsAndDependencies(List<Plugin> requestedPlugins); void outputPluginReplacementInfo(Plugin lowerVersion, Plugin higherVersion); @Deprecated JSONObject getJson(String urlString); JSONObject getJson(URL url, String cacheKey); void getUCJson(VersionNumber jenkinsVersion); JSONArray getPluginDependencyJsonArray(Plugin plugin, JSONObject ucJson); VersionNumber getLatestPluginVersion(String pluginName); List<Plugin> resolveDependenciesFromManifest(Plugin plugin); List<Plugin> resolveDependenciesFromJson(Plugin plugin, JSONObject pluginJson); List<Plugin> resolveDirectDependencies(Plugin plugin); Map<String, Plugin> resolveRecursiveDependencies(Plugin plugin); boolean downloadPlugin(Plugin plugin, File location); String getPluginDownloadUrl(Plugin plugin); boolean downloadToFile(String urlString, Plugin plugin, File fileLocation); @SuppressFBWarnings({"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", "PATH_TRAVERSAL_IN"}) boolean downloadToFile(String urlString, Plugin plugin, File fileLocation, int maxRetries); String getAttributeFromManifest(File file, String key); VersionNumber getJenkinsVersionFromWar(); String getPluginVersion(File file); Map<String, Plugin> installedPlugins(); @SuppressFBWarnings({"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", "PATH_TRAVERSAL_IN"}) Map<String, Plugin> bundledPlugins(); String getJenkinsUCLatest(); void setJenkinsUCLatest(String updateCenterLatest); void setInstalledPluginVersions(Map<String, Plugin> installedPlugins); void setBundledPluginVersions(Map<String, Plugin> bundledPlugins); void setAllPluginsAndDependencies(Map<String, Plugin> allPluginsAndDependencies); void setEffectivePlugins(Map<String, Plugin> effectivePlugins); void setPluginsToBeDownloaded(List<Plugin> pluginsToBeDownloaded); void logVerbose(String message); void setLatestUcJson(JSONObject latestUcJson); void setLatestUcPlugins(JSONObject latestPlugins); void setExperimentalUcJson(JSONObject experimentalUcJson); void setAllSecurityWarnings(Map<String, List<SecurityWarning>> securityWarnings); void setPluginInfoJson(JSONObject pluginInfoJson); void setCm(CacheManager cm); List<Plugin> getFailedPlugins(); }
PluginManager { public boolean warningExists(Plugin plugin) { String pluginName = plugin.getName(); List<SecurityWarning> securityWarnings = new ArrayList<>(); if (allSecurityWarnings.containsKey(pluginName)) { for (SecurityWarning securityWarning : allSecurityWarnings.get(pluginName)) { for (SecurityWarning.SecurityVersion effectedVersion : securityWarning.getSecurityVersions()) { Matcher m = effectedVersion.getPattern().matcher(plugin.getVersion().toString()); if (m.matches()) { securityWarnings.add(securityWarning); } } } } plugin.setSecurityWarnings(securityWarnings); return !securityWarnings.isEmpty(); } @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "we want the user to be able to specify a path")  PluginManager(Config cfg); void start(); void start(boolean downloadUc); List<Plugin> findPluginsToDownload(Map<String, Plugin> requestedPlugins); Map<String, Plugin> findEffectivePlugins(List<Plugin> pluginsToBeDownloaded); void listPlugins(); void logPlugins(String description, List<Plugin> plugins); Map<String, List<SecurityWarning>> getSecurityWarnings(); void showAllSecurityWarnings(); void showSpecificSecurityWarnings(List<Plugin> plugins); List<Plugin> getLatestVersionsOfPlugins(List<Plugin> plugins); boolean warningExists(Plugin plugin); void checkVersionCompatibility(VersionNumber jenkinsVersion, List<Plugin> pluginsToBeDownloaded); void downloadPlugins(List<Plugin> plugins); Map<String, Plugin> findPluginsAndDependencies(List<Plugin> requestedPlugins); void outputPluginReplacementInfo(Plugin lowerVersion, Plugin higherVersion); @Deprecated JSONObject getJson(String urlString); JSONObject getJson(URL url, String cacheKey); void getUCJson(VersionNumber jenkinsVersion); JSONArray getPluginDependencyJsonArray(Plugin plugin, JSONObject ucJson); VersionNumber getLatestPluginVersion(String pluginName); List<Plugin> resolveDependenciesFromManifest(Plugin plugin); List<Plugin> resolveDependenciesFromJson(Plugin plugin, JSONObject pluginJson); List<Plugin> resolveDirectDependencies(Plugin plugin); Map<String, Plugin> resolveRecursiveDependencies(Plugin plugin); boolean downloadPlugin(Plugin plugin, File location); String getPluginDownloadUrl(Plugin plugin); boolean downloadToFile(String urlString, Plugin plugin, File fileLocation); @SuppressFBWarnings({"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", "PATH_TRAVERSAL_IN"}) boolean downloadToFile(String urlString, Plugin plugin, File fileLocation, int maxRetries); String getAttributeFromManifest(File file, String key); VersionNumber getJenkinsVersionFromWar(); String getPluginVersion(File file); Map<String, Plugin> installedPlugins(); @SuppressFBWarnings({"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", "PATH_TRAVERSAL_IN"}) Map<String, Plugin> bundledPlugins(); String getJenkinsUCLatest(); void setJenkinsUCLatest(String updateCenterLatest); void setInstalledPluginVersions(Map<String, Plugin> installedPlugins); void setBundledPluginVersions(Map<String, Plugin> bundledPlugins); void setAllPluginsAndDependencies(Map<String, Plugin> allPluginsAndDependencies); void setEffectivePlugins(Map<String, Plugin> effectivePlugins); void setPluginsToBeDownloaded(List<Plugin> pluginsToBeDownloaded); void logVerbose(String message); void setLatestUcJson(JSONObject latestUcJson); void setLatestUcPlugins(JSONObject latestPlugins); void setExperimentalUcJson(JSONObject experimentalUcJson); void setAllSecurityWarnings(Map<String, List<SecurityWarning>> securityWarnings); void setPluginInfoJson(JSONObject pluginInfoJson); void setCm(CacheManager cm); List<Plugin> getFailedPlugins();  }