public void testBuiltinModule() throws Exception {
   Tuple<Path, Environment> env = createEnv(fs, temp);
   Path pluginDir = createPluginDir(temp);
   String pluginZip = createPlugin("lang-painless", pluginDir);
   UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
   assertTrue(e.getMessage(), e.getMessage().contains("is a system module"));
   assertInstallCleaned(env.v2());
 }
 public void testExistingPlugin() throws Exception {
   Tuple<Path, Environment> env = createEnv(fs, temp);
   Path pluginDir = createPluginDir(temp);
   String pluginZip = createPlugin("fake", pluginDir);
   installPlugin(pluginZip, env.v1());
   UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
   assertTrue(e.getMessage(), e.getMessage().contains("already exists"));
   assertInstallCleaned(env.v2());
 }
 public void testConfigNotDir() throws Exception {
   Tuple<Path, Environment> env = createEnv(fs, temp);
   Path pluginDir = createPluginDir(temp);
   Path configDir = pluginDir.resolve("config");
   Files.createFile(configDir);
   String pluginZip = createPlugin("fake", pluginDir);
   UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
   assertTrue(e.getMessage(), e.getMessage().contains("not a directory"));
   assertInstallCleaned(env.v2());
 }
 public void testMissingDirectory() throws Exception {
   Tuple<Path, Environment> env = createEnv(fs, temp);
   Path pluginDir = createPluginDir(temp);
   Files.createFile(pluginDir.resolve(PluginInfo.ES_PLUGIN_PROPERTIES));
   String pluginZip = writeZip(pluginDir, null);
   UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
   assertTrue(
       e.getMessage(),
       e.getMessage().contains("`elasticsearch` directory is missing in the plugin zip"));
   assertInstallCleaned(env.v2());
 }
 public void testBinContainsDir() throws Exception {
   Tuple<Path, Environment> env = createEnv(fs, temp);
   Path pluginDir = createPluginDir(temp);
   Path dirInBinDir = pluginDir.resolve("bin").resolve("foo");
   Files.createDirectories(dirInBinDir);
   Files.createFile(dirInBinDir.resolve("somescript"));
   String pluginZip = createPlugin("fake", pluginDir);
   UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
   assertTrue(
       e.getMessage(), e.getMessage().contains("Directories not allowed in bin dir for plugin"));
   assertInstallCleaned(env.v2());
 }
  public void testInstallMisspelledOfficialPlugins() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    UserException e = expectThrows(UserException.class, () -> installPlugin("xpack", env.v1()));
    assertThat(e.getMessage(), containsString("Unknown plugin xpack, did you mean [x-pack]?"));

    e = expectThrows(UserException.class, () -> installPlugin("analysis-smartnc", env.v1()));
    assertThat(
        e.getMessage(),
        containsString("Unknown plugin analysis-smartnc, did you mean [analysis-smartcn]?"));

    e = expectThrows(UserException.class, () -> installPlugin("repository", env.v1()));
    assertThat(
        e.getMessage(),
        containsString(
            "Unknown plugin repository, did you mean any of [repository-s3, repository-gcs]?"));

    e = expectThrows(UserException.class, () -> installPlugin("unknown_plugin", env.v1()));
    assertThat(e.getMessage(), containsString("Unknown plugin unknown_plugin"));
  }
 public void testUnknownPlugin() throws Exception {
   Tuple<Path, Environment> env = createEnv(fs, temp);
   UserException e = expectThrows(UserException.class, () -> installPlugin("foo", env.v1()));
   assertTrue(e.getMessage(), e.getMessage().contains("Unknown plugin foo"));
 }
 public void testMissingPluginId() throws IOException {
   final Tuple<Path, Environment> env = createEnv(fs, temp);
   final UserException e = expectThrows(UserException.class, () -> installPlugin(null, env.v1()));
   assertTrue(e.getMessage(), e.getMessage().contains("plugin id is required"));
 }