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

Side by Side Diff: net/tools/testserver/device_management.py

Issue 6532019: New policy protobuf protocol. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix one more leak Created 9 years, 10 months 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
« chrome/browser/policy/cloud_policy_cache.cc ('K') | « net/net.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python2.5 1 #!/usr/bin/python2.5
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """A bare-bones test server for testing cloud policy support. 6 """A bare-bones test server for testing cloud policy support.
7 7
8 This implements a simple cloud policy test server that can be used to test 8 This implements a simple cloud policy test server that can be used to test
9 chrome's device management service client. The policy information is read from 9 chrome's device management service client. The policy information is read from
10 the file named device_management in the server's data directory. It contains 10 the file named device_management in the server's data directory. It contains
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 def GetUniqueParam(self, name): 88 def GetUniqueParam(self, name):
89 """Extracts a unique query parameter from the request. 89 """Extracts a unique query parameter from the request.
90 90
91 Args: 91 Args:
92 name: Names the parameter to fetch. 92 name: Names the parameter to fetch.
93 Returns: 93 Returns:
94 The parameter value or None if the parameter doesn't exist or is not 94 The parameter value or None if the parameter doesn't exist or is not
95 unique. 95 unique.
96 """ 96 """
97 if not self._params: 97 if not self._params:
98 self._params = cgi.parse_qs(self._path[self._path.find('?')+1:]) 98 self._params = cgi.parse_qs(self._path[self._path.find('?') + 1:])
99 99
100 param_list = self._params.get(name, []) 100 param_list = self._params.get(name, [])
101 if len(param_list) == 1: 101 if len(param_list) == 1:
102 return param_list[0] 102 return param_list[0]
103 return None; 103 return None;
104 104
105 def HandleRequest(self): 105 def HandleRequest(self):
106 """Handles a request. 106 """Handles a request.
107 107
108 Parses the data supplied at construction time and returns a pair indicating 108 Parses the data supplied at construction time and returns a pair indicating
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 if not device_id: 166 if not device_id:
167 return (400, 'Missing device identifier') 167 return (400, 'Missing device identifier')
168 168
169 # Register the device and create a token. 169 # Register the device and create a token.
170 dmtoken = self._server.RegisterDevice(device_id) 170 dmtoken = self._server.RegisterDevice(device_id)
171 171
172 # Send back the reply. 172 # Send back the reply.
173 response = dm.DeviceManagementResponse() 173 response = dm.DeviceManagementResponse()
174 response.error = dm.DeviceManagementResponse.SUCCESS 174 response.error = dm.DeviceManagementResponse.SUCCESS
175 response.register_response.device_management_token = dmtoken 175 response.register_response.device_management_token = dmtoken
176 response.register_response.device_name = self.GetDeviceName()
177 176
178 self.DumpMessage('Response', response) 177 self.DumpMessage('Response', response)
179 178
180 return (200, response.SerializeToString()) 179 return (200, response.SerializeToString())
181 180
182 def ProcessUnregister(self, msg): 181 def ProcessUnregister(self, msg):
183 """Handles a register request. 182 """Handles a register request.
184 183
185 Checks for authorization, unregisters the device and constructs the 184 Checks for authorization, unregisters the device and constructs the
186 response. 185 response.
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 490
492 Args: 491 Args:
493 device_id: The device identifier provided by the client. 492 device_id: The device identifier provided by the client.
494 493
495 Returns: 494 Returns:
496 The newly generated device token for the device. 495 The newly generated device token for the device.
497 """ 496 """
498 dmtoken_chars = [] 497 dmtoken_chars = []
499 while len(dmtoken_chars) < 32: 498 while len(dmtoken_chars) < 32:
500 dmtoken_chars.append(random.choice('0123456789abcdef')) 499 dmtoken_chars.append(random.choice('0123456789abcdef'))
501 dmtoken= ''.join(dmtoken_chars) 500 dmtoken = ''.join(dmtoken_chars)
502 self._registered_devices[dmtoken] = device_id 501 self._registered_devices[dmtoken] = device_id
503 return dmtoken 502 return dmtoken
504 503
505 def LookupDevice(self, dmtoken): 504 def LookupDevice(self, dmtoken):
506 """Looks up a device by DMToken. 505 """Looks up a device by DMToken.
507 506
508 Args: 507 Args:
509 dmtoken: The device management token provided by the client. 508 dmtoken: The device management token provided by the client.
510 509
511 Returns: 510 Returns:
512 The corresponding device identifier or None if not found. 511 The corresponding device identifier or None if not found.
513 """ 512 """
514 return self._registered_devices.get(dmtoken, None) 513 return self._registered_devices.get(dmtoken, None)
515 514
516 def UnregisterDevice(self, dmtoken): 515 def UnregisterDevice(self, dmtoken):
517 """Unregisters a device identified by the given DM token. 516 """Unregisters a device identified by the given DM token.
518 517
519 Args: 518 Args:
520 dmtoken: The device management token provided by the client. 519 dmtoken: The device management token provided by the client.
521 """ 520 """
522 if dmtoken in self._registered_devices: 521 if dmtoken in self._registered_devices:
523 del self._registered_devices[dmtoken] 522 del self._registered_devices[dmtoken]
OLDNEW
« chrome/browser/policy/cloud_policy_cache.cc ('K') | « net/net.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698