HDFS-14242. OIV WebImageViewer: NPE when param op is not specified. Contributed by Siyao Meng.

Signed-off-by: Wei-Chiu Chuang <weichiu@apache.org>
This commit is contained in:
Siyao Meng 2019-02-06 12:18:35 -08:00 committed by Wei-Chiu Chuang
parent d3de8e162b
commit 6aa63452b3
2 changed files with 25 additions and 1 deletions

View File

@ -85,10 +85,15 @@ class FSImageHandler extends SimpleChannelInboundHandler<HttpRequest> {
}
QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());
// check path. throw exception if path doesn't start with WEBHDFS_PREFIX
String path = getPath(decoder);
final String op = getOp(decoder);
// check null op
if (op == null) {
throw new IllegalArgumentException("Param op must be specified.");
}
final String content;
String path = getPath(decoder);
switch (op) {
case "GETFILESTATUS":
content = image.getFileStatus(path);

View File

@ -624,6 +624,25 @@ public class TestOfflineImageViewer {
}
}
@Test
public void testWebImageViewerNullOp() throws Exception {
WebImageViewer viewer = new WebImageViewer(
NetUtils.createSocketAddr("localhost:0"));
try {
viewer.initServer(originalFsimage.getAbsolutePath());
int port = viewer.getPort();
// null op
URL url = new URL("http://localhost:" + port +
"/webhdfs/v1/");
// should get HTTP_BAD_REQUEST. NPE gets HTTP_INTERNAL_ERROR
verifyHttpResponseCode(HttpURLConnection.HTTP_BAD_REQUEST, url);
} finally {
// shutdown the viewer
viewer.close();
}
}
@Test
public void testWebImageViewerSecureMode() throws Exception {
Configuration conf = new Configuration();