@@ -3468,6 +3468,49 @@ def testPatchRemove(self):
34683468 self .assertEqual (len (results ['attributes' ]['nosy' ]), 0 )
34693469 self .assertListEqual (results ['attributes' ]['nosy' ], [])
34703470
3471+ def testRestExposeHeaders (self ):
3472+
3473+ local_client = self .server .client
3474+ body = b'{ "data": "Joe Doe 1" }'
3475+ env = { "CONTENT_TYPE" : "application/json" ,
3476+ "CONTENT_LENGTH" : len (body ),
3477+ "REQUEST_METHOD" : "PUT" ,
3478+ "HTTP_ORIGIN" : "http://tracker.example"
3479+ }
3480+ local_client .env .update (env )
3481+
3482+ local_client .db .config ["WEB_ALLOWED_API_ORIGINS" ] = " * "
3483+
3484+ headers = {"accept" : "application/json; version=1" ,
3485+ "content-type" : env ['CONTENT_TYPE' ],
3486+ "content-length" : env ['CONTENT_LENGTH' ],
3487+ "origin" : env ['HTTP_ORIGIN' ]
3488+ }
3489+ self .headers = headers
3490+ # we need to generate a FieldStorage the looks like
3491+ # FieldStorage(None, None, 'string') rather than
3492+ # FieldStorage(None, None, [])
3493+ body_file = BytesIO (body ) # FieldStorage needs a file
3494+ form = client .BinaryFieldStorage (body_file ,
3495+ headers = headers ,
3496+ environ = env )
3497+ local_client .request .headers .get = self .get_header
3498+ results = self .server .dispatch ('PUT' ,
3499+ "/rest/data/user/%s/realname" % self .joeid ,
3500+ form )
3501+
3502+ for header in [ "X-RateLimit-Limit" ,
3503+ "X-RateLimit-Remaining" ,
3504+ "X-RateLimit-Reset" ,
3505+ "X-RateLimit-Limit-Period" ,
3506+ "Retry-After" ,
3507+ "Sunset" ,
3508+ "Allow" ,
3509+ ]:
3510+ self .assertIn (
3511+ header ,
3512+ self .server .client .additional_headers [
3513+ "Access-Control-Expose-Headers" ])
34713514
34723515 def testRestMatchWildcardOrigin (self ):
34733516 # cribbed from testDispatch #1
0 commit comments