Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: chrome/browser/policy/test/policy_testserver.py

Issue 342233005: Move ownership of the ComponentCloudPolicyService to the broker. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed comments Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 """ 436 """
437 token_info, error = self.CheckToken() 437 token_info, error = self.CheckToken()
438 if not token_info: 438 if not token_info:
439 return error 439 return error
440 440
441 key_update_request = msg.device_state_key_update_request 441 key_update_request = msg.device_state_key_update_request
442 if len(key_update_request.server_backed_state_key) > 0: 442 if len(key_update_request.server_backed_state_key) > 0:
443 self.server.UpdateStateKeys(token_info['device_token'], 443 self.server.UpdateStateKeys(token_info['device_token'],
444 key_update_request.server_backed_state_key) 444 key_update_request.server_backed_state_key)
445 445
446 # If this is a publicaccount request then get the username now and use it 446 # If this is a |publicaccount| request then get the |username| now and use
bartfab (slow) 2014/06/20 16:41:11 Nit: s/request then/request,/
Joao da Silva 2014/06/20 17:25:33 Done.
447 # in every PolicyFetchResponse produced. This is required to validate 447 # it in every PolicyFetchResponse produced. This is required to validate
448 # policy for extensions in public accounts. 448 # policy for extensions in device-local accounts.
449 username = self.server.GetPolicies().get('policy_user', None) 449 # Unfortunately the username can't be obtained from |msg| because that
bartfab (slow) 2014/06/20 16:41:11 Nit 1: s/Unfortunately/Unfortunately, / Nit 2: s/u
Joao da Silva 2014/06/20 17:25:33 Done.
450 # requires interacting with GAIA.
451 username = None
450 for request in msg.policy_request.request: 452 for request in msg.policy_request.request:
451 if request.policy_type == 'google/chromeos/publicaccount': 453 if request.policy_type == 'google/chromeos/publicaccount':
452 username = request.settings_entity_id 454 username = request.settings_entity_id
453 455
454 response = dm.DeviceManagementResponse() 456 response = dm.DeviceManagementResponse()
455 for request in msg.policy_request.request: 457 for request in msg.policy_request.request:
456 if (request.policy_type in 458 if (request.policy_type in
457 ('google/android/user', 459 ('google/android/user',
458 'google/chromeos/device', 460 'google/chromeos/device',
459 'google/chromeos/publicaccount', 461 'google/chromeos/publicaccount',
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 continue 632 continue
631 633
632 # Create protobuf message for this policy. 634 # Create protobuf message for this policy.
633 policy_message = eval('cp.' + field.message_type.name + '()') 635 policy_message = eval('cp.' + field.message_type.name + '()')
634 policy_message.policy_options.mode = mode 636 policy_message.policy_options.mode = mode
635 field_descriptor = policy_message.DESCRIPTOR.fields_by_name['value'] 637 field_descriptor = policy_message.DESCRIPTOR.fields_by_name['value']
636 self.SetProtobufMessageField(policy_message, field_descriptor, value) 638 self.SetProtobufMessageField(policy_message, field_descriptor, value)
637 settings.__getattribute__(field.name).CopyFrom(policy_message) 639 settings.__getattribute__(field.name).CopyFrom(policy_message)
638 640
639 def ProcessCloudPolicyForExtensions(self, request, response, token_info, 641 def ProcessCloudPolicyForExtensions(self, request, response, token_info,
640 username): 642 username=None):
641 """Handles a request for policy for extensions. 643 """Handles a request for policy for extensions.
642 644
643 A request for policy for extensions is slightly different from the other 645 A request for policy for extensions is slightly different from the other
644 cloud policy requests, because it can trigger 0, one or many 646 cloud policy requests, because it can trigger 0, one or many
645 PolicyFetchResponse messages in the response. 647 PolicyFetchResponse messages in the response.
646 648
647 Args: 649 Args:
648 request: The PolicyFetchRequest that triggered this handler. 650 request: The PolicyFetchRequest that triggered this handler.
649 response: The DevicePolicyResponse message for the response. Multiple 651 response: The DevicePolicyResponse message for the response. Multiple
650 PolicyFetchResponses will be appended to this message. 652 PolicyFetchResponses will be appended to this message.
651 token_info: The token extracted from the request. 653 token_info: The token extracted from the request.
652 username: The username for the response. 654 username: The username for the response. May be None.
653 """ 655 """
654 # Send one PolicyFetchResponse for each extension that has 656 # Send one PolicyFetchResponse for each extension that has
655 # configuration data at the server. 657 # configuration data at the server.
656 ids = self.server.ListMatchingComponents('google/chrome/extension') 658 ids = self.server.ListMatchingComponents('google/chrome/extension')
657 for settings_entity_id in ids: 659 for settings_entity_id in ids:
658 # Reuse the extension policy request, to trigger the same signature 660 # Reuse the extension policy request, to trigger the same signature
659 # type in the response. 661 # type in the response.
660 request.settings_entity_id = settings_entity_id 662 request.settings_entity_id = settings_entity_id
661 fetch_response = response.response.add() 663 fetch_response = response.response.add()
662 self.ProcessCloudPolicy(request, token_info, fetch_response, username) 664 self.ProcessCloudPolicy(request, token_info, fetch_response, username)
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 # provided needs to be encoded as ASCII to set the correct byte pattern. 755 # provided needs to be encoded as ASCII to set the correct byte pattern.
754 invalidation_name = policy.get('invalidation_name') 756 invalidation_name = policy.get('invalidation_name')
755 if invalidation_name is not None: 757 if invalidation_name is not None:
756 policy_data.invalidation_name = invalidation_name.encode('ascii') 758 policy_data.invalidation_name = invalidation_name.encode('ascii')
757 759
758 if signing_key: 760 if signing_key:
759 policy_data.public_key_version = current_key_index + 1 761 policy_data.public_key_version = current_key_index + 1
760 762
761 if username: 763 if username:
762 policy_data.username = username 764 policy_data.username = username
763 elif msg.policy_type == 'google/chromeos/publicaccount': 765 elif msg.policy_type == 'google/chromeos/publicaccount':
bartfab (slow) 2014/06/20 16:41:11 This is redundant now.
Joao da Silva 2014/06/20 17:25:33 Done.
764 policy_data.username = msg.settings_entity_id 766 policy_data.username = msg.settings_entity_id
765 else: 767 else:
766 # For regular user/device policy, there is no way for the testserver to 768 # For regular user/device policy, there is no way for the testserver to
767 # know the user name belonging to the GAIA auth token we received (short 769 # know the user name belonging to the GAIA auth token we received (short
768 # of actually talking to GAIA). To address this, we read the username from 770 # of actually talking to GAIA). To address this, we read the username from
769 # the policy configuration dictionary, or use a default. 771 # the policy configuration dictionary, or use a default.
770 policy_data.username = policy.get('policy_user', 'user@example.com') 772 policy_data.username = policy.get('policy_user', 'user@example.com')
771 policy_data.device_id = token_info['device_id'] 773 policy_data.device_id = token_info['device_id']
772 signed_data = policy_data.SerializeToString() 774 signed_data = policy_data.SerializeToString()
773 775
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 if (self.options.log_to_console): 1242 if (self.options.log_to_console):
1241 logger.addHandler(logging.StreamHandler()) 1243 logger.addHandler(logging.StreamHandler())
1242 if (self.options.log_file): 1244 if (self.options.log_file):
1243 logger.addHandler(logging.FileHandler(self.options.log_file)) 1245 logger.addHandler(logging.FileHandler(self.options.log_file))
1244 1246
1245 testserver_base.TestServerRunner.run_server(self) 1247 testserver_base.TestServerRunner.run_server(self)
1246 1248
1247 1249
1248 if __name__ == '__main__': 1250 if __name__ == '__main__':
1249 sys.exit(PolicyServerRunner().main()) 1251 sys.exit(PolicyServerRunner().main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698