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

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

Issue 132033002: Add support for Android and iOS policy fetch types to the testserver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 A tuple of HTTP status code and response data to send to the client. 357 A tuple of HTTP status code and response data to send to the client.
358 """ 358 """
359 token_info, error = self.CheckToken() 359 token_info, error = self.CheckToken()
360 if not token_info: 360 if not token_info:
361 return error 361 return error
362 362
363 response = dm.DeviceManagementResponse() 363 response = dm.DeviceManagementResponse()
364 for request in msg.request: 364 for request in msg.request:
365 fetch_response = response.policy_response.response.add() 365 fetch_response = response.policy_response.response.add()
366 if (request.policy_type in 366 if (request.policy_type in
367 ('google/chrome/user', 367 ('google/android/user',
368 'google/chromeos/user', 368 'google/chrome/extension',
369 'google/chromeos/device', 369 'google/chromeos/device',
370 'google/chromeos/publicaccount', 370 'google/chromeos/publicaccount',
371 'google/chrome/extension')): 371 'google/chromeos/user',
372 'google/chrome/user',
373 'google/ios/user')):
372 if request_type != 'policy': 374 if request_type != 'policy':
373 fetch_response.error_code = 400 375 fetch_response.error_code = 400
374 fetch_response.error_message = 'Invalid request type' 376 fetch_response.error_message = 'Invalid request type'
375 else: 377 else:
376 self.ProcessCloudPolicy(request, token_info, fetch_response) 378 self.ProcessCloudPolicy(request, token_info, fetch_response)
377 else: 379 else:
378 fetch_response.error_code = 400 380 fetch_response.error_code = 400
379 fetch_response.error_message = 'Invalid policy_type' 381 fetch_response.error_message = 'Invalid policy_type'
380 382
381 return (200, response.SerializeToString()) 383 return (200, response.SerializeToString())
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 538
537 # Response is only given if the scope is specified in the config file. 539 # Response is only given if the scope is specified in the config file.
538 # Normally 'google/chromeos/device', 'google/chromeos/user' and 540 # Normally 'google/chromeos/device', 'google/chromeos/user' and
539 # 'google/chromeos/publicaccount' should be accepted. 541 # 'google/chromeos/publicaccount' should be accepted.
540 policy = self.server.GetPolicies() 542 policy = self.server.GetPolicies()
541 policy_value = '' 543 policy_value = ''
542 policy_key = msg.policy_type 544 policy_key = msg.policy_type
543 if msg.settings_entity_id: 545 if msg.settings_entity_id:
544 policy_key += '/' + msg.settings_entity_id 546 policy_key += '/' + msg.settings_entity_id
545 if msg.policy_type in token_info['allowed_policy_types']: 547 if msg.policy_type in token_info['allowed_policy_types']:
546 if (msg.policy_type == 'google/chromeos/user' or 548 if msg.policy_type in ('google/android/user',
547 msg.policy_type == 'google/chrome/user' or 549 'google/chromeos/publicaccount',
548 msg.policy_type == 'google/chromeos/publicaccount'): 550 'google/chromeos/user',
551 'google/chrome/user',
552 'google/ios/user'):
549 settings = cp.CloudPolicySettings() 553 settings = cp.CloudPolicySettings()
550 payload = self.server.ReadPolicyFromDataDir(policy_key, settings) 554 payload = self.server.ReadPolicyFromDataDir(policy_key, settings)
551 if payload is None: 555 if payload is None:
552 self.GatherUserPolicySettings(settings, policy.get(policy_key, {})) 556 self.GatherUserPolicySettings(settings, policy.get(policy_key, {}))
553 payload = settings.SerializeToString() 557 payload = settings.SerializeToString()
554 elif dp is not None and msg.policy_type == 'google/chromeos/device': 558 elif dp is not None and msg.policy_type == 'google/chromeos/device':
555 settings = dp.ChromeDeviceSettingsProto() 559 settings = dp.ChromeDeviceSettingsProto()
556 payload = self.server.ReadPolicyFromDataDir(policy_key, settings) 560 payload = self.server.ReadPolicyFromDataDir(policy_key, settings)
557 if payload is None: 561 if payload is None:
558 self.GatherDevicePolicySettings(settings, policy.get(policy_key, {})) 562 self.GatherDevicePolicySettings(settings, policy.get(policy_key, {}))
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 'google/chrome/extension' 774 'google/chrome/extension'
771 ], 775 ],
772 dm.DeviceRegisterRequest.USER: [ 776 dm.DeviceRegisterRequest.USER: [
773 'google/chromeos/user', 777 'google/chromeos/user',
774 'google/chrome/extension' 778 'google/chrome/extension'
775 ], 779 ],
776 dm.DeviceRegisterRequest.DEVICE: [ 780 dm.DeviceRegisterRequest.DEVICE: [
777 'google/chromeos/device', 781 'google/chromeos/device',
778 'google/chromeos/publicaccount' 782 'google/chromeos/publicaccount'
779 ], 783 ],
784 dm.DeviceRegisterRequest.ANDROID_BROWSER: [
785 'google/android/user'
786 ],
787 dm.DeviceRegisterRequest.IOS_BROWSER: [
788 'google/ios/user'
789 ],
780 dm.DeviceRegisterRequest.TT: ['google/chromeos/user', 790 dm.DeviceRegisterRequest.TT: ['google/chromeos/user',
781 'google/chrome/user'], 791 'google/chrome/user'],
782 } 792 }
783 if machine_id in KIOSK_MACHINE_IDS: 793 if machine_id in KIOSK_MACHINE_IDS:
784 enrollment_mode = dm.DeviceRegisterResponse.RETAIL 794 enrollment_mode = dm.DeviceRegisterResponse.RETAIL
785 else: 795 else:
786 enrollment_mode = dm.DeviceRegisterResponse.ENTERPRISE 796 enrollment_mode = dm.DeviceRegisterResponse.ENTERPRISE
787 self._registered_tokens[dmtoken] = { 797 self._registered_tokens[dmtoken] = {
788 'device_id': device_id, 798 'device_id': device_id,
789 'device_token': dmtoken, 799 'device_token': dmtoken,
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 if (self.options.log_to_console): 980 if (self.options.log_to_console):
971 logger.addHandler(logging.StreamHandler()) 981 logger.addHandler(logging.StreamHandler())
972 if (self.options.log_file): 982 if (self.options.log_file):
973 logger.addHandler(logging.FileHandler(self.options.log_file)) 983 logger.addHandler(logging.FileHandler(self.options.log_file))
974 984
975 testserver_base.TestServerRunner.run_server(self) 985 testserver_base.TestServerRunner.run_server(self)
976 986
977 987
978 if __name__ == '__main__': 988 if __name__ == '__main__':
979 sys.exit(PolicyServerRunner().main()) 989 sys.exit(PolicyServerRunner().main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698