@@ -1307,6 +1307,63 @@ describe('read-only masterKey', () => {
13071307 } ) ;
13081308 expect ( Array . isArray ( res . data ) ) . toBe ( true ) ;
13091309 } ) ;
1310+
1311+ it ( 'should throw when trying to delete a file with readOnlyMasterKey' , async ( ) => {
1312+ // Create a file with the real master key
1313+ const uploadRes = await request ( {
1314+ method : 'POST' ,
1315+ url : `${ Parse . serverURL } /files/readonly-delete-test.txt` ,
1316+ headers : {
1317+ 'X-Parse-Application-Id' : Parse . applicationId ,
1318+ 'X-Parse-Master-Key' : Parse . masterKey ,
1319+ 'Content-Type' : 'text/plain' ,
1320+ } ,
1321+ body : 'file content' ,
1322+ } ) ;
1323+ const filename = uploadRes . data . name ;
1324+ expect ( filename ) . toBeDefined ( ) ;
1325+
1326+ // Attempt delete with readOnlyMasterKey — should be rejected
1327+ loggerErrorSpy . calls . reset ( ) ;
1328+ try {
1329+ await request ( {
1330+ method : 'DELETE' ,
1331+ url : `${ Parse . serverURL } /files/${ filename } ` ,
1332+ headers : {
1333+ 'X-Parse-Application-Id' : Parse . applicationId ,
1334+ 'X-Parse-Master-Key' : 'read-only-test' ,
1335+ } ,
1336+ } ) ;
1337+ fail ( 'should have thrown' ) ;
1338+ } catch ( res ) {
1339+ expect ( res . status ) . toBe ( 403 ) ;
1340+ expect ( res . data . error ) . toBe ( 'Permission denied' ) ;
1341+ }
1342+
1343+ // Verify file still exists
1344+ const getRes = await request ( { url : uploadRes . data . url } ) ;
1345+ expect ( getRes . status ) . toBe ( 200 ) ;
1346+ } ) ;
1347+
1348+ it ( 'should throw when trying to create a file with readOnlyMasterKey' , async ( ) => {
1349+ loggerErrorSpy . calls . reset ( ) ;
1350+ try {
1351+ await request ( {
1352+ method : 'POST' ,
1353+ url : `${ Parse . serverURL } /files/readonly-create-test.txt` ,
1354+ headers : {
1355+ 'X-Parse-Application-Id' : Parse . applicationId ,
1356+ 'X-Parse-Master-Key' : 'read-only-test' ,
1357+ 'Content-Type' : 'text/plain' ,
1358+ } ,
1359+ body : 'file content' ,
1360+ } ) ;
1361+ fail ( 'should have thrown' ) ;
1362+ } catch ( res ) {
1363+ expect ( res . status ) . toBe ( 403 ) ;
1364+ expect ( res . data . error ) . toBe ( 'Permission denied' ) ;
1365+ }
1366+ } ) ;
13101367} ) ;
13111368
13121369describe ( 'rest context' , ( ) => {
0 commit comments