@@ -94,7 +94,7 @@ describe('schemas', () => {
9494 headers : restKeyHeaders ,
9595 } , ( error , response , body ) => {
9696 expect ( response . statusCode ) . toEqual ( 401 ) ;
97- expect ( body . error ) . toEqual ( 'unauthorized ' ) ;
97+ expect ( body . error ) . toEqual ( 'master key not specified ' ) ;
9898 done ( ) ;
9999 } ) ;
100100 } ) ;
@@ -318,4 +318,101 @@ describe('schemas', () => {
318318 done ( ) ;
319319 } ) ;
320320 } ) ;
321+
322+ it ( 'requires the master key to modify schemas' , done => {
323+ request . post ( {
324+ url : 'http://localhost:8378/1/schemas/NewClass' ,
325+ headers : masterKeyHeaders ,
326+ json : true ,
327+ body : { } ,
328+ } , ( error , response , body ) => {
329+ request . put ( {
330+ url : 'http://localhost:8378/1/schemas/NewClass' ,
331+ headers : noAuthHeaders ,
332+ json : true ,
333+ body : { } ,
334+ } , ( error , response , body ) => {
335+ expect ( response . statusCode ) . toEqual ( 403 ) ;
336+ expect ( body . error ) . toEqual ( 'unauthorized' ) ;
337+ done ( ) ;
338+ } ) ;
339+ } ) ;
340+ } ) ;
341+
342+ it ( 'rejects class name mis-matches' , done => {
343+ request . put ( {
344+ url : 'http://localhost:8378/1/schemas/NewClass' ,
345+ headers : masterKeyHeaders ,
346+ json : true ,
347+ body : { className : 'WrongClassName' }
348+ } , ( error , response , body ) => {
349+ expect ( response . statusCode ) . toEqual ( 400 ) ;
350+ expect ( body . code ) . toEqual ( Parse . Error . INVALID_CLASS_NAME ) ;
351+ expect ( body . error ) . toEqual ( 'class name mismatch between WrongClassName and NewClass' ) ;
352+ } ) ;
353+ } ) ;
354+
355+ it ( 'refuses to add fields to non-existent classes' , done => {
356+ request . put ( {
357+ url : 'http://localhost:8378/1/schemas/NoClass' ,
358+ headers : masterKeyHeaders ,
359+ json : true ,
360+ body : {
361+ fields : {
362+ newField : { type : 'String' }
363+ }
364+ }
365+ } , ( error , response , body ) => {
366+ expect ( response . statusCode ) . toEqual ( 400 ) ;
367+ expect ( body . code ) . toEqual ( Parse . Error . INVALID_CLASS_NAME ) ;
368+ expect ( body . error ) . toEqual ( 'class NoClass does not exist' ) ;
369+ done ( ) ;
370+ } ) ;
371+ } ) ;
372+
373+ it ( 'put with no modifications returns all fields' , done => {
374+ var obj = hasAllPODobject ( ) ;
375+ obj . save ( )
376+ . then ( ( ) => {
377+ request . put ( {
378+ url : 'http://localhost:8378/1/schemas/HasAllPOD'
379+ headers : masterKeyHeaders ,
380+ json : true ,
381+ body : { } ,
382+ } , ( error , response , body ) => {
383+ expect ( body ) . toEqual ( plainOldDataSchema ) ;
384+ done ( ) ;
385+ } ) ;
386+ } ) ;
387+ } ) ;
388+
389+ it ( 'lets you add fields' , done => {
390+ request . post ( {
391+ url : 'http://localhost:8378/1/schemas/NewClass' ,
392+ headers : masterKeyHeaders ,
393+ json : true ,
394+ body : { } ,
395+ } , ( error , response , body ) => {
396+ request . put ( {
397+ url : 'http://localhost:8378/1/schemas/NewClass' ,
398+ headers : masterKeyHeaders ,
399+ json : true ,
400+ body : {
401+ fields : {
402+ newField : { type : 'String' }
403+ }
404+ }
405+ } , ( error , response , body ) => {
406+ expect ( body ) . toEqual ( 'blah' ) ;
407+ request . get ( {
408+ url : 'http://localhost:8378/1/schemas/NewClass' ,
409+ headers : masterKeyHeaders ,
410+ json : true ,
411+ } , ( error , response , body ) => {
412+ expect ( body ) . toEqual ( 'blah' ) ;
413+ done ( ) ;
414+ } ) ;
415+ } ) ;
416+ } )
417+ } ) ;
321418} ) ;
0 commit comments