Files
@ b49ea1926119
Branch filter:
Location: kallithea/kallithea/tests/functional/test_admin_permissions.py
b49ea1926119
5.1 KiB
text/x-python
tests: make lock tests stable against running 'py.test -k user'
Add some cleanup, and merge some tests to make sure they really have a
well-known starting point.
Add some cleanup, and merge some tests to make sure they really have a
well-known starting point.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | import time
from kallithea.model.db import User, UserIpMap
from kallithea.model.user import UserModel
from kallithea.model.meta import Session
from kallithea.tests.base import *
from tg.util.webtest import test_context
class TestAdminPermissionsController(TestController):
def test_index(self):
self.log_user()
response = self.app.get(url('admin_permissions'))
# Test response...
def test_index_ips(self):
self.log_user()
response = self.app.get(url('admin_permissions_ips'))
# Test response...
response.mustcontain('All IP addresses are allowed')
def test_add_ips(self, auto_clear_ip_permissions):
self.log_user()
default_user_id = User.get_default_user().user_id
response = self.app.post(url('edit_user_ips_update', id=default_user_id),
params=dict(new_ip='127.0.0.0/24',
_authentication_token=self.authentication_token()))
# IP permissions are cached, need to invalidate this cache explicitly
invalidate_all_caches()
self.app.get(url('admin_permissions_ips'), status=302)
# REMOTE_ADDR must match 127.0.0.0/24
response = self.app.get(url('admin_permissions_ips'),
extra_environ={'REMOTE_ADDR': '127.0.0.1'})
response.mustcontain('127.0.0.0/24')
response.mustcontain('127.0.0.0 - 127.0.0.255')
def test_delete_ips(self, auto_clear_ip_permissions):
self.log_user()
default_user_id = User.get_default_user().user_id
## first add
new_ip = '127.0.0.0/24'
with test_context(self.app):
user_model = UserModel()
ip_obj = user_model.add_extra_ip(default_user_id, new_ip)
Session().commit()
## double check that add worked
# IP permissions are cached, need to invalidate this cache explicitly
invalidate_all_caches()
self.app.get(url('admin_permissions_ips'), status=302)
# REMOTE_ADDR must match 127.0.0.0/24
response = self.app.get(url('admin_permissions_ips'),
extra_environ={'REMOTE_ADDR': '127.0.0.1'})
response.mustcontain('127.0.0.0/24')
response.mustcontain('127.0.0.0 - 127.0.0.255')
## now delete
response = self.app.post(url('edit_user_ips_delete', id=default_user_id),
params=dict(del_ip_id=ip_obj.ip_id,
_authentication_token=self.authentication_token()),
extra_environ={'REMOTE_ADDR': '127.0.0.1'})
# IP permissions are cached, need to invalidate this cache explicitly
invalidate_all_caches()
response = self.app.get(url('admin_permissions_ips'))
response.mustcontain('All IP addresses are allowed')
response.mustcontain(no=['127.0.0.0/24'])
response.mustcontain(no=['127.0.0.0 - 127.0.0.255'])
def test_index_overview(self):
self.log_user()
response = self.app.get(url('admin_permissions_perms'))
# Test response...
def test_edit_permissions_permissions(self):
user = User.get_by_username(TEST_USER_REGULAR_LOGIN)
# Test unauthenticated access - it will redirect to login page
response = self.app.post(
url('edit_repo_perms_update', repo_name=HG_REPO),
params=dict(
perm_new_member_1='repository.read',
perm_new_member_name_1=user.username,
perm_new_member_type_1='user',
_authentication_token=self.authentication_token()),
status=302)
assert not response.location.endswith(url('edit_repo_perms_update', repo_name=HG_REPO))
assert response.location.endswith(url('login_home', came_from=url('edit_repo_perms_update', repo_name=HG_REPO)))
response = self.app.post(
url('edit_repo_perms_revoke', repo_name=HG_REPO),
params=dict(
obj_type='user',
user_id=user.user_id,
_authentication_token=self.authentication_token()),
status=302)
assert response.location.endswith(url('login_home', came_from=url('edit_repo_perms_revoke', repo_name=HG_REPO)))
# Test authenticated access
self.log_user()
response = self.app.post(
url('edit_repo_perms_update', repo_name=HG_REPO),
params=dict(
perm_new_member_1='repository.read',
perm_new_member_name_1=user.username,
perm_new_member_type_1='user',
_authentication_token=self.authentication_token()),
status=302)
assert response.location.endswith(url('edit_repo_perms_update', repo_name=HG_REPO))
response = self.app.post(
url('edit_repo_perms_revoke', repo_name=HG_REPO),
params=dict(
obj_type='user',
user_id=user.user_id,
_authentication_token=self.authentication_token()),
status=200)
assert not response.body
|