| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 | |
| 7 """Unittests for grit.format.policy_templates.writers.admx_writer.""" | |
| 8 | |
| 9 | |
| 10 import os | |
| 11 import sys | |
| 12 import unittest | |
| 13 if __name__ == '__main__': | |
| 14 sys.path.append(os.path.join(os.path.dirname(__file__), '../../../..')) | |
| 15 | |
| 16 | |
| 17 from grit.format.policy_templates.writers import admx_writer | |
| 18 from grit.format.policy_templates.writers import xml_writer_base_unittest | |
| 19 from xml.dom import minidom | |
| 20 | |
| 21 | |
| 22 class AdmxWriterUnittest(xml_writer_base_unittest.XmlWriterBaseTest): | |
| 23 | |
| 24 def _CreateDocumentElement(self): | |
| 25 dom_impl = minidom.getDOMImplementation('') | |
| 26 doc = dom_impl.createDocument(None, 'root', None) | |
| 27 return doc.documentElement | |
| 28 | |
| 29 def setUp(self): | |
| 30 # Writer configuration. This dictionary contains parameter used by the ADMX | |
| 31 # Writer | |
| 32 config = { | |
| 33 'win_group_policy_class': 'TestClass', | |
| 34 'win_supported_os': 'SUPPORTED_TESTOS', | |
| 35 'win_reg_mandatory_key_name': 'Software\\Policies\\Test', | |
| 36 'win_reg_recommended_key_name': 'Software\\Policies\\Test\\Recommended', | |
| 37 'win_mandatory_category_path': ['test_category'], | |
| 38 'win_recommended_category_path': ['test_recommended_category'], | |
| 39 'admx_namespace': 'ADMXWriter.Test.Namespace', | |
| 40 'admx_prefix': 'test_prefix', | |
| 41 'build': 'test_product', | |
| 42 } | |
| 43 self.writer = admx_writer.GetWriter(config) | |
| 44 self.writer.Init() | |
| 45 | |
| 46 def _GetPoliciesElement(self, doc): | |
| 47 node_list = doc.getElementsByTagName('policies') | |
| 48 self.assertTrue(node_list.length == 1) | |
| 49 return node_list.item(0) | |
| 50 | |
| 51 def _GetCategoriesElement(self, doc): | |
| 52 node_list = doc.getElementsByTagName('categories') | |
| 53 self.assertTrue(node_list.length == 1) | |
| 54 return node_list.item(0) | |
| 55 | |
| 56 def testEmpty(self): | |
| 57 self.writer.BeginTemplate() | |
| 58 self.writer.EndTemplate() | |
| 59 | |
| 60 output = self.writer.GetTemplateText() | |
| 61 expected_output = ( | |
| 62 '<?xml version="1.0" ?>\n' | |
| 63 '<policyDefinitions revision="1.0" schemaVersion="1.0">\n' | |
| 64 ' <policyNamespaces>\n' | |
| 65 ' <target namespace="ADMXWriter.Test.Namespace"' | |
| 66 ' prefix="test_prefix"/>\n' | |
| 67 ' <using namespace="Microsoft.Policies.Windows" prefix="windows"/>\n' | |
| 68 ' </policyNamespaces>\n' | |
| 69 ' <resources minRequiredRevision="1.0"/>\n' | |
| 70 ' <supportedOn>\n' | |
| 71 ' <definitions>\n' | |
| 72 ' <definition displayName="' | |
| 73 '$(string.SUPPORTED_TESTOS)" name="SUPPORTED_TESTOS"/>\n' | |
| 74 ' </definitions>\n' | |
| 75 ' </supportedOn>\n' | |
| 76 ' <categories>\n' | |
| 77 ' <category displayName="$(string.test_category)"' | |
| 78 ' name="test_category"/>\n' | |
| 79 ' <category displayName="$(string.test_recommended_category)"' | |
| 80 ' name="test_recommended_category"/>\n' | |
| 81 ' </categories>\n' | |
| 82 ' <policies/>\n' | |
| 83 '</policyDefinitions>') | |
| 84 self.AssertXMLEquals(output, expected_output) | |
| 85 | |
| 86 def testEmptyVersion(self): | |
| 87 self.writer.config['version'] = '39.0.0.0' | |
| 88 self.writer.BeginTemplate() | |
| 89 self.writer.EndTemplate() | |
| 90 | |
| 91 output = self.writer.GetTemplateText() | |
| 92 expected_output = ( | |
| 93 '<?xml version="1.0" ?>\n' | |
| 94 '<policyDefinitions revision="1.0" schemaVersion="1.0">\n' | |
| 95 ' <!--test_product version: 39.0.0.0-->\n' | |
| 96 ' <policyNamespaces>\n' | |
| 97 ' <target namespace="ADMXWriter.Test.Namespace"' | |
| 98 ' prefix="test_prefix"/>\n' | |
| 99 ' <using namespace="Microsoft.Policies.Windows" prefix="windows"/>\n' | |
| 100 ' </policyNamespaces>\n' | |
| 101 ' <resources minRequiredRevision="1.0"/>\n' | |
| 102 ' <supportedOn>\n' | |
| 103 ' <definitions>\n' | |
| 104 ' <definition displayName="' | |
| 105 '$(string.SUPPORTED_TESTOS)" name="SUPPORTED_TESTOS"/>\n' | |
| 106 ' </definitions>\n' | |
| 107 ' </supportedOn>\n' | |
| 108 ' <categories>\n' | |
| 109 ' <category displayName="$(string.test_category)"' | |
| 110 ' name="test_category"/>\n' | |
| 111 ' <category displayName="$(string.test_recommended_category)"' | |
| 112 ' name="test_recommended_category"/>\n' | |
| 113 ' </categories>\n' | |
| 114 ' <policies/>\n' | |
| 115 '</policyDefinitions>') | |
| 116 self.AssertXMLEquals(output, expected_output) | |
| 117 | |
| 118 def testEmptyPolicyGroup(self): | |
| 119 empty_policy_group = { | |
| 120 'name': 'PolicyGroup', | |
| 121 'policies': [] | |
| 122 } | |
| 123 # Initialize writer to write a policy group. | |
| 124 self.writer.BeginTemplate() | |
| 125 # Write policy group | |
| 126 self.writer.BeginPolicyGroup(empty_policy_group) | |
| 127 self.writer.EndPolicyGroup() | |
| 128 | |
| 129 output = self.GetXMLOfChildren(self._GetPoliciesElement(self.writer._doc)) | |
| 130 expected_output = '' | |
| 131 self.AssertXMLEquals(output, expected_output) | |
| 132 | |
| 133 output = self.GetXMLOfChildren( | |
| 134 self._GetCategoriesElement(self.writer._doc)) | |
| 135 expected_output = ( | |
| 136 '<category displayName="$(string.test_category)"' | |
| 137 ' name="test_category"/>\n' | |
| 138 '<category displayName="$(string.test_recommended_category)"' | |
| 139 ' name="test_recommended_category"/>\n' | |
| 140 '<category displayName="$(string.PolicyGroup_group)"' | |
| 141 ' name="PolicyGroup">\n' | |
| 142 ' <parentCategory ref="test_category"/>\n' | |
| 143 '</category>') | |
| 144 | |
| 145 self.AssertXMLEquals(output, expected_output) | |
| 146 | |
| 147 def testPolicyGroup(self): | |
| 148 empty_policy_group = { | |
| 149 'name': 'PolicyGroup', | |
| 150 'policies': [ | |
| 151 {'name': 'PolicyStub2', | |
| 152 'type': 'main'}, | |
| 153 {'name': 'PolicyStub1', | |
| 154 'type': 'main'}, | |
| 155 ] | |
| 156 } | |
| 157 # Initialize writer to write a policy group. | |
| 158 self.writer.BeginTemplate() | |
| 159 # Write policy group | |
| 160 self.writer.BeginPolicyGroup(empty_policy_group) | |
| 161 self.writer.EndPolicyGroup() | |
| 162 | |
| 163 output = self.GetXMLOfChildren(self._GetPoliciesElement(self.writer._doc)) | |
| 164 expected_output = '' | |
| 165 self.AssertXMLEquals(output, expected_output) | |
| 166 | |
| 167 output = self.GetXMLOfChildren( | |
| 168 self._GetCategoriesElement(self.writer._doc)) | |
| 169 expected_output = ( | |
| 170 '<category displayName="$(string.test_category)"' | |
| 171 ' name="test_category"/>\n' | |
| 172 '<category displayName="$(string.test_recommended_category)"' | |
| 173 ' name="test_recommended_category"/>\n' | |
| 174 '<category displayName="$(string.PolicyGroup_group)"' | |
| 175 ' name="PolicyGroup">\n' | |
| 176 ' <parentCategory ref="test_category"/>\n' | |
| 177 '</category>') | |
| 178 self.AssertXMLEquals(output, expected_output) | |
| 179 | |
| 180 | |
| 181 def _initWriterForPolicy(self, writer, policy): | |
| 182 '''Initializes the writer to write the given policy next. | |
| 183 ''' | |
| 184 policy_group = { | |
| 185 'name': 'PolicyGroup', | |
| 186 'policies': [policy] | |
| 187 } | |
| 188 writer.BeginTemplate() | |
| 189 writer.BeginPolicyGroup(policy_group) | |
| 190 | |
| 191 def testMainPolicy(self): | |
| 192 main_policy = { | |
| 193 'name': 'DummyMainPolicy', | |
| 194 'type': 'main', | |
| 195 } | |
| 196 | |
| 197 self._initWriterForPolicy(self.writer, main_policy) | |
| 198 | |
| 199 self.writer.WritePolicy(main_policy) | |
| 200 | |
| 201 output = self.GetXMLOfChildren(self._GetPoliciesElement(self.writer._doc)) | |
| 202 expected_output = ( | |
| 203 '<policy class="TestClass" displayName="$(string.DummyMainPolicy)"' | |
| 204 ' explainText="$(string.DummyMainPolicy_Explain)"' | |
| 205 ' key="Software\\Policies\\Test" name="DummyMainPolicy"' | |
| 206 ' presentation="$(presentation.DummyMainPolicy)"' | |
| 207 ' valueName="DummyMainPolicy">\n' | |
| 208 ' <parentCategory ref="PolicyGroup"/>\n' | |
| 209 ' <supportedOn ref="SUPPORTED_TESTOS"/>\n' | |
| 210 ' <enabledValue>\n' | |
| 211 ' <decimal value="1"/>\n' | |
| 212 ' </enabledValue>\n' | |
| 213 ' <disabledValue>\n' | |
| 214 ' <decimal value="0"/>\n' | |
| 215 ' </disabledValue>\n' | |
| 216 '</policy>') | |
| 217 | |
| 218 self.AssertXMLEquals(output, expected_output) | |
| 219 | |
| 220 def testRecommendedPolicy(self): | |
| 221 main_policy = { | |
| 222 'name': 'DummyMainPolicy', | |
| 223 'type': 'main', | |
| 224 } | |
| 225 | |
| 226 policy_group = { | |
| 227 'name': 'PolicyGroup', | |
| 228 'policies': [main_policy], | |
| 229 } | |
| 230 self.writer.BeginTemplate() | |
| 231 self.writer.BeginRecommendedPolicyGroup(policy_group) | |
| 232 | |
| 233 self.writer.WriteRecommendedPolicy(main_policy) | |
| 234 | |
| 235 output = self.GetXMLOfChildren(self._GetPoliciesElement(self.writer._doc)) | |
| 236 expected_output = ( | |
| 237 '<policy class="TestClass" displayName="$(string.DummyMainPolicy)"' | |
| 238 ' explainText="$(string.DummyMainPolicy_Explain)"' | |
| 239 ' key="Software\\Policies\\Test\\Recommended"' | |
| 240 ' name="DummyMainPolicy_recommended"' | |
| 241 ' presentation="$(presentation.DummyMainPolicy)"' | |
| 242 ' valueName="DummyMainPolicy">\n' | |
| 243 ' <parentCategory ref="PolicyGroup_recommended"/>\n' | |
| 244 ' <supportedOn ref="SUPPORTED_TESTOS"/>\n' | |
| 245 ' <enabledValue>\n' | |
| 246 ' <decimal value="1"/>\n' | |
| 247 ' </enabledValue>\n' | |
| 248 ' <disabledValue>\n' | |
| 249 ' <decimal value="0"/>\n' | |
| 250 ' </disabledValue>\n' | |
| 251 '</policy>') | |
| 252 | |
| 253 self.AssertXMLEquals(output, expected_output) | |
| 254 | |
| 255 def testRecommendedOnlyPolicy(self): | |
| 256 main_policy = { | |
| 257 'name': 'DummyMainPolicy', | |
| 258 'type': 'main', | |
| 259 'features': { | |
| 260 'can_be_recommended': True, | |
| 261 'can_be_mandatory': False, | |
| 262 } | |
| 263 } | |
| 264 | |
| 265 policy_group = { | |
| 266 'name': 'PolicyGroup', | |
| 267 'policies': [main_policy], | |
| 268 } | |
| 269 self.writer.BeginTemplate() | |
| 270 self.writer.BeginRecommendedPolicyGroup(policy_group) | |
| 271 | |
| 272 self.writer.WritePolicy(main_policy) | |
| 273 self.writer.WriteRecommendedPolicy(main_policy) | |
| 274 | |
| 275 output = self.GetXMLOfChildren(self._GetPoliciesElement(self.writer._doc)) | |
| 276 expected_output = ( | |
| 277 '<policy class="TestClass" displayName="$(string.DummyMainPolicy)"' | |
| 278 ' explainText="$(string.DummyMainPolicy_Explain)"' | |
| 279 ' key="Software\\Policies\\Test\\Recommended"' | |
| 280 ' name="DummyMainPolicy_recommended"' | |
| 281 ' presentation="$(presentation.DummyMainPolicy)"' | |
| 282 ' valueName="DummyMainPolicy">\n' | |
| 283 ' <parentCategory ref="PolicyGroup_recommended"/>\n' | |
| 284 ' <supportedOn ref="SUPPORTED_TESTOS"/>\n' | |
| 285 ' <enabledValue>\n' | |
| 286 ' <decimal value="1"/>\n' | |
| 287 ' </enabledValue>\n' | |
| 288 ' <disabledValue>\n' | |
| 289 ' <decimal value="0"/>\n' | |
| 290 ' </disabledValue>\n' | |
| 291 '</policy>') | |
| 292 | |
| 293 self.AssertXMLEquals(output, expected_output) | |
| 294 | |
| 295 def testStringPolicy(self): | |
| 296 string_policy = { | |
| 297 'name': 'SampleStringPolicy', | |
| 298 'type': 'string', | |
| 299 } | |
| 300 self._initWriterForPolicy(self.writer, string_policy) | |
| 301 | |
| 302 self.writer.WritePolicy(string_policy) | |
| 303 output = self.GetXMLOfChildren(self._GetPoliciesElement(self.writer._doc)) | |
| 304 expected_output = ( | |
| 305 '<policy class="TestClass" displayName="$(string.SampleStringPolicy)"' | |
| 306 ' explainText="$(string.SampleStringPolicy_Explain)"' | |
| 307 ' key="Software\\Policies\\Test" name="SampleStringPolicy"' | |
| 308 ' presentation="$(presentation.SampleStringPolicy)">\n' | |
| 309 ' <parentCategory ref="PolicyGroup"/>\n' | |
| 310 ' <supportedOn ref="SUPPORTED_TESTOS"/>\n' | |
| 311 ' <elements>\n' | |
| 312 ' <text id="SampleStringPolicy" maxLength="1000000"' | |
| 313 ' valueName="SampleStringPolicy"/>\n' | |
| 314 ' </elements>\n' | |
| 315 '</policy>') | |
| 316 self.AssertXMLEquals(output, expected_output) | |
| 317 | |
| 318 def testIntPolicy(self): | |
| 319 int_policy = { | |
| 320 'name': 'SampleIntPolicy', | |
| 321 'type': 'int', | |
| 322 } | |
| 323 self._initWriterForPolicy(self.writer, int_policy) | |
| 324 | |
| 325 self.writer.WritePolicy(int_policy) | |
| 326 output = self.GetXMLOfChildren(self._GetPoliciesElement(self.writer._doc)) | |
| 327 expected_output = ( | |
| 328 '<policy class="TestClass" displayName="$(string.SampleIntPolicy)"' | |
| 329 ' explainText="$(string.SampleIntPolicy_Explain)"' | |
| 330 ' key="Software\\Policies\\Test" name="SampleIntPolicy"' | |
| 331 ' presentation="$(presentation.SampleIntPolicy)">\n' | |
| 332 ' <parentCategory ref="PolicyGroup"/>\n' | |
| 333 ' <supportedOn ref="SUPPORTED_TESTOS"/>\n' | |
| 334 ' <elements>\n' | |
| 335 ' <decimal id="SampleIntPolicy" maxValue="2000000000" ' | |
| 336 'valueName="SampleIntPolicy"/>\n' | |
| 337 ' </elements>\n' | |
| 338 '</policy>') | |
| 339 self.AssertXMLEquals(output, expected_output) | |
| 340 | |
| 341 def testIntEnumPolicy(self): | |
| 342 enum_policy = { | |
| 343 'name': 'SampleEnumPolicy', | |
| 344 'type': 'int-enum', | |
| 345 'items': [ | |
| 346 {'name': 'item_1', 'value': 0}, | |
| 347 {'name': 'item_2', 'value': 1}, | |
| 348 ] | |
| 349 } | |
| 350 | |
| 351 self._initWriterForPolicy(self.writer, enum_policy) | |
| 352 self.writer.WritePolicy(enum_policy) | |
| 353 output = self.GetXMLOfChildren(self._GetPoliciesElement(self.writer._doc)) | |
| 354 expected_output = ( | |
| 355 '<policy class="TestClass" displayName="$(string.SampleEnumPolicy)"' | |
| 356 ' explainText="$(string.SampleEnumPolicy_Explain)"' | |
| 357 ' key="Software\\Policies\\Test" name="SampleEnumPolicy"' | |
| 358 ' presentation="$(presentation.SampleEnumPolicy)">\n' | |
| 359 ' <parentCategory ref="PolicyGroup"/>\n' | |
| 360 ' <supportedOn ref="SUPPORTED_TESTOS"/>\n' | |
| 361 ' <elements>\n' | |
| 362 ' <enum id="SampleEnumPolicy" valueName="SampleEnumPolicy">\n' | |
| 363 ' <item displayName="$(string.item_1)">\n' | |
| 364 ' <value>\n' | |
| 365 ' <decimal value="0"/>\n' | |
| 366 ' </value>\n' | |
| 367 ' </item>\n' | |
| 368 ' <item displayName="$(string.item_2)">\n' | |
| 369 ' <value>\n' | |
| 370 ' <decimal value="1"/>\n' | |
| 371 ' </value>\n' | |
| 372 ' </item>\n' | |
| 373 ' </enum>\n' | |
| 374 ' </elements>\n' | |
| 375 '</policy>') | |
| 376 self.AssertXMLEquals(output, expected_output) | |
| 377 | |
| 378 def testStringEnumPolicy(self): | |
| 379 enum_policy = { | |
| 380 'name': 'SampleEnumPolicy', | |
| 381 'type': 'string-enum', | |
| 382 'items': [ | |
| 383 {'name': 'item_1', 'value': 'one'}, | |
| 384 {'name': 'item_2', 'value': 'two'}, | |
| 385 ] | |
| 386 } | |
| 387 | |
| 388 # This test is different than the others because it also tests that space | |
| 389 # usage inside <string> nodes is correct. | |
| 390 dom_impl = minidom.getDOMImplementation('') | |
| 391 self.writer._doc = dom_impl.createDocument(None, 'policyDefinitions', None) | |
| 392 self.writer._active_policies_elem = self.writer._doc.documentElement | |
| 393 self.writer._active_mandatory_policy_group_name = 'PolicyGroup' | |
| 394 self.writer.WritePolicy(enum_policy) | |
| 395 output = self.writer.GetTemplateText() | |
| 396 expected_output = ( | |
| 397 '<?xml version="1.0" ?>\n' | |
| 398 '<policyDefinitions>\n' | |
| 399 ' <policy class="TestClass" displayName="$(string.SampleEnumPolicy)"' | |
| 400 ' explainText="$(string.SampleEnumPolicy_Explain)"' | |
| 401 ' key="Software\\Policies\\Test" name="SampleEnumPolicy"' | |
| 402 ' presentation="$(presentation.SampleEnumPolicy)">\n' | |
| 403 ' <parentCategory ref="PolicyGroup"/>\n' | |
| 404 ' <supportedOn ref="SUPPORTED_TESTOS"/>\n' | |
| 405 ' <elements>\n' | |
| 406 ' <enum id="SampleEnumPolicy" valueName="SampleEnumPolicy">\n' | |
| 407 ' <item displayName="$(string.item_1)">\n' | |
| 408 ' <value>\n' | |
| 409 ' <string>one</string>\n' | |
| 410 ' </value>\n' | |
| 411 ' </item>\n' | |
| 412 ' <item displayName="$(string.item_2)">\n' | |
| 413 ' <value>\n' | |
| 414 ' <string>two</string>\n' | |
| 415 ' </value>\n' | |
| 416 ' </item>\n' | |
| 417 ' </enum>\n' | |
| 418 ' </elements>\n' | |
| 419 ' </policy>\n' | |
| 420 '</policyDefinitions>') | |
| 421 self.AssertXMLEquals(output, expected_output) | |
| 422 | |
| 423 def testListPolicy(self): | |
| 424 list_policy = { | |
| 425 'name': 'SampleListPolicy', | |
| 426 'type': 'list', | |
| 427 } | |
| 428 self._initWriterForPolicy(self.writer, list_policy) | |
| 429 self.writer.WritePolicy(list_policy) | |
| 430 output = self.GetXMLOfChildren(self._GetPoliciesElement(self.writer._doc)) | |
| 431 expected_output = ( | |
| 432 '<policy class="TestClass" displayName="$(string.SampleListPolicy)"' | |
| 433 ' explainText="$(string.SampleListPolicy_Explain)"' | |
| 434 ' key="Software\\Policies\\Test" name="SampleListPolicy"' | |
| 435 ' presentation="$(presentation.SampleListPolicy)">\n' | |
| 436 ' <parentCategory ref="PolicyGroup"/>\n' | |
| 437 ' <supportedOn ref="SUPPORTED_TESTOS"/>\n' | |
| 438 ' <elements>\n' | |
| 439 ' <list id="SampleListPolicyDesc"' | |
| 440 ' key="Software\Policies\Test\SampleListPolicy" valuePrefix=""/>\n' | |
| 441 ' </elements>\n' | |
| 442 '</policy>') | |
| 443 | |
| 444 self.AssertXMLEquals(output, expected_output) | |
| 445 | |
| 446 def testStringEnumListPolicy(self): | |
| 447 list_policy = { | |
| 448 'name': 'SampleListPolicy', | |
| 449 'type': 'string-enum-list', | |
| 450 'items': [ | |
| 451 {'name': 'item_1', 'value': 'one'}, | |
| 452 {'name': 'item_2', 'value': 'two'}, | |
| 453 ] | |
| 454 } | |
| 455 self._initWriterForPolicy(self.writer, list_policy) | |
| 456 self.writer.WritePolicy(list_policy) | |
| 457 output = self.GetXMLOfChildren(self._GetPoliciesElement(self.writer._doc)) | |
| 458 expected_output = ( | |
| 459 '<policy class="TestClass" displayName="$(string.SampleListPolicy)"' | |
| 460 ' explainText="$(string.SampleListPolicy_Explain)"' | |
| 461 ' key="Software\\Policies\\Test" name="SampleListPolicy"' | |
| 462 ' presentation="$(presentation.SampleListPolicy)">\n' | |
| 463 ' <parentCategory ref="PolicyGroup"/>\n' | |
| 464 ' <supportedOn ref="SUPPORTED_TESTOS"/>\n' | |
| 465 ' <elements>\n' | |
| 466 ' <list id="SampleListPolicyDesc"' | |
| 467 ' key="Software\Policies\Test\SampleListPolicy" valuePrefix=""/>\n' | |
| 468 ' </elements>\n' | |
| 469 '</policy>') | |
| 470 | |
| 471 self.AssertXMLEquals(output, expected_output) | |
| 472 | |
| 473 def testDictionaryPolicy(self): | |
| 474 dict_policy = { | |
| 475 'name': 'SampleDictionaryPolicy', | |
| 476 'type': 'dict', | |
| 477 } | |
| 478 self._initWriterForPolicy(self.writer, dict_policy) | |
| 479 | |
| 480 self.writer.WritePolicy(dict_policy) | |
| 481 output = self.GetXMLOfChildren(self._GetPoliciesElement(self.writer._doc)) | |
| 482 expected_output = ( | |
| 483 '<policy class="TestClass" displayName="$(string.' | |
| 484 'SampleDictionaryPolicy)"' | |
| 485 ' explainText="$(string.SampleDictionaryPolicy_Explain)"' | |
| 486 ' key="Software\\Policies\\Test" name="SampleDictionaryPolicy"' | |
| 487 ' presentation="$(presentation.SampleDictionaryPolicy)">\n' | |
| 488 ' <parentCategory ref="PolicyGroup"/>\n' | |
| 489 ' <supportedOn ref="SUPPORTED_TESTOS"/>\n' | |
| 490 ' <elements>\n' | |
| 491 ' <text id="SampleDictionaryPolicy" maxLength="1000000"' | |
| 492 ' valueName="SampleDictionaryPolicy"/>\n' | |
| 493 ' </elements>\n' | |
| 494 '</policy>') | |
| 495 self.AssertXMLEquals(output, expected_output) | |
| 496 | |
| 497 def testPlatform(self): | |
| 498 # Test that the writer correctly chooses policies of platform Windows. | |
| 499 self.assertTrue(self.writer.IsPolicySupported({ | |
| 500 'supported_on': [ | |
| 501 {'platforms': ['win', 'zzz']}, {'platforms': ['aaa']} | |
| 502 ] | |
| 503 })) | |
| 504 self.assertFalse(self.writer.IsPolicySupported({ | |
| 505 'supported_on': [ | |
| 506 {'platforms': ['mac', 'linux']}, {'platforms': ['aaa']} | |
| 507 ] | |
| 508 })) | |
| 509 | |
| 510 def testStringEncodings(self): | |
| 511 enum_policy_a = { | |
| 512 'name': 'SampleEnumPolicy.A', | |
| 513 'type': 'string-enum', | |
| 514 'items': [ | |
| 515 {'name': 'tls1.2', 'value': 'tls1.2'} | |
| 516 ] | |
| 517 } | |
| 518 enum_policy_b = { | |
| 519 'name': 'SampleEnumPolicy.B', | |
| 520 'type': 'string-enum', | |
| 521 'items': [ | |
| 522 {'name': 'tls1.2', 'value': 'tls1.2'} | |
| 523 ] | |
| 524 } | |
| 525 | |
| 526 dom_impl = minidom.getDOMImplementation('') | |
| 527 self.writer._doc = dom_impl.createDocument(None, 'policyDefinitions', None) | |
| 528 self.writer._active_policies_elem = self.writer._doc.documentElement | |
| 529 self.writer._active_mandatory_policy_group_name = 'PolicyGroup' | |
| 530 self.writer.WritePolicy(enum_policy_a) | |
| 531 self.writer.WritePolicy(enum_policy_b) | |
| 532 output = self.writer.GetTemplateText() | |
| 533 expected_output = ( | |
| 534 '<?xml version="1.0" ?>\n' | |
| 535 '<policyDefinitions>\n' | |
| 536 ' <policy class="TestClass" displayName="$(string.SampleEnumPolicy_A)"' | |
| 537 ' explainText="$(string.SampleEnumPolicy_A_Explain)"' | |
| 538 ' key="Software\\Policies\\Test" name="SampleEnumPolicy.A"' | |
| 539 ' presentation="$(presentation.SampleEnumPolicy.A)">\n' | |
| 540 ' <parentCategory ref="PolicyGroup"/>\n' | |
| 541 ' <supportedOn ref="SUPPORTED_TESTOS"/>\n' | |
| 542 ' <elements>\n' | |
| 543 ' <enum id="SampleEnumPolicy.A" valueName="SampleEnumPolicy.A">\n' | |
| 544 ' <item displayName="$(string.tls1_2)">\n' | |
| 545 ' <value>\n' | |
| 546 ' <string>tls1.2</string>\n' | |
| 547 ' </value>\n' | |
| 548 ' </item>\n' | |
| 549 ' </enum>\n' | |
| 550 ' </elements>\n' | |
| 551 ' </policy>\n' | |
| 552 ' <policy class="TestClass" displayName="$(string.SampleEnumPolicy_B)"' | |
| 553 ' explainText="$(string.SampleEnumPolicy_B_Explain)"' | |
| 554 ' key="Software\\Policies\\Test" name="SampleEnumPolicy.B"' | |
| 555 ' presentation="$(presentation.SampleEnumPolicy.B)">\n' | |
| 556 ' <parentCategory ref="PolicyGroup"/>\n' | |
| 557 ' <supportedOn ref="SUPPORTED_TESTOS"/>\n' | |
| 558 ' <elements>\n' | |
| 559 ' <enum id="SampleEnumPolicy.B" valueName="SampleEnumPolicy.B">\n' | |
| 560 ' <item displayName="$(string.tls1_2)">\n' | |
| 561 ' <value>\n' | |
| 562 ' <string>tls1.2</string>\n' | |
| 563 ' </value>\n' | |
| 564 ' </item>\n' | |
| 565 ' </enum>\n' | |
| 566 ' </elements>\n' | |
| 567 ' </policy>\n' | |
| 568 '</policyDefinitions>') | |
| 569 self.AssertXMLEquals(output, expected_output) | |
| 570 | |
| 571 | |
| 572 if __name__ == '__main__': | |
| 573 unittest.main() | |
| OLD | NEW |