| OLD | NEW |
| 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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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] |
| OLD | NEW |