@@ -538,35 +538,50 @@ function parse_body_encryption_xml(req) {
538538
539539function parse_body_object_lock_conf_xml ( req ) {
540540 const configuration = req . body . ObjectLockConfiguration ;
541- const retention = configuration . Rule [ 0 ] . DefaultRetention [ 0 ] ;
542-
543- if ( ( retention . Days && retention . Years ) || ( ! retention . Days && ! retention . Years ) ||
544- ( retention . Mode [ 0 ] !== 'GOVERNANCE' && retention . Mode [ 0 ] !== 'COMPLIANCE' ) ) throw new S3Error ( S3Error . MalformedXML ) ;
545-
546- const conf = {
547- object_lock_enabled : configuration . ObjectLockEnabled [ 0 ] ,
548- rule : { default_retention : { mode : retention . Mode [ 0 ] , } }
549- } ;
541+ try {
542+ const retention = configuration ?. Rule ?. [ 0 ] ?. DefaultRetention ?. [ 0 ] ;
543+ const object_lock_enabled = configuration ?. ObjectLockEnabled ?. [ 0 ] ;
544+ if ( object_lock_enabled !== 'Enabled' ) {
545+ dbg . error ( 'invalid object_lock_enabled, can only be Enabled' , object_lock_enabled ) ;
546+ throw new S3Error ( S3Error . MalformedXML ) ;
547+ }
548+ const conf = {
549+ object_lock_enabled,
550+ } ;
550551
551- if ( retention . Days ) {
552- const days = parseInt ( retention . Days [ 0 ] , 10 ) ;
553- if ( days <= 0 ) {
554- const err = new S3Error ( S3Error . InvalidArgument ) ;
555- err . message = 'Default retention period must be a positive integer value' ;
556- throw err ;
552+ if ( retention ) {
553+ conf . rule = { default_retention : { mode : retention . Mode [ 0 ] } } ;
554+ if ( ( ! retention . Days && ! retention . Years ) || ( retention . Mode [ 0 ] !== 'GOVERNANCE' && retention . Mode [ 0 ] !== 'COMPLIANCE' ) ) {
555+ dbg . error ( 'invalid object lock confugration retention' , retention ) ;
556+ throw new S3Error ( S3Error . MalformedXML ) ;
557+ }
558+ if ( retention . Days ) {
559+ const days = parseInt ( retention . Days [ 0 ] , 10 ) ;
560+ if ( ! Number . isInteger ( days ) || days <= 0 ) {
561+ const err = new S3Error ( S3Error . InvalidArgument ) ;
562+ err . message = 'Default retention period must be a positive integer value' ;
563+ throw err ;
564+ }
565+ conf . rule . default_retention . days = days ;
566+ }
567+ if ( retention . Years ) {
568+ const years = parseInt ( retention . Years [ 0 ] , 10 ) ;
569+ if ( ! Number . isInteger ( years ) || years <= 0 ) {
570+ const err = new S3Error ( S3Error . InvalidArgument ) ;
571+ err . message = 'Default retention period must be a positive integer value' ;
572+ throw err ;
573+ }
574+ conf . rule . default_retention . years = years ;
575+ }
557576 }
558- conf . rule . default_retention . days = days ;
559- }
560- if ( retention . Years ) {
561- const years = parseInt ( retention . Years [ 0 ] , 10 ) ;
562- if ( years <= 0 ) {
563- const err = new S3Error ( S3Error . InvalidArgument ) ;
564- err . message = 'Default retention period must be a positive integer value' ;
577+ return conf ;
578+ } catch ( err ) {
579+ dbg . error ( 'parse_body_object_lock_conf_xml failed' , err ) ;
580+ if ( err instanceof S3Error ) {
565581 throw err ;
566582 }
567- conf . rule . default_retention . years = years ;
583+ throw new S3Error ( S3Error . MalformedXML ) ;
568584 }
569- return conf ;
570585}
571586
572587function parse_body_website_xml ( req ) {
0 commit comments