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

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

Issue 5153002: Use a service to create device management backends. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 10 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
OLDNEW
1 #!/usr/bin/python2.5 1 #!/usr/bin/python2.5
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2010 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 from files in a directory. The files should contain policy definitions in JSON 10 from files in a directory. The files should contain policy definitions in JSON
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 if not token: 179 if not token:
180 return response 180 return response
181 181
182 # Stuff the policy dictionary into a response message and send it back. 182 # Stuff the policy dictionary into a response message and send it back.
183 response = dm.DeviceManagementResponse() 183 response = dm.DeviceManagementResponse()
184 response.error = dm.DeviceManagementResponse.SUCCESS 184 response.error = dm.DeviceManagementResponse.SUCCESS
185 response.policy_response.CopyFrom(dm.DevicePolicyResponse()) 185 response.policy_response.CopyFrom(dm.DevicePolicyResponse())
186 186
187 # Respond only if the client requested policy for the cros/device scope, 187 # Respond only if the client requested policy for the cros/device scope,
188 # since that's where chrome policy is supposed to live in. 188 # since that's where chrome policy is supposed to live in.
189 if msg.policy_scope == 'cros/device': 189 if msg.policy_scope == 'chromeos/device':
190 setting = response.policy_response.setting.add() 190 setting = response.policy_response.setting.add()
191 setting.policy_key = 'chrome-policy' 191 setting.policy_key = 'chrome-policy'
192 policy_value = dm.GenericSetting() 192 policy_value = dm.GenericSetting()
193 for (key, value) in self._server.policy.iteritems(): 193 for (key, value) in self._server.policy.iteritems():
194 entry = policy_value.named_value.add() 194 entry = policy_value.named_value.add()
195 entry.name = key 195 entry.name = key
196 entry_value = dm.GenericValue() 196 entry_value = dm.GenericValue()
197 if isinstance(value, bool): 197 if isinstance(value, bool):
198 entry_value.value_type = dm.GenericValue.VALUE_TYPE_BOOL 198 entry_value.value_type = dm.GenericValue.VALUE_TYPE_BOOL
199 entry_value.bool_value = value 199 entry_value.bool_value = value
(...skipping 19 matching lines...) Expand all
219 219
220 Extracts the token from the request and passed to the server in order to 220 Extracts the token from the request and passed to the server in order to
221 look up the client. Returns a pair of token and error response. If the token 221 look up the client. Returns a pair of token and error response. If the token
222 is None, the error response is a pair of status code and error message. 222 is None, the error response is a pair of status code and error message.
223 223
224 Returns: 224 Returns:
225 A pair of DM token and error response. If the token is None, the message 225 A pair of DM token and error response. If the token is None, the message
226 will contain the error response to send back. 226 will contain the error response to send back.
227 """ 227 """
228 error = None 228 error = None
229 229 dmtoken = None
230 match = re.match('GoogleDMToken token=(\\w+)', 230 match = re.match('GoogleDMToken token=(\\w+)',
231 self._headers.getheader('Authorization', '')) 231 self._headers.getheader('Authorization', ''))
232 if match: 232 if match:
233 dmtoken = match.group(1) 233 dmtoken = match.group(1)
234 if not dmtoken: 234 if not dmtoken:
235 error = dm.DeviceManagementResponse.DEVICE_MANAGEMENT_TOKEN_INVALID 235 error = dm.DeviceManagementResponse.DEVICE_MANAGEMENT_TOKEN_INVALID
236 elif not self._server.LookupDevice(dmtoken): 236 elif not self._server.LookupDevice(dmtoken):
237 error = dm.DeviceManagementResponse.DEVICE_NOT_FOUND 237 error = dm.DeviceManagementResponse.DEVICE_NOT_FOUND
238 else: 238 else:
239 return (dmtoken, None) 239 return (dmtoken, None)
240 240
241 response = dm.DeviceManagementResponse() 241 response = dm.DeviceManagementResponse()
242 response.error = error 242 response.error = error
243 243
244 self.DumpMessage('Response', response) 244 self.DumpMessage('Response', response)
245 245
246 return (None, (200, response.SerializeToString())) 246 return (None, (200, response.SerializeToString()))
247 247
248 def DumpMessage(self, label, msg): 248 def DumpMessage(self, label, msg):
249 """Helper for logging an ASCII dump of a protobuf message.""" 249 """Helper for logging an ASCII dump of a protobuf message."""
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 return self._registered_devices.get(dmtoken, None) 309 return self._registered_devices.get(dmtoken, None)
310 310
311 def UnregisterDevice(self, dmtoken): 311 def UnregisterDevice(self, dmtoken):
312 """Unregisters a device identified by the given DM token. 312 """Unregisters a device identified by the given DM token.
313 313
314 Args: 314 Args:
315 dmtoken: The device management token provided by the client. 315 dmtoken: The device management token provided by the client.
316 """ 316 """
317 if dmtoken in self._registered_devices: 317 if dmtoken in self._registered_devices:
318 del self._registered_devices[dmtoken] 318 del self._registered_devices[dmtoken]
OLDNEW
« chrome/test/test_url_request_context_getter.h ('K') | « chrome/test/testing_profile.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698