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

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

Issue 1140333002: Added log messages for cases of failure of open files in policy_testserver.py. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed cloud_policy_client.cc from the CL Created 5 years, 7 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 import tlslite.utils.cryptomath 72 import tlslite.utils.cryptomath
73 import urlparse 73 import urlparse
74 74
75 # The name and availability of the json module varies in python versions. 75 # The name and availability of the json module varies in python versions.
76 try: 76 try:
77 import simplejson as json 77 import simplejson as json
78 except ImportError: 78 except ImportError:
79 try: 79 try:
80 import json 80 import json
81 except ImportError: 81 except ImportError:
82 logging.error('Could not import json')
Mattias Nissler (ping if slow) 2015/05/18 13:29:17 I think it's meanwhile fine to just import json un
82 json = None 83 json = None
83 84
84 import asn1der 85 import asn1der
85 import testserver_base 86 import testserver_base
86 87
87 import device_management_backend_pb2 as dm 88 import device_management_backend_pb2 as dm
88 import cloud_policy_pb2 as cp 89 import cloud_policy_pb2 as cp
89 90
90 # Policy for extensions is not supported on Android nor iOS. 91 # Policy for extensions is not supported on Android nor iOS.
91 try: 92 try:
92 import chrome_extension_policy_pb2 as ep 93 import chrome_extension_policy_pb2 as ep
93 except ImportError: 94 except ImportError:
95 logging.error('Could not import chrome_extension_policy_pb2')
Mattias Nissler (ping if slow) 2015/05/18 13:29:17 This will add log spew I guess. A better way of do
94 ep = None 96 ep = None
95 97
96 # Device policy is only available on Chrome OS builds. 98 # Device policy is only available on Chrome OS builds.
97 try: 99 try:
98 import chrome_device_policy_pb2 as dp 100 import chrome_device_policy_pb2 as dp
99 except ImportError: 101 except ImportError:
102 logging.error('Could not import chrome_device_policy_pb2')
100 dp = None 103 dp = None
101 104
102 # ASN.1 object identifier for PKCS#1/RSA. 105 # ASN.1 object identifier for PKCS#1/RSA.
103 PKCS1_RSA_OID = '\x2a\x86\x48\x86\xf7\x0d\x01\x01\x01' 106 PKCS1_RSA_OID = '\x2a\x86\x48\x86\xf7\x0d\x01\x01\x01'
104 107
105 # List of bad machine identifiers that trigger the |valid_serial_number_missing| 108 # List of bad machine identifiers that trigger the |valid_serial_number_missing|
106 # flag to be set set in the policy fetch response. 109 # flag to be set set in the policy fetch response.
107 BAD_MACHINE_IDS = [ '123490EN400015' ] 110 BAD_MACHINE_IDS = [ '123490EN400015' ]
108 111
109 # List of machines that trigger the server to send kiosk enrollment response 112 # List of machines that trigger the server to send kiosk enrollment response
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 self._registered_tokens = json.loads(file_contents, strict=False) 982 self._registered_tokens = json.loads(file_contents, strict=False)
980 except IOError: 983 except IOError:
981 pass 984 pass
982 985
983 def GetPolicies(self): 986 def GetPolicies(self):
984 """Returns the policies to be used, reloaded form the backend file every 987 """Returns the policies to be used, reloaded form the backend file every
985 time this is called. 988 time this is called.
986 """ 989 """
987 policy = {} 990 policy = {}
988 if json is None: 991 if json is None:
989 print 'No JSON module, cannot parse policy information' 992 logging.error('No JSON module, cannot parse policy information')
990 else : 993 else :
991 try: 994 try:
992 policy = json.loads(open(self.policy_path).read(), strict=False) 995 policy = json.loads(open(self.policy_path).read(), strict=False)
993 except IOError: 996 except IOError:
994 print 'Failed to load policy from %s' % self.policy_path 997 logging.error('Failed to load policies from %s' % self.policy_path)
995 return policy 998 return policy
996 999
997 def RegisterDevice(self, device_id, machine_id, type): 1000 def RegisterDevice(self, device_id, machine_id, type):
998 """Registers a device or user and generates a DM token for it. 1001 """Registers a device or user and generates a DM token for it.
999 1002
1000 Args: 1003 Args:
1001 device_id: The device identifier provided by the client. 1004 device_id: The device identifier provided by the client.
1002 1005
1003 Returns: 1006 Returns:
1004 The newly generated device token for the device. 1007 The newly generated device token for the device.
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 if (self.options.log_to_console): 1287 if (self.options.log_to_console):
1285 logger.addHandler(logging.StreamHandler()) 1288 logger.addHandler(logging.StreamHandler())
1286 if (self.options.log_file): 1289 if (self.options.log_file):
1287 logger.addHandler(logging.FileHandler(self.options.log_file)) 1290 logger.addHandler(logging.FileHandler(self.options.log_file))
1288 1291
1289 testserver_base.TestServerRunner.run_server(self) 1292 testserver_base.TestServerRunner.run_server(self)
1290 1293
1291 1294
1292 if __name__ == '__main__': 1295 if __name__ == '__main__':
1293 sys.exit(PolicyServerRunner().main()) 1296 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