當前位置: 首頁>>代碼示例>>Python>>正文


Python UserModel.add_extra_ip方法代碼示例

本文整理匯總了Python中kallithea.model.user.UserModel.add_extra_ip方法的典型用法代碼示例。如果您正苦於以下問題:Python UserModel.add_extra_ip方法的具體用法?Python UserModel.add_extra_ip怎麽用?Python UserModel.add_extra_ip使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在kallithea.model.user.UserModel的用法示例。


在下文中一共展示了UserModel.add_extra_ip方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_ip_restriction_hg

# 需要導入模塊: from kallithea.model.user import UserModel [as 別名]
# 或者: from kallithea.model.user.UserModel import add_extra_ip [as 別名]
    def test_ip_restriction_hg(self, webserver):
        user_model = UserModel()
        try:
            user_model.add_extra_ip(TEST_USER_ADMIN_LOGIN, '10.10.10.10/32')
            Session().commit()
            clone_url = webserver.repo_url(HG_REPO)
            stdout, stderr = Command(TESTS_TMP_PATH).execute('hg clone', clone_url, _get_tmp_dir(), ignoreReturnCode=True)
            assert 'abort: HTTP Error 403: Forbidden' in stderr
        finally:
            #release IP restrictions
            for ip in UserIpMap.query():
                UserIpMap.delete(ip.ip_id)
            Session().commit()

        # IP permissions are cached, need to wait for the cache in the server process to expire
        time.sleep(1.5)

        clone_url = webserver.repo_url(HG_REPO)
        stdout, stderr = Command(TESTS_TMP_PATH).execute('hg clone', clone_url, _get_tmp_dir())

        assert 'requesting all changes' in stdout
        assert 'adding changesets' in stdout
        assert 'adding manifests' in stdout
        assert 'adding file changes' in stdout

        assert stderr == ''
開發者ID:t-kenji,項目名稱:kallithea-mirror,代碼行數:28,代碼來源:test_vcs_operations.py

示例2: add_ip

# 需要導入模塊: from kallithea.model.user import UserModel [as 別名]
# 或者: from kallithea.model.user.UserModel import add_extra_ip [as 別名]
    def add_ip(self, id):
        """POST /user_ips:Add an existing item"""
        # url('user_ips', id=ID, method='put')

        ip = request.POST.get('new_ip')
        user_model = UserModel()

        try:
            user_model.add_extra_ip(id, ip)
            Session().commit()
            h.flash(_("Added ip %s to user whitelist") % ip, category='success')
        except formencode.Invalid, error:
            msg = error.error_dict['ip']
            h.flash(msg, category='error')
開發者ID:zhumengyuan,項目名稱:kallithea,代碼行數:16,代碼來源:users.py

示例3: test_delete_ips

# 需要導入模塊: from kallithea.model.user import UserModel [as 別名]
# 或者: from kallithea.model.user.UserModel import add_extra_ip [as 別名]
    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'])
開發者ID:t-kenji,項目名稱:kallithea-mirror,代碼行數:36,代碼來源:test_admin_permissions.py

示例4: add_ip

# 需要導入模塊: from kallithea.model.user import UserModel [as 別名]
# 或者: from kallithea.model.user.UserModel import add_extra_ip [as 別名]
    def add_ip(self, id):
        ip = request.POST.get('new_ip')
        user_model = UserModel()

        try:
            user_model.add_extra_ip(id, ip)
            Session().commit()
            h.flash(_("Added IP address %s to user whitelist") % ip, category='success')
        except formencode.Invalid as error:
            msg = error.error_dict['ip']
            h.flash(msg, category='error')
        except Exception:
            log.error(traceback.format_exc())
            h.flash(_('An error occurred while adding IP address'),
                    category='error')

        if 'default_user' in request.POST:
            raise HTTPFound(location=url('admin_permissions_ips'))
        raise HTTPFound(location=url('edit_user_ips', id=id))
