| 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 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 device_id: The device identifier provided by the client. | 758 device_id: The device identifier provided by the client. |
| 759 | 759 |
| 760 Returns: | 760 Returns: |
| 761 The newly generated device token for the device. | 761 The newly generated device token for the device. |
| 762 """ | 762 """ |
| 763 dmtoken_chars = [] | 763 dmtoken_chars = [] |
| 764 while len(dmtoken_chars) < 32: | 764 while len(dmtoken_chars) < 32: |
| 765 dmtoken_chars.append(random.choice('0123456789abcdef')) | 765 dmtoken_chars.append(random.choice('0123456789abcdef')) |
| 766 dmtoken = ''.join(dmtoken_chars) | 766 dmtoken = ''.join(dmtoken_chars) |
| 767 allowed_policy_types = { | 767 allowed_policy_types = { |
| 768 dm.DeviceRegisterRequest.BROWSER: ['google/chrome/user'], | 768 dm.DeviceRegisterRequest.BROWSER: [ |
| 769 'google/chrome/user', |
| 770 'google/chrome/extension' |
| 771 ], |
| 769 dm.DeviceRegisterRequest.USER: [ | 772 dm.DeviceRegisterRequest.USER: [ |
| 770 'google/chromeos/user', | 773 'google/chromeos/user', |
| 771 'google/chrome/extension' | 774 'google/chrome/extension' |
| 772 ], | 775 ], |
| 773 dm.DeviceRegisterRequest.DEVICE: [ | 776 dm.DeviceRegisterRequest.DEVICE: [ |
| 774 'google/chromeos/device', | 777 'google/chromeos/device', |
| 775 'google/chromeos/publicaccount' | 778 'google/chromeos/publicaccount' |
| 776 ], | 779 ], |
| 777 dm.DeviceRegisterRequest.TT: ['google/chromeos/user', | 780 dm.DeviceRegisterRequest.TT: ['google/chromeos/user', |
| 778 'google/chrome/user'], | 781 'google/chrome/user'], |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 """Returns the server base URL. | 905 """Returns the server base URL. |
| 903 | 906 |
| 904 Respects the |server_base_url| configuration parameter, if present. Falls | 907 Respects the |server_base_url| configuration parameter, if present. Falls |
| 905 back to construct the URL from the server hostname and port otherwise. | 908 back to construct the URL from the server hostname and port otherwise. |
| 906 | 909 |
| 907 Returns: | 910 Returns: |
| 908 The URL to use for constructing URLs that get returned to clients. | 911 The URL to use for constructing URLs that get returned to clients. |
| 909 """ | 912 """ |
| 910 base_url = self.server_base_url | 913 base_url = self.server_base_url |
| 911 if base_url is None: | 914 if base_url is None: |
| 912 base_url = 'http://%s:%s' % (self.server_name, self.server_port) | 915 base_url = 'http://%s:%s' % self.server_address[:2] |
| 913 | 916 |
| 914 return base_url | 917 return base_url |
| 915 | 918 |
| 916 | 919 |
| 917 class PolicyServerRunner(testserver_base.TestServerRunner): | 920 class PolicyServerRunner(testserver_base.TestServerRunner): |
| 918 | 921 |
| 919 def __init__(self): | 922 def __init__(self): |
| 920 super(PolicyServerRunner, self).__init__() | 923 super(PolicyServerRunner, self).__init__() |
| 921 | 924 |
| 922 def create_server(self, server_data): | 925 def create_server(self, server_data): |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 if (self.options.log_to_console): | 970 if (self.options.log_to_console): |
| 968 logger.addHandler(logging.StreamHandler()) | 971 logger.addHandler(logging.StreamHandler()) |
| 969 if (self.options.log_file): | 972 if (self.options.log_file): |
| 970 logger.addHandler(logging.FileHandler(self.options.log_file)) | 973 logger.addHandler(logging.FileHandler(self.options.log_file)) |
| 971 | 974 |
| 972 testserver_base.TestServerRunner.run_server(self) | 975 testserver_base.TestServerRunner.run_server(self) |
| 973 | 976 |
| 974 | 977 |
| 975 if __name__ == '__main__': | 978 if __name__ == '__main__': |
| 976 sys.exit(PolicyServerRunner().main()) | 979 sys.exit(PolicyServerRunner().main()) |
| OLD | NEW |