OLD | NEW |
---|---|
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 """A bare-bones test server for testing cloud policy support. | 5 """A bare-bones test server for testing cloud policy support. |
6 | 6 |
7 This implements a simple cloud policy test server that can be used to test | 7 This implements a simple cloud policy test server that can be used to test |
8 chrome's device management service client. The policy information is read from | 8 chrome's device management service client. The policy information is read from |
9 the file named device_management in the server's data directory. It contains | 9 the file named device_management in the server's data directory. It contains |
10 enforced and recommended policies for the device and user scope, and a list | 10 enforced and recommended policies for the device and user scope, and a list |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 # Check server side requirements, as defined in | 195 # Check server side requirements, as defined in |
196 # device_management_backend.proto. | 196 # device_management_backend.proto. |
197 if (self.GetUniqueParam('devicetype') != '2' or | 197 if (self.GetUniqueParam('devicetype') != '2' or |
198 self.GetUniqueParam('apptype') != 'Chrome' or | 198 self.GetUniqueParam('apptype') != 'Chrome' or |
199 (request_type != 'ping' and | 199 (request_type != 'ping' and |
200 len(self.GetUniqueParam('deviceid')) >= 64) or | 200 len(self.GetUniqueParam('deviceid')) >= 64) or |
201 len(self.GetUniqueParam('agent')) >= 64): | 201 len(self.GetUniqueParam('agent')) >= 64): |
202 return (400, 'Invalid request parameter') | 202 return (400, 'Invalid request parameter') |
203 if request_type == 'register': | 203 if request_type == 'register': |
204 return self.ProcessRegister(rmsg.register_request) | 204 return self.ProcessRegister(rmsg.register_request) |
205 if request_type == 'api_authorization': | |
206 return self.ProcessApiAuthorization(rmsg.service_api_access_request) | |
205 elif request_type == 'unregister': | 207 elif request_type == 'unregister': |
206 return self.ProcessUnregister(rmsg.unregister_request) | 208 return self.ProcessUnregister(rmsg.unregister_request) |
207 elif request_type == 'policy' or request_type == 'ping': | 209 elif request_type == 'policy' or request_type == 'ping': |
208 return self.ProcessPolicy(rmsg.policy_request, request_type) | 210 return self.ProcessPolicy(rmsg.policy_request, request_type) |
209 elif request_type == 'enterprise_check': | 211 elif request_type == 'enterprise_check': |
210 return self.ProcessAutoEnrollment(rmsg.auto_enrollment_request) | 212 return self.ProcessAutoEnrollment(rmsg.auto_enrollment_request) |
211 else: | 213 else: |
212 return (400, 'Invalid request parameter') | 214 return (400, 'Invalid request parameter') |
213 | 215 |
214 def CreatePolicyForExternalPolicyData(self, policy_key): | 216 def CreatePolicyForExternalPolicyData(self, policy_key): |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 response = dm.DeviceManagementResponse() | 287 response = dm.DeviceManagementResponse() |
286 response.register_response.device_management_token = ( | 288 response.register_response.device_management_token = ( |
287 token_info['device_token']) | 289 token_info['device_token']) |
288 response.register_response.machine_name = token_info['machine_name'] | 290 response.register_response.machine_name = token_info['machine_name'] |
289 response.register_response.enrollment_type = token_info['enrollment_mode'] | 291 response.register_response.enrollment_type = token_info['enrollment_mode'] |
290 | 292 |
291 self.DumpMessage('Response', response) | 293 self.DumpMessage('Response', response) |
292 | 294 |
293 return (200, response.SerializeToString()) | 295 return (200, response.SerializeToString()) |
294 | 296 |
297 def ProcessApiAuthorization(self, msg): | |
298 """Handles an API authorization request. | |
299 | |
300 Args: | |
301 msg: The DeviceServiceApiAccessRequest message received from the client. | |
302 | |
303 Returns: | |
304 A tuple of HTTP status code and response data to send to the client. | |
305 """ | |
306 | |
307 # Prepare and send the response. | |
308 response = dm.DeviceManagementResponse() | |
309 response.service_api_access_response.CopyFrom( | |
310 dm.DeviceServiceApiAccessResponse()) | |
Mattias Nissler (ping if slow)
2013/04/22 10:59:00
Don't you need to put an access code string here t
David Roche
2013/04/23 01:36:08
Done.
| |
311 | |
312 self.DumpMessage('Response', response) | |
313 | |
314 return (200, response.SerializeToString()) | |
315 | |
295 def ProcessUnregister(self, msg): | 316 def ProcessUnregister(self, msg): |
296 """Handles a register request. | 317 """Handles a register request. |
297 | 318 |
298 Checks for authorization, unregisters the device and constructs the | 319 Checks for authorization, unregisters the device and constructs the |
299 response. | 320 response. |
300 | 321 |
301 Args: | 322 Args: |
302 msg: The DeviceUnregisterRequest message received from the client. | 323 msg: The DeviceUnregisterRequest message received from the client. |
303 | 324 |
304 Returns: | 325 Returns: |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
913 if (self.options.log_to_console): | 934 if (self.options.log_to_console): |
914 logger.addHandler(logging.StreamHandler()) | 935 logger.addHandler(logging.StreamHandler()) |
915 if (self.options.log_file): | 936 if (self.options.log_file): |
916 logger.addHandler(logging.FileHandler(self.options.log_file)) | 937 logger.addHandler(logging.FileHandler(self.options.log_file)) |
917 | 938 |
918 testserver_base.TestServerRunner.run_server(self) | 939 testserver_base.TestServerRunner.run_server(self) |
919 | 940 |
920 | 941 |
921 if __name__ == '__main__': | 942 if __name__ == '__main__': |
922 sys.exit(PolicyServerRunner().main()) | 943 sys.exit(PolicyServerRunner().main()) |
OLD | NEW |