50
50
import org .apache .hadoop .hbase .testclassification .MediumTests ;
51
51
import org .apache .hadoop .hbase .testclassification .RestTests ;
52
52
import org .apache .hadoop .hbase .util .Bytes ;
53
+ import org .apache .http .Header ;
53
54
import org .junit .AfterClass ;
54
55
import org .junit .BeforeClass ;
55
56
import org .junit .ClassRule ;
@@ -329,6 +330,12 @@ public void testNamespaceCreateAndDeleteXMLAndJSON() throws IOException, JAXBExc
329
330
jsonString = jsonMapper .writeValueAsString (model2 );
330
331
response = client .post (namespacePath2 , Constants .MIMETYPE_JSON , Bytes .toBytes (jsonString ));
331
332
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 ());
332
339
333
340
// Check that created namespaces correctly.
334
341
nd1 = findNamespace (admin , NAMESPACE1 );
@@ -379,16 +386,20 @@ public void testNamespaceCreateAndDeletePBAndNoBody() throws IOException, JAXBEx
379
386
model4 = testNamespacesInstanceModel .buildTestModel (NAMESPACE4 , NAMESPACE4_PROPS );
380
387
testNamespacesInstanceModel .checkModel (model4 , NAMESPACE4 , NAMESPACE4_PROPS );
381
388
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
+
382
393
// 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 []{});
384
395
assertEquals (403 , response .getCode ());
385
396
response = client .put (namespacePath4 , Constants .MIMETYPE_PROTOBUF ,
386
397
model4 .createProtobufOutput ());
387
398
assertEquals (403 , response .getCode ());
388
399
389
400
// Test cannot create tables when in read only mode.
390
401
conf .set ("hbase.rest.readonly" , "true" );
391
- response = client .post (namespacePath3 , Constants . MIMETYPE_BINARY , new byte []{});
402
+ response = client .post (namespacePath3 , nullHeaders , new byte []{});
392
403
assertEquals (403 , response .getCode ());
393
404
response = client .put (namespacePath4 , Constants .MIMETYPE_PROTOBUF ,
394
405
model4 .createProtobufOutput ());
@@ -399,12 +410,16 @@ public void testNamespaceCreateAndDeletePBAndNoBody() throws IOException, JAXBEx
399
410
assertNull (nd4 );
400
411
conf .set ("hbase.rest.readonly" , "false" );
401
412
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 []{});
404
415
assertEquals (201 , response .getCode ());
416
+ // Create namespace with protobuf content-type.
405
417
response = client .post (namespacePath4 , Constants .MIMETYPE_PROTOBUF ,
406
418
model4 .createProtobufOutput ());
407
419
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 ());
408
423
409
424
// Check that created namespaces correctly.
410
425
nd3 = findNamespace (admin , NAMESPACE3 );
@@ -415,7 +430,7 @@ public void testNamespaceCreateAndDeletePBAndNoBody() throws IOException, JAXBEx
415
430
checkNamespaceProperties (nd4 , NAMESPACE4_PROPS );
416
431
417
432
// 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 []{});
419
434
assertEquals (403 , response .getCode ());
420
435
response = client .post (namespacePath4 , Constants .MIMETYPE_PROTOBUF ,
421
436
model4 .createProtobufOutput ());
0 commit comments