test_pagure_lib_gitolite_config.py 23 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. # -*- coding: utf-8 -*-
  2. """
  3. (c) 2017 - Copyright Red Hat Inc
  4. Authors:
  5. Pierre-Yves Chibon <pingou@pingoured.fr>
  6. """
  7. from __future__ import unicode_literals
  8. __requires__ = ['SQLAlchemy >= 0.8']
  9. import pkg_resources
  10. import datetime
  11. import os
  12. import shutil
  13. import sys
  14. import tempfile
  15. import time
  16. import unittest
  17. from io import open
  18. import pygit2
  19. from mock import patch, MagicMock
  20. sys.path.insert(0, os.path.join(os.path.dirname(
  21. os.path.abspath(__file__)), '..'))
  22. import pagure
  23. import pagure.lib.git
  24. import tests
  25. from pagure.lib.repo import PagureRepo
  26. CORE_CONFIG = """repo test
  27. R = @all
  28. RW+ = pingou
  29. repo docs/test
  30. R = @all
  31. RW+ = pingou
  32. repo tickets/test
  33. RW+ = pingou
  34. repo requests/test
  35. RW+ = pingou
  36. repo test2
  37. R = @all
  38. RW+ = pingou
  39. repo docs/test2
  40. R = @all
  41. RW+ = pingou
  42. repo tickets/test2
  43. RW+ = pingou
  44. repo requests/test2
  45. RW+ = pingou
  46. repo somenamespace/test3
  47. R = @all
  48. RW+ = pingou
  49. repo docs/somenamespace/test3
  50. R = @all
  51. RW+ = pingou
  52. repo tickets/somenamespace/test3
  53. RW+ = pingou
  54. repo requests/somenamespace/test3
  55. RW+ = pingou"""
  56. class PagureLibGitoliteConfigtests(tests.Modeltests):
  57. """ Tests for pagure.lib.git """
  58. maxDiff = None
  59. def setUp(self):
  60. """ Set up the environnment, ran before every tests. """
  61. super(PagureLibGitoliteConfigtests, self).setUp()
  62. tests.create_projects(self.session)
  63. self.outputconf = os.path.join(self.path, 'test_gitolite.conf')
  64. self.preconf = os.path.join(self.path, 'header_gitolite')
  65. with open(self.preconf, 'w') as stream:
  66. stream.write('# this is a header that is manually added\n')
  67. stream.write('\n')
  68. stream.write('@group1 = foo bar baz\n')
  69. stream.write('@group2 = threebean puiterwijk kevin pingou\n')
  70. self.postconf = os.path.join(self.path, 'footer_gitolite')
  71. with open(self.postconf, 'w', encoding="utf-8") as stream:
  72. stream.write('# end of generated configuration\n')
  73. stream.write('# \ó/\n')
  74. stream.write('# end of footer\n')
  75. def tearDown(self):
  76. """ Tearn down the environnment, ran before every tests. """
  77. super(PagureLibGitoliteConfigtests, self).tearDown()
  78. if os.path.exists(self.outputconf):
  79. os.unlink(self.outputconf)
  80. self.assertFalse(os.path.exists(self.outputconf))
  81. def test_write_gitolite_pre_post_projectNone(self):
  82. """ Test the write_gitolite_acls function of pagure.lib.git with
  83. a postconf set """
  84. helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
  85. helper.write_gitolite_acls(
  86. self.session,
  87. self.outputconf,
  88. project=None,
  89. preconf=self.preconf,
  90. postconf=self.postconf
  91. )
  92. self.assertTrue(os.path.exists(self.outputconf))
  93. with open(self.outputconf, 'r') as stream:
  94. data = stream.read()
  95. exp = """# this is a header that is manually added
  96. @group1 = foo bar baz
  97. @group2 = threebean puiterwijk kevin pingou
  98. # end of header
  99. %s
  100. # end of body
  101. # end of generated configuration
  102. # \ó/
  103. # end of footer
  104. """ % CORE_CONFIG
  105. #print data
  106. self.assertEqual(data, exp)
  107. def test_write_gitolite_pre_post_projectNone_to_existing_file(self):
  108. """ Test the write_gitolite_acls function of pagure.lib.git with
  109. a postconf set with existing output file """
  110. with open(self.outputconf, 'w') as stream:
  111. pass
  112. helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
  113. helper.write_gitolite_acls(
  114. self.session,
  115. self.outputconf,
  116. project=None,
  117. preconf=self.preconf,
  118. postconf=self.postconf
  119. )
  120. self.assertTrue(os.path.exists(self.outputconf))
  121. with open(self.outputconf) as stream:
  122. data = stream.read()
  123. self.assertEqual(data, '')
  124. def test_write_gitolite_pre_post_project_1(self):
  125. """ Test the write_gitolite_acls function of pagure.lib.git with
  126. a postconf set """
  127. with open(self.outputconf, 'w') as stream:
  128. pass
  129. helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
  130. helper.write_gitolite_acls(
  131. self.session,
  132. self.outputconf,
  133. project=-1,
  134. preconf=self.preconf,
  135. postconf=self.postconf
  136. )
  137. self.assertTrue(os.path.exists(self.outputconf))
  138. with open(self.outputconf) as stream:
  139. data = stream.read()
  140. exp = """# this is a header that is manually added
  141. @group1 = foo bar baz
  142. @group2 = threebean puiterwijk kevin pingou
  143. # end of header
  144. %s
  145. # end of body
  146. # end of generated configuration
  147. # \ó/
  148. # end of footer
  149. """ % CORE_CONFIG
  150. #print data
  151. self.assertEqual(data, exp)
  152. def test_write_gitolite_pre_post_project_test(self):
  153. """ Test the write_gitolite_acls function of pagure.lib.git with
  154. a postconf set """
  155. with open(self.outputconf, 'w') as stream:
  156. pass
  157. project = pagure.lib._get_project(self.session, 'test')
  158. helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
  159. helper.write_gitolite_acls(
  160. self.session,
  161. self.outputconf,
  162. project=project,
  163. preconf=self.preconf,
  164. postconf=self.postconf
  165. )
  166. self.assertTrue(os.path.exists(self.outputconf))
  167. with open(self.outputconf) as stream:
  168. data = stream.read()
  169. exp = """# this is a header that is manually added
  170. @group1 = foo bar baz
  171. @group2 = threebean puiterwijk kevin pingou
  172. # end of header
  173. repo test
  174. R = @all
  175. RW+ = pingou
  176. repo docs/test
  177. R = @all
  178. RW+ = pingou
  179. repo tickets/test
  180. RW+ = pingou
  181. repo requests/test
  182. RW+ = pingou
  183. # end of body
  184. # end of generated configuration
  185. # \ó/
  186. # end of footer
  187. """
  188. #print data
  189. self.assertEqual(data, exp)
  190. def test_write_gitolite_pre_post_project_test_full_file(self):
  191. """ Test the write_gitolite_acls function of pagure.lib.git with
  192. a postconf set """
  193. # Re-generate the gitolite config for all the projects
  194. self.test_write_gitolite_pre_post_project_1()
  195. self.assertTrue(os.path.exists(self.outputconf))
  196. project = pagure.lib._get_project(self.session, 'test')
  197. project.user_id = 2
  198. self.session.add(project)
  199. self.session.commit()
  200. project = pagure.lib._get_project(self.session, 'test')
  201. msg = pagure.lib.add_user_to_project(
  202. self.session,
  203. project=project,
  204. new_user='pingou',
  205. user='foo',
  206. access='commit'
  207. )
  208. self.assertEqual(msg, 'User added')
  209. self.session.commit()
  210. project = pagure.lib._get_project(self.session, 'test')
  211. helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
  212. helper.write_gitolite_acls(
  213. self.session,
  214. self.outputconf,
  215. project=project,
  216. preconf=self.preconf,
  217. postconf=self.postconf
  218. )
  219. self.assertTrue(os.path.exists(self.outputconf))
  220. with open(self.outputconf) as stream:
  221. data = stream.read()
  222. exp = """# this is a header that is manually added
  223. @group1 = foo bar baz
  224. @group2 = threebean puiterwijk kevin pingou
  225. # end of header
  226. repo test2
  227. R = @all
  228. RW+ = pingou
  229. repo docs/test2
  230. R = @all
  231. RW+ = pingou
  232. repo tickets/test2
  233. RW+ = pingou
  234. repo requests/test2
  235. RW+ = pingou
  236. repo somenamespace/test3
  237. R = @all
  238. RW+ = pingou
  239. repo docs/somenamespace/test3
  240. R = @all
  241. RW+ = pingou
  242. repo tickets/somenamespace/test3
  243. RW+ = pingou
  244. repo requests/somenamespace/test3
  245. RW+ = pingou
  246. repo test
  247. R = @all
  248. RW+ = foo
  249. RW+ = pingou
  250. repo docs/test
  251. R = @all
  252. RW+ = foo
  253. RW+ = pingou
  254. repo tickets/test
  255. RW+ = foo
  256. RW+ = pingou
  257. repo requests/test
  258. RW+ = foo
  259. RW+ = pingou
  260. # end of body
  261. # end of generated configuration
  262. # \ó/
  263. # end of footer
  264. """
  265. #print data
  266. self.assertEqual(data, exp)
  267. @patch.dict('pagure.config.config',
  268. {'ENABLE_DOCS': False, 'ENABLE_TICKETS': False})
  269. def test_write_gitolite_disabled_docs_tickets(self):
  270. """ Test the write_gitolite_acls function when docs and tickets
  271. are disabled """
  272. # Re-generate the gitolite config for all the projects
  273. project = pagure.lib._get_project(self.session, 'test')
  274. project.user_id = 2
  275. self.session.add(project)
  276. self.session.commit()
  277. project = pagure.lib._get_project(self.session, 'test')
  278. msg = pagure.lib.add_user_to_project(
  279. self.session,
  280. project=project,
  281. new_user='pingou',
  282. user='foo',
  283. access='commit'
  284. )
  285. self.assertEqual(msg, 'User added')
  286. self.session.commit()
  287. project = pagure.lib._get_project(self.session, 'test')
  288. helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
  289. helper.write_gitolite_acls(
  290. self.session,
  291. self.outputconf,
  292. project=project,
  293. )
  294. self.assertTrue(os.path.exists(self.outputconf))
  295. with open(self.outputconf) as stream:
  296. data = stream.read()
  297. exp = """repo test
  298. R = @all
  299. RW+ = foo
  300. RW+ = pingou
  301. repo requests/test
  302. RW+ = foo
  303. RW+ = pingou
  304. repo test2
  305. R = @all
  306. RW+ = pingou
  307. repo requests/test2
  308. RW+ = pingou
  309. repo somenamespace/test3
  310. R = @all
  311. RW+ = pingou
  312. repo requests/somenamespace/test3
  313. RW+ = pingou
  314. # end of body
  315. """
  316. self.assertEqual(data, exp)
  317. class PagureLibGitoliteGroupConfigtests(tests.Modeltests):
  318. """ Tests for generating the gitolite configuration file for a group
  319. change
  320. """
  321. maxDiff = None
  322. def setUp(self):
  323. """ Set up the environnment, ran before every tests. """
  324. super(PagureLibGitoliteGroupConfigtests, self).setUp()
  325. pagure.lib.git.SESSION = self.session
  326. tests.create_projects(self.session)
  327. pagure.lib.add_group(
  328. self.session,
  329. group_name='grp',
  330. display_name='grp group',
  331. description=None,
  332. group_type='user',
  333. user='pingou',
  334. is_admin=False,
  335. blacklist=[],
  336. )
  337. pagure.lib.add_group(
  338. self.session,
  339. group_name='grp2',
  340. display_name='grp2 group',
  341. description=None,
  342. group_type='user',
  343. user='foo',
  344. is_admin=False,
  345. blacklist=[],
  346. )
  347. self.session.commit()
  348. self.outputconf = os.path.join(self.path, 'test_gitolite.conf')
  349. self.preconf = os.path.join(self.path, 'header_gitolite')
  350. with open(self.preconf, 'w') as stream:
  351. stream.write('# this is a header that is manually added\n')
  352. stream.write('\n')
  353. stream.write('@group1 = foo bar baz\n')
  354. stream.write('@group2 = threebean puiterwijk kevin pingou\n')
  355. self.postconf = os.path.join(self.path, 'footer_gitolite')
  356. with open(self.postconf, 'w') as stream:
  357. stream.write('# end of generated configuration\n')
  358. stream.write('# \ó/\n')
  359. stream.write('# end of footer\n')
  360. def tearDown(self):
  361. """ Tearn down the environnment, ran before every tests. """
  362. super(PagureLibGitoliteGroupConfigtests, self).tearDown()
  363. if os.path.exists(self.outputconf):
  364. os.unlink(self.outputconf)
  365. self.assertFalse(os.path.exists(self.outputconf))
  366. def test_write_gitolite_project_test_group(self):
  367. """ Test the write_gitolite_acls when updating a single group. """
  368. with open(self.outputconf, 'w') as stream:
  369. pass
  370. project = pagure.lib._get_project(self.session, 'test')
  371. group = pagure.lib.search_groups(self.session, group_name='grp')
  372. helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
  373. helper.write_gitolite_acls(
  374. self.session,
  375. self.outputconf,
  376. project=project,
  377. preconf=self.preconf,
  378. postconf=self.postconf,
  379. group=group,
  380. )
  381. self.assertTrue(os.path.exists(self.outputconf))
  382. with open(self.outputconf) as stream:
  383. data = stream.read()
  384. exp = """# this is a header that is manually added
  385. @group1 = foo bar baz
  386. @group2 = threebean puiterwijk kevin pingou
  387. # end of header
  388. @grp = pingou
  389. repo test
  390. R = @all
  391. RW+ = pingou
  392. repo docs/test
  393. R = @all
  394. RW+ = pingou
  395. repo tickets/test
  396. RW+ = pingou
  397. repo requests/test
  398. RW+ = pingou
  399. # end of body
  400. # end of generated configuration
  401. # \ó/
  402. # end of footer
  403. """
  404. #print data
  405. self.assertEqual(data, exp)
  406. def test_write_gitolite_project_test_all_groups(self):
  407. """ Test the write_gitolite_acls when updating all groups. """
  408. with open(self.outputconf, 'w') as stream:
  409. pass
  410. project = pagure.lib._get_project(self.session, 'test')
  411. helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
  412. helper.write_gitolite_acls(
  413. self.session,
  414. self.outputconf,
  415. project=project,
  416. preconf=self.preconf,
  417. postconf=self.postconf,
  418. )
  419. self.assertTrue(os.path.exists(self.outputconf))
  420. with open(self.outputconf) as stream:
  421. data = stream.read()
  422. exp = """# this is a header that is manually added
  423. @group1 = foo bar baz
  424. @group2 = threebean puiterwijk kevin pingou
  425. # end of header
  426. @grp = pingou
  427. @grp2 = foo
  428. # end of groups
  429. repo test
  430. R = @all
  431. RW+ = pingou
  432. repo docs/test
  433. R = @all
  434. RW+ = pingou
  435. repo tickets/test
  436. RW+ = pingou
  437. repo requests/test
  438. RW+ = pingou
  439. # end of body
  440. # end of generated configuration
  441. # \ó/
  442. # end of footer
  443. """
  444. #print data
  445. self.assertEqual(data, exp)
  446. def test_write_gitolite_project_all_projects_groups(self):
  447. """ Test the generating the entire gitolite config. """
  448. with open(self.outputconf, 'w') as stream:
  449. pass
  450. helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
  451. helper.write_gitolite_acls(
  452. self.session,
  453. self.outputconf,
  454. project=-1,
  455. preconf=self.preconf,
  456. postconf=self.postconf,
  457. )
  458. self.assertTrue(os.path.exists(self.outputconf))
  459. with open(self.outputconf) as stream:
  460. data = stream.read()
  461. exp = """# this is a header that is manually added
  462. @group1 = foo bar baz
  463. @group2 = threebean puiterwijk kevin pingou
  464. # end of header
  465. @grp = pingou
  466. @grp2 = foo
  467. # end of groups
  468. %s
  469. # end of body
  470. # end of generated configuration
  471. # \ó/
  472. # end of footer
  473. """ % CORE_CONFIG
  474. #print data
  475. self.assertEqual(data, exp)
  476. def test_write_gitolite_project_all_projects_one_group(self):
  477. """ Test the generating the entire gitolite config. """
  478. # Generate the full gitolite config that we will update
  479. self.test_write_gitolite_project_all_projects_groups()
  480. project = pagure.lib._get_project(self.session, 'test')
  481. group = pagure.lib.search_groups(self.session, group_name='grp')
  482. # Let's add `foo` to `grp` so something changes
  483. msg = pagure.lib.add_user_to_group(
  484. self.session,
  485. username='foo',
  486. group=group,
  487. user='pingou',
  488. is_admin=False,
  489. )
  490. self.session.commit()
  491. self.assertEqual(msg, 'User `foo` added to the group `grp`.')
  492. # Let's add `foo` to `test` so the project changes as well
  493. msg = pagure.lib.add_user_to_project(
  494. self.session,
  495. project=project,
  496. new_user='foo',
  497. user='pingou',
  498. access='commit'
  499. )
  500. self.assertEqual(msg, 'User added')
  501. self.session.commit()
  502. helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
  503. helper.write_gitolite_acls(
  504. self.session,
  505. self.outputconf,
  506. project=project,
  507. group=group,
  508. preconf=self.preconf,
  509. postconf=self.postconf,
  510. )
  511. self.assertTrue(os.path.exists(self.outputconf))
  512. with open(self.outputconf) as stream:
  513. data = stream.read()
  514. exp = """# this is a header that is manually added
  515. @group1 = foo bar baz
  516. @group2 = threebean puiterwijk kevin pingou
  517. # end of header
  518. @grp = foo pingou
  519. @grp2 = foo
  520. # end of groups
  521. repo test2
  522. R = @all
  523. RW+ = pingou
  524. repo docs/test2
  525. R = @all
  526. RW+ = pingou
  527. repo tickets/test2
  528. RW+ = pingou
  529. repo requests/test2
  530. RW+ = pingou
  531. repo somenamespace/test3
  532. R = @all
  533. RW+ = pingou
  534. repo docs/somenamespace/test3
  535. R = @all
  536. RW+ = pingou
  537. repo tickets/somenamespace/test3
  538. RW+ = pingou
  539. repo requests/somenamespace/test3
  540. RW+ = pingou
  541. repo test
  542. R = @all
  543. RW+ = pingou
  544. RW+ = foo
  545. repo docs/test
  546. R = @all
  547. RW+ = pingou
  548. RW+ = foo
  549. repo tickets/test
  550. RW+ = pingou
  551. RW+ = foo
  552. repo requests/test
  553. RW+ = pingou
  554. RW+ = foo
  555. # end of body
  556. # end of generated configuration
  557. # \ó/
  558. # end of footer
  559. """
  560. #print data
  561. self.assertEqual(data, exp)
  562. def test_write_gitolite_delete_group(self):
  563. """ Test the updating the gitolite config after having
  564. deleted a group.
  565. """
  566. # Generate the full gitolite config that we will update
  567. self.test_write_gitolite_project_all_projects_groups()
  568. # Delete the group `grp`
  569. self.assertEqual(len(pagure.lib.search_groups(self.session)), 2)
  570. group = pagure.lib.search_groups(self.session, group_name='grp')
  571. self.session.delete(group)
  572. self.session.commit()
  573. self.assertEqual(len(pagure.lib.search_groups(self.session)), 1)
  574. helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
  575. helper.write_gitolite_acls(
  576. self.session,
  577. self.outputconf,
  578. project=None,
  579. preconf=self.preconf,
  580. postconf=self.postconf,
  581. )
  582. self.assertTrue(os.path.exists(self.outputconf))
  583. with open(self.outputconf) as stream:
  584. data = stream.read()
  585. exp = """# this is a header that is manually added
  586. @group1 = foo bar baz
  587. @group2 = threebean puiterwijk kevin pingou
  588. # end of header
  589. @grp2 = foo
  590. # end of groups
  591. %s
  592. # end of body
  593. # end of generated configuration
  594. # \ó/
  595. # end of footer
  596. """ % CORE_CONFIG
  597. #print data
  598. self.assertEqual(data, exp)
  599. @patch('pagure.lib.git_auth.get_git_auth_helper')
  600. def test_task_generate_gitolite_acls_one_group(self, get_helper):
  601. """ Test the generate_gitolite_acls task to ensure if group is None
  602. then None is passed to the helper. """
  603. helper = MagicMock()
  604. get_helper.return_value = helper
  605. pagure.lib.SESSIONMAKER = self.session.session_factory
  606. pagure.lib.tasks.generate_gitolite_acls(
  607. namespace=None, name='test', user=None, group=None)
  608. get_helper.assert_called_with()
  609. args = helper.generate_acls.call_args
  610. self.assertIsNone(args[1].get('group'))
  611. self.assertIsNotNone(args[1].get('project'))
  612. def test_write_gitolite_project_test_private(self):
  613. """ Test the write_gitolite_acls function of pagure.lib.git with
  614. a postconf set """
  615. # Make the test project private
  616. project = pagure.lib._get_project(self.session, 'test')
  617. project.private = True
  618. self.session.add(project)
  619. self.session.commit()
  620. # Re-generate the gitolite config just for this project
  621. helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
  622. helper.write_gitolite_acls(
  623. self.session,
  624. self.outputconf,
  625. project=None,
  626. )
  627. self.assertTrue(os.path.exists(self.outputconf))
  628. with open(self.outputconf) as stream:
  629. data = stream.read()
  630. exp = """@grp = pingou
  631. @grp2 = foo
  632. # end of groups
  633. repo test
  634. RW+ = pingou
  635. repo docs/test
  636. RW+ = pingou
  637. repo tickets/test
  638. RW+ = pingou
  639. repo requests/test
  640. RW+ = pingou
  641. repo test2
  642. R = @all
  643. RW+ = pingou
  644. repo docs/test2
  645. R = @all
  646. RW+ = pingou
  647. repo tickets/test2
  648. RW+ = pingou
  649. repo requests/test2
  650. RW+ = pingou
  651. repo somenamespace/test3
  652. R = @all
  653. RW+ = pingou
  654. repo docs/somenamespace/test3
  655. R = @all
  656. RW+ = pingou
  657. repo tickets/somenamespace/test3
  658. RW+ = pingou
  659. repo requests/somenamespace/test3
  660. RW+ = pingou
  661. # end of body
  662. """
  663. #print data
  664. self.assertEqual(data, exp)
  665. def test_remove_acls(self):
  666. """ Test the remove_acls function of pagure.lib.git when deleting
  667. a project """
  668. pagure.config.config['GITOLITE_CONFIG'] = self.outputconf
  669. with open(self.outputconf, 'w') as stream:
  670. pass
  671. helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
  672. helper.write_gitolite_acls(
  673. self.session,
  674. self.outputconf,
  675. project=-1,
  676. )
  677. self.assertTrue(os.path.exists(self.outputconf))
  678. with open(self.outputconf) as stream:
  679. data = stream.read()
  680. exp = """@grp = pingou
  681. @grp2 = foo
  682. # end of groups
  683. %s
  684. # end of body
  685. """ % CORE_CONFIG
  686. #print data
  687. self.assertEqual(data, exp)
  688. # Test removing a project from the existing config
  689. project = pagure.lib.get_authorized_project(
  690. self.session, project_name='test')
  691. helper.remove_acls(self.session, project=project)
  692. with open(self.outputconf) as stream:
  693. data = stream.read()
  694. exp = """@grp = pingou
  695. @grp2 = foo
  696. # end of groups
  697. repo test2
  698. R = @all
  699. RW+ = pingou
  700. repo docs/test2
  701. R = @all
  702. RW+ = pingou
  703. repo tickets/test2
  704. RW+ = pingou
  705. repo requests/test2
  706. RW+ = pingou
  707. repo somenamespace/test3
  708. R = @all
  709. RW+ = pingou
  710. repo docs/somenamespace/test3
  711. R = @all
  712. RW+ = pingou
  713. repo tickets/somenamespace/test3
  714. RW+ = pingou
  715. repo requests/somenamespace/test3
  716. RW+ = pingou
  717. # end of body
  718. """
  719. #print data
  720. self.assertEqual(data, exp)
  721. def test_remove_acls_no_project(self):
  722. """ Test the remove_acls function of pagure.lib.git when no project
  723. is specified """
  724. pagure.config.config['GITOLITE_CONFIG'] = self.outputconf
  725. with open(self.outputconf, 'w') as stream:
  726. pass
  727. helper = pagure.lib.git_auth.get_git_auth_helper('gitolite3')
  728. helper.write_gitolite_acls(
  729. self.session,
  730. self.outputconf,
  731. project=-1,
  732. )
  733. self.assertTrue(os.path.exists(self.outputconf))
  734. with open(self.outputconf) as stream:
  735. data = stream.read()
  736. exp = """@grp = pingou
  737. @grp2 = foo
  738. # end of groups
  739. %s
  740. # end of body
  741. """ % CORE_CONFIG
  742. #print data
  743. self.assertEqual(data, exp)
  744. # Test nothing changes if no project is specified
  745. self.assertRaises(
  746. RuntimeError,
  747. helper.remove_acls,
  748. self.session,
  749. project=None
  750. )
  751. with open(self.outputconf) as stream:
  752. data = stream.read()
  753. self.assertEqual(data, exp)
  754. if __name__ == '__main__':
  755. unittest.main(verbosity=2)