| 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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 self.headers.getheader('Authorization', '')) | 283 self.headers.getheader('Authorization', '')) |
| 284 logging.debug('oauth token -> ' + str(self.GetUniqueParam('oauth_token'))) | 284 logging.debug('oauth token -> ' + str(self.GetUniqueParam('oauth_token'))) |
| 285 logging.debug('deviceid -> ' + str(self.GetUniqueParam('deviceid'))) | 285 logging.debug('deviceid -> ' + str(self.GetUniqueParam('deviceid'))) |
| 286 self.DumpMessage('Request', rmsg) | 286 self.DumpMessage('Request', rmsg) |
| 287 | 287 |
| 288 request_type = self.GetUniqueParam('request') | 288 request_type = self.GetUniqueParam('request') |
| 289 # Check server side requirements, as defined in | 289 # Check server side requirements, as defined in |
| 290 # device_management_backend.proto. | 290 # device_management_backend.proto. |
| 291 if (self.GetUniqueParam('devicetype') != '2' or | 291 if (self.GetUniqueParam('devicetype') != '2' or |
| 292 self.GetUniqueParam('apptype') != 'Chrome' or | 292 self.GetUniqueParam('apptype') != 'Chrome' or |
| 293 (self.GetUniqueParam('deviceid') is not None and | 293 len(self.GetUniqueParam('deviceid')) >= 64): |
| 294 len(self.GetUniqueParam('deviceid')) >= 64)): | |
| 295 return (400, 'Invalid request parameter') | 294 return (400, 'Invalid request parameter') |
| 296 if request_type == 'register': | 295 if request_type == 'register': |
| 297 response = self.ProcessRegister(rmsg.register_request) | 296 response = self.ProcessRegister(rmsg.register_request) |
| 298 elif request_type == 'api_authorization': | 297 elif request_type == 'api_authorization': |
| 299 response = self.ProcessApiAuthorization(rmsg.service_api_access_request) | 298 response = self.ProcessApiAuthorization(rmsg.service_api_access_request) |
| 300 elif request_type == 'unregister': | 299 elif request_type == 'unregister': |
| 301 response = self.ProcessUnregister(rmsg.unregister_request) | 300 response = self.ProcessUnregister(rmsg.unregister_request) |
| 302 elif request_type == 'policy': | 301 elif request_type == 'policy': |
| 303 response = self.ProcessPolicy(rmsg, request_type) | 302 response = self.ProcessPolicy(rmsg, request_type) |
| 304 elif request_type == 'enterprise_check': | 303 elif request_type == 'enterprise_check': |
| 305 response = self.ProcessAutoEnrollment(rmsg.auto_enrollment_request) | 304 response = self.ProcessAutoEnrollment(rmsg.auto_enrollment_request) |
| 306 elif request_type == 'device_state_retrieval': | 305 elif request_type == 'device_state_retrieval': |
| 307 response = self.ProcessDeviceStateRetrievalRequest( | 306 response = self.ProcessDeviceStateRetrievalRequest( |
| 308 rmsg.device_state_retrieval_request) | 307 rmsg.device_state_retrieval_request) |
| 309 elif request_type == 'status_upload': | 308 elif request_type == 'status_upload': |
| 310 response = self.ProcessStatusUploadRequest( | 309 response = self.ProcessStatusUploadRequest( |
| 311 rmsg.device_status_report_request, rmsg.session_status_report_request) | 310 rmsg.device_status_report_request, rmsg.session_status_report_request) |
| 312 elif request_type == 'device_attribute_update_permission': | 311 elif request_type == 'device_attribute_update_permission': |
| 313 response = self.ProcessDeviceAttributeUpdatePermissionRequest() | 312 response = self.ProcessDeviceAttributeUpdatePermissionRequest() |
| 314 elif request_type == 'device_attribute_update': | 313 elif request_type == 'device_attribute_update': |
| 315 response = self.ProcessDeviceAttributeUpdateRequest() | 314 response = self.ProcessDeviceAttributeUpdateRequest() |
| 316 elif request_type == 'remote_commands': | 315 elif request_type == 'remote_commands': |
| 317 response = self.ProcessRemoteCommandsRequest() | 316 response = self.ProcessRemoteCommandsRequest() |
| 318 elif request_type == 'check_android_management': | |
| 319 response = self.ProcessCheckAndroidManagementRequest( | |
| 320 rmsg.check_android_management_request, | |
| 321 str(self.GetUniqueParam('oauth_token'))) | |
| 322 else: | 317 else: |
| 323 return (400, 'Invalid request parameter') | 318 return (400, 'Invalid request parameter') |
| 324 | 319 |
| 325 if isinstance(response[1], basestring): | 320 if isinstance(response[1], basestring): |
| 326 body = response[1] | 321 body = response[1] |
| 327 elif isinstance(response[1], google.protobuf.message.Message): | 322 elif isinstance(response[1], google.protobuf.message.Message): |
| 328 self.DumpMessage('Response', response[1]) | 323 self.DumpMessage('Response', response[1]) |
| 329 body = response[1].SerializeToString() | 324 body = response[1].SerializeToString() |
| 330 else: | 325 else: |
| 331 body = '' | 326 body = '' |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 return (200, response) | 617 return (200, response) |
| 623 | 618 |
| 624 def ProcessRemoteCommandsRequest(self): | 619 def ProcessRemoteCommandsRequest(self): |
| 625 """Handles a remote command request. | 620 """Handles a remote command request. |
| 626 | 621 |
| 627 Returns: | 622 Returns: |
| 628 A tuple of HTTP status code and response data to send to the client. | 623 A tuple of HTTP status code and response data to send to the client. |
| 629 """ | 624 """ |
| 630 return (200, '') | 625 return (200, '') |
| 631 | 626 |
| 632 def ProcessCheckAndroidManagementRequest(self, msg, oauth_token): | |
| 633 """Handles a check Android management request. | |
| 634 | |
| 635 Returns: | |
| 636 A tuple of HTTP status code and response data to send to the client. | |
| 637 """ | |
| 638 check_android_management_response = dm.CheckAndroidManagementResponse() | |
| 639 | |
| 640 response = dm.DeviceManagementResponse() | |
| 641 response.check_android_management_response.CopyFrom( | |
| 642 check_android_management_response) | |
| 643 if oauth_token == 'managed-auth-token': | |
| 644 return (409, response) | |
| 645 elif oauth_token == 'unmanaged-auth-token': | |
| 646 return (200, response) | |
| 647 else: | |
| 648 return (403, response) | |
| 649 | |
| 650 def SetProtobufMessageField(self, group_message, field, field_value): | 627 def SetProtobufMessageField(self, group_message, field, field_value): |
| 651 """Sets a field in a protobuf message. | 628 """Sets a field in a protobuf message. |
| 652 | 629 |
| 653 Args: | 630 Args: |
| 654 group_message: The protobuf message. | 631 group_message: The protobuf message. |
| 655 field: The field of the message to set, it should be a member of | 632 field: The field of the message to set, it should be a member of |
| 656 group_message.DESCRIPTOR.fields. | 633 group_message.DESCRIPTOR.fields. |
| 657 field_value: The value to set. | 634 field_value: The value to set. |
| 658 """ | 635 """ |
| 659 if field.label == field.LABEL_REPEATED: | 636 if field.label == field.LABEL_REPEATED: |
| (...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1376 if (self.options.log_to_console): | 1353 if (self.options.log_to_console): |
| 1377 logger.addHandler(logging.StreamHandler()) | 1354 logger.addHandler(logging.StreamHandler()) |
| 1378 if (self.options.log_file): | 1355 if (self.options.log_file): |
| 1379 logger.addHandler(logging.FileHandler(self.options.log_file)) | 1356 logger.addHandler(logging.FileHandler(self.options.log_file)) |
| 1380 | 1357 |
| 1381 testserver_base.TestServerRunner.run_server(self) | 1358 testserver_base.TestServerRunner.run_server(self) |
| 1382 | 1359 |
| 1383 | 1360 |
| 1384 if __name__ == '__main__': | 1361 if __name__ == '__main__': |
| 1385 sys.exit(PolicyServerRunner().main()) | 1362 sys.exit(PolicyServerRunner().main()) |
| OLD | NEW |