From 107bf485f410c420068752859480939709053cb5 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Aug 17 2017 08:35:16 +0000 Subject: Simplify the gitolite rules for forks and add tests for them Signed-off-by: Pierre-Yves Chibon --- diff --git a/dist_git_auth.py b/dist_git_auth.py index 890133e..9974c09 100644 --- a/dist_git_auth.py +++ b/dist_git_auth.py @@ -116,7 +116,7 @@ class DistGitoliteAuth(Gitolite3Auth): if project.is_fork: access = 'RW+C' - if repos == '': + if repos == '' and not project.is_fork: # First, whitelist the supported branches from PDC for branch in get_supported_branches(project.namespace, project.name): config.append(' %s %s = %s' % (access, branch, project.user.user)) diff --git a/dist_git_auth_tests.py b/dist_git_auth_tests.py index 77d6538..2f07ec8 100644 --- a/dist_git_auth_tests.py +++ b/dist_git_auth_tests.py @@ -6,7 +6,8 @@ import os import mock # These are the tests from the pagure/ git repo. -# Run with PYTHONPATH=.:/path/to/pagure/checkout nosetests dist_git_auth_tests.py +# Run with: +# PYTHONPATH=.:/path/to/pagure/checkout nosetests dist_git_auth_tests.py import pagure import tests @@ -211,7 +212,7 @@ repo requests/test def test_get_supported_branches(self): """ Test for real what is returned by PDC. """ - expected = ['master', 'f26', 'f25', 'f24', 'el6'] + expected = ['master', 'f26', 'f25', 'el6'] actual = dist_git_auth.get_supported_branches('rpms', 'nethack') self.assertEquals(set(actual), set(expected)) @@ -313,3 +314,88 @@ repo requests/test # end of body''' self.assertMultiLineEqual(expected, contents.strip()) + + @mock.patch('dist_git_auth.get_supported_branches') + def test_write_gitolite_acls_fork( + self, get_supported_branches): + """ Test updating the gitolite configuration file when forking a + project. + + """ + + get_supported_branches.return_value = ['master', 'f9000'] + self.test_write_gitolite_acls() + + print("Forking the test project.") + project = pagure.lib._get_project(self.session, 'test') + pagure.lib.fork_project( + session=self.session, + user='pingou', + repo=project, + gitfolder=self.path, + docfolder=None, + ticketfolder=None, + requestfolder=None) + + print("Rewriting %r" % self.configfile) + dist_git_auth.DistGitoliteAuth.write_gitolite_acls( + self.session, + configfile=self.configfile, + project=-1 + ) + + print("Checking the contents of %r" % self.configfile) + with open(self.configfile, 'r') as f: + contents = f.read() + + expected = '''repo test + R = @all + RWC master = pingou + RWC f9000 = pingou + - f[0-9][0-9] = @all + - epel[0-9] = @all + - epel[0-9][0-9] = @all + - el[0-9] = @all + - olpc[0-9] = @all + RWC = pingou + +repo requests/test + RWC = pingou + +repo test2 + R = @all + RWC master = pingou + RWC f9000 = pingou + - f[0-9][0-9] = @all + - epel[0-9] = @all + - epel[0-9][0-9] = @all + - el[0-9] = @all + - olpc[0-9] = @all + RWC = pingou + +repo requests/test2 + RWC = pingou + +repo somenamespace/test3 + R = @all + RWC master = pingou + RWC f9000 = pingou + - f[0-9][0-9] = @all + - epel[0-9] = @all + - epel[0-9][0-9] = @all + - el[0-9] = @all + - olpc[0-9] = @all + RWC = pingou + +repo requests/somenamespace/test3 + RWC = pingou + +repo forks/pingou/test + R = @all + RW+C = pingou + +repo requests/forks/pingou/test + RW+C = pingou + +# end of body''' + self.assertMultiLineEqual(expected, contents.strip())