def _TestAuthFacebookUser(action, tester, user_dict, device_dict=None, user_cookie=None): """Called by the ServiceTester in order to test login/facebook, link/facebook, and register/facebook calls. """ ident_dict = {'key': 'FacebookGraph:%s' % user_dict['id'], 'authority': 'Facebook', 'access_token': 'access_token'} if device_dict: device_dict.pop('device_uuid', None) device_dict.pop('test_udid', None) # Mock responses from Facebook. with mock.patch('tornado.httpclient.AsyncHTTPClient', MockAsyncHTTPClient()) as mock_client: # Add response to request for an access token. mock_client.map(r'https://graph.facebook.com/oauth/access_token', 'access_token=%s&expires=3600' % ident_dict['access_token']) # Response to request for user info. auth_test._AddMockJSONResponse(mock_client, r'https://graph.facebook.com/me\?', user_dict) # Add empty response to request for photos and friends. auth_test._AddMockJSONResponse(mock_client, r'https://graph.facebook.com/me/photos\?', {'data': []}) auth_test._AddMockJSONResponse(mock_client, r'https://graph.facebook.com/me/friends\?', {'data': []}) response = auth_test._AuthFacebookOrGoogleUser(tester, action, user_dict, ident_dict, device_dict, user_cookie) return auth_test._ValidateAuthUser(tester, action, user_dict, ident_dict, device_dict, user_cookie, response)
def _TestAuthGoogleUser(action, tester, user_dict, device_dict=None, user_cookie=None): """Called by the ServiceTester in order to test login/google, link/google, and register/google calls. """ ident_dict = { 'key': 'Email:%s' % Identity.CanonicalizeEmail(user_dict['email']), 'authority': 'Google', 'refresh_token': 'refresh_token', 'access_token': 'access_token', 'expires': util._TEST_TIME + 3600 } if device_dict: device_dict.pop('device_uuid', None) device_dict.pop('test_udid', None) # Mock responses from Google. with mock.patch('tornado.httpclient.AsyncHTTPClient', MockAsyncHTTPClient()) as mock_client: # Response to request for access token. auth_test._AddMockJSONResponse( mock_client, r'https://accounts.google.com/o/oauth2/token', { 'access_token': ident_dict['access_token'], 'token_type': 'Bearer', 'expires_in': ident_dict['expires'] - util._TEST_TIME, 'id_token': 'id_token', 'refresh_token': ident_dict['refresh_token'] }) # Response to request for user info. auth_test._AddMockJSONResponse( mock_client, r'https://www.googleapis.com/oauth2/v1/userinfo\?', user_dict) # Response to request for people (i.e. contacts). auth_test._AddMockJSONResponse( mock_client, r'https://www.google.com/m8/feeds/contacts/default/full', { 'feed': { 'entry': [], 'openSearch$startIndex': { '$t': '1' }, 'openSearch$totalResults': { '$t': '0' } } }) response = auth_test._AuthFacebookOrGoogleUser(tester, action, user_dict, ident_dict, device_dict, user_cookie) return auth_test._ValidateAuthUser(tester, action, user_dict, ident_dict, device_dict, user_cookie, response)
def _TestAuthFacebookUser(action, tester, user_dict, device_dict=None, user_cookie=None): """Called by the ServiceTester in order to test login/facebook, link/facebook, and register/facebook calls. """ ident_dict = { 'key': 'FacebookGraph:%s' % user_dict['id'], 'authority': 'Facebook', 'access_token': 'access_token' } if device_dict: device_dict.pop('device_uuid', None) device_dict.pop('test_udid', None) # Mock responses from Facebook. with mock.patch('tornado.httpclient.AsyncHTTPClient', MockAsyncHTTPClient()) as mock_client: # Add response to request for an access token. mock_client.map( r'https://graph.facebook.com/oauth/access_token', 'access_token=%s&expires=3600' % ident_dict['access_token']) # Response to request for user info. auth_test._AddMockJSONResponse(mock_client, r'https://graph.facebook.com/me\?', user_dict) # Add empty response to request for photos and friends. auth_test._AddMockJSONResponse( mock_client, r'https://graph.facebook.com/me/photos\?', {'data': []}) auth_test._AddMockJSONResponse( mock_client, r'https://graph.facebook.com/me/friends\?', {'data': []}) response = auth_test._AuthFacebookOrGoogleUser(tester, action, user_dict, ident_dict, device_dict, user_cookie) return auth_test._ValidateAuthUser(tester, action, user_dict, ident_dict, device_dict, user_cookie, response)
def _TestAuthGoogleUser(action, tester, user_dict, device_dict=None, user_cookie=None): """Called by the ServiceTester in order to test login/google, link/google, and register/google calls. """ ident_dict = {'key': 'Email:%s' % Identity.CanonicalizeEmail(user_dict['email']), 'authority': 'Google', 'refresh_token': 'refresh_token', 'access_token': 'access_token', 'expires': util._TEST_TIME + 3600} if device_dict: device_dict.pop('device_uuid', None) device_dict.pop('test_udid', None) # Mock responses from Google. with mock.patch('tornado.httpclient.AsyncHTTPClient', MockAsyncHTTPClient()) as mock_client: # Response to request for access token. auth_test._AddMockJSONResponse(mock_client, r'https://accounts.google.com/o/oauth2/token', {'access_token': ident_dict['access_token'], 'token_type': 'Bearer', 'expires_in': ident_dict['expires'] - util._TEST_TIME, 'id_token': 'id_token', 'refresh_token': ident_dict['refresh_token']}) # Response to request for user info. auth_test._AddMockJSONResponse(mock_client, r'https://www.googleapis.com/oauth2/v1/userinfo\?', user_dict) # Response to request for people (i.e. contacts). auth_test._AddMockJSONResponse(mock_client, r'https://www.google.com/m8/feeds/contacts/default/full', {'feed': {'entry': [], 'openSearch$startIndex': {'$t': '1'}, 'openSearch$totalResults': {'$t': '0'}}}) response = auth_test._AuthFacebookOrGoogleUser(tester, action, user_dict, ident_dict, device_dict, user_cookie) return auth_test._ValidateAuthUser(tester, action, user_dict, ident_dict, device_dict, user_cookie, response)