@@ -13,6 +13,7 @@ const {
1313const {
1414 LOCATION_NAME_DMF ,
1515} = require ( '../constants' ) ;
16+ const constants = require ( '../../constants' ) ;
1617
1718const { ValidLifecycleRules : supportedLifecycleRules } = require ( 'arsenal' ) . models ;
1819
@@ -889,4 +890,47 @@ describe('Config', () => {
889890 assert . strictEqual ( config . instanceId . length , 6 ) ;
890891 } ) ;
891892 } ) ;
893+
894+ describe ( 'apisLengthLimits configuration' , ( ) => {
895+ let sandbox ;
896+ let readFileStub ;
897+
898+ beforeEach ( ( ) => {
899+ sandbox = sinon . createSandbox ( ) ;
900+ readFileStub = sandbox . stub ( fs , 'readFileSync' ) ;
901+ readFileStub . callThrough ( ) ;
902+ } ) ;
903+
904+ afterEach ( ( ) => {
905+ sandbox . restore ( ) ;
906+ } ) ;
907+
908+ it ( 'should use default API and overwrite when config is provided' , ( ) => {
909+ const multiObjectDeleteSize = 42 ;
910+ const modifiedConfig = {
911+ ...defaultConfig ,
912+ apiBodySizeLimits : { 'multiObjectDelete' : multiObjectDeleteSize } ,
913+ } ;
914+ readFileStub . withArgs ( sinon . match ( / c o n f i g .j s o n $ / ) ) . returns ( JSON . stringify ( modifiedConfig ) ) ;
915+ const config = new ConfigObject ( ) ;
916+
917+ assert . deepStrictEqual ( config . apiBodySizeLimits , {
918+ 'multiObjectDelete' : multiObjectDeleteSize , // Configured: overwrites default
919+ 'bucketPutPolicy' : constants . defaultApiBodySizeLimits [ 'bucketPutPolicy' ] , // Not configured: default
920+ } ) ;
921+ } ) ;
922+
923+ it ( 'should fail if a user tries to modify a non-existent API' , ( ) => {
924+ const modifiedConfig = {
925+ ...defaultConfig ,
926+ apiBodySizeLimits : { 'anApiNotSetInConstants.js' : 42 } ,
927+ } ;
928+ readFileStub . withArgs ( sinon . match ( / c o n f i g .j s o n $ / ) ) . returns ( JSON . stringify ( modifiedConfig ) ) ;
929+
930+ assert . throws (
931+ ( ) => new ConfigObject ( ) ,
932+ / b a d c o n f i g : a p i B o d y S i z e L i m i t s f o r " a n A p i N o t S e t I n C o n s t a n t s .j s " c a n n o t b e c o n f i g u r e d /
933+ ) ;
934+ } ) ;
935+ } ) ;
892936} ) ;
0 commit comments