開發者ID:t-kenji,項目名稱:kallithea-mirror,代碼行數:21,代碼來源:users.py

示例5: test_ip_restriction_git

# 需要導入模塊: from kallithea.model.user import UserModel [as 別名]
# 或者: from kallithea.model.user.UserModel import add_extra_ip [as 別名]
    def test_ip_restriction_git(self):
        user_model = UserModel()
        try:
            user_model.add_extra_ip(TEST_USER_ADMIN_LOGIN, '10.10.10.10/32')
            Session().commit()
            clone_url = _construct_url(GIT_REPO)
            stdout, stderr = Command('/tmp').execute('git clone', clone_url)
            msg = ("""The requested URL returned error: 403""")
            assert msg in stderr
        finally:
            #release IP restrictions
            for ip in UserIpMap.getAll():
                UserIpMap.delete(ip.ip_id)
            Session().commit()

        time.sleep(2)
        clone_url = _construct_url(GIT_REPO)
        stdout, stderr = Command('/tmp').execute('git clone', clone_url)

        assert 'Cloning into' in stdout + stderr
        assert stderr == '' or stdout == ''
開發者ID:zhumengyuan,項目名稱:kallithea,代碼行數:23,代碼來源:manual_test_vcs_operations.py

示例6: test_ip_restriction_git

# 需要導入模塊: from kallithea.model.user import UserModel [as 別名]
# 或者: from kallithea.model.user.UserModel import add_extra_ip [as 別名]
    def test_ip_restriction_git(self, webserver):
        user_model = UserModel()
        try:
            user_model.add_extra_ip(TEST_USER_ADMIN_LOGIN, '10.10.10.10/32')
            Session().commit()
            clone_url = webserver.repo_url(GIT_REPO)
            stdout, stderr = Command(TESTS_TMP_PATH).execute('git clone', clone_url, _get_tmp_dir(), ignoreReturnCode=True)
            # The message apparently changed in Git 1.8.3, so match it loosely.
            assert re.search(r'\b403\b', stderr)
        finally:
            #release IP restrictions
            for ip in UserIpMap.query():
                UserIpMap.delete(ip.ip_id)
            Session().commit()

        # IP permissions are cached, need to wait for the cache in the server process to expire
        time.sleep(1.5)

        clone_url = webserver.repo_url(GIT_REPO)
        stdout, stderr = Command(TESTS_TMP_PATH).execute('git clone', clone_url, _get_tmp_dir())

        assert 'Cloning into' in stdout + stderr
        assert stderr == '' or stdout == ''
開發者ID:t-kenji,項目名稱:kallithea-mirror,代碼行數:25,代碼來源:test_vcs_operations.py

示例7: test_ip_restriction_hg

# 需要導入模塊: from kallithea.model.user import UserModel [as 別名]
# 或者: from kallithea.model.user.UserModel import add_extra_ip [as 別名]
    def test_ip_restriction_hg(self):
        user_model = UserModel()
        try:
            user_model.add_extra_ip(TEST_USER_ADMIN_LOGIN, '10.10.10.10/32')
            Session().commit()
            clone_url = _construct_url(HG_REPO)
            stdout, stderr = Command('/tmp').execute('hg clone', clone_url)
            assert 'abort: HTTP Error 403: Forbidden' in stderr
        finally:
            #release IP restrictions
            for ip in UserIpMap.getAll():
                UserIpMap.delete(ip.ip_id)
            Session().commit()

        time.sleep(2)
        clone_url = _construct_url(HG_REPO)
        stdout, stderr = Command('/tmp').execute('hg clone', clone_url)

        assert 'requesting all changes' in stdout
        assert 'adding changesets' in stdout
        assert 'adding manifests' in stdout
        assert 'adding file changes' in stdout

        assert stderr == ''
開發者ID:zhumengyuan,項目名稱:kallithea,代碼行數:26,代碼來源:manual_test_vcs_operations.py


注:本文中的kallithea.model.user.UserModel.add_extra_ip方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。