test_win_dacl.py 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. # -*- coding: utf-8 -*-
  2. # Import Python Libs
  3. from __future__ import absolute_import, unicode_literals, print_function
  4. import os
  5. import tempfile
  6. # Import Salt Testing Libs
  7. from tests.support.helpers import destructiveTest, generate_random_name, patch
  8. from tests.support.mixins import LoaderModuleMockMixin
  9. from tests.support.mock import NO_MOCK, NO_MOCK_REASON
  10. from tests.support.unit import TestCase, skipIf
  11. # Import Salt Libs
  12. import salt.utils.platform
  13. import salt.utils.win_dacl as win_dacl
  14. import salt.utils.win_reg as win_reg
  15. try:
  16. import pywintypes
  17. import win32security
  18. HAS_WIN32 = True
  19. except ImportError:
  20. HAS_WIN32 = False
  21. FAKE_KEY = 'SOFTWARE\\{0}'.format(generate_random_name('SaltTesting-'))
  22. @skipIf(NO_MOCK, NO_MOCK_REASON)
  23. @skipIf(not HAS_WIN32, 'Requires pywin32')
  24. @skipIf(not salt.utils.platform.is_windows(), 'System is not Windows')
  25. class WinDaclTestCase(TestCase):
  26. '''
  27. Test cases for salt.utils.win_dacl in the registry
  28. '''
  29. def test_get_sid_string(self):
  30. '''
  31. Validate getting a pysid object from a name
  32. '''
  33. sid_obj = win_dacl.get_sid('Administrators')
  34. self.assertTrue(
  35. isinstance(sid_obj, pywintypes.SIDType))
  36. self.assertEqual(
  37. win32security.LookupAccountSid(None, sid_obj)[0],
  38. 'Administrators')
  39. def test_get_sid_sid_string(self):
  40. '''
  41. Validate getting a pysid object from a SID string
  42. '''
  43. sid_obj = win_dacl.get_sid('S-1-5-32-544')
  44. self.assertTrue(isinstance(sid_obj, pywintypes.SIDType))
  45. self.assertEqual(win32security.LookupAccountSid(None, sid_obj)[0],
  46. 'Administrators')
  47. def test_get_sid_string_name(self):
  48. '''
  49. Validate getting a pysid object from a SID string
  50. '''
  51. sid_obj = win_dacl.get_sid('Administrators')
  52. self.assertTrue(isinstance(sid_obj, pywintypes.SIDType))
  53. self.assertEqual(win_dacl.get_sid_string(sid_obj), 'S-1-5-32-544')
  54. def test_get_sid_string_none(self):
  55. '''
  56. Validate getting a pysid object from None (NULL SID)
  57. '''
  58. sid_obj = win_dacl.get_sid(None)
  59. self.assertTrue(isinstance(sid_obj, pywintypes.SIDType))
  60. self.assertEqual(win_dacl.get_sid_string(sid_obj), 'S-1-0-0')
  61. def test_get_name(self):
  62. '''
  63. Get the name
  64. '''
  65. # Case
  66. self.assertEqual(win_dacl.get_name('adMiniStrAtorS'), 'Administrators')
  67. # SID String
  68. self.assertEqual(win_dacl.get_name('S-1-5-32-544'), 'Administrators')
  69. # SID Object
  70. sid_obj = win_dacl.get_sid('Administrators')
  71. self.assertTrue(isinstance(sid_obj, pywintypes.SIDType))
  72. self.assertEqual(win_dacl.get_name(sid_obj), 'Administrators')
  73. @skipIf(NO_MOCK, NO_MOCK_REASON)
  74. @skipIf(not HAS_WIN32, 'Requires pywin32')
  75. @skipIf(not salt.utils.platform.is_windows(), 'System is not Windows')
  76. class WinDaclRegTestCase(TestCase, LoaderModuleMockMixin):
  77. obj_name = 'HKLM\\' + FAKE_KEY
  78. obj_type = 'registry'
  79. '''
  80. Test cases for salt.utils.win_dacl in the registry
  81. '''
  82. def setup_loader_modules(self):
  83. return {win_dacl: {}}
  84. def setUp(self):
  85. self.assertTrue(win_reg.set_value(hive='HKLM',
  86. key=FAKE_KEY,
  87. vname='fake_name',
  88. vdata='fake_data'))
  89. def tearDown(self):
  90. win_reg.delete_key_recursive(hive='HKLM', key=FAKE_KEY)
  91. @destructiveTest
  92. def test_owner(self):
  93. '''
  94. Test the set_owner function
  95. Test the get_owner function
  96. '''
  97. self.assertTrue(win_dacl.set_owner(obj_name=self.obj_name,
  98. principal='Backup Operators',
  99. obj_type=self.obj_type))
  100. self.assertEqual(win_dacl.get_owner(obj_name=self.obj_name,
  101. obj_type=self.obj_type),
  102. 'Backup Operators')
  103. @destructiveTest
  104. def test_primary_group(self):
  105. '''
  106. Test the set_primary_group function
  107. Test the get_primary_group function
  108. '''
  109. self.assertTrue(win_dacl.set_primary_group(obj_name=self.obj_name,
  110. principal='Backup Operators',
  111. obj_type=self.obj_type))
  112. self.assertEqual(win_dacl.get_primary_group(obj_name=self.obj_name,
  113. obj_type=self.obj_type),
  114. 'Backup Operators')
  115. @destructiveTest
  116. def test_set_permissions(self):
  117. '''
  118. Test the set_permissions function
  119. '''
  120. self.assertTrue(win_dacl.set_permissions(obj_name=self.obj_name,
  121. principal='Backup Operators',
  122. permissions='full_control',
  123. access_mode='grant',
  124. obj_type=self.obj_type,
  125. reset_perms=False,
  126. protected=None))
  127. expected = {
  128. 'Not Inherited': {
  129. 'Backup Operators': {
  130. 'grant': {
  131. 'applies to': 'This key and subkeys',
  132. 'permissions': 'Full Control'}}}}
  133. self.assertEqual(win_dacl.get_permissions(obj_name=self.obj_name,
  134. principal='Backup Operators',
  135. obj_type=self.obj_type),
  136. expected)
  137. @destructiveTest
  138. def test_get_permissions(self):
  139. '''
  140. Test the get_permissions function
  141. '''
  142. self.assertTrue(win_dacl.set_permissions(obj_name=self.obj_name,
  143. principal='Backup Operators',
  144. permissions='full_control',
  145. access_mode='grant',
  146. obj_type=self.obj_type,
  147. reset_perms=False,
  148. protected=None))
  149. expected = {
  150. 'Not Inherited': {
  151. 'Backup Operators': {
  152. 'grant': {
  153. 'applies to': 'This key and subkeys',
  154. 'permissions': 'Full Control'}}}}
  155. self.assertEqual(win_dacl.get_permissions(obj_name=self.obj_name,
  156. principal='Backup Operators',
  157. obj_type=self.obj_type),
  158. expected)
  159. @destructiveTest
  160. def test_has_permission(self):
  161. '''
  162. Test the has_permission function
  163. '''
  164. self.assertTrue(win_dacl.set_permissions(obj_name=self.obj_name,
  165. principal='Backup Operators',
  166. permissions='full_control',
  167. access_mode='grant',
  168. obj_type=self.obj_type,
  169. reset_perms=False,
  170. protected=None))
  171. # Test has_permission exact
  172. self.assertTrue(win_dacl.has_permission(obj_name=self.obj_name,
  173. principal='Backup Operators',
  174. permission='full_control',
  175. access_mode='grant',
  176. obj_type=self.obj_type,
  177. exact=True))
  178. # Test has_permission contains
  179. self.assertTrue(win_dacl.has_permission(obj_name=self.obj_name,
  180. principal='Backup Operators',
  181. permission='read',
  182. access_mode='grant',
  183. obj_type=self.obj_type,
  184. exact=False))
  185. @destructiveTest
  186. def test_rm_permissions(self):
  187. '''
  188. Test the rm_permissions function
  189. '''
  190. self.assertTrue(win_dacl.set_permissions(obj_name=self.obj_name,
  191. principal='Backup Operators',
  192. permissions='full_control',
  193. access_mode='grant',
  194. obj_type=self.obj_type,
  195. reset_perms=False,
  196. protected=None))
  197. self.assertTrue(win_dacl.rm_permissions(obj_name=self.obj_name,
  198. principal='Backup Operators',
  199. obj_type=self.obj_type))
  200. self.assertEqual(win_dacl.get_permissions(obj_name=self.obj_name,
  201. principal='Backup Operators',
  202. obj_type=self.obj_type),
  203. {})
  204. @destructiveTest
  205. def test_inheritance(self):
  206. '''
  207. Test the set_inheritance function
  208. Test the get_inheritance function
  209. '''
  210. self.assertTrue(win_dacl.set_inheritance(obj_name=self.obj_name,
  211. enabled=True,
  212. obj_type=self.obj_type,
  213. clear=False))
  214. self.assertTrue(win_dacl.get_inheritance(obj_name=self.obj_name,
  215. obj_type=self.obj_type))
  216. self.assertTrue(win_dacl.set_inheritance(obj_name=self.obj_name,
  217. enabled=False,
  218. obj_type=self.obj_type,
  219. clear=False))
  220. self.assertFalse(win_dacl.get_inheritance(obj_name=self.obj_name,
  221. obj_type=self.obj_type))
  222. @destructiveTest
  223. def test_check_perms(self):
  224. '''
  225. Test the check_perms function
  226. '''
  227. with patch.dict(win_dacl.__opts__, {"test": False}):
  228. result = win_dacl.check_perms(
  229. obj_name=self.obj_name,
  230. obj_type=self.obj_type,
  231. ret={},
  232. owner='Users',
  233. grant_perms={'Backup Operators': {'perms': 'read'}},
  234. deny_perms={'Backup Operators': {'perms': ['delete']},
  235. 'NETWORK SERVICE': {'perms': ['delete',
  236. 'set_value',
  237. 'write_dac',
  238. 'write_owner']}},
  239. inheritance=True,
  240. reset=False)
  241. expected = {'changes': {'owner': 'Users',
  242. 'perms': {'Backup Operators': {'grant': 'read',
  243. 'deny': ['delete']},
  244. 'NETWORK SERVICE': {'deny': ['delete',
  245. 'set_value',
  246. 'write_dac',
  247. 'write_owner']}}},
  248. 'comment': '',
  249. 'name': self.obj_name,
  250. 'result': True}
  251. self.assertDictEqual(result, expected)
  252. expected = {
  253. 'Not Inherited': {
  254. 'Backup Operators': {
  255. 'grant': {
  256. 'applies to': 'This key and subkeys',
  257. 'permissions': 'Read'},
  258. 'deny': {
  259. 'applies to': 'This key and subkeys',
  260. 'permissions': ['Delete']}}}}
  261. self.assertDictEqual(
  262. win_dacl.get_permissions(
  263. obj_name=self.obj_name,
  264. principal='Backup Operators',
  265. obj_type=self.obj_type),
  266. expected)
  267. expected = {
  268. 'Not Inherited': {
  269. 'NETWORK SERVICE': {
  270. 'deny': {
  271. 'applies to': 'This key and subkeys',
  272. 'permissions': ['Set Value',
  273. 'Delete',
  274. 'Write Owner',
  275. 'Write DAC']}}}}
  276. self.assertDictEqual(
  277. win_dacl.get_permissions(
  278. obj_name=self.obj_name,
  279. principal='NETWORK SERVICE',
  280. obj_type=self.obj_type),
  281. expected)
  282. self.assertEqual(
  283. win_dacl.get_owner(
  284. obj_name=self.obj_name,
  285. obj_type=self.obj_type),
  286. 'Users')
  287. @destructiveTest
  288. def test_check_perms_test_true(self):
  289. '''
  290. Test the check_perms function
  291. '''
  292. with patch.dict(win_dacl.__opts__, {"test": True}):
  293. result = win_dacl.check_perms(
  294. obj_name=self.obj_name,
  295. obj_type=self.obj_type,
  296. ret=None,
  297. owner='Users',
  298. grant_perms={'Backup Operators': {'perms': 'read'}},
  299. deny_perms={'NETWORK SERVICE': {'perms': ['delete',
  300. 'set_value',
  301. 'write_dac',
  302. 'write_owner']},
  303. 'Backup Operators': {'perms': ['delete']}},
  304. inheritance=True,
  305. reset=False)
  306. expected = {
  307. 'changes': {'owner': 'Users',
  308. 'perms': {'Backup Operators': {'grant': 'read',
  309. 'deny': ['delete']},
  310. 'NETWORK SERVICE': {'deny': ['delete',
  311. 'set_value',
  312. 'write_dac',
  313. 'write_owner']}}},
  314. 'comment': '',
  315. 'name': self.obj_name,
  316. 'result': None}
  317. self.assertDictEqual(result, expected)
  318. self.assertNotEqual(
  319. win_dacl.get_owner(
  320. obj_name=self.obj_name,
  321. obj_type=self.obj_type),
  322. 'Users')
  323. self.assertEqual(
  324. win_dacl.get_permissions(
  325. obj_name=self.obj_name,
  326. principal='Backup Operators',
  327. obj_type=self.obj_type),
  328. {})
  329. def test_set_perms(self):
  330. '''
  331. Test the set_perms function
  332. '''
  333. result = win_dacl.set_perms(
  334. obj_name=self.obj_name,
  335. obj_type=self.obj_type,
  336. grant_perms={'Backup Operators': {'perms': 'read'}},
  337. deny_perms={'NETWORK SERVICE': {'perms': ['delete',
  338. 'set_value',
  339. 'write_dac',
  340. 'write_owner']}},
  341. inheritance=True,
  342. reset=False)
  343. expected = {
  344. 'deny': {'NETWORK SERVICE': {'perms': ['delete',
  345. 'set_value',
  346. 'write_dac',
  347. 'write_owner']}},
  348. 'grant': {'Backup Operators': {'perms': 'read'}}}
  349. self.assertDictEqual(result, expected)
  350. @skipIf(NO_MOCK, NO_MOCK_REASON)
  351. @skipIf(not HAS_WIN32, 'Requires pywin32')
  352. @skipIf(not salt.utils.platform.is_windows(), 'System is not Windows')
  353. class WinDaclFileTestCase(TestCase, LoaderModuleMockMixin):
  354. obj_name = ''
  355. obj_type = 'file'
  356. '''
  357. Test cases for salt.utils.win_dacl in the file system
  358. '''
  359. def setup_loader_modules(self):
  360. return {win_dacl: {}}
  361. def setUp(self):
  362. config_file_fd, self.obj_name = tempfile.mkstemp(prefix='SaltTesting-',
  363. suffix='txt')
  364. os.close(config_file_fd)
  365. def tearDown(self):
  366. os.remove(self.obj_name)
  367. @destructiveTest
  368. def test_owner(self):
  369. '''
  370. Test the set_owner function
  371. Test the get_owner function
  372. '''
  373. self.assertTrue(win_dacl.set_owner(obj_name=self.obj_name,
  374. principal='Backup Operators',
  375. obj_type=self.obj_type))
  376. self.assertEqual(win_dacl.get_owner(obj_name=self.obj_name,
  377. obj_type=self.obj_type),
  378. 'Backup Operators')
  379. @destructiveTest
  380. def test_primary_group(self):
  381. '''
  382. Test the set_primary_group function
  383. Test the get_primary_group function
  384. '''
  385. self.assertTrue(win_dacl.set_primary_group(obj_name=self.obj_name,
  386. principal='Backup Operators',
  387. obj_type=self.obj_type))
  388. self.assertEqual(win_dacl.get_primary_group(obj_name=self.obj_name,
  389. obj_type=self.obj_type),
  390. 'Backup Operators')
  391. @destructiveTest
  392. def test_set_permissions(self):
  393. '''
  394. Test the set_permissions function
  395. '''
  396. self.assertTrue(win_dacl.set_permissions(obj_name=self.obj_name,
  397. principal='Backup Operators',
  398. permissions='full_control',
  399. access_mode='grant',
  400. obj_type=self.obj_type,
  401. reset_perms=False,
  402. protected=None))
  403. expected = {
  404. 'Not Inherited': {
  405. 'Backup Operators': {
  406. 'grant': {
  407. 'applies to': 'Not Inherited (file)',
  408. 'permissions': 'Full control'}}}}
  409. self.assertEqual(win_dacl.get_permissions(obj_name=self.obj_name,
  410. principal='Backup Operators',
  411. obj_type=self.obj_type),
  412. expected)
  413. @destructiveTest
  414. def test_get_permissions(self):
  415. '''
  416. Test the get_permissions function
  417. '''
  418. self.assertTrue(win_dacl.set_permissions(obj_name=self.obj_name,
  419. principal='Backup Operators',
  420. permissions='full_control',
  421. access_mode='grant',
  422. obj_type=self.obj_type,
  423. reset_perms=False,
  424. protected=None))
  425. expected = {
  426. 'Not Inherited': {
  427. 'Backup Operators': {
  428. 'grant': {
  429. 'applies to': 'Not Inherited (file)',
  430. 'permissions': 'Full control'}}}}
  431. self.assertEqual(win_dacl.get_permissions(obj_name=self.obj_name,
  432. principal='Backup Operators',
  433. obj_type=self.obj_type),
  434. expected)
  435. @destructiveTest
  436. def test_has_permission(self):
  437. '''
  438. Test the has_permission function
  439. '''
  440. self.assertTrue(win_dacl.set_permissions(obj_name=self.obj_name,
  441. principal='Backup Operators',
  442. permissions='full_control',
  443. access_mode='grant',
  444. obj_type=self.obj_type,
  445. reset_perms=False,
  446. protected=None))
  447. # Test has_permission exact
  448. self.assertTrue(win_dacl.has_permission(obj_name=self.obj_name,
  449. principal='Backup Operators',
  450. permission='full_control',
  451. access_mode='grant',
  452. obj_type=self.obj_type,
  453. exact=True))
  454. # Test has_permission contains
  455. self.assertTrue(win_dacl.has_permission(obj_name=self.obj_name,
  456. principal='Backup Operators',
  457. permission='read',
  458. access_mode='grant',
  459. obj_type=self.obj_type,
  460. exact=False))
  461. @destructiveTest
  462. def test_rm_permissions(self):
  463. '''
  464. Test the rm_permissions function
  465. '''
  466. self.assertTrue(win_dacl.set_permissions(obj_name=self.obj_name,
  467. principal='Backup Operators',
  468. permissions='full_control',
  469. access_mode='grant',
  470. obj_type=self.obj_type,
  471. reset_perms=False,
  472. protected=None))
  473. self.assertTrue(win_dacl.rm_permissions(obj_name=self.obj_name,
  474. principal='Backup Operators',
  475. obj_type=self.obj_type))
  476. self.assertEqual(win_dacl.get_permissions(obj_name=self.obj_name,
  477. principal='Backup Operators',
  478. obj_type=self.obj_type),
  479. {})
  480. @destructiveTest
  481. def test_inheritance(self):
  482. '''
  483. Test the set_inheritance function
  484. Test the get_inheritance function
  485. '''
  486. self.assertTrue(win_dacl.set_inheritance(obj_name=self.obj_name,
  487. enabled=True,
  488. obj_type=self.obj_type,
  489. clear=False))
  490. self.assertTrue(win_dacl.get_inheritance(obj_name=self.obj_name,
  491. obj_type=self.obj_type))
  492. self.assertTrue(win_dacl.set_inheritance(obj_name=self.obj_name,
  493. enabled=False,
  494. obj_type=self.obj_type,
  495. clear=False))
  496. self.assertFalse(win_dacl.get_inheritance(obj_name=self.obj_name,
  497. obj_type=self.obj_type))
  498. @destructiveTest
  499. def test_check_perms(self):
  500. '''
  501. Test the check_perms function
  502. '''
  503. with patch.dict(win_dacl.__opts__, {"test": False}):
  504. result = win_dacl.check_perms(
  505. obj_name=self.obj_name,
  506. obj_type=self.obj_type,
  507. ret={},
  508. owner='Users',
  509. grant_perms={'Backup Operators': {'perms': 'read'}},
  510. deny_perms={'Backup Operators': {'perms': ['delete']},
  511. 'NETWORK SERVICE': {'perms': ['delete',
  512. 'change_permissions',
  513. 'write_attributes',
  514. 'write_data']}},
  515. inheritance=True,
  516. reset=False)
  517. expected = {
  518. 'changes': {'owner': 'Users',
  519. 'perms': {'Backup Operators': {'grant': 'read',
  520. 'deny': ['delete']},
  521. 'NETWORK SERVICE': {'deny': ['delete',
  522. 'change_permissions',
  523. 'write_attributes',
  524. 'write_data']}}},
  525. 'comment': '',
  526. 'name': self.obj_name,
  527. 'result': True}
  528. self.assertDictEqual(result, expected)
  529. expected = {
  530. 'Not Inherited': {
  531. 'Backup Operators': {
  532. 'grant': {
  533. 'applies to': 'Not Inherited (file)',
  534. 'permissions': 'Read'},
  535. 'deny': {
  536. 'applies to': 'Not Inherited (file)',
  537. 'permissions': ['Delete']}}}}
  538. self.assertDictEqual(
  539. win_dacl.get_permissions(
  540. obj_name=self.obj_name,
  541. principal='Backup Operators',
  542. obj_type=self.obj_type),
  543. expected)
  544. expected = {
  545. 'Not Inherited': {
  546. 'NETWORK SERVICE': {
  547. 'deny': {
  548. 'applies to': 'Not Inherited (file)',
  549. 'permissions': ['Delete',
  550. 'Create files / write data',
  551. 'Write attributes',
  552. 'Change permissions']}}}}
  553. self.assertDictEqual(
  554. win_dacl.get_permissions(
  555. obj_name=self.obj_name,
  556. principal='NETWORK SERVICE',
  557. obj_type=self.obj_type),
  558. expected)
  559. self.assertEqual(
  560. win_dacl.get_owner(
  561. obj_name=self.obj_name,
  562. obj_type=self.obj_type),
  563. 'Users')
  564. @destructiveTest
  565. def test_check_perms_test_true(self):
  566. '''
  567. Test the check_perms function
  568. '''
  569. with patch.dict(win_dacl.__opts__, {"test": True}):
  570. result = win_dacl.check_perms(
  571. obj_name=self.obj_name,
  572. obj_type=self.obj_type,
  573. ret=None,
  574. owner='Users',
  575. grant_perms={'Backup Operators': {'perms': 'read'}},
  576. deny_perms={'NETWORK SERVICE': {'perms': ['delete',
  577. 'set_value',
  578. 'write_dac',
  579. 'write_owner']},
  580. 'Backup Operators': {'perms': ['delete']}},
  581. inheritance=True,
  582. reset=False)
  583. expected = {
  584. 'changes': {'owner': 'Users',
  585. 'perms': {'Backup Operators': {'grant': 'read',
  586. 'deny': ['delete']},
  587. 'NETWORK SERVICE': {'deny': ['delete',
  588. 'set_value',
  589. 'write_dac',
  590. 'write_owner']}}},
  591. 'comment': '',
  592. 'name': self.obj_name,
  593. 'result': None}
  594. self.assertDictEqual(result, expected)
  595. self.assertNotEqual(
  596. win_dacl.get_owner(
  597. obj_name=self.obj_name,
  598. obj_type=self.obj_type),
  599. 'Users')
  600. self.assertEqual(
  601. win_dacl.get_permissions(
  602. obj_name=self.obj_name,
  603. principal='Backup Operators',
  604. obj_type=self.obj_type),
  605. {})
  606. def test_set_perms(self):
  607. '''
  608. Test the set_perms function
  609. '''
  610. result = win_dacl.set_perms(
  611. obj_name=self.obj_name,
  612. obj_type=self.obj_type,
  613. grant_perms={'Backup Operators': {'perms': 'read'}},
  614. deny_perms={'NETWORK SERVICE': {'perms': ['delete',
  615. 'change_permissions',
  616. 'write_attributes',
  617. 'write_data']}},
  618. inheritance=True,
  619. reset=False)
  620. expected = {
  621. 'deny': {'NETWORK SERVICE': {'perms': ['delete',
  622. 'change_permissions',
  623. 'write_attributes',
  624. 'write_data']}},
  625. 'grant': {'Backup Operators': {'perms': 'read'}}}
  626. self.assertDictEqual(result, expected)