@@ -5,6 +5,7 @@ const sinon = require('sinon');
55
66const { bucketPut } = require ( '../../../lib/api/bucketPut' ) ;
77const bucketPutVersioning = require ( '../../../lib/api/bucketPutVersioning' ) ;
8+ const bucketPutPolicy = require ( '../../../lib/api/bucketPutPolicy' ) ;
89const objectPut = require ( '../../../lib/api/objectPut' ) ;
910const objectCopy = require ( '../../../lib/api/objectCopy' ) ;
1011const DummyRequest = require ( '../DummyRequest' ) ;
@@ -45,6 +46,7 @@ function _createObjectCopyRequest(destBucketName) {
4546 objectKey,
4647 headers : { } ,
4748 url : `/${ destBucketName } /${ objectKey } ` ,
49+ socket : { } ,
4850 } ;
4951 return new DummyRequest ( params ) ;
5052}
@@ -68,6 +70,7 @@ describe('objectCopy with versioning', () => {
6870
6971 before ( done => {
7072 cleanup ( ) ;
73+ sinon . spy ( metadata , 'putObjectMD' ) ;
7174 async . series ( [
7275 callback => bucketPut ( authInfo , putDestBucketRequest , log ,
7376 callback ) ,
@@ -96,7 +99,10 @@ describe('objectCopy with versioning', () => {
9699 } ) ;
97100 } ) ;
98101
99- after ( ( ) => cleanup ( ) ) ;
102+ after ( ( ) => {
103+ metadata . putObjectMD . restore ( ) ;
104+ cleanup ( ) ;
105+ } ) ;
100106
101107 it ( 'should delete null version when creating new null version, ' +
102108 'even when null version is not the latest version' , done => {
@@ -125,6 +131,94 @@ describe('objectCopy with versioning', () => {
125131 } ) ;
126132 } ) ;
127133 } ) ;
134+
135+ it ( 'should not set bucketOwnerId if requesting account owns dest bucket' , done => {
136+ const testObjectCopyRequest = _createObjectCopyRequest ( destBucketName ) ;
137+ objectCopy ( authInfo , testObjectCopyRequest , sourceBucketName , objectKey ,
138+ undefined , log , err => {
139+ assert . ifError ( err ) ;
140+ sinon . assert . calledWith (
141+ metadata . putObjectMD . lastCall ,
142+ destBucketName ,
143+ objectKey ,
144+ sinon . match ( { _data : { bucketOwnerId : sinon . match . typeOf ( 'undefined' ) } } ) ,
145+ sinon . match . any ,
146+ sinon . match . any ,
147+ sinon . match . any
148+ ) ;
149+ done ( ) ;
150+ } ) ;
151+ } ) ;
152+
153+ // TODO: S3C-9965
154+ // Skipped because the policy is not checked correctly
155+ // When source bucket policy is checked destination arn is used
156+ it . skip ( 'should set bucketOwnerId if requesting account differs from dest bucket owner' , done => {
157+ const authInfo2 = makeAuthInfo ( 'accessKey2' ) ;
158+ const testObjectCopyRequest = _createObjectCopyRequest ( destBucketName ) ;
159+ const testPutSrcPolicyRequest = new DummyRequest ( {
160+ bucketName : sourceBucketName ,
161+ namespace,
162+ headers : { host : `${ sourceBucketName } .s3.amazonaws.com` } ,
163+ url : '/' ,
164+ socket : { } ,
165+ post : JSON . stringify ( {
166+ Version : '2012-10-17' ,
167+ Statement : [
168+ {
169+ Sid : 'AllowCrossAccountRead' ,
170+ Effect : 'Allow' ,
171+ Principal : { AWS : `arn:aws:iam::${ authInfo2 . shortid } :root` } ,
172+ Action : [ 's3:GetObject' ] ,
173+ Resource : [
174+ `arn:aws:s3:::${ sourceBucketName } /*`
175+ ] ,
176+ } ,
177+ ] ,
178+ } ) ,
179+ } ) ;
180+ const testPutDestPolicyRequest = new DummyRequest ( {
181+ bucketName : destBucketName ,
182+ namespace,
183+ headers : { host : `${ destBucketName } .s3.amazonaws.com` } ,
184+ url : '/' ,
185+ socket : { } ,
186+ post : JSON . stringify ( {
187+ Version : '2012-10-17' ,
188+ Statement : [
189+ {
190+ Sid : 'AllowCrossAccountWrite' ,
191+ Effect : 'Allow' ,
192+ Principal : { AWS : `arn:aws:iam::${ authInfo2 . shortid } :root` } ,
193+ Action : [ 's3:PutObject' ] ,
194+ Resource : [
195+ `arn:aws:s3:::${ destBucketName } /*`
196+ ] ,
197+ } ,
198+ ] ,
199+ } ) ,
200+ } ) ;
201+ bucketPutPolicy ( authInfo , testPutSrcPolicyRequest , log , err => {
202+ assert . ifError ( err ) ;
203+ bucketPutPolicy ( authInfo , testPutDestPolicyRequest , log , err => {
204+ assert . ifError ( err ) ;
205+ objectCopy ( authInfo2 , testObjectCopyRequest , sourceBucketName , objectKey ,
206+ undefined , log , err => {
207+ sinon . assert . calledWith (
208+ metadata . putObjectMD . lastCall ,
209+ destBucketName ,
210+ objectKey ,
211+ sinon . match ( { _data : { bucketOwnerId : authInfo . canonicalID } } ) ,
212+ sinon . match . any ,
213+ sinon . match . any ,
214+ sinon . match . any
215+ ) ;
216+ assert . ifError ( err ) ;
217+ done ( ) ;
218+ } ) ;
219+ } ) ;
220+ } ) ;
221+ } ) ;
128222} ) ;
129223
130224describe ( 'non-versioned objectCopy' , ( ) => {
0 commit comments