5050import org .apache .hadoop .hbase .testclassification .MediumTests ;
5151import org .apache .hadoop .hbase .testclassification .RestTests ;
5252import org .apache .hadoop .hbase .util .Bytes ;
53+ import org .apache .http .Header ;
5354import org .junit .AfterClass ;
5455import org .junit .BeforeClass ;
5556import org .junit .ClassRule ;
@@ -329,6 +330,12 @@ public void testNamespaceCreateAndDeleteXMLAndJSON() throws IOException, JAXBExc
329330 jsonString = jsonMapper .writeValueAsString (model2 );
330331 response = client .post (namespacePath2 , Constants .MIMETYPE_JSON , Bytes .toBytes (jsonString ));
331332 assertEquals (201 , response .getCode ());
333+ //check passing null content-type with a payload returns 415
334+ Header [] nullHeaders = null ;
335+ response = client .post (namespacePath1 , nullHeaders , toXML (model1 ));
336+ assertEquals (415 , response .getCode ());
337+ response = client .post (namespacePath1 , nullHeaders , Bytes .toBytes (jsonString ));
338+ assertEquals (415 , response .getCode ());
332339
333340 // Check that created namespaces correctly.
334341 nd1 = findNamespace (admin , NAMESPACE1 );
@@ -379,16 +386,20 @@ public void testNamespaceCreateAndDeletePBAndNoBody() throws IOException, JAXBEx
379386 model4 = testNamespacesInstanceModel .buildTestModel (NAMESPACE4 , NAMESPACE4_PROPS );
380387 testNamespacesInstanceModel .checkModel (model4 , NAMESPACE4 , NAMESPACE4_PROPS );
381388
389+ //Defines null headers for use in tests where no body content is provided, so that we set
390+ // no content-type in the request
391+ Header [] nullHeaders = null ;
392+
382393 // Test cannot PUT (alter) non-existent namespace.
383- response = client .put (namespacePath3 , Constants . MIMETYPE_BINARY , new byte []{});
394+ response = client .put (namespacePath3 , nullHeaders , new byte []{});
384395 assertEquals (403 , response .getCode ());
385396 response = client .put (namespacePath4 , Constants .MIMETYPE_PROTOBUF ,
386397 model4 .createProtobufOutput ());
387398 assertEquals (403 , response .getCode ());
388399
389400 // Test cannot create tables when in read only mode.
390401 conf .set ("hbase.rest.readonly" , "true" );
391- response = client .post (namespacePath3 , Constants . MIMETYPE_BINARY , new byte []{});
402+ response = client .post (namespacePath3 , nullHeaders , new byte []{});
392403 assertEquals (403 , response .getCode ());
393404 response = client .put (namespacePath4 , Constants .MIMETYPE_PROTOBUF ,
394405 model4 .createProtobufOutput ());
@@ -399,12 +410,16 @@ public void testNamespaceCreateAndDeletePBAndNoBody() throws IOException, JAXBEx
399410 assertNull (nd4 );
400411 conf .set ("hbase.rest.readonly" , "false" );
401412
402- // Create namespace via no body and protobuf .
403- response = client .post (namespacePath3 , Constants . MIMETYPE_BINARY , new byte []{});
413+ // Create namespace with no body and binary content type .
414+ response = client .post (namespacePath3 , nullHeaders , new byte []{});
404415 assertEquals (201 , response .getCode ());
416+ // Create namespace with protobuf content-type.
405417 response = client .post (namespacePath4 , Constants .MIMETYPE_PROTOBUF ,
406418 model4 .createProtobufOutput ());
407419 assertEquals (201 , response .getCode ());
420+ //check setting unsupported content-type returns 415
421+ response = client .post (namespacePath3 , Constants .MIMETYPE_BINARY , new byte []{});
422+ assertEquals (415 , response .getCode ());
408423
409424 // Check that created namespaces correctly.
410425 nd3 = findNamespace (admin , NAMESPACE3 );
@@ -415,7 +430,7 @@ public void testNamespaceCreateAndDeletePBAndNoBody() throws IOException, JAXBEx
415430 checkNamespaceProperties (nd4 , NAMESPACE4_PROPS );
416431
417432 // Check cannot post tables that already exist.
418- response = client .post (namespacePath3 , Constants . MIMETYPE_BINARY , new byte []{});
433+ response = client .post (namespacePath3 , nullHeaders , new byte []{});
419434 assertEquals (403 , response .getCode ());
420435 response = client .post (namespacePath4 , Constants .MIMETYPE_PROTOBUF ,
421436 model4 .createProtobufOutput ());
0 commit comments