|
70 | 70 | import org.opensearch.core.util.FileSystemUtils;
|
71 | 71 | import org.opensearch.env.Environment;
|
72 | 72 | import org.opensearch.env.TestEnvironment;
|
| 73 | +import org.opensearch.semver.SemverRange; |
73 | 74 | import org.opensearch.test.OpenSearchTestCase;
|
74 | 75 | import org.opensearch.test.PosixPermissionsResetter;
|
| 76 | +import org.opensearch.test.VersionUtils; |
75 | 77 | import org.junit.After;
|
76 | 78 | import org.junit.Before;
|
77 | 79 |
|
@@ -284,6 +286,35 @@ static void writePlugin(String name, Path structure, String... additionalProps)
|
284 | 286 | writeJar(structure.resolve("plugin.jar"), className);
|
285 | 287 | }
|
286 | 288 |
|
| 289 | + static void writePlugin(String name, Path structure, SemverRange opensearchVersionRange, String... additionalProps) throws IOException { |
| 290 | + String[] properties = Stream.concat( |
| 291 | + Stream.of( |
| 292 | + "description", |
| 293 | + "fake desc", |
| 294 | + "name", |
| 295 | + name, |
| 296 | + "version", |
| 297 | + "1.0", |
| 298 | + "dependencies", |
| 299 | + "{opensearch:\"" + opensearchVersionRange + "\"}", |
| 300 | + "java.version", |
| 301 | + System.getProperty("java.specification.version"), |
| 302 | + "classname", |
| 303 | + "FakePlugin" |
| 304 | + ), |
| 305 | + Arrays.stream(additionalProps) |
| 306 | + ).toArray(String[]::new); |
| 307 | + PluginTestUtil.writePluginProperties(structure, properties); |
| 308 | + String className = name.substring(0, 1).toUpperCase(Locale.ENGLISH) + name.substring(1) + "Plugin"; |
| 309 | + writeJar(structure.resolve("plugin.jar"), className); |
| 310 | + } |
| 311 | + |
| 312 | + static Path createPlugin(String name, Path structure, SemverRange opensearchVersionRange, String... additionalProps) |
| 313 | + throws IOException { |
| 314 | + writePlugin(name, structure, opensearchVersionRange, additionalProps); |
| 315 | + return writeZip(structure, null); |
| 316 | + } |
| 317 | + |
287 | 318 | static void writePluginSecurityPolicy(Path pluginDir, String... permissions) throws IOException {
|
288 | 319 | StringBuilder securityPolicyContent = new StringBuilder("grant {\n ");
|
289 | 320 | for (String permission : permissions) {
|
@@ -867,6 +898,32 @@ public void testInstallMisspelledOfficialPlugins() throws Exception {
|
867 | 898 | assertThat(e.getMessage(), containsString("Unknown plugin unknown_plugin"));
|
868 | 899 | }
|
869 | 900 |
|
| 901 | + public void testInstallPluginWithCompatibleDependencies() throws Exception { |
| 902 | + Tuple<Path, Environment> env = createEnv(fs, temp); |
| 903 | + Path pluginDir = createPluginDir(temp); |
| 904 | + String pluginZip = createPlugin("fake", pluginDir, SemverRange.fromString("~" + Version.CURRENT.toString())).toUri() |
| 905 | + .toURL() |
| 906 | + .toString(); |
| 907 | + skipJarHellCommand.execute(terminal, Collections.singletonList(pluginZip), false, env.v2()); |
| 908 | + assertThat(terminal.getOutput(), containsString("100%")); |
| 909 | + } |
| 910 | + |
| 911 | + public void testInstallPluginWithIncompatibleDependencies() throws Exception { |
| 912 | + Tuple<Path, Environment> env = createEnv(fs, temp); |
| 913 | + Path pluginDir = createPluginDir(temp); |
| 914 | + // Core version is behind plugin version by one w.r.t patch, hence incompatible |
| 915 | + Version coreVersion = Version.CURRENT; |
| 916 | + Version pluginVersion = VersionUtils.getVersion(coreVersion.major, coreVersion.minor, (byte) (coreVersion.revision + 1)); |
| 917 | + String pluginZip = createPlugin("fake", pluginDir, SemverRange.fromString("~" + pluginVersion.toString())).toUri() |
| 918 | + .toURL() |
| 919 | + .toString(); |
| 920 | + IllegalArgumentException e = expectThrows( |
| 921 | + IllegalArgumentException.class, |
| 922 | + () -> skipJarHellCommand.execute(terminal, Collections.singletonList(pluginZip), false, env.v2()) |
| 923 | + ); |
| 924 | + assertThat(e.getMessage(), containsString("Plugin [fake] was built for OpenSearch version ~" + pluginVersion)); |
| 925 | + } |
| 926 | + |
870 | 927 | public void testBatchFlag() throws Exception {
|
871 | 928 | MockTerminal terminal = new MockTerminal();
|
872 | 929 | installPlugin(terminal, true);
|
|
0 commit comments