@@ -15,9 +15,6 @@ const {
1515 makeAuthInfo,
1616} = require ( '../helpers' ) ;
1717
18- // Endpoints exercised through api.callApiMethod. Each entry describes a
19- // request that, once auth is denied, should still return CORS headers when
20- // an Origin header is present and the bucket has a matching CORS rule.
2118const endpoints = [
2219 { apiMethod : 'bucketGet' , httpMethod : 'GET' , url : '/' , query : { } } ,
2320 { apiMethod : 'bucketHead' , httpMethod : 'HEAD' , url : '/' , query : { } } ,
@@ -109,9 +106,6 @@ function buildResponseSpy(sandbox) {
109106 headers,
110107 setHeader : sandbox . spy ( ( k , v ) => { headers [ k . toLowerCase ( ) ] = v ; } ) ,
111108 getHeader : k => headers [ k . toLowerCase ( ) ] ,
112- writeHead : sandbox . stub ( ) ,
113- write : sandbox . stub ( ) ,
114- end : sandbox . stub ( ) ,
115109 } ;
116110}
117111
@@ -218,20 +212,14 @@ describe('CORS headers on 403 auth failures (api.callApiMethod)', () => {
218212} ) ;
219213
220214describe ( 'CORS headers on 403 via handler (fast path)' , ( ) => {
221- // Verifies the wrapper's fast path: when auth succeeds but the
222- // handler's own ACL/policy check denies, the handler has already
223- // loaded the bucket and passed corsHeaders through its callback.
224- // The wrapper should forward them without calling metadata.getBucket
225- // itself.
226215 let sandbox ;
227216
228217 before ( done => setupBucketWithCors ( done ) ) ;
229218
230219 beforeEach ( ( ) => {
231220 sandbox = sinon . createSandbox ( ) ;
232- // Stub auth to succeed as a *different* account. The handler then
233- // runs standardMetadataValidateBucket which denies because the
234- // bucket is owned by accessKey1.
221+ // Auth succeeds as accessKey2 so the handler runs and then
222+ // denies at its own ACL check (bucket is owned by accessKey1).
235223 const otherAuth = makeAuthInfo ( 'accessKey2' ) ;
236224 const authServer = {
237225 doAuth : sandbox . stub ( ) . callsArgWith ( 2 , null , otherAuth ,
@@ -259,27 +247,18 @@ describe('CORS headers on 403 via handler (fast path)', () => {
259247 assert ( corsHeaders ,
260248 'handler should have supplied corsHeaders' ) ;
261249 assert . strictEqual (
262- corsHeaders [ 'access-control-allow-origin' ] , origin ,
263- 'corsHeaders should include access-control-allow-origin' ) ;
264- // Fast path: the wrapper did not setHeader on the response.
265- // The route-level transport is what would ultimately call
266- // setCommonResponseHeaders in production.
250+ corsHeaders [ 'access-control-allow-origin' ] , origin ) ;
251+ // Fast path: wrapper forwards corsHeaders via the callback
252+ // instead of setting them on the response directly.
267253 assert . strictEqual (
268254 response . getHeader ( 'access-control-allow-origin' ) ,
269- undefined ,
270- 'wrapper should not set CORS headers directly when the '
271- + 'handler already provided them' ) ;
255+ undefined ) ;
272256 done ( ) ;
273257 } ) ;
274258 } ) ;
275259} ) ;
276260
277261describe ( 'CORS headers on 200 successful responses (per-handler)' , ( ) => {
278- // Sanity-check that the existing per-handler path continues to work.
279- // Pass-through tests: a request with matching CORS should receive
280- // CORS headers on 200. This guards against regressions when we change
281- // the error path.
282-
283262 before ( done => setupBucketWithCors ( done ) ) ;
284263
285264 it ( 'bucketGet returns corsHeaders to callback on 200' , done => {
0 commit comments