#NEWLINE# def check_cors( self , request_headers , expect_response , expected_origin = None , expected_allow_headers = None , server_response = None ) : #NEWLINE# #INDENT# "Check that CORS headers are handled correctly.\n\n    Args:\n      request_headers: A list of (header, value), to be used as headers in the\n        request.\n      expect_response: A boolean, whether or not CORS headers are expected in\n        the response.\n      expected_origin: A string or None.  If this is a string, this is the value\n        that's expected in the response's allow origin header.  This can be\n        None if expect_response is False.\n      expected_allow_headers: A string or None.  If this is a string, this is\n        the value that's expected in the response's allow headers header.  If\n        this is None, then the response shouldn't have any allow headers\n        headers.\n      server_response: A dispatcher.ResponseTuple or None.  The backend's\n        response, to be wrapped and returned as the server's response.  If\n        this is None, a generic response will be generated.\n\n    Returns:\n      A string containing the body of the response that would be sent.\n    " #NEWLINE# orig_request = test_utils . build_request ( '/_ah/api/fake/path' , http_headers = request_headers ) #NEWLINE# spi_request = orig_request . copy ( ) #NEWLINE# if ( server_response is None ) : #NEWLINE# #INDENT# server_response = dispatcher . ResponseTuple ( '200 OK' , [ ( 'Content-type' , 'application/json' ) ] , '{}' ) #NEWLINE# #UNINDENT# response = self . server . handle_spi_response ( orig_request , spi_request , server_response , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , self . start_response ) #NEWLINE# headers = dict ( self . response_headers ) #NEWLINE# if expect_response : #NEWLINE# #INDENT# self . assertIn ( endpoints_server . _CORS_HEADER_ALLOW_ORIGIN , headers ) #NEWLINE# self . assertEqual ( headers [ endpoints_server . _CORS_HEADER_ALLOW_ORIGIN ] , expected_origin ) #NEWLINE# self . assertIn ( endpoints_server . _CORS_HEADER_ALLOW_METHODS , headers ) #NEWLINE# self . assertEqual ( set ( headers [ endpoints_server . _CORS_HEADER_ALLOW_METHODS ] . split ( ',' ) ) , endpoints_server . _CORS_ALLOWED_METHODS ) #NEWLINE# if ( expected_allow_headers is not None ) : #NEWLINE# #INDENT# self . assertIn ( endpoints_server . _CORS_HEADER_ALLOW_HEADERS , headers ) #NEWLINE# self . assertEqual ( headers [ endpoints_server . _CORS_HEADER_ALLOW_HEADERS ] , expected_allow_headers ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . assertNotIn ( endpoints_server . _CORS_HEADER_ALLOW_HEADERS , headers ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# self . assertNotIn ( endpoints_server . _CORS_HEADER_ALLOW_ORIGIN , headers ) #NEWLINE# self . assertNotIn ( endpoints_server . _CORS_HEADER_ALLOW_METHODS , headers ) #NEWLINE# self . assertNotIn ( endpoints_server . _CORS_HEADER_ALLOW_HEADERS , headers ) #NEWLINE# #UNINDENT# return '' . join ( response )