| 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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 elif request_type == 'policy': | 301 elif request_type == 'policy': |
| 302 response = self.ProcessPolicy(rmsg, request_type) | 302 response = self.ProcessPolicy(rmsg, request_type) |
| 303 elif request_type == 'enterprise_check': | 303 elif request_type == 'enterprise_check': |
| 304 response = self.ProcessAutoEnrollment(rmsg.auto_enrollment_request) | 304 response = self.ProcessAutoEnrollment(rmsg.auto_enrollment_request) |
| 305 elif request_type == 'device_state_retrieval': | 305 elif request_type == 'device_state_retrieval': |
| 306 response = self.ProcessDeviceStateRetrievalRequest( | 306 response = self.ProcessDeviceStateRetrievalRequest( |
| 307 rmsg.device_state_retrieval_request) | 307 rmsg.device_state_retrieval_request) |
| 308 elif request_type == 'status_upload': | 308 elif request_type == 'status_upload': |
| 309 response = self.ProcessStatusUploadRequest( | 309 response = self.ProcessStatusUploadRequest( |
| 310 rmsg.device_status_report_request, rmsg.session_status_report_request) | 310 rmsg.device_status_report_request, rmsg.session_status_report_request) |
| 311 elif request_type == 'device_attribute_update_permission': |
| 312 response = self.ProcessDeviceAttributeUpdatePermissionRequest() |
| 313 elif request_type == 'device_attribute_update': |
| 314 response = self.ProcessDeviceAttributeUpdateRequest() |
| 315 elif request_type == 'remote_commands': |
| 316 response = self.ProcessRemoteCommandsRequest() |
| 311 else: | 317 else: |
| 312 return (400, 'Invalid request parameter') | 318 return (400, 'Invalid request parameter') |
| 313 | 319 |
| 314 if isinstance(response[1], basestring): | 320 if isinstance(response[1], basestring): |
| 315 body = response[1] | 321 body = response[1] |
| 316 elif isinstance(response[1], google.protobuf.message.Message): | 322 elif isinstance(response[1], google.protobuf.message.Message): |
| 317 self.DumpMessage('Response', response[1]) | 323 self.DumpMessage('Response', response[1]) |
| 318 body = response[1].SerializeToString() | 324 body = response[1].SerializeToString() |
| 319 else: | 325 else: |
| 320 body = '' | 326 body = '' |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 session_status_report_response = dm.SessionStatusReportResponse() | 585 session_status_report_response = dm.SessionStatusReportResponse() |
| 580 | 586 |
| 581 response = dm.DeviceManagementResponse() | 587 response = dm.DeviceManagementResponse() |
| 582 response.device_status_report_response.CopyFrom( | 588 response.device_status_report_response.CopyFrom( |
| 583 device_status_report_response) | 589 device_status_report_response) |
| 584 response.session_status_report_response.CopyFrom( | 590 response.session_status_report_response.CopyFrom( |
| 585 session_status_report_response) | 591 session_status_report_response) |
| 586 | 592 |
| 587 return (200, response) | 593 return (200, response) |
| 588 | 594 |
| 595 def ProcessDeviceAttributeUpdatePermissionRequest(self): |
| 596 """Handles a device attribute update permission request. |
| 597 |
| 598 Returns: |
| 599 A tuple of HTTP status code and response data to send to the client. |
| 600 """ |
| 601 response = dm.DeviceManagementResponse() |
| 602 response.device_attribute_update_permission_response.result = ( |
| 603 dm.DeviceAttributeUpdatePermissionResponse.ATTRIBUTE_UPDATE_ALLOWED) |
| 604 |
| 605 return (200, response) |
| 606 |
| 607 def ProcessDeviceAttributeUpdateRequest(self): |
| 608 """Handles a device attribute update request. |
| 609 |
| 610 Returns: |
| 611 A tuple of HTTP status code and response data to send to the client. |
| 612 """ |
| 613 response = dm.DeviceManagementResponse() |
| 614 response.device_attribute_update_response.result = ( |
| 615 dm.DeviceAttributeUpdateResponse.ATTRIBUTE_UPDATE_SUCCESS) |
| 616 |
| 617 return (200, response) |
| 618 |
| 619 def ProcessRemoteCommandsRequest(self): |
| 620 """Handles a remote command request. |
| 621 |
| 622 Returns: |
| 623 A tuple of HTTP status code and response data to send to the client. |
| 624 """ |
| 625 return (200, '') |
| 626 |
| 589 def SetProtobufMessageField(self, group_message, field, field_value): | 627 def SetProtobufMessageField(self, group_message, field, field_value): |
| 590 """Sets a field in a protobuf message. | 628 """Sets a field in a protobuf message. |
| 591 | 629 |
| 592 Args: | 630 Args: |
| 593 group_message: The protobuf message. | 631 group_message: The protobuf message. |
| 594 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 |
| 595 group_message.DESCRIPTOR.fields. | 633 group_message.DESCRIPTOR.fields. |
| 596 field_value: The value to set. | 634 field_value: The value to set. |
| 597 """ | 635 """ |
| 598 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... |
| 1315 if (self.options.log_to_console): | 1353 if (self.options.log_to_console): |
| 1316 logger.addHandler(logging.StreamHandler()) | 1354 logger.addHandler(logging.StreamHandler()) |
| 1317 if (self.options.log_file): | 1355 if (self.options.log_file): |
| 1318 logger.addHandler(logging.FileHandler(self.options.log_file)) | 1356 logger.addHandler(logging.FileHandler(self.options.log_file)) |
| 1319 | 1357 |
| 1320 testserver_base.TestServerRunner.run_server(self) | 1358 testserver_base.TestServerRunner.run_server(self) |
| 1321 | 1359 |
| 1322 | 1360 |
| 1323 if __name__ == '__main__': | 1361 if __name__ == '__main__': |
| 1324 sys.exit(PolicyServerRunner().main()) | 1362 sys.exit(PolicyServerRunner().main()) |
| OLD | NEW |