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 == 'remote_commands': | |
314 response = self.ProcessRemoteCommandsRequest() | |
311 else: | 315 else: |
312 return (400, 'Invalid request parameter') | 316 return (400, 'Invalid request parameter') |
313 | 317 |
314 if isinstance(response[1], basestring): | 318 if isinstance(response[1], basestring): |
315 body = response[1] | 319 body = response[1] |
316 elif isinstance(response[1], google.protobuf.message.Message): | 320 elif isinstance(response[1], google.protobuf.message.Message): |
317 self.DumpMessage('Response', response[1]) | 321 self.DumpMessage('Response', response[1]) |
318 body = response[1].SerializeToString() | 322 body = response[1].SerializeToString() |
319 else: | 323 else: |
320 body = '' | 324 body = '' |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
579 session_status_report_response = dm.SessionStatusReportResponse() | 583 session_status_report_response = dm.SessionStatusReportResponse() |
580 | 584 |
581 response = dm.DeviceManagementResponse() | 585 response = dm.DeviceManagementResponse() |
582 response.device_status_report_response.CopyFrom( | 586 response.device_status_report_response.CopyFrom( |
583 device_status_report_response) | 587 device_status_report_response) |
584 response.session_status_report_response.CopyFrom( | 588 response.session_status_report_response.CopyFrom( |
585 session_status_report_response) | 589 session_status_report_response) |
586 | 590 |
587 return (200, response) | 591 return (200, response) |
588 | 592 |
593 def ProcessDeviceAttributeUpdatePermissionRequest(self): | |
594 """Handles a device attribute update permission request. | |
595 | |
596 Returns: | |
597 A tuple of HTTP status code and response data to send to the client. | |
598 """ | |
599 response = dm.DeviceManagementResponse() | |
600 response.device_attribute_update_permission_response.result =\ | |
achuithb
2016/03/03 22:45:00
Can we use parens instead of \ for line break?
jdufault
2016/03/04 20:42:47
Done.
| |
601 dm.DeviceAttributeUpdatePermissionResponse.ATTRIBUTE_UPDATE_ALLOWED | |
602 | |
603 return (200, response) | |
604 | |
605 def ProcessRemoteCommandsRequest(self): | |
606 """Handles a remote command request. | |
607 | |
608 Returns: | |
609 A tuple of HTTP status code and response data to send to the client. | |
610 """ | |
611 return (200, '') | |
612 | |
589 def SetProtobufMessageField(self, group_message, field, field_value): | 613 def SetProtobufMessageField(self, group_message, field, field_value): |
590 """Sets a field in a protobuf message. | 614 """Sets a field in a protobuf message. |
591 | 615 |
592 Args: | 616 Args: |
593 group_message: The protobuf message. | 617 group_message: The protobuf message. |
594 field: The field of the message to set, it should be a member of | 618 field: The field of the message to set, it should be a member of |
595 group_message.DESCRIPTOR.fields. | 619 group_message.DESCRIPTOR.fields. |
596 field_value: The value to set. | 620 field_value: The value to set. |
597 """ | 621 """ |
598 if field.label == field.LABEL_REPEATED: | 622 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): | 1339 if (self.options.log_to_console): |
1316 logger.addHandler(logging.StreamHandler()) | 1340 logger.addHandler(logging.StreamHandler()) |
1317 if (self.options.log_file): | 1341 if (self.options.log_file): |
1318 logger.addHandler(logging.FileHandler(self.options.log_file)) | 1342 logger.addHandler(logging.FileHandler(self.options.log_file)) |
1319 | 1343 |
1320 testserver_base.TestServerRunner.run_server(self) | 1344 testserver_base.TestServerRunner.run_server(self) |
1321 | 1345 |
1322 | 1346 |
1323 if __name__ == '__main__': | 1347 if __name__ == '__main__': |
1324 sys.exit(PolicyServerRunner().main()) | 1348 sys.exit(PolicyServerRunner().main()) |
OLD | NEW |