Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: sync/tools/testserver/chromiumsync.py

Issue 58093002: [sync] Serve fake OAuth2 tokens from python sync server (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address feedback Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | sync/tools/testserver/sync_testserver.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """An implementation of the server side of the Chromium sync protocol. 5 """An implementation of the server side of the Chromium sync protocol.
6 6
7 The details of the protocol are described mostly by comments in the protocol 7 The details of the protocol are described mostly by comments in the protocol
8 buffer definition at chrome/browser/sync/protocol/sync.proto. 8 buffer definition at chrome/browser/sync/protocol/sync.proto.
9 """ 9 """
10 10
(...skipping 1140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 # The implementation supports exactly one account; its state is here. 1151 # The implementation supports exactly one account; its state is here.
1152 self.account = SyncDataModel() 1152 self.account = SyncDataModel()
1153 self.account_lock = threading.Lock() 1153 self.account_lock = threading.Lock()
1154 # Clients that have talked to us: a map from the full client ID 1154 # Clients that have talked to us: a map from the full client ID
1155 # to its nickname. 1155 # to its nickname.
1156 self.clients = {} 1156 self.clients = {}
1157 self.client_name_generator = ('+' * times + chr(c) 1157 self.client_name_generator = ('+' * times + chr(c)
1158 for times in xrange(0, sys.maxint) for c in xrange(ord('A'), ord('Z'))) 1158 for times in xrange(0, sys.maxint) for c in xrange(ord('A'), ord('Z')))
1159 self.transient_error = False 1159 self.transient_error = False
1160 self.sync_count = 0 1160 self.sync_count = 0
1161 # Gaia OAuth2 Token fields and their default values.
1162 self.response_code = 200
1163 self.request_token = 'rt1'
1164 self.access_token = 'at1'
1165 self.expires_in = 3600
1166 self.token_type = 'Bearer'
1167
1161 1168
1162 def GetShortClientName(self, query): 1169 def GetShortClientName(self, query):
1163 parsed = cgi.parse_qs(query[query.find('?')+1:]) 1170 parsed = cgi.parse_qs(query[query.find('?')+1:])
1164 client_id = parsed.get('client_id') 1171 client_id = parsed.get('client_id')
1165 if not client_id: 1172 if not client_id:
1166 return '?' 1173 return '?'
1167 client_id = client_id[0] 1174 client_id = client_id[0]
1168 if client_id not in self.clients: 1175 if client_id not in self.clients:
1169 self.clients[client_id] = self.client_name_generator.next() 1176 self.clients[client_id] = self.client_name_generator.next()
1170 return self.clients[client_id] 1177 return self.clients[client_id]
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1475 sending_nigori_node = False 1482 sending_nigori_node = False
1476 for entry in entries: 1483 for entry in entries:
1477 if entry.name == 'Nigori': 1484 if entry.name == 'Nigori':
1478 sending_nigori_node = True 1485 sending_nigori_node = True
1479 reply = update_response.entries.add() 1486 reply = update_response.entries.add()
1480 reply.CopyFrom(entry) 1487 reply.CopyFrom(entry)
1481 update_sieve.SaveProgress(new_timestamp, update_response) 1488 update_sieve.SaveProgress(new_timestamp, update_response)
1482 1489
1483 if update_request.need_encryption_key or sending_nigori_node: 1490 if update_request.need_encryption_key or sending_nigori_node:
1484 update_response.encryption_keys.extend(self.account.GetKeystoreKeys()) 1491 update_response.encryption_keys.extend(self.account.GetKeystoreKeys())
1492
1493 def HandleGetOauth2Token(self):
1494 return (int(self.response_code),
1495 '{\n'
1496 ' \"refresh_token\": \"' + self.request_token + '\",\n'
1497 ' \"access_token\": \"' + self.access_token + '\",\n'
1498 ' \"expires_in\": ' + str(self.expires_in) + ',\n'
1499 ' \"token_type\": \"' + self.token_type +'\"\n'
1500 '}')
1501
1502 def HandleSetOauth2Token(self, response_code, request_token, access_token,
1503 expires_in, token_type):
1504 if response_code != 0:
1505 self.response_code = response_code
1506 if request_token != '':
1507 self.request_token = request_token
1508 if access_token != '':
1509 self.access_token = access_token
1510 if expires_in != 0:
1511 self.expires_in = expires_in
1512 if token_type != '':
1513 self.token_type = token_type
1514
1515 return (200,
1516 '<html><title>Set OAuth2 Token</title>'
1517 '<H1>This server will now return the OAuth2 Token:</H1>'
1518 '<p>response_code: ' + str(self.response_code) + '</p>'
1519 '<p>request_token: ' + self.request_token + '</p>'
1520 '<p>access_token: ' + self.access_token + '</p>'
1521 '<p>expires_in: ' + str(self.expires_in) + '</p>'
1522 '<p>token_type: ' + self.token_type + '</p>'
1523 '</html>')
OLDNEW
« no previous file with comments | « no previous file | sync/tools/testserver/sync_testserver.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698