Serving _site plugins do not pick up on index.html for sub directories

If one asks for `http://es:9200/_plugin/PLUGIN_NAME/` and the the plugin's _site directory contains an index.html file, it will be correctly served.

This is not the case for sub directories: a _site/folder/index.html is not served when requesting  `http://es:9200/_plugin/PLUGIN_NAME/folder/` but one gets a 403 Forbidden response as if trying to browse the folder.

Closes #4845.
This commit is contained in:
David Pilato 2014-01-22 18:33:48 +01:00
parent 241bb09db1
commit f4411e697e
4 changed files with 57 additions and 2 deletions

View File

@ -177,8 +177,17 @@ public class HttpServer extends AbstractLifecycleComponent<HttpServer> {
return;
}
if (!file.isFile()) {
channel.sendResponse(new StringRestResponse(FORBIDDEN));
return;
// If it's not a dir, we send a 403
if (!file.isDirectory()) {
channel.sendResponse(new StringRestResponse(FORBIDDEN));
return;
}
// We don't serve dir but if index.html exists in dir we should serve it
file = new File(file, "index.html");
if (!file.exists() || file.isHidden() || !file.isFile()) {
channel.sendResponse(new StringRestResponse(FORBIDDEN));
return;
}
}
if (!file.getAbsolutePath().startsWith(siteFile.getAbsolutePath())) {
channel.sendResponse(new StringRestResponse(FORBIDDEN));

View File

@ -73,4 +73,32 @@ public class SitePluginTests extends ElasticsearchIntegrationTest {
assertThat(response.errorCode(), equalTo(RestStatus.OK.getStatus()));
assertThat(response.response(), containsString("<title>Dummy Site Plugin</title>"));
}
/**
* Test direct access to an existing file (index.html)
*/
@Test
public void testAnyPage() throws Exception {
HttpClientResponse response = httpClient("test").request("/_plugin/dummy/index.html");
assertThat(response.errorCode(), equalTo(RestStatus.OK.getStatus()));
assertThat(response.response(), containsString("<title>Dummy Site Plugin</title>"));
}
/**
* Test case for #4845: https://github.com/elasticsearch/elasticsearch/issues/4845
* Serving _site plugins do not pick up on index.html for sub directories
*/
@Test
public void testWelcomePageInSubDirs() throws Exception {
HttpClientResponse response = httpClient("test").request("/_plugin/subdir/dir/");
assertThat(response.errorCode(), equalTo(RestStatus.OK.getStatus()));
assertThat(response.response(), containsString("<title>Dummy Site Plugin (subdir)</title>"));
response = httpClient("test").request("/_plugin/subdir/dir_without_index/");
assertThat(response.errorCode(), equalTo(RestStatus.FORBIDDEN.getStatus()));
response = httpClient("test").request("/_plugin/subdir/dir_without_index/page.html");
assertThat(response.errorCode(), equalTo(RestStatus.OK.getStatus()));
assertThat(response.response(), containsString("<title>Dummy Site Plugin (page)</title>"));
}
}

View File

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Dummy Site Plugin (subdir)</title>
</head>
<body>
<p>Welcome to this dummy elasticsearch plugin</p>
</body>
</html>

View File

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Dummy Site Plugin (page)</title>
</head>
<body>
<p>Welcome to this dummy elasticsearch plugin</p>
</body>
</html>