From 366521f5596d48dc4294911dfb04ca0d838b9b0e Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Aug 08 2017 16:13:12 +0000 Subject: [PATCH 1/3] Fix running the tests with the latest version of pagure Signed-off-by: Pierre-Yves Chibon --- diff --git a/dist_git_auth_tests.py b/dist_git_auth_tests.py index 25e9dfe..cf6f7af 100644 --- a/dist_git_auth_tests.py +++ b/dist_git_auth_tests.py @@ -55,6 +55,8 @@ repo somenamespace/test3 repo requests/somenamespace/test3 RWC = pingou + +# end of body """ @@ -202,8 +204,10 @@ repo test repo requests/test RWC = foo - RWC = pingou''' - self.assertMultiLineEqual(contents.strip(), expected) + RWC = pingou + +# end of body''' + self.assertMultiLineEqual(expected, contents.strip()) def test_get_supported_branches(self): """ Test for real what is returned by PDC. """ From 18466d439e28be0cb7d1f601b81227da1f0fc693 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Aug 08 2017 16:13:12 +0000 Subject: [PATCH 2/3] Drop the + access for the groups, it generates an invalid config And add the corresponding unit-tests Signed-off-by: Pierre-Yves Chibon --- diff --git a/dist_git_auth.py b/dist_git_auth.py index 428a955..1a26c84 100644 --- a/dist_git_auth.py +++ b/dist_git_auth.py @@ -115,7 +115,7 @@ class DistGitoliteAuth(Gitolite3Auth): config.append(_blacklist) if project.committer_groups: - config.append(' %s+ = @%s' % (access, ' @'.join( + config.append(' %s = @%s' % (access, ' @'.join( [ group.group_name for group in project.committer_groups diff --git a/dist_git_auth_tests.py b/dist_git_auth_tests.py index cf6f7af..77d6538 100644 --- a/dist_git_auth_tests.py +++ b/dist_git_auth_tests.py @@ -214,3 +214,102 @@ repo requests/test expected = ['master', 'f26', 'f25', 'f24', 'el6'] actual = dist_git_auth.get_supported_branches('rpms', 'nethack') self.assertEquals(set(actual), set(expected)) + + @mock.patch('dist_git_auth.get_supported_branches') + def test_write_gitolite_acls_test_project_w_group( + self, get_supported_branches): + """ Test updating the gitolite configuration file for just one + project (project == a pagure.lib.model.Project). + + """ + + get_supported_branches.return_value = ['master', 'f9000'] + self.test_write_gitolite_acls() + + print("Modifying the test project so the output differs.") + project = pagure.lib._get_project(self.session, 'test') + project.user_id = 2 + self.session.add(project) + self.session.commit() + + # Add a group to a project and someone to this group + project = pagure.lib._get_project(self.session, 'test') + msg = pagure.lib.add_group_to_project( + session=self.session, + project=project, + new_group='test_grp', + user='pingou', + access='admin', + create=True, + is_admin=True) + self.assertEqual(msg, 'Group added') + grp = pagure.lib.search_groups(self.session, group_name='test_grp') + msg = pagure.lib.add_user_to_group( + session=self.session, + username='pingou', + group=grp, + user='pingou', + is_admin=False) + self.session.commit() + + print("Rewriting %r" % self.configfile) + project = pagure.lib._get_project(self.session, 'test') + dist_git_auth.DistGitoliteAuth.write_gitolite_acls( + self.session, + configfile=self.configfile, + project=project + ) + + print("Checking the contents of %r" % self.configfile) + with open(self.configfile, 'r') as f: + contents = f.read() + + expected = '''@test_grp = pingou +# end of groups + +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 test + R = @all + RWC master = foo + RWC f9000 = foo + - 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 = @test_grp + RWC = foo + +repo requests/test + RWC = @test_grp + RWC = foo + +# end of body''' + self.assertMultiLineEqual(expected, contents.strip()) From b95a492c5d6d5bd76f03990e539c3d5055fd75d8 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Aug 08 2017 16:13:12 +0000 Subject: [PATCH 3/3] Give RW+C to the forks Signed-off-by: Pierre-Yves Chibon --- diff --git a/dist_git_auth.py b/dist_git_auth.py index 1a26c84..33bd55d 100644 --- a/dist_git_auth.py +++ b/dist_git_auth.py @@ -101,7 +101,7 @@ class DistGitoliteAuth(Gitolite3Auth): access = 'RWC' if project.is_fork: - access = 'RW+' + access = 'RW+C' if repos == '': # First, whitelist the supported branches from PDC @@ -132,7 +132,7 @@ class DistGitoliteAuth(Gitolite3Auth): if deploykey.pushaccess: access = 'RW' if project.is_fork: - access = 'RW+' + access = 'RW+C' # Note: the replace of / with _ is because gitolite # users can't contain a /. At first, this might look # like deploy keys in a project called