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 len(self.GetUniqueParam('deviceid')) >= 64): | 293 (self.GetUniqueParam('deviceid') is not None and |
294 len(self.GetUniqueParam('deviceid')) >= 64)): | |
294 return (400, 'Invalid request parameter') | 295 return (400, 'Invalid request parameter') |
295 if request_type == 'register': | 296 if request_type == 'register': |
296 response = self.ProcessRegister(rmsg.register_request) | 297 response = self.ProcessRegister(rmsg.register_request) |
297 elif request_type == 'api_authorization': | 298 elif request_type == 'api_authorization': |
298 response = self.ProcessApiAuthorization(rmsg.service_api_access_request) | 299 response = self.ProcessApiAuthorization(rmsg.service_api_access_request) |
299 elif request_type == 'unregister': | 300 elif request_type == 'unregister': |
300 response = self.ProcessUnregister(rmsg.unregister_request) | 301 response = self.ProcessUnregister(rmsg.unregister_request) |
301 elif request_type == 'policy': | 302 elif request_type == 'policy': |
302 response = self.ProcessPolicy(rmsg, request_type) | 303 response = self.ProcessPolicy(rmsg, request_type) |
303 elif request_type == 'enterprise_check': | 304 elif request_type == 'enterprise_check': |
304 response = self.ProcessAutoEnrollment(rmsg.auto_enrollment_request) | 305 response = self.ProcessAutoEnrollment(rmsg.auto_enrollment_request) |
305 elif request_type == 'device_state_retrieval': | 306 elif request_type == 'device_state_retrieval': |
306 response = self.ProcessDeviceStateRetrievalRequest( | 307 response = self.ProcessDeviceStateRetrievalRequest( |
307 rmsg.device_state_retrieval_request) | 308 rmsg.device_state_retrieval_request) |
308 elif request_type == 'status_upload': | 309 elif request_type == 'status_upload': |
309 response = self.ProcessStatusUploadRequest( | 310 response = self.ProcessStatusUploadRequest( |
310 rmsg.device_status_report_request, rmsg.session_status_report_request) | 311 rmsg.device_status_report_request, rmsg.session_status_report_request) |
311 elif request_type == 'device_attribute_update_permission': | 312 elif request_type == 'device_attribute_update_permission': |
312 response = self.ProcessDeviceAttributeUpdatePermissionRequest() | 313 response = self.ProcessDeviceAttributeUpdatePermissionRequest() |
313 elif request_type == 'device_attribute_update': | 314 elif request_type == 'device_attribute_update': |
314 response = self.ProcessDeviceAttributeUpdateRequest() | 315 response = self.ProcessDeviceAttributeUpdateRequest() |
315 elif request_type == 'remote_commands': | 316 elif request_type == 'remote_commands': |
316 response = self.ProcessRemoteCommandsRequest() | 317 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'))) | |
317 else: | 322 else: |
318 return (400, 'Invalid request parameter') | 323 return (400, 'Invalid request parameter') |
319 | 324 |
320 if isinstance(response[1], basestring): | 325 if isinstance(response[1], basestring): |
321 body = response[1] | 326 body = response[1] |
322 elif isinstance(response[1], google.protobuf.message.Message): | 327 elif isinstance(response[1], google.protobuf.message.Message): |
323 self.DumpMessage('Response', response[1]) | 328 self.DumpMessage('Response', response[1]) |
324 body = response[1].SerializeToString() | 329 body = response[1].SerializeToString() |
325 else: | 330 else: |
326 body = '' | 331 body = '' |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
617 return (200, response) | 622 return (200, response) |
618 | 623 |
619 def ProcessRemoteCommandsRequest(self): | 624 def ProcessRemoteCommandsRequest(self): |
620 """Handles a remote command request. | 625 """Handles a remote command request. |
621 | 626 |
622 Returns: | 627 Returns: |
623 A tuple of HTTP status code and response data to send to the client. | 628 A tuple of HTTP status code and response data to send to the client. |
624 """ | 629 """ |
625 return (200, '') | 630 return (200, '') |
626 | 631 |
632 def ProcessCheckAndroidManagementRequest(self, msg, oauth_token): | |
633 """Handles a check android management request. | |
bartfab (slow)
2016/05/02 14:55:49
Nit: s/android/Android/
Polina Bondarenko
2016/05/03 13:41:55
Done.
| |
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 | |
627 def SetProtobufMessageField(self, group_message, field, field_value): | 650 def SetProtobufMessageField(self, group_message, field, field_value): |
628 """Sets a field in a protobuf message. | 651 """Sets a field in a protobuf message. |
629 | 652 |
630 Args: | 653 Args: |
631 group_message: The protobuf message. | 654 group_message: The protobuf message. |
632 field: The field of the message to set, it should be a member of | 655 field: The field of the message to set, it should be a member of |
633 group_message.DESCRIPTOR.fields. | 656 group_message.DESCRIPTOR.fields. |
634 field_value: The value to set. | 657 field_value: The value to set. |
635 """ | 658 """ |
636 if field.label == field.LABEL_REPEATED: | 659 if field.label == field.LABEL_REPEATED: |
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1353 if (self.options.log_to_console): | 1376 if (self.options.log_to_console): |
1354 logger.addHandler(logging.StreamHandler()) | 1377 logger.addHandler(logging.StreamHandler()) |
1355 if (self.options.log_file): | 1378 if (self.options.log_file): |
1356 logger.addHandler(logging.FileHandler(self.options.log_file)) | 1379 logger.addHandler(logging.FileHandler(self.options.log_file)) |
1357 | 1380 |
1358 testserver_base.TestServerRunner.run_server(self) | 1381 testserver_base.TestServerRunner.run_server(self) |
1359 | 1382 |
1360 | 1383 |
1361 if __name__ == '__main__': | 1384 if __name__ == '__main__': |
1362 sys.exit(PolicyServerRunner().main()) | 1385 sys.exit(PolicyServerRunner().main()) |
OLD | NEW |