# HG changeset patch # User Mads Kiilerich # Date 1588612360 -7200 # Node ID a67945aec3df1db0d92aed9e231f0f5025ee7ec1 # Parent 32ca332042cde2e069ca2974e5e71dc9ffdbdfc1# Parent 4c7eca54cd55ebb5ea9b5ed4bc1f11ef5e275f6a Let i18n branch track stable branch diff -r 32ca332042cd -r a67945aec3df docs/contributing.rst --- a/docs/contributing.rst Mon May 04 19:08:30 2020 +0200 +++ b/docs/contributing.rst Mon May 04 19:12:40 2020 +0200 @@ -269,8 +269,8 @@ Debugging ^^^^^^^^^ -A good way to trace what Kallithea is doing is to keep an eye on the output of -stdout/stderr from the server process. Perhaps change ``my.ini`` to log at +A good way to trace what Kallithea is doing is to keep an eye on the output on +stdout/stderr of the server process. Perhaps change ``my.ini`` to log at ``DEBUG`` or ``INFO`` level, especially ``[logger_kallithea]``, but perhaps also other loggers. It is often easier to add additional ``log`` or ``print`` statements than to use a Python debugger. diff -r 32ca332042cd -r a67945aec3df docs/setup.rst --- a/docs/setup.rst Mon May 04 19:08:30 2020 +0200 +++ b/docs/setup.rst Mon May 04 19:12:40 2020 +0200 @@ -153,6 +153,16 @@ process, the server process will raise an exception each time it attempts to write the ``authorized_keys`` file. +.. note:: It is possible to configure the SSH server to look for authorized + keys in multiple files, for example reserving ``ssh/authorized_keys`` to be + used for normal SSH and with Kallithea using + ``.ssh/authorized_keys_kallithea``. In ``/etc/ssh/sshd_config`` set + ``AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys_kallithea`` + and restart sshd, and in ``my.ini`` set ``ssh_authorized_keys = + /home/kallithea/.ssh/authorized_keys_kallithea``. Note that this new + location will apply to all system users, and that multiple entries for the + same SSH key will shadow each other. + .. warning:: The handling of SSH access is steered directly by the command specified in the ``authorized_keys`` file. There is no interaction with the web UI. Once SSH access is correctly configured and enabled, it will work diff -r 32ca332042cd -r a67945aec3df kallithea/controllers/error.py --- a/kallithea/controllers/error.py Mon May 04 19:08:30 2020 +0200 +++ b/kallithea/controllers/error.py Mon May 04 19:12:40 2020 +0200 @@ -41,11 +41,8 @@ class ErrorController(BaseController): """Generates error documents as and when they are required. - The ErrorDocuments middleware forwards to ErrorController when error + The errorpage middleware renders /error/document when error related status codes are returned from the application. - - This behavior can be altered by changing the parameters to the - ErrorDocuments middleware in your config/middleware.py file. """ def _before(self, *args, **kwargs): diff -r 32ca332042cd -r a67945aec3df kallithea/controllers/root.py --- a/kallithea/controllers/root.py Mon May 04 19:08:30 2020 +0200 +++ b/kallithea/controllers/root.py Mon May 04 19:12:40 2020 +0200 @@ -31,5 +31,5 @@ def __init__(self): self.mapper = make_map(config) - # the following assignment hooks in error handling + # The URL '/error/document' (the default TG errorpage.path) should be handled by ErrorController.document self.error = ErrorController() diff -r 32ca332042cd -r a67945aec3df kallithea/i18n/be/LC_MESSAGES/kallithea.po --- a/kallithea/i18n/be/LC_MESSAGES/kallithea.po Mon May 04 19:08:30 2020 +0200 +++ b/kallithea/i18n/be/LC_MESSAGES/kallithea.po Mon May 04 19:12:40 2020 +0200 @@ -5,7 +5,7 @@ msgstr "" "Project-Id-Version: Kallithea 0.3\n" "Report-Msgid-Bugs-To: translations@kallithea-scm.org\n" -"POT-Creation-Date: 2020-04-27 13:26+0200\n" +"POT-Creation-Date: 2020-05-04 19:12+0200\n" "PO-Revision-Date: 2017-08-20 10:44+0000\n" "Last-Translator: Viktar Vauchkevich \n" "Language-Team: Belarusian \n" "Language-Team: Czech \n" "Language-Team: Danish \n" "Language-Team: German \n" "Language-Team: Greek \n" "Language-Team: Spanish \n" "Language-Team: French \n" "Language-Team: Hungarian \n" "Language-Team: Japanese \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" -"Generated-By: Babel 2.8.0\n" +"Generated-By: Babel 2.7.0\n" #: kallithea/controllers/changelog.py:67 #: kallithea/controllers/pullrequests.py:247 kallithea/lib/base.py:602 @@ -91,31 +91,31 @@ msgid "Cannot compare repositories without using common ancestor" msgstr "" -#: kallithea/controllers/error.py:70 +#: kallithea/controllers/error.py:67 msgid "No response" msgstr "" -#: kallithea/controllers/error.py:71 +#: kallithea/controllers/error.py:68 msgid "Unknown error" msgstr "" +#: kallithea/controllers/error.py:81 +msgid "The request could not be understood by the server due to malformed syntax." +msgstr "" + #: kallithea/controllers/error.py:84 -msgid "The request could not be understood by the server due to malformed syntax." -msgstr "" - -#: kallithea/controllers/error.py:87 msgid "Unauthorized access to resource" msgstr "" -#: kallithea/controllers/error.py:89 +#: kallithea/controllers/error.py:86 msgid "You don't have permission to view this page" msgstr "" -#: kallithea/controllers/error.py:91 +#: kallithea/controllers/error.py:88 msgid "The resource could not be found" msgstr "" -#: kallithea/controllers/error.py:93 +#: kallithea/controllers/error.py:90 msgid "" "The server encountered an unexpected condition which prevented it from " "fulfilling the request." @@ -1215,7 +1215,7 @@ msgid "chmod" msgstr "" -#: kallithea/lib/helpers.py:1314 +#: kallithea/lib/helpers.py:1323 #, python-format msgid "" "%s repository is not mapped to db perhaps it was created or renamed from " diff -r 32ca332042cd -r a67945aec3df kallithea/i18n/lb/LC_MESSAGES/kallithea.po --- a/kallithea/i18n/lb/LC_MESSAGES/kallithea.po Mon May 04 19:08:30 2020 +0200 +++ b/kallithea/i18n/lb/LC_MESSAGES/kallithea.po Mon May 04 19:12:40 2020 +0200 @@ -3,7 +3,7 @@ msgid "" msgstr "" "Report-Msgid-Bugs-To: translations@kallithea-scm.org\n" -"POT-Creation-Date: 2020-05-04 18:57+0200\n" +"POT-Creation-Date: 2020-05-04 19:12+0200\n" "PO-Revision-Date: 2020-04-13 19:42+0000\n" "Last-Translator: Dennis Fink \n" "Language: lb\n" @@ -88,32 +88,32 @@ msgid "Cannot compare repositories without using common ancestor" msgstr "" -#: kallithea/controllers/error.py:70 +#: kallithea/controllers/error.py:67 msgid "No response" msgstr "Keng Äntwert" -#: kallithea/controllers/error.py:71 +#: kallithea/controllers/error.py:68 msgid "Unknown error" msgstr "Onbekannten Feeler" -#: kallithea/controllers/error.py:84 +#: kallithea/controllers/error.py:81 msgid "" "The request could not be understood by the server due to malformed syntax." msgstr "" -#: kallithea/controllers/error.py:87 +#: kallithea/controllers/error.py:84 msgid "Unauthorized access to resource" msgstr "" -#: kallithea/controllers/error.py:89 +#: kallithea/controllers/error.py:86 msgid "You don't have permission to view this page" msgstr "" -#: kallithea/controllers/error.py:91 +#: kallithea/controllers/error.py:88 msgid "The resource could not be found" msgstr "" -#: kallithea/controllers/error.py:93 +#: kallithea/controllers/error.py:90 msgid "" "The server encountered an unexpected condition which prevented it from " "fulfilling the request." @@ -1218,7 +1218,7 @@ msgid "chmod" msgstr "" -#: kallithea/lib/helpers.py:1314 +#: kallithea/lib/helpers.py:1323 #, python-format msgid "" "%s repository is not mapped to db perhaps it was created or renamed from " diff -r 32ca332042cd -r a67945aec3df kallithea/i18n/nb_NO/LC_MESSAGES/kallithea.po --- a/kallithea/i18n/nb_NO/LC_MESSAGES/kallithea.po Mon May 04 19:08:30 2020 +0200 +++ b/kallithea/i18n/nb_NO/LC_MESSAGES/kallithea.po Mon May 04 19:12:40 2020 +0200 @@ -4,7 +4,7 @@ msgstr "" "Project-Id-Version: Kallithea 0.3.99\n" "Report-Msgid-Bugs-To: translations@kallithea-scm.org\n" -"POT-Creation-Date: 2020-04-27 13:26+0200\n" +"POT-Creation-Date: 2020-05-04 19:12+0200\n" "PO-Revision-Date: 2019-04-30 22:25+0000\n" "Last-Translator: Allan Nordhøy \n" "Language-Team: Norwegian Bokmål \n" "Language-Team: Flemish \n" "Language-Team: Polish \n" "Language-Team: Portuguese (Brazil) \n" "Language-Team: Russian \n" "Language-Team: Slovak \n" "Language-Team: Turkish \n" "Language-Team: Ukrainian \n" "Language-Team: Chinese (Simplified) \n" "Language-Team: Chinese (Traditional) %r %r', suffix, issue_pat, issue_server_link, issue_sub) + issue_prefix = CONFIG.get('issue_prefix%s' % suffix) + if issue_prefix: + log.error('found unsupported issue_prefix%s = %r - use issue_sub%s instead', suffix, issue_prefix, suffix) + if not issue_pat: + log.error('skipping incomplete issue pattern %r: it needs a regexp', k) + continue + if not issue_server_link: + log.error('skipping incomplete issue pattern %r: it needs issue_server_link%s', k, suffix) + continue + if issue_sub is None: # issue_sub can be empty but should be present + log.error('skipping incomplete issue pattern %r: it needs (a potentially empty) issue_sub%s', k, suffix) continue # Wrap tmp_urlify_issues_f with substitution of this pattern, while making sure all loop variables (and compiled regexpes) are bound try: issue_re = re.compile(issue_pat) except re.error as e: - log.error('skipping invalid issue pattern %r: %r -> %r %r. Error: %s', suffix, issue_pat, issue_server_link, issue_sub, str(e)) + log.error('skipping invalid issue pattern %r: %r -> %r %r. Error: %s', k, issue_pat, issue_server_link, issue_sub, str(e)) continue - log.debug('issue pattern %r: %r -> %r %r', suffix, issue_pat, issue_server_link, issue_sub) + log.debug('issue pattern %r: %r -> %r %r', k, issue_pat, issue_server_link, issue_sub) def issues_replace(match_obj, issue_server_link=issue_server_link, issue_sub=issue_sub): diff -r 32ca332042cd -r a67945aec3df kallithea/lib/hooks.py --- a/kallithea/lib/hooks.py Mon May 04 19:08:30 2020 +0200 +++ b/kallithea/lib/hooks.py Mon May 04 19:12:40 2020 +0200 @@ -66,7 +66,10 @@ def repo_size(ui, repo, hooktype=None, **kwargs): - """Show size of Mercurial repository, to be called after push.""" + """Show size of Mercurial repository. + + Called as Mercurial hook changegroup.repo_size after push. + """ size_hg_f, size_root_f, size_total_f = _get_scm_size('.hg', safe_str(repo.root)) last_cs = repo[len(repo) - 1] @@ -103,12 +106,13 @@ def log_push_action(ui, repo, node, node_last, **kwargs): """ - Entry point for Mercurial hook changegroup.push_logger. + Register that changes have been added to the repo - log the action *and* invalidate caches. + Note: This hook is not only logging, but also the side effect invalidating + caches! The function should perhaps be renamed. + + Called as Mercurial hook changegroup.kallithea_log_push_action . The pushed changesets is given by the revset 'node:node_last'. - - Note: This hook is not only logging, but also the side effect invalidating - cahes! The function should perhaps be renamed. """ revs = [ascii_str(repo[r].hex()) for r in mercurial.scmutil.revrange(repo, [b'%s:%s' % (node, node_last)])] process_pushed_raw_ids(revs) @@ -119,7 +123,7 @@ """ Register that changes have been added to the repo - log the action *and* invalidate caches. - Called from Mercurial changegroup.push_logger calling hook log_push_action, + Called from Mercurial changegroup.kallithea_log_push_action calling hook log_push_action, or from the Git post-receive hook calling handle_git_post_receive ... or from scm _handle_push. """ diff -r 32ca332042cd -r a67945aec3df kallithea/lib/inifile.py --- a/kallithea/lib/inifile.py Mon May 04 19:08:30 2020 +0200 +++ b/kallithea/lib/inifile.py Mon May 04 19:12:40 2020 +0200 @@ -77,12 +77,13 @@ ... #variable6 = 6.1 ... #variable7 = 7.0 ... variable7 = 7.1 + ... variable8 = 8.0 ... ''' >>> mako_variable_values = {'mako_variable': 'VALUE', 'mako_function': (lambda: 'FUNCTION RESULT'), ... 'conditional_options': 'option-a', 'http_server': 'nc'} >>> settings = { # only partially used - ... '[first-section]': {'variable2': 'VAL2', 'first_extra': 'EXTRA'}, - ... '[comment-section]': {'variable3': '3.0', 'variable4': '4.1', 'variable5': '5.2', 'variable6': '6.2', 'variable7': '7.0'}, + ... '[first-section]': {'variable2': 'VAL2', 'first_extra': 'EXTRA', 'spacey': ' '}, + ... '[comment-section]': {'variable3': '3.0', 'variable4': '4.1', 'variable5': '5.2', 'variable6': '6.2', 'variable7': '7.0', 'variable8': None, 'variable9': None}, ... '[third-section]': {'third_extra': ' 3'}, ... '[fourth-section]': {'fourth_extra': '4', 'fourth': '"four"'}, ... } @@ -96,6 +97,7 @@ variable2 = VAL2 first_extra = EXTRA + spacey = # FUNCTION RESULT @@ -114,6 +116,10 @@ variable6 = 6.2 variable7 = 7.0 #variable7 = 7.1 + #variable8 = 8.0 + + variable8 = None + variable9 = None [fourth-section] fourth = "four" @@ -160,6 +166,8 @@ lines = re.sub(r'^(#)?([^#\n\s]*)[ \t]*=[ \t]*(.*)$', comment_out, lines, flags=re.MULTILINE) + # 2nd pass: + # find the best comment line and un-comment or add after def add_after_comment(m): """process a section comment line and add new value""" line = m.group(0) @@ -178,11 +186,12 @@ lines = re.sub(r'^#([^#\n\s]*)[ \t]*=[ \t]*(.*)$', add_after_comment, lines, flags=re.MULTILINE) - # add unused section settings + # 3rd pass: + # settings that haven't been consumed yet at is appended to section if section_settings: lines += '\n' + ''.join('%s = %s\n' % (key, value) for key, value in sorted(section_settings.items())) - return sectionname + '\n' + lines + return sectionname + '\n' + re.sub('[ \t]+\n', '\n', lines) # process sections until comments before next section or end ini_lines = re.sub(r'''^ diff -r 32ca332042cd -r a67945aec3df kallithea/tests/api/api_base.py --- a/kallithea/tests/api/api_base.py Mon May 04 19:08:30 2020 +0200 +++ b/kallithea/tests/api/api_base.py Mon May 04 19:12:40 2020 +0200 @@ -638,32 +638,32 @@ response = api_call(self, params) repo = RepoModel().get_by_repo_name(self.REPO) - ret = repo.get_api_data() + assert len(repo.repo_to_perm) >= 2 # make sure we actually are testing something - probably the default 2 permissions, possibly more + + expected = repo.get_api_data() members = [] - followers = [] - assert 2 == len(repo.repo_to_perm) for user in repo.repo_to_perm: perm = user.permission.permission_name user_obj = user.user user_data = {'name': user_obj.username, 'type': "user", 'permission': perm} members.append(user_data) - for user_group in repo.users_group_to_perm: perm = user_group.permission.permission_name user_group_obj = user_group.users_group user_group_data = {'name': user_group_obj.users_group_name, 'type': "user_group", 'permission': perm} members.append(user_group_data) + expected['members'] = members + + followers = [] for user in repo.followers: followers.append(user.user.get_api_data()) - ret['members'] = members - ret['followers'] = followers + expected['followers'] = followers - expected = ret try: self._compare_ok(id_, expected, given=response.body) finally: diff -r 32ca332042cd -r a67945aec3df kallithea/tests/functional/test_admin_auth_settings.py --- a/kallithea/tests/functional/test_admin_auth_settings.py Mon May 04 19:08:30 2020 +0200 +++ b/kallithea/tests/functional/test_admin_auth_settings.py Mon May 04 19:12:40 2020 +0200 @@ -155,12 +155,12 @@ response = self.app.get( url=base.url(controller='admin/my_account', action='my_account'), extra_environ={'THE_USER_NAME': 'johnd', - 'THE_USER_EMAIL': 'john@example.org', + 'THE_USER_EMAIL': 'john2@example.org', 'THE_USER_FIRSTNAME': 'John', 'THE_USER_LASTNAME': 'Doe', } ) - assert response.form['email'].value == 'john@example.org' + assert response.form['email'].value == 'john2@example.org' assert response.form['firstname'].value == 'John' assert response.form['lastname'].value == 'Doe' diff -r 32ca332042cd -r a67945aec3df kallithea/tests/functional/test_admin_settings.py --- a/kallithea/tests/functional/test_admin_settings.py Mon May 04 19:08:30 2020 +0200 +++ b/kallithea/tests/functional/test_admin_settings.py Mon May 04 19:12:40 2020 +0200 @@ -46,8 +46,7 @@ response.mustcontain('test_hooks_1') response.mustcontain('cd %s' % base.TESTS_TMP_PATH) - def test_edit_custom_hook(self): - self.log_user() + # test_edit_custom_hook response = self.app.post(base.url('admin_settings_hooks'), params=dict(hook_ui_key='test_hooks_1', hook_ui_value='old_value_of_hook_1', @@ -58,8 +57,7 @@ response.mustcontain('test_hooks_1') response.mustcontain('new_value_of_hook_1') - def test_add_existing_custom_hook(self): - self.log_user() + # test_add_existing_custom_hook response = self.app.post(base.url('admin_settings_hooks'), params=dict(new_hook_ui_key='test_hooks_1', new_hook_ui_value='attempted_new_value', diff -r 32ca332042cd -r a67945aec3df kallithea/tests/models/test_permissions.py --- a/kallithea/tests/models/test_permissions.py Mon May 04 19:08:30 2020 +0200 +++ b/kallithea/tests/models/test_permissions.py Mon May 04 19:12:40 2020 +0200 @@ -68,13 +68,7 @@ def test_default_perms_set(self): u1_auth = AuthUser(user_id=self.u1.user_id) - perms = { - 'repositories_groups': {}, - 'global': set(['hg.create.repository', 'repository.read', - 'hg.register.manual_activate']), - 'repositories': {base.HG_REPO: 'repository.read'} - } - assert u1_auth.permissions['repositories'][base.HG_REPO] == perms['repositories'][base.HG_REPO] + assert u1_auth.permissions['repositories'][base.HG_REPO] == 'repository.read' new_perm = 'repository.write' RepoModel().grant_user_permission(repo=base.HG_REPO, user=self.u1, perm=new_perm) @@ -85,12 +79,7 @@ def test_default_admin_perms_set(self): a1_auth = AuthUser(user_id=self.a1.user_id) - perms = { - 'repositories_groups': {}, - 'global': set(['hg.admin', 'hg.create.write_on_repogroup.true']), - 'repositories': {base.HG_REPO: 'repository.admin'} - } - assert a1_auth.permissions['repositories'][base.HG_REPO] == perms['repositories'][base.HG_REPO] + assert a1_auth.permissions['repositories'][base.HG_REPO] == 'repository.admin' new_perm = 'repository.write' RepoModel().grant_user_permission(repo=base.HG_REPO, user=self.a1, perm=new_perm) @@ -98,33 +87,24 @@ # cannot really downgrade admins permissions !? they still gets set as # admin ! u1_auth = AuthUser(user_id=self.a1.user_id) - assert u1_auth.permissions['repositories'][base.HG_REPO] == perms['repositories'][base.HG_REPO] + assert u1_auth.permissions['repositories'][base.HG_REPO] == 'repository.admin' def test_default_group_perms(self): self.g1 = fixture.create_repo_group('test1', skip_if_exists=True) self.g2 = fixture.create_repo_group('test2', skip_if_exists=True) u1_auth = AuthUser(user_id=self.u1.user_id) - perms = { - 'repositories_groups': {'test1': 'group.read', 'test2': 'group.read'}, - 'global': set(Permission.DEFAULT_USER_PERMISSIONS), - 'repositories': {base.HG_REPO: 'repository.read'} - } - assert u1_auth.permissions['repositories'][base.HG_REPO] == perms['repositories'][base.HG_REPO] - assert u1_auth.permissions['repositories_groups'] == perms['repositories_groups'] - assert u1_auth.permissions['global'] == perms['global'] + assert u1_auth.permissions['repositories'][base.HG_REPO] == 'repository.read' + assert u1_auth.permissions['repositories_groups'].get('test1') == 'group.read' + assert u1_auth.permissions['repositories_groups'].get('test2') == 'group.read' + assert u1_auth.permissions['global'] == set(Permission.DEFAULT_USER_PERMISSIONS) def test_default_admin_group_perms(self): self.g1 = fixture.create_repo_group('test1', skip_if_exists=True) self.g2 = fixture.create_repo_group('test2', skip_if_exists=True) a1_auth = AuthUser(user_id=self.a1.user_id) - perms = { - 'repositories_groups': {'test1': 'group.admin', 'test2': 'group.admin'}, - 'global': set(['hg.admin', 'hg.create.write_on_repogroup.true']), - 'repositories': {base.HG_REPO: 'repository.admin'} - } - - assert a1_auth.permissions['repositories'][base.HG_REPO] == perms['repositories'][base.HG_REPO] - assert a1_auth.permissions['repositories_groups'] == perms['repositories_groups'] + assert a1_auth.permissions['repositories'][base.HG_REPO] == 'repository.admin' + assert a1_auth.permissions['repositories_groups'].get('test1') == 'group.admin' + assert a1_auth.permissions['repositories_groups'].get('test2') == 'group.admin' def test_propagated_permission_from_users_group_by_explicit_perms_exist(self): # make group @@ -158,14 +138,7 @@ perm=new_perm_gr) # check perms u3_auth = AuthUser(user_id=self.u3.user_id) - perms = { - 'repositories_groups': {}, - 'global': set(['hg.create.repository', 'repository.read', - 'hg.register.manual_activate']), - 'repositories': {base.HG_REPO: 'repository.read'} - } assert u3_auth.permissions['repositories'][base.HG_REPO] == new_perm_gr - assert u3_auth.permissions['repositories_groups'] == perms['repositories_groups'] def test_propagated_permission_from_users_group_lower_weight(self): # make group @@ -189,24 +162,19 @@ perm=new_perm_l) # check perms u1_auth = AuthUser(user_id=self.u1.user_id) - perms = { - 'repositories_groups': {}, - 'global': set(['hg.create.repository', 'repository.read', - 'hg.register.manual_activate']), - 'repositories': {base.HG_REPO: 'repository.write'} - } assert u1_auth.permissions['repositories'][base.HG_REPO] == new_perm_h - assert u1_auth.permissions['repositories_groups'] == perms['repositories_groups'] def test_repo_in_group_permissions(self): self.g1 = fixture.create_repo_group('group1', skip_if_exists=True) self.g2 = fixture.create_repo_group('group2', skip_if_exists=True) # both perms should be read ! u1_auth = AuthUser(user_id=self.u1.user_id) - assert u1_auth.permissions['repositories_groups'] == {'group1': 'group.read', 'group2': 'group.read'} + assert u1_auth.permissions['repositories_groups'].get('group1') == 'group.read' + assert u1_auth.permissions['repositories_groups'].get('group2') == 'group.read' a1_auth = AuthUser(user_id=self.anon.user_id) - assert a1_auth.permissions['repositories_groups'] == {'group1': 'group.read', 'group2': 'group.read'} + assert a1_auth.permissions['repositories_groups'].get('group1') == 'group.read' + assert a1_auth.permissions['repositories_groups'].get('group2') == 'group.read' # Change perms to none for both groups RepoGroupModel().grant_user_permission(repo_group=self.g1, @@ -217,10 +185,12 @@ perm='group.none') u1_auth = AuthUser(user_id=self.u1.user_id) - assert u1_auth.permissions['repositories_groups'] == {'group1': 'group.none', 'group2': 'group.none'} + assert u1_auth.permissions['repositories_groups'].get('group1') == 'group.none' + assert u1_auth.permissions['repositories_groups'].get('group2') == 'group.none' a1_auth = AuthUser(user_id=self.anon.user_id) - assert a1_auth.permissions['repositories_groups'] == {'group1': 'group.none', 'group2': 'group.none'} + assert a1_auth.permissions['repositories_groups'].get('group1') == 'group.none' + assert a1_auth.permissions['repositories_groups'].get('group2') == 'group.none' # add repo to group name = db.URL_SEP.join([self.g1.group_name, 'test_perm']) @@ -230,10 +200,12 @@ cur_user=self.u1,) u1_auth = AuthUser(user_id=self.u1.user_id) - assert u1_auth.permissions['repositories_groups'] == {'group1': 'group.none', 'group2': 'group.none'} + assert u1_auth.permissions['repositories_groups'].get('group1') == 'group.none' + assert u1_auth.permissions['repositories_groups'].get('group2') == 'group.none' a1_auth = AuthUser(user_id=self.anon.user_id) - assert a1_auth.permissions['repositories_groups'] == {'group1': 'group.none', 'group2': 'group.none'} + assert a1_auth.permissions['repositories_groups'].get('group1') == 'group.none' + assert a1_auth.permissions['repositories_groups'].get('group2') == 'group.none' # grant permission for u2 ! RepoGroupModel().grant_user_permission(repo_group=self.g1, user=self.u2, @@ -244,20 +216,23 @@ assert self.u1 != self.u2 # u1 and anon should have not change perms while u2 should ! u1_auth = AuthUser(user_id=self.u1.user_id) - assert u1_auth.permissions['repositories_groups'] == {'group1': 'group.none', 'group2': 'group.none'} + assert u1_auth.permissions['repositories_groups'].get('group1') == 'group.none' + assert u1_auth.permissions['repositories_groups'].get('group2') == 'group.none' u2_auth = AuthUser(user_id=self.u2.user_id) - assert u2_auth.permissions['repositories_groups'] == {'group1': 'group.read', 'group2': 'group.read'} + assert u2_auth.permissions['repositories_groups'].get('group1') == 'group.read' + assert u2_auth.permissions['repositories_groups'].get('group2') == 'group.read' a1_auth = AuthUser(user_id=self.anon.user_id) - assert a1_auth.permissions['repositories_groups'] == {'group1': 'group.none', 'group2': 'group.none'} + assert a1_auth.permissions['repositories_groups'].get('group1') == 'group.none' + assert a1_auth.permissions['repositories_groups'].get('group2') == 'group.none' def test_repo_group_user_as_user_group_member(self): # create Group1 self.g1 = fixture.create_repo_group('group1', skip_if_exists=True) a1_auth = AuthUser(user_id=self.anon.user_id) - assert a1_auth.permissions['repositories_groups'] == {'group1': 'group.read'} + assert a1_auth.permissions['repositories_groups'].get('group1') == 'group.read' # set default permission to none RepoGroupModel().grant_user_permission(repo_group=self.g1, @@ -276,10 +251,10 @@ # check his permissions a1_auth = AuthUser(user_id=self.anon.user_id) - assert a1_auth.permissions['repositories_groups'] == {'group1': 'group.none'} + assert a1_auth.permissions['repositories_groups'].get('group1') == 'group.none' u1_auth = AuthUser(user_id=self.u1.user_id) - assert u1_auth.permissions['repositories_groups'] == {'group1': 'group.none'} + assert u1_auth.permissions['repositories_groups'].get('group1') == 'group.none' # grant ug1 read permissions for RepoGroupModel().grant_user_group_permission(repo_group=self.g1, @@ -295,10 +270,10 @@ a1_auth = AuthUser(user_id=self.anon.user_id) - assert a1_auth.permissions['repositories_groups'] == {'group1': 'group.none'} + assert a1_auth.permissions['repositories_groups'].get('group1') == 'group.none' u1_auth = AuthUser(user_id=self.u1.user_id) - assert u1_auth.permissions['repositories_groups'] == {'group1': 'group.read'} + assert u1_auth.permissions['repositories_groups'].get('group1') == 'group.read' def test_inherit_nice_permissions_from_default_user(self): user_model = UserModel() @@ -516,7 +491,7 @@ perm='group.write') Session().commit() u1_auth = AuthUser(user_id=self.u1.user_id) - assert u1_auth.permissions['repositories_groups'] == {'group1': 'group.write'} + assert u1_auth.permissions['repositories_groups'].get('group1') == 'group.write' def test_inactive_user_group_does_not_affect_repo_group_permissions_inverse(self): self.ug1 = fixture.create_user_group('G1') @@ -536,7 +511,7 @@ perm='group.admin') Session().commit() u1_auth = AuthUser(user_id=self.u1.user_id) - assert u1_auth.permissions['repositories_groups'] == {'group1': 'group.admin'} + assert u1_auth.permissions['repositories_groups'].get('group1') == 'group.admin' def test_inactive_user_group_does_not_affect_user_group_permissions(self): self.ug1 = fixture.create_user_group('G1') diff -r 32ca332042cd -r a67945aec3df kallithea/tests/models/test_repo_groups.py --- a/kallithea/tests/models/test_repo_groups.py Mon May 04 19:08:30 2020 +0200 +++ b/kallithea/tests/models/test_repo_groups.py Mon May 04 19:12:40 2020 +0200 @@ -63,7 +63,7 @@ assert self.__check_path('newGroup') - def test_create_same_name_group(self): + # test_create_same_name_group with pytest.raises(IntegrityError): fixture.create_repo_group('newGroup') Session().rollback() diff -r 32ca332042cd -r a67945aec3df kallithea/tests/other/test_auth_ldap.py --- a/kallithea/tests/other/test_auth_ldap.py Mon May 04 19:08:30 2020 +0200 +++ b/kallithea/tests/other/test_auth_ldap.py Mon May 04 19:12:40 2020 +0200 @@ -24,7 +24,7 @@ def authenticate_ldap(self, username, password): return 'spam dn', dict(test_ldap_firstname=['spam ldap first name'], test_ldap_lastname=['spam ldap last name'], - test_ldap_email=['spam ldap email']) + test_ldap_email=['%s ldap email' % username]) def test_update_user_attributes_from_ldap(monkeypatch, create_test_user, @@ -56,13 +56,13 @@ assert user_data is not None assert user_data.get('firstname') == 'spam ldap first name' assert user_data.get('lastname') == 'spam ldap last name' - assert user_data.get('email') == 'spam ldap email' + assert user_data.get('email') == '%s ldap email' % username # Verify that authentication overwrote user attributes with the ones # retrieved from LDAP. assert user.firstname == 'spam ldap first name' assert user.lastname == 'spam ldap last name' - assert user.email == 'spam ldap email' + assert user.email == '%s ldap email' % username def test_init_user_attributes_from_ldap(monkeypatch, arrange_ldap_auth): @@ -85,7 +85,7 @@ assert user_data is not None assert user_data.get('firstname') == 'spam ldap first name' assert user_data.get('lastname') == 'spam ldap last name' - assert user_data.get('email') == 'spam ldap email' + assert user_data.get('email') == '%s ldap email' % username # Verify that authentication created new user with attributes # retrieved from LDAP. @@ -93,7 +93,7 @@ assert new_user is not None assert new_user.firstname == 'spam ldap first name' assert new_user.lastname == 'spam ldap last name' - assert new_user.email == 'spam ldap email' + assert new_user.email == '%s ldap email' % username class _AuthLdapNoEmailMock():