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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 Parses the data supplied at construction time and returns a pair indicating | 272 Parses the data supplied at construction time and returns a pair indicating |
273 http status code and response data to be sent back to the client. | 273 http status code and response data to be sent back to the client. |
274 | 274 |
275 Returns: | 275 Returns: |
276 A tuple of HTTP status code and response data to send to the client. | 276 A tuple of HTTP status code and response data to send to the client. |
277 """ | 277 """ |
278 rmsg = dm.DeviceManagementRequest() | 278 rmsg = dm.DeviceManagementRequest() |
279 length = int(self.headers.getheader('content-length')) | 279 length = int(self.headers.getheader('content-length')) |
280 rmsg.ParseFromString(self.rfile.read(length)) | 280 rmsg.ParseFromString(self.rfile.read(length)) |
281 | 281 |
282 logging.debug('gaia auth token -> ' + | 282 gaia_header = self.headers.getheader('Authorization', '') |
283 self.headers.getheader('Authorization', '')) | 283 |
| 284 logging.debug('gaia auth token -> ' + gaia_header) |
284 logging.debug('oauth token -> ' + str(self.GetUniqueParam('oauth_token'))) | 285 logging.debug('oauth token -> ' + str(self.GetUniqueParam('oauth_token'))) |
285 logging.debug('deviceid -> ' + str(self.GetUniqueParam('deviceid'))) | 286 logging.debug('deviceid -> ' + str(self.GetUniqueParam('deviceid'))) |
286 self.DumpMessage('Request', rmsg) | 287 self.DumpMessage('Request', rmsg) |
287 | 288 |
288 request_type = self.GetUniqueParam('request') | 289 request_type = self.GetUniqueParam('request') |
289 # Check server side requirements, as defined in | 290 # Check server side requirements, as defined in |
290 # device_management_backend.proto. | 291 # device_management_backend.proto. |
291 if (self.GetUniqueParam('devicetype') != '2' or | 292 if (self.GetUniqueParam('devicetype') != '2' or |
292 self.GetUniqueParam('apptype') != 'Chrome' or | 293 self.GetUniqueParam('apptype') != 'Chrome' or |
293 len(self.GetUniqueParam('deviceid')) >= 64): | 294 (self.GetUniqueParam('deviceid') is not None and |
| 295 len(self.GetUniqueParam('deviceid')) >= 64)): |
294 return (400, 'Invalid request parameter') | 296 return (400, 'Invalid request parameter') |
295 if request_type == 'register': | 297 if request_type == 'register': |
296 response = self.ProcessRegister(rmsg.register_request) | 298 response = self.ProcessRegister(rmsg.register_request) |
297 elif request_type == 'api_authorization': | 299 elif request_type == 'api_authorization': |
298 response = self.ProcessApiAuthorization(rmsg.service_api_access_request) | 300 response = self.ProcessApiAuthorization(rmsg.service_api_access_request) |
299 elif request_type == 'unregister': | 301 elif request_type == 'unregister': |
300 response = self.ProcessUnregister(rmsg.unregister_request) | 302 response = self.ProcessUnregister(rmsg.unregister_request) |
301 elif request_type == 'policy': | 303 elif request_type == 'policy': |
302 response = self.ProcessPolicy(rmsg, request_type) | 304 response = self.ProcessPolicy(rmsg, request_type) |
303 elif request_type == 'enterprise_check': | 305 elif request_type == 'enterprise_check': |
304 response = self.ProcessAutoEnrollment(rmsg.auto_enrollment_request) | 306 response = self.ProcessAutoEnrollment(rmsg.auto_enrollment_request) |
305 elif request_type == 'device_state_retrieval': | 307 elif request_type == 'device_state_retrieval': |
306 response = self.ProcessDeviceStateRetrievalRequest( | 308 response = self.ProcessDeviceStateRetrievalRequest( |
307 rmsg.device_state_retrieval_request) | 309 rmsg.device_state_retrieval_request) |
308 elif request_type == 'status_upload': | 310 elif request_type == 'status_upload': |
309 response = self.ProcessStatusUploadRequest( | 311 response = self.ProcessStatusUploadRequest( |
310 rmsg.device_status_report_request, rmsg.session_status_report_request) | 312 rmsg.device_status_report_request, rmsg.session_status_report_request) |
| 313 elif request_type == 'check_android_management_request': |
| 314 gaia_token = gaia_header[len('GoogleLogin auth='):] |
| 315 response = self.ProcessCheckAndroidManagementRequest( |
| 316 rmsg.check_android_management_request, |
| 317 gaia_token) |
311 else: | 318 else: |
312 return (400, 'Invalid request parameter') | 319 return (400, 'Invalid request parameter') |
313 | 320 |
314 if isinstance(response[1], basestring): | 321 if isinstance(response[1], basestring): |
315 body = response[1] | 322 body = response[1] |
316 elif isinstance(response[1], google.protobuf.message.Message): | 323 elif isinstance(response[1], google.protobuf.message.Message): |
317 self.DumpMessage('Response', response[1]) | 324 self.DumpMessage('Response', response[1]) |
318 body = response[1].SerializeToString() | 325 body = response[1].SerializeToString() |
319 else: | 326 else: |
320 body = '' | 327 body = '' |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 session_status_report_response = dm.SessionStatusReportResponse() | 586 session_status_report_response = dm.SessionStatusReportResponse() |
580 | 587 |
581 response = dm.DeviceManagementResponse() | 588 response = dm.DeviceManagementResponse() |
582 response.device_status_report_response.CopyFrom( | 589 response.device_status_report_response.CopyFrom( |
583 device_status_report_response) | 590 device_status_report_response) |
584 response.session_status_report_response.CopyFrom( | 591 response.session_status_report_response.CopyFrom( |
585 session_status_report_response) | 592 session_status_report_response) |
586 | 593 |
587 return (200, response) | 594 return (200, response) |
588 | 595 |
| 596 def ProcessCheckAndroidManagementRequest(self, msg, gaia_token): |
| 597 """Handles a check android management request. |
| 598 |
| 599 Returns: |
| 600 A tuple of HTTP status code and response data to send to the client. |
| 601 """ |
| 602 check_android_management_response = dm.CheckAndroidManagementResponse() |
| 603 |
| 604 response = dm.DeviceManagementResponse() |
| 605 response.check_android_management_response.CopyFrom( |
| 606 check_android_management_response) |
| 607 if gaia_token == 'managed-auth-token': |
| 608 return (409, response) |
| 609 elif gaia_token == 'unmanaged-auth-token': |
| 610 return (200, response) |
| 611 else: |
| 612 return (400, response) |
| 613 |
589 def SetProtobufMessageField(self, group_message, field, field_value): | 614 def SetProtobufMessageField(self, group_message, field, field_value): |
590 """Sets a field in a protobuf message. | 615 """Sets a field in a protobuf message. |
591 | 616 |
592 Args: | 617 Args: |
593 group_message: The protobuf message. | 618 group_message: The protobuf message. |
594 field: The field of the message to set, it should be a member of | 619 field: The field of the message to set, it should be a member of |
595 group_message.DESCRIPTOR.fields. | 620 group_message.DESCRIPTOR.fields. |
596 field_value: The value to set. | 621 field_value: The value to set. |
597 """ | 622 """ |
598 if field.label == field.LABEL_REPEATED: | 623 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): | 1340 if (self.options.log_to_console): |
1316 logger.addHandler(logging.StreamHandler()) | 1341 logger.addHandler(logging.StreamHandler()) |
1317 if (self.options.log_file): | 1342 if (self.options.log_file): |
1318 logger.addHandler(logging.FileHandler(self.options.log_file)) | 1343 logger.addHandler(logging.FileHandler(self.options.log_file)) |
1319 | 1344 |
1320 testserver_base.TestServerRunner.run_server(self) | 1345 testserver_base.TestServerRunner.run_server(self) |
1321 | 1346 |
1322 | 1347 |
1323 if __name__ == '__main__': | 1348 if __name__ == '__main__': |
1324 sys.exit(PolicyServerRunner().main()) | 1349 sys.exit(PolicyServerRunner().main()) |
OLD | NEW |