Changeset 21

Show
Ignore:
Timestamp:
2008年07月27日 00时21分26秒 (4 years ago)
Author:
jiangx
Message:

Fix #4: Better unicode support. Do not use "sys.setdefaultencoding" any longer.

Location:
trunk
Files:
12 modified

Legend:

Unmodified
Added
Removed
  • trunk/pysvnmanager/controllers/authz.py

    r17 r21  
    1515        self.reposlist = self.authz.get_manageable_repos_list(self.login_as) 
    1616         
    17     def __auth_failed(self, reposname=None): 
     17    def __auth_failed(self): 
    1818        if not self.reposlist: 
    19             return True 
    20         elif reposname and not reposname in self.reposlist: 
    2119            return True 
    2220        else: 
     
    3836            if i == '*' or i =='$authenticated' or i == '$anonymous': 
    3937                continue 
    40             if i[0] == '@': 
    41                 all_avail_users.append([_("Group:")+i[1:], i]) 
    42             else: 
    43                 all_avail_users.append([i, i]) 
     38            all_avail_users.append([_("Group:")+i[1:], i]) 
    4439        for alias in self.authz.aliaslist: 
    4540            i = alias.uname 
    46             if i[0] == '&': 
    47                 all_avail_users.append([_("Alias:")+i[1:], i]) 
    48             else: 
    49                 all_avail_users.append([i, i]) 
     41            all_avail_users.append([_("Alias:")+i[1:], i]) 
    5042        for user in self.authz.userlist: 
    5143            i = user.uname 
     
    111103        reposname = d.get('reposname') 
    112104        path = d.get('path') 
    113  
    114105        module = self.authz.get_module(reposname, path) 
    115106        if not module: 
  • trunk/pysvnmanager/controllers/check.py

    r17 r21  
    1515        self.reposlist = self.authz.get_manageable_repos_list(self.login_as) 
    1616 
    17     def __auth_failed(self, reposname=None): 
     17    def __authz_failed(self): 
    1818        if not self.reposlist: 
    19             return True 
    20         elif reposname and not reposname in self.reposlist: 
    2119            return True 
    2220        else: 
     
    2422     
    2523    def index(self): 
    26         if self.__auth_failed(): 
     24        if self.__authz_failed(): 
    2725            return render('/auth_failed.mako') 
    2826 
     
    3533     
    3634    def access_map(self): 
    37         if self.__auth_failed(): 
     35        if self.__authz_failed(): 
    3836            return render('/auth_failed.mako') 
    3937 
     
    7876         
    7977    def get_auth_path(self, repos=None, type=None, path=None): 
    80         if self.__auth_failed(): 
     78        if self.__authz_failed(): 
    8179            return render('/auth_failed.mako') 
    8280 
  • trunk/pysvnmanager/controllers/role.py

    r19 r21  
    119119            msg = unicode(e) 
    120120 
    121         log.info(_("User %(user)s changed group: %(grp)s. (rev:%(rev)s,%(msg)s)") % \ 
     121        log.info(_(u"User %(user)s changed group: %(grp)s. (rev:%(rev)s,%(msg)s)") % \ 
    122122                 {'user':session.get('user'), 'grp': rolename, 'rev': revision, 'msg': msg} ) 
    123123         
  • trunk/pysvnmanager/model/auth/http.py

    r2 r21  
    55def htpasswd_login(username, password, config): 
    66    authn_file = getattr(config, 'authn_file', '') 
    7     try: 
    8         if authn_file: 
    9             pwdfile = open(authn_file) 
    10             for line in pwdfile: 
    11                 user, pwdhash = line.strip().split(':',1) 
    12                 if username == user: 
    13                     if pwdhash == crypt(password, pwdhash[:2]): 
    14                         return True 
    15                     break 
    16     except: 
    17         pass 
     7 
     8    if authn_file: 
     9        pwdfile = open(authn_file) 
     10        for line in pwdfile: 
     11            user, pwdhash = line.strip().split(':',1) 
     12            if username == user: 
     13                if pwdhash == crypt(password, pwdhash[:2]): 
     14                    return True 
     15                break 
    1816 
    1917    return False 
  • trunk/pysvnmanager/model/svnauthz.py

    r19 r21  
    2121    def _(message): return message 
    2222 
    23 reload(sys) # in Python2.5, method sys.setdefaultencoding  
     23#reload(sys) # in Python2.5, method sys.setdefaultencoding  
    2424            #will be delete after initialize. we need reload it. 
    25 sys.setdefaultencoding('utf-8') 
     25#sys.setdefaultencoding('utf-8') 
    2626 
    2727RIGHTS_W = 4 
     
    4040def check_valid_groupname(name): 
    4141    if name == '*': 
    42         return '' 
     42        return 
    4343    else: 
    4444        if name[0]=='$': 
     
    4848def check_valid_reposname(name): 
    4949    if name == '/': 
    50         return '' 
     50        return 
    5151    else: 
    5252        bad_chars = r'''^[\.$&@-]|[\\/:]|[*?"'<>|,;%#$]''' 
     
    5454     
    5555def check_valid_string(check_str, bad_chars=""): 
     56    check_str = normalize_user(check_str) 
    5657    msg = '' 
    5758    if not check_str: 
     
    6263        p = re.compile(bad_chars) 
    6364        if p.search(check_str): 
    64             msg = _("Name (%s) contains invalid characters.") % check_str 
    65     return msg 
     65            msg = _(u"Name (%s) contains invalid characters.") % check_str 
     66 
     67    if msg: 
     68        raise Exception, msg 
    6669 
    6770def normalize_user(name): 
    6871    if isinstance(name, basestring): 
    6972        name = name.strip() 
     73 
     74    if isinstance(name, str): 
     75        name = unicode(name, 'utf-8') 
     76 
    7077    return name 
    7178 
     
    7683    if not name: 
    7784        name = '/' 
     85 
     86    if isinstance(name, str): 
     87        name = unicode(name, 'utf-8') 
     88 
    7889    return name 
    7990 
     
    8697    elif isinstance(name, basestring) and name[0] != '/': 
    8798        name = '/'+name 
    88          
     99     
     100    if isinstance(name, str): 
     101        name = unicode(name, 'utf-8') 
     102 
    89103    return name 
    90104 
     
    119133 
    120134    def __init__(self, name): 
    121         name = name.strip() 
     135        name = normalize_user(name) 
    122136 
    123137        if not name: 
     
    148162            obj = obj.username 
    149163        elif isinstance(obj, (str, unicode)): 
    150             obj = obj.strip() 
     164            obj = normalize_user(obj) 
    151165        else: 
    152166            return False 
     
    180194    >>> a.uname 
    181195    '&aliasname' 
    182     >>> str(a) 
     196    >>> unicode(a) 
    183197    'aliasname = username' 
    184198    >>> user in a 
     
    186200    >>> user = User('jiangxin') 
    187201    >>> a.user = user 
    188     >>> str(a) 
     202    >>> unicode(a) 
    189203    'aliasname = jiangxin' 
    190204    >>> 'JiangXin' in a 
     
    197211    True 
    198212    >>> a = Alias('admin') 
    199     >>> str(a) 
     213    >>> unicode(a) 
    200214    'admin = ' 
    201215    >>> a.username 
     
    217231            raise Exception, 'Wrong parameter for userobj.' 
    218232 
    219         aliasname = aliasname.strip() 
    220  
    221         if not aliasname: 
    222             raise Exception, _('Aliasname is not provided.') 
    223         elif aliasname and aliasname[0]=='&': 
    224             raise Exception, _('Aliasname should not begin with &.') 
    225  
     233        aliasname = normalize_user(aliasname) 
     234        check_valid_aliasname(aliasname) 
    226235        self.__name = aliasname 
    227236        self.__userobj = userobj 
     
    235244 
    236245    def __get_unique_name(self): 
    237         return '&'+self.__name 
     246        return u'&'+self.__name 
    238247 
    239248    uname = property(__get_unique_name) 
     
    243252            return self.__userobj.name 
    244253        else: 
    245             return '' 
     254            return u'' 
    246255 
    247256    username = property(__get_username) 
     
    255264 
    256265    def __str__(self): 
    257         return "%s = %s" % (self.name, self.username) 
     266        return u"%s = %s" % (self.aliasname, self.username) 
    258267 
    259268    def __cmp__(self, obj): 
     
    270279            obj = obj.uname 
    271280        elif isinstance(obj, basestring): 
    272             obj = obj.strip() 
     281            obj = normalize_user(obj) 
    273282 
    274283        if not obj: 
     
    392401 
    393402    def __init__(self, name=''): 
    394         name = name.strip() 
    395  
    396         if not name: 
    397             raise Exception, _('Group name is not provided.') 
    398         elif name and name[0]=='@': 
    399             raise Exception, _('Group name should not begin with @.') 
    400  
     403        name = normalize_user(name) 
     404        check_valid_groupname(name) 
    401405        self.name = name 
    402406        self.__members = [] 
     
    404408    def __get_unique_name(self): 
    405409        if self.name[0] != '$' and self.name != '*': 
    406             return '@'+self.name 
     410            return u'@'+self.name 
    407411        else: 
    408412            return self.name 
     
    425429    def __str__(self): 
    426430        if self.name[0] != '$' and self.name != '*': 
    427             return "%s = %s" % (self.name, ', '.join(sorted(self.membernames))) 
    428         else: 
    429             return "# Built-in group: %s" % self.name 
     431            return u"%s = %s" % (self.name, ', '.join(sorted(self.membernames))) 
     432        else: 
     433            return u"# Built-in group: %s" % self.name 
    430434 
    431435    def __iter__(self): 
     
    476480            if isinstance(member, (str, unicode)): 
    477481                for user in member.split(','): 
    478                     if user.strip(): 
    479                         ulist.append(user.strip()) 
     482                    user = normalize_user(user) 
     483                    if user: 
     484                        ulist.append(user) 
    480485            elif isinstance(member, (list, tuple)): 
    481486                ulist.extend(member) 
     
    484489        for user in ulist: 
    485490            if isinstance(user, (str, unicode)): 
     491                user = normalize_user(user) 
    486492                if user not in mlist: 
    487493                    continue 
     
    513519            obj = obj.uname 
    514520        elif isinstance(obj, (str, unicode)): 
    515             obj = obj.strip() 
     521            obj = normalize_user(obj) 
    516522        else: 
    517523            return False 
     
    566572 
    567573        if autocreate: 
    568             msg = check_valid_username(name) 
    569             if msg: 
    570                 raise Exception, msg 
     574            check_valid_username(name) 
    571575            user = User(name) 
    572576            self.user_list.append(user) 
     
    592596    def get_or_set(self, name, autocreate = True): 
    593597        assert isinstance(name, basestring) 
    594  
    595598        name = normalize_user(name) 
    596599 
     
    604607 
    605608        if autocreate: 
    606             msg = check_valid_aliasname(name) 
    607             if msg: 
    608                 raise Exception, msg 
     609            check_valid_aliasname(name) 
    609610            alias = Alias(name) 
    610611            self.alias_list.append(alias) 
     
    615616    def remove(self, name): 
    616617        if isinstance(name, (str, unicode)): 
    617             alias = self.get(name.strip()) 
     618            alias = self.get(name) 
    618619        else: 
    619620            alias = name 
     
    625626 
    626627    def __str__(self): 
    627         buff = "[aliases]\n" 
     628        buff = u"[aliases]\n" 
    628629        for alias in sorted(self.alias_list): 
    629630            buff += unicode(alias) 
     
    648649    def get_or_set(self, name, autocreate = True): 
    649650        assert isinstance(name, basestring) 
    650          
    651651        name = normalize_user(name) 
    652652        if not name: 
     
    659659 
    660660        if autocreate: 
    661             msg = check_valid_groupname(name) 
    662             if msg: 
    663                 raise Exception, msg 
     661            check_valid_groupname(name) 
    664662            group = Group(name) 
    665663            self.group_list.append(group) 
     
    672670            name = name.name 
    673671        else: 
    674             name = name.strip() 
     672            name = normalize_user(name) 
    675673        item = self.get(name) 
    676674        if item: 
     
    811809        unamelist = map(lambda x: x.uname, self.__rule_list) 
    812810        for (user, rights) in rules.items(): 
    813             user = user.strip() 
     811            user = normalize_user(user) 
    814812 
    815813            if user in unamelist: 
     
    936934    """ 
    937935    def __init__(self, name): 
    938         name = name.strip() 
     936        name = normalize_repos(name) 
    939937        self.__repos_name = name 
    940938        self.__admins = [] 
    941939        self.module_list = [] 
    942         self.authz = '' 
    943940 
    944941    def __iter__(self): 
     
    950947 
    951948    def __set_name(self, name): 
    952         self.__repos_name = name.strip() 
     949        self.__repos_name = normalize_repos(name) 
    953950 
    954951    name = property(__get_name, __set_name) 
     
    10641061 
    10651062        if autocreate: 
    1066             msg = check_valid_reposname(name) 
    1067             if msg: 
    1068                 raise Exception, msg 
     1063            check_valid_reposname(name) 
    10691064            repos = Repos(name) 
    10701065            self.repos_list.append(repos) 
     
    11811176        else: 
    11821177            rev = 0 
    1183         self.__version = "%s.%d" % (major, rev) 
     1178        self.__version = u"%s.%d" % (major, rev) 
    11841179         
    11851180    def modulelist(self): 
     
    12361231                f = self.__file 
    12371232                f.truncate(0) 
    1238             f.write(unicode(self)) 
     1233            f.write(unicode(self).encode('utf-8')) 
    12391234            if isinstance(self.__file, (basestring)): 
    12401235                f.close() 
     
    12441239         
    12451240    def __str__(self): 
    1246         buff = "" 
     1241        buff = u"" 
    12471242        buff += self.compose_version() 
    12481243        buff += self.compose_acl() 
     
    12691264            path = section 
    12701265 
    1271         reposname = reposname.strip() 
    1272         path = path.strip() 
     1266        reposname = normalize_repos(reposname) 
     1267        path = normalize_path(path) 
    12731268 
    12741269        self.add_rules(reposname, path, contents, force=True) 
     
    12761271    def parse_aliases(self, aliases): 
    12771272        for (name, username) in aliases.items(): 
    1278             name = name.strip() 
    1279             username = username.strip() 
     1273            name = normalize_user(name) 
     1274            username = normalize_user(username) 
    12801275            self.add_alias(name, username) 
    12811276 
     
    12871282                i = pattern.search(acl) 
    12881283                if i: 
    1289                     name  = i.group(1).strip() 
    1290                     admin = i.group(2).strip() 
     1284                    name  = normalize_repos(i.group(1)) 
     1285                    admin = normalize_user(i.group(2)) 
    12911286                    if name and admin: 
    12921287                        repos = self.__reposlist.get_or_set(name) 
     
    13391334            admins = repos.admins 
    13401335            if admins: 
    1341                 buff += "# admin : %s = %s\n" % (repos.name, admins) 
     1336                buff += u"# admin : %s = %s\n" % (repos.name, admins) 
    13421337        return buff 
    13431338 
     
    13471342        elif isinstance(user, Alias): 
    13481343            user = user.username 
     1344        elif isinstance(user, basestring): 
     1345            user = normalize_user(user) 
    13491346        elif not user: 
    13501347            return False 
     
    13571354                admins = repos.admins 
    13581355            for i in admins.split(','): 
    1359                 if i: i = i.strip() 
     1356                if i: i = normalize_user(i) 
    13601357                 
    13611358                if not i: continue 
     
    15461543        if isinstance(members, (str, unicode)): 
    15471544            for user in members.split(','): 
    1548                 user = user.strip() 
     1545                user = normalize_user(user) 
    15491546                if user: 
    15501547                    ulist.append(user) 
     
    15811578 
    15821579    def del_alias(self, name, force=False): 
    1583         name = name.strip() 
    1584  
    15851580        alias = self.__aliaslist.get(name) 
    15861581        if not alias: 
     
    16241619    def check_rights(self, user, repos, path, required): 
    16251620        if isinstance(user, (str, unicode)): 
    1626             user = user.strip() 
     1621            user = normalize_user(user) 
    16271622        if isinstance(repos, (str, unicode)): 
    1628             repos = repos.strip() 
     1623            repos = normalize_repos(repos) 
    16291624        if isinstance(path, (str, unicode)): 
    1630             path  = path.strip().rstrip('/') 
     1625            path  = normalize_path(path) 
    16311626 
    16321627        if isinstance(required, (str, unicode)): 
     
    16831678    def get_access_map(self, user=None, reposname='/', descend=True): 
    16841679        if isinstance(user, (str, unicode)): 
    1685             user = user.strip() 
     1680            user = normalize_user(user) 
    16861681        if not user: 
    16871682            user = '*' 
     
    17181713    def get_path_access_msgs(self, user, reposname, path, abbr=False): 
    17191714        if isinstance(user, (str, unicode)): 
    1720             user = user.strip() 
     1715            user = normalize_user(user) 
    17211716        if not user: 
    17221717            user = '*' 
     
    17541749    def get_access_map_msgs(self, user='*', reposname=None, abbr=False): 
    17551750        if isinstance(user, (str, unicode)): 
    1756             user = user.strip() 
     1751            user = normalize_user(user) 
    17571752        if not user: 
    17581753            user = '*' 
  • trunk/pysvnmanager/templates/auth_failed.mako

    r2 r21  
    11## -*- coding: utf-8 -*- 
    2 <%inherit file="/base.mako" /> 
    3  
     2<h2> 
    43${_("Permission denied.")} 
     4</h2> 
  • trunk/pysvnmanager/tests/functional/test_authz.py

    r16 r21  
     1## -*- coding: utf-8 -*- 
     2 
    13from pysvnmanager.tests import * 
    24from pysvnmanager.controllers import authz 
     
    3032 
    3133    def test_init_repos_list(self): 
     34        # authn test 
     35        res = self.app.get(url_for(controller='authz', action='init_repos_list')) 
     36        assert res.status == 302 
     37        self.assertEqual(res.header('location'), '/security') 
     38 
     39        # authz test 
     40        self.login('nobody') 
     41        res = self.app.get(url_for(controller='authz', action='init_repos_list')) 
     42        assert res.status == 200, res.status 
     43        self.assert_('Permission denied.' in res.body, res.body) 
     44 
    3245        # Login as superuser 
    3346        self.login('root') 
     
    4558     
    4659    def test_repos_changed(self): 
     60        # authn test 
     61        res = self.app.get(url_for(controller='authz', action='repos_changed')) 
     62        assert res.status == 302 
     63        self.assertEqual(res.header('location'), '/security') 
     64 
     65        # authz test 
     66        self.login('nobody') 
     67        res = self.app.get(url_for(controller='authz', action='repos_changed')) 
     68        assert res.status == 200, res.status 
     69        self.assert_('Permission denied.' in res.body, res.body) 
     70 
    4771        # Login as superuser 
    4872        self.login('root') 
     
    7397''' == res.body, res.body 
    7498 
    75     def test_delete_admin(self): 
     99    def test_path_changed(self): 
     100        params={} 
     101        # authn test 
     102        res = self.app.get(url_for(controller='authz', action='path_changed')) 
     103        assert res.status == 302 
     104        self.assertEqual(res.header('location'), '/security') 
     105 
     106        # authz test 
     107        self.login('nobody') 
     108        res = self.app.get(url_for(controller='authz', action='path_changed')) 
     109        assert res.status == 200, res.status 
     110        self.assert_('Permission denied.' in res.body, res.body) 
     111 
     112        self.login('root') 
     113        params = {'reposname':'/', 'path':u'/tags//'} 
     114        res = self.app.get(url_for(controller='authz', action='path_changed'), params) 
     115        assert res.status == 200 
     116        assert '''user[0]="&pm"; 
     117rights[0]="rw"; 
     118user[1]="$authenticated"; 
     119rights[1]="r"; 
     120total=2; 
     121revision="0.2.1"; 
     122''' == res.body, res.body 
     123 
     124        self.login('root') 
     125        params = {'reposname':'document', 'path':'/trunk/商务部'} 
     126        res = self.app.get(url_for(controller='authz', action='path_changed'), params) 
     127        assert res.status == 200 
     128        assert '''user[0]="*"; 
     129rights[0]=""; 
     130user[1]="@admin"; 
     131rights[1]="rw"; 
     132user[2]="@biz"; 
     133rights[2]="rw"; 
     134total=3; 
     135revision="0.2.1"; 
     136''' == res.body, res.body 
     137 
     138        self.login('root') 
     139        params = {'reposname':'/', 'path':'/noexist'} 
     140        res = self.app.get(url_for(controller='authz', action='path_changed'), params) 
     141        assert res.status == 200 
     142        assert '' == res.body, res.body 
     143 
     144 
     145    def test_save_authz(self): 
     146        # authn test 
     147        res = self.app.get(url_for(controller='authz', action='save_authz')) 
     148        assert res.status == 302 
     149        self.assertEqual(res.header('location'), '/security') 
     150 
     151        # authz test 
     152        self.login('nobody') 
     153        res = self.app.get(url_for(controller='authz', action='save_authz')) 
     154        assert res.status == 200, res.status 
     155        self.assert_('Permission denied.' in res.body, res.body) 
     156         
    76157        # Login as superuser 
    77158        self.login('root') 
     
    95176        self.rollback() 
    96177         
     178        self.login('jiangxin') 
    97179        params = {'reposname':'/', 'admins':'root'} 
    98180        res = self.app.get(url_for(controller='authz', action='save_authz'), params) 
     
    101183        self.rollback() 
    102184 
    103  
    104  
    105          
    106185        self.login('root') 
    107186        params = {'reposname':'/repos1', 'admins':'user1'} 
    108187        res = self.app.get(url_for(controller='authz', action='save_authz'), params) 
    109         #assert res.status == 200 
    110         #assert "" == res.body, res.body 
     188        assert res.status == 200 
     189        assert "" == res.body, res.body 
    111190        self.rollback() 
    112191     
     
    114193        params = {'reposname':'/repos1', 'admins':'user1, root'} 
    115194        res = self.app.get(url_for(controller='authz', action='save_authz'), params) 
    116         #assert res.status == 200 
    117         #assert "" == res.body, res.body 
     195        assert res.status == 200 
     196        assert "" == res.body, res.body 
    118197        self.rollback() 
    119198     
     
    121200        params = {'reposname':'/repos1', 'admins':'user1, root'} 
    122201        res = self.app.get(url_for(controller='authz', action='save_authz'), params) 
    123         #assert res.status == 200 
    124         #assert "You can not delete yourself from admin list." == res.body, res.body 
     202        assert res.status == 200 
     203        assert "You can not delete yourself from admin list." == res.body, res.body 
    125204 
    126205        self.login('admin1') 
    127206        params = {'reposname':'/repos1', 'admins':'admin1, admin2'} 
    128207        res = self.app.get(url_for(controller='authz', action='save_authz'), params) 
    129         #assert res.status == 200 
    130         #assert "" == res.body, res.body 
    131         self.rollback() 
    132      
    133  
    134     def test_save_authz(self): 
    135         pass 
     208        assert res.status == 200 
     209        assert "" == res.body, res.body 
     210        self.rollback() 
    136211     
    137212    def test_delete_authz(self): 
    138         pass 
    139          
     213        # authn test 
     214        res = self.app.get(url_for(controller='authz', action='delete_authz')) 
     215        assert res.status == 302 
     216        self.assertEqual(res.header('location'), '/security') 
     217 
     218        # authz test 
     219        self.login('nobody') 
     220        res = self.app.get(url_for(controller='authz', action='delete_authz')) 
     221        assert res.status == 200, res.status 
     222        self.assert_('Permission denied.' in res.body, res.body) 
  • trunk/pysvnmanager/tests/functional/test_check.py

    r17 r21  
     1## -*- coding: utf-8 -*- 
     2 
    13from pysvnmanager.tests import * 
    24from pysvnmanager.controllers import check 
     
    3436 
    3537 
    36     def test_path_authz(self): 
     38    def test_access_map(self): 
     39        # authn test 
     40        res = self.app.get(url_for(controller='check', action='access_map')) 
     41        assert res.status == 302 
     42        self.assertEqual(res.header('location'), '/security') 
     43 
     44        # authz test 
     45        self.login('nobody') 
     46        res = self.app.get(url_for(controller='check', action='access_map')) 
     47        assert res.status == 200, res.status 
     48        self.assert_('Permission denied.' in res.body, res.body) 
     49         
    3750        # Login as superuser 
    3851        self.login('root') 
     
    4255                  'reposinput':'select',  
    4356                  'reposselector':'///repos1', 
    44                   'pathinput':'manual', 
    45                   'pathname':'/trunk/src/test', 
     57                  'pathinput':'select', 
     58                  'pathselector':'/trunk/src/test', 
    4659                  'abbr':'True', 
    4760                  } 
     
    5063        assert '''<div id='acl_path_msg'>[repos1:/trunk/src/test] user1 =</div>''' in res.body, res.body 
    5164 
     65        params['userinput'] = 'select' 
     66        params['reposinput'] = 'select' 
     67        params['pathinput'] = 'select' 
    5268        params['userselector'] = 'user1' 
    5369        params['reposselector'] = 'reposX' 
    54         params['pathname'] = '/trunk/src/test' 
     70        params['pathselector'] = '/trunk/src/test' 
    5571        res = self.app.get(url_for(controller='check', action='access_map'), params) 
    5672        assert '''<div id='acl_path_msg'>[reposX:/trunk/src/test] user1 = r</div>''' in res.body, res.body 
    5773 
    58         params['userselector'] = 'user2' 
    59         params['reposselector'] = 'repos1' 
     74        params['userinput'] = 'manual' 
     75        params['reposinput'] = 'manual' 
     76        params['pathinput'] = 'manual' 
     77        params['username'] = 'user2' 
     78        params['reposname'] = 'repos1' 
    6079        params['pathname'] = '/trunk/src/test' 
    6180        res = self.app.get(url_for(controller='check', action='access_map'), params) 
    6281        assert '''<div id='acl_path_msg'>[repos1:/trunk/src/test] user2 = r</div>''' in res.body, res.body 
    6382 
     83        params['userinput'] = 'select' 
     84        params['reposinput'] = 'select' 
     85        params['pathinput'] = 'manual' 
    6486        params['userselector'] = 'user2' 
    6587        params['reposselector'] = 'reposX' 
     
    6890        assert '''<div id='acl_path_msg'>[reposX:/trunk] user2 =</div>''' in res.body, res.body 
    6991 
     92        params['userinput'] = 'select' 
     93        params['reposinput'] = 'select' 
     94        params['pathinput'] = 'select' 
    7095        params['userselector'] = 'user3' 
    7196        params['reposselector'] = 'repos1' 
    72         params['pathname'] = '/trunk' 
     97        params['pathselector'] = '/trunk' 
    7398        res = self.app.get(url_for(controller='check', action='access_map'), params) 
    7499        assert '''<div id='acl_path_msg'>[repos1:/trunk] user3 =</div>''' in res.body, res.body 
     
    76101        params['userselector'] = 'user4' 
    77102        params['reposselector'] = 'repos1' 
    78         params['pathname'] = '/trunk' 
     103        params['pathselector'] = '/trunk' 
    79104        res = self.app.get(url_for(controller='check', action='access_map'), params) 
    80105        assert '''<div id='acl_path_msg'>[repos1:/trunk] user4 = r</div>''' in res.body, res.body 
     
    82107        params['userselector'] = 'user4' 
    83108        params['reposselector'] = 'reposX' 
    84         params['pathname'] = '/trunk' 
     109        params['pathselector'] = '/trunk' 
    85110        res = self.app.get(url_for(controller='check', action='access_map'), params) 
    86111        assert '''<div id='acl_path_msg'>[reposX:/trunk] user4 = r</div>''' in res.body, res.body 
     
    88113        params['userselector'] = 'user5' 
    89114        params['reposselector'] = 'reposX' 
    90         params['pathname'] = '/trunk' 
     115        params['pathselector'] = '/trunk' 
    91116        res = self.app.get(url_for(controller='check', action='access_map'), params) 
    92117        assert '''<div id='acl_path_msg'>[reposX:/trunk] user5 =</div>''' in res.body, res.body 
    93118 
    94119 
    95     def test_access_map(self): 
    96         # Test redirect to login pange 
    97         res = self.app.get(url_for(controller='check', action='access_map')) 
     120    def test_authz_path(self): 
     121        # authn test 
     122        res = self.app.get(url_for(controller='check', action='get_auth_path')) 
    98123        assert res.status == 302 
    99124        self.assertEqual(res.header('location'), '/security') 
    100125 
    101         # Login as common user 
     126        # authz test 
    102127        self.login('nobody') 
    103         res = self.app.get(url_for(controller='check', action='access_map')) 
     128        res = self.app.get(url_for(controller='check', action='get_auth_path')) 
     129        assert res.status == 200, res.status 
     130        self.assert_('Permission denied.' in res.body, res.body) 
     131 
     132        self.login('root') 
     133        params = {} 
     134        params['repos'] = '/' 
     135        res = self.app.get(url_for(controller='check', action='get_auth_path'), params) 
    104136        assert res.status == 200 
    105         assert 'Permission denied.' in res.body, res.body 
     137        assert '''id[0]="...";name[0]="Please choose..."; 
     138id[1]="/trunk/src";name[1]="/trunk/src"; 
     139id[2]="/trunk";name[2]="/trunk"; 
     140id[3]="/";name[3]="/"; 
     141id[4]="/tags";name[4]="/tags"; 
     142id[5]="/branches";name[5]="/branches"; 
     143total=6; 
     144''' == res.body, res.body 
    106145 
    107         # Login as common user 
    108         self.login('admin1') 
    109         res = self.app.get(url_for(controller='check', action='access_map')) 
     146        params['repos'] = 'noexist' 
     147        res = self.app.get(url_for(controller='check', action='get_auth_path'), params) 
    110148        assert res.status == 200 
    111         assert 'Permission denied.' == res.body, res.body 
    112          
    113         params = { 
    114                   'userinput':'select',  
    115                   'userselector':'user1', 
    116                   'reposinput':'select',  
    117                   'reposselector':'repos1', 
    118                   'pathinput':'manual', 
    119                   'pathname':'/trunk/src/test', 
    120                   'abbr':'True', 
    121                   } 
    122         res = self.app.get(url_for(controller='check', action='access_map'), params) 
     149        assert '' == res.body, res.body 
     150 
     151        params['repos'] = 'repos1' 
     152        res = self.app.get(url_for(controller='check', action='get_auth_path'), params) 
    123153        assert res.status == 200 
    124         assert '''<div id='acl_path_msg'>[repos1:/trunk/src/test] user1 =</div>''' in res.body, res.body 
     154        assert '''id[0]="...";name[0]="Please choose..."; 
     155id[1]="/trunk/src";name[1]="/trunk/src"; 
     156id[2]="/trunk";name[2]="/trunk"; 
     157id[3]="/";name[3]="/"; 
     158total=4; 
     159''' == res.body, res.body 
    125160 
    126         params['reposselector'] = 'reposX' 
    127         res = self.app.get(url_for(controller='check', action='access_map'), params) 
    128         assert 'Permission denied.' == res.body, res.body 
     161        params['repos'] = 'document' 
     162        res = self.app.get(url_for(controller='check', action='get_auth_path'), params) 
     163        assert res.status == 200 
     164        assert u'''id[0]="...";name[0]="Please choose..."; 
     165id[1]="/branches";name[1]="/branches"; 
     166id[2]="/tags";name[2]="/tags"; 
     167id[3]="/trunk/.htgroup";name[3]="/trunk/.htgroup"; 
     168id[4]="/trunk/tech";name[4]="/trunk/tech"; 
     169id[5]="/trunk/tech/.htaccess";name[5]="/trunk/tech/.htaccess"; 
     170id[6]="/trunk/商务部";name[6]="/trunk/商务部"; 
     171id[7]="/trunk/商务部/.htaccess";name[7]="/trunk/商务部/.htaccess"; 
     172id[8]="/trunk/行政部";name[8]="/trunk/行政部"; 
     173id[9]="/trunk/行政部/.htaccess";name[9]="/trunk/行政部/.htaccess"; 
     174total=10; 
     175''' == unicode(res.body, 'utf-8'), res.body 
  • trunk/pysvnmanager/tests/functional/test_login.py

    r4 r21  
     1## -*- coding: utf-8 -*- 
     2 
    13from pysvnmanager.tests import * 
     4from pylons import config 
    25 
    36class TestLoginController(TestController): 
    47 
    5     def test_index(self): 
    6         response = self.app.get(url_for(controller='login')) 
    7         # Test response... 
     8    def test_login_logout(self): 
     9        params={} 
     10        # login successful 
     11        params['username'] = 'root' 
     12        d = eval(config.get('test_users', {})) 
     13        password = d.get(params['username'],'') 
     14        params['password'] = password 
     15        res = self.app.get(url_for(controller='security', action='submit'), params) 
     16        self.assert_(res.status == 302) 
     17        self.assert_(res.all_headers('location') == ['/check']) 
     18        self.assert_(res.session['user'] == 'root', res.session) 
     19         
     20        # keep session test 
     21        res = self.app.get(url_for(controller='security', action='index')) 
     22        self.assert_('<h2>Login</h2>' in res.body, res.body) 
     23        self.assert_(res.session['user'] == 'root', res.session) 
     24                                    
     25        # login with wrong password 
     26        params['username'] = 'root' 
     27        params['password'] = 'wrong_passwd' 
     28        res = self.app.get(url_for(controller='security', action='submit'), params) 
     29        self.assert_(res.status == 200, res.status) 
     30        self.assert_('Login failed for user: root' in res.body, res.body) 
     31        self.assert_(res.session.get('user') == None, res.session.get('user')) 
     32         
     33        self.login('jiangxin') 
     34        res = self.app.get(url_for(controller='security', action='index')) 
     35        self.assert_(res.session.get('user') == 'jiangxin', res.session) 
     36 
     37        # logout 
     38        res = self.app.get(url_for(controller='security', action='logout')) 
     39        self.assert_(res.status == 302) 
     40        self.assert_(res.all_headers('location') == ['/security']) 
     41        self.assert_(res.session.get('user') == None, res.session.get('user')) 
  • trunk/pysvnmanager/tests/functional/test_role.py

    r16 r21  
     1## -*- coding: utf-8 -*- 
     2 
    13from pysvnmanager.tests import * 
    24from pysvnmanager.controllers import role 
     
    2931 
    3032    def test_get_role_info(self): 
     33        # authn test 
     34        res = self.app.get(url_for(controller='role', action='get_role_info')) 
     35        assert res.status == 302 
     36        self.assertEqual(res.header('location'), '/security') 
     37 
     38        # authz test 
     39        self.login('nobody') 
     40        res = self.app.get(url_for(controller='role', action='get_role_info')) 
     41        assert res.status == 200, res.status 
     42        self.assert_('Permission denied.' in res.body, res.body) 
     43         
    3144        # Login as superuser 
    3245        self.login('root') 
     
    8194 
    8295    def test_save_group(self): 
    83         pass 
     96        # authn test 
     97        res = self.app.get(url_for(controller='role', action='save_group')) 
     98        assert res.status == 302 
     99        self.assertEqual(res.header('location'), '/security') 
     100 
     101        # authz test 
     102        self.login('nobody') 
     103        res = self.app.get(url_for(controller='role', action='save_group')) 
     104        assert res.status == 200, res.status 
     105        self.assert_('Permission denied.' in res.body, res.body) 
    84106 
    85107    def test_delete_group(self): 
    86         pass 
     108        # authn test 
     109        res = self.app.get(url_for(controller='role', action='delete_group')) 
     110        assert res.status == 302 
     111        self.assertEqual(res.header('location'), '/security') 
     112 
     113        # authz test 
     114        self.login('nobody') 
     115        res = self.app.get(url_for(controller='role', action='delete_group')) 
     116        assert res.status == 200, res.status 
     117        self.assert_('Permission denied.' in res.body, res.body) 
    87118 
    88119    def test_save_alias(self): 
    89         pass 
     120        # authn test 
     121        res = self.app.get(url_for(controller='role', action='save_alias')) 
     122        assert res.status == 302 
     123        self.assertEqual(res.header('location'), '/security') 
     124 
     125        # authz test 
     126        self.login('nobody') 
     127        res = self.app.get(url_for(controller='role', action='save_alias')) 
     128        assert res.status == 200, res.status 
     129        self.assert_('Permission denied.' in res.body, res.body) 
    90130 
    91131    def test_delete_alias(self): 
    92         pass 
     132        # authn test 
     133        res = self.app.get(url_for(controller='role', action='delete_alias')) 
     134        assert res.status == 302 
     135        self.assertEqual(res.header('location'), '/security') 
    93136 
     137        # authz test 
     138        self.login('nobody') 
     139        res = self.app.get(url_for(controller='role', action='delete_alias')) 
     140        assert res.status == 200, res.status 
     141        self.assert_('Permission denied.' in res.body, res.body) 
  • trunk/pysvnmanager/tests/test_models.py

    r19 r21  
    2828# admin : repos3 = admin3 
    2929# admin : reposx =  
     30# admin : 版本库1 = @管理组1 
    3031 
    3132[groups] 
     
    3940team3=user3,user33,@team1 
    4041all=@team1,user3,user4 
     42组1=&别名1, 用户2 
     43管理组1=&别名1, 蒋鑫 
    4144 
    4245[aliases] 
    4346admin=jiangxin 
    4447007=james 
     48别名1=用户1 
    4549 
    4650[repos1:/trunk/src] 
     
    7579@all = r 
    7680@admins = rw 
     81 
     82[版本库1:/] 
     83* =  
     84@管理组1 = rw 
     85 
     86[版本库1:/项目1] 
     87* =  
     88@组1 = rw 
     89用户3 = r 
    7790        ''' 
    7891        assert(self.f.tell()==0) 
     
    8699    def testUser(self): 
    87100        user1 = User('Tom') 
    88         self.assert_(str(user1) == 'Tom') 
     101        self.assert_(unicode(user1) == 'Tom') 
    89102        self.assertRaises(Exception, User, "") 
    90103        user2 = User('Jerry') 
     
    105118        alias1=Alias('admin') 
    106119        alias1.user = user1 
    107         self.assert_(str(alias1) == 'admin = Tom', str(alias1)) 
     120        self.assert_(unicode(alias1) == 'admin = Tom', unicode(alias1)) 
    108121        alias2=Alias('manager', user1) 
    109         self.assert_(str(alias2) == 'manager = Tom', str(alias1)) 
     122        self.assert_(unicode(alias2) == 'manager = Tom', unicode(alias1)) 
    110123 
    111124        self.assert_('&Manager' in alias2) 
     
    146159 
    147160        group1.append([group2, alias]) 
    148         self.assert_(str(group1) == 'team1 = &admin, @team2, user1, user2', str(group1)) 
     161        self.assert_(unicode(group1) == 'team1 = &admin, @team2, user1, user2', unicode(group1)) 
    149162        self.assert_([m.uname for m in group1] == ['user1', 'user2', '@team2', '&admin'], [m.uname for m in group1]) 
    150163         
     
    186199         
    187200        g = Group('$authenticated') 
    188         self.assert_(str(g) == "# Built-in group: $authenticated") 
     201        self.assert_(unicode(g) == "# Built-in group: $authenticated") 
    189202 
    190203    def testIsValidName(self): 
    191         self.assert_(check_valid_username('蒋,鑫')=="Name (蒋,鑫) contains invalid characters.") 
    192         self.assert_(check_valid_username('jiang;xin')=="Name (jiang;xin) contains invalid characters.") 
    193         self.assert_(check_valid_username('')=="Name is not given.", check_valid_username('')) 
    194         self.assert_(check_valid_username(User('user'))=="Name is not string.") 
    195         self.assert_(check_valid_reposname('my/repos')=="Name (my/repos) contains invalid characters.") 
    196         self.assert_(check_valid_reposname('/')=="") 
     204        self.assertRaises(Exception, check_valid_username, '蒋,鑫') 
     205        self.assertRaises(Exception, check_valid_username, 'jiang;xin') 
     206        self.assertRaises(Exception, check_valid_username, '') 
     207        self.assertRaises(Exception, check_valid_username, User('user')) 
     208        self.assertRaises(Exception, check_valid_reposname, 'my/repos') 
     209        check_valid_reposname('/') 
    197210         
    198211    def testUserList(self): 
     
    232245        self.assert_([a.uname for a in alist] == ['&admin', '&root'], [a.uname for a in alist]) 
    233246 
    234         self.assert_(str(alist)=="[aliases]\nadmin = \nroot = \n", repr(str(alist))) 
     247        self.assert_(unicode(alist)=="[aliases]\nadmin = \nroot = \n", repr(unicode(alist))) 
    235248         
    236249        self.assert_(alist.get_or_set('')==None) 
     
    269282        self.assert_([g.uname for g in glist] == ['@team1', '@team2'], [g.uname for g in glist]) 
    270283 
    271         self.assert_(str(glist)=="[groups]\nteam1 = @team2, user1\nteam2 = &admin, user2\n", repr(str(glist))) 
     284        self.assert_(unicode(glist)=="[groups]\nteam1 = @team2, user1\nteam2 = &admin, user2\n", repr(unicode(glist))) 
    272285         
    273286        self.assert_(glist.get_or_set('')==None) 
     
    282295        self.assertRaises(Exception, glist.remove, '@team2') 
    283296        self.assertRaises(Exception, glist.remove, g2) 
    284         self.assert_(str(glist)=='[groups]\nteam1 = @team2, user1\nteam2 = &admin, user2\n', repr(str(glist))) 
     297        self.assert_(unicode(glist)=='[groups]\nteam1 = @team2, user1\nteam2 = &admin, user2\n', repr(unicode(glist))) 
    285298        glist.remove('@team2',force=True) 
    286299        glist.remove('notexist') 
    287         self.assert_(str(glist)=="[groups]\nteam1 = user1\n", repr(str(glist))) 
     300        self.assert_(unicode(glist)=="[groups]\nteam1 = user1\n", repr(unicode(glist))) 
    288301         
    289302    def testRules(self): 
     
    302315        rule1.rights = RIGHTS_ALL 
    303316        self.assert_(rule1.rights == RIGHTS_R|RIGHTS_W) 
    304         self.assert_(str(rule1)=='@group1 = rw', repr(str(rule1))) 
     317        self.assert_(unicode(rule1)=='@group1 = rw', repr(unicode(rule1))) 
    305318        self.assert_(rule1.get_permission(group1) == (RIGHTS_ALL, RIGHTS_NONE)) 
    306319        self.assert_(rule1.get_permission(user1) == (RIGHTS_ALL, RIGHTS_NONE)) 
     
    313326        rulelist = [rule1, rule0] 
    314327        rulelist.append('@choose...') 
    315         self.assert_([str(r) for r in rulelist]==['@group1 = rw', '@group0 = ', '@choose...'], [str(r) for r in rulelist]) 
    316         self.assert_([str(r) for r in sorted(rulelist)]==['@group0 = ', '@group1 = rw', '@choose...'], [str(r) for r in sorted(rulelist)]) 
     328        self.assert_([unicode(r) for r in rulelist]==['@group1 = rw', '@group0 = ', '@choose...'], [unicode(r) for r in rulelist]) 
     329        self.assert_([unicode(r) for r in sorted(rulelist)]==['@group0 = ', '@group1 = rw', '@choose...'], [unicode(r) for r in sorted(rulelist)]) 
    317330         
    318331 
     
    321334        self.assert_(module.path == '/trunk') 
    322335        self.assert_(module.fullname == '/:/trunk') 
    323         self.assert_(str(module)=='') 
     336        self.assert_(unicode(module)=='') 
    324337         
    325338        obj = Group('* ') 
     
    333346        obj = Group(' $authenticated ') 
    334347        module.update_rule(obj, 'r') 
    335         self.assert_(str(module) ==  
     348        self.assert_(unicode(module) ==  
    336349'''[/trunk] 
    337350$authenticated = r 
     
    339352@admins = rw 
    340353jiang =  
    341 ''', repr(str(module))) 
    342         self.assert_([str(r) for r in module]==['* = r', '@admins = rw', 'jiang = ', '$authenticated = r'], [str(r) for r in module]) 
    343         self.assert_([str(r) for r in module.rules]==['* = r', '@admins = rw', 'jiang = ', '$authenticated = r'], [str(r) for r in module.rules]) 
     354''', repr(unicode(module))) 
     355        self.assert_([unicode(r) for r in module]==['* = r', '@admins = rw', 'jiang = ', '$authenticated = r'], [unicode(r) for r in module]) 
     356        self.assert_([unicode(r) for r in module.rules]==['* = r', '@admins = rw', 'jiang = ', '$authenticated = r'], [unicode(r) for r in module.rules]) 
    344357         
    345358        module.del_rule('@admins= rw') 
    346         self.assert_([str(r) for r in module]==['* = r', 'jiang = ', '$authenticated = r'], [str(r) for r in module]) 
     359        self.assert_([unicode(r) for r in module]==['* = r', 'jiang = ', '$authenticated = r'], [unicode(r) for r in module]) 
    347360         
    348361        module = Module('myrepos', '') 
     
    357370        groupauth = Group('$authenticated') 
    358371        module.update_rule(groupauth,'r') 
    359         self.assert_(str(module) == '''[myrepos:/] 
     372        self.assert_(unicode(module) == '''[myrepos:/] 
    360373$authenticated = r 
    361374* =  
    362375@team1 = rw 
    363376jiang =  
    364 ''', repr(str(module))) 
     377''', repr(unicode(module))) 
    365378        self.assert_(module.get_permit_bits(user1)==(RIGHTS_R, RIGHTS_ALL),module.get_permit_bits(user1)) 
    366379        self.assert_(module.get_permit_str(user1)=='r',module.get_permit_str(user1)) 
     
    378391         
    379392        module.clean_rules() 
    380         self.assert_([str(r) for r in module]==[], [str(r) for r in module]) 
     393        self.assert_([unicode(r) for r in module]==[], [unicode(r) for r in module]) 
    381394 
    382395        self.assert_(Module('repos1', '/trunk')>Module('repos0', '/trunk')) 
     
    428441        mod2.update_rule(alias1,'rw') 
    429442 
    430         self.assert_(str(repos1)=='[repos1:/tags]\n&alias1 = rw\n\n[repos1:/trunk]\nuser1 = r\n\n', repr(str(repos1))) 
     443        self.assert_(unicode(repos1)=='[repos1:/tags]\n&alias1 = rw\n\n[repos1:/trunk]\nuser1 = r\n\n', repr(unicode(repos1))) 
    431444         
    432445        repos1.del_all_modules() 
     
    461474        self.assertRaises(Exception, rlist.get_or_set, 'wrong/repos') 
    462475         
    463         self.assert_(str(rlist)=='[repos2:/trunk]\nuser1 = r\n\n', repr(str(rlist))) 
     476        self.assert_(unicode(rlist)=='[repos2:/trunk]\nuser1 = r\n\n', repr(unicode(rlist))) 
    464477         
    465478        self.assert_([r.name for r in rlist] == ['/', 'repos1', 'repos2'], [r.name for r in rlist]) 
     
    486499        admin = authz.add_alias('admin', 'u1') 
    487500        team1 = authz.add_group('team1') 
    488         self.assert_(str(team1)=='team1 = ', str(team1)) 
     501        self.assert_(unicode(team1)=='team1 = ', unicode(team1)) 
    489502        team1 = authz.set_group('team1', None) 
    490         self.assert_(str(team1)=='team1 = ', str(team1)) 
     503        self.assert_(unicode(team1)=='team1 = ', unicode(team1)) 
    491504        team1 = authz.set_group('team1', 'u2, u3') 
    492         self.assert_(str(team1)=='team1 = u2, u3', str(team1)) 
     505        self.assert_(unicode(team1)=='team1 = u2, u3', unicode(team1)) 
    493506        team1 = authz.add_group_member('team1', u4) 
    494         self.assert_(str(team1)=='team1 = u2, u3, u4', str(team1)) 
     507        self.assert_(unicode(team1)=='team1 = u2, u3, u4', unicode(team1)) 
    495508        repos1 = authz.add_repos('repos1') 
    496509         
     
    522535        self.assert_(rl.get('repos2').admins == 'admin2', rl.get('repos2').admins) 
    523536        self.assert_(self.authz.compose_acl() ==  
    524 '''# admin : / = &admin, root 
     537u'''# admin : / = &admin, root 
    525538# admin : repos1 = @admin 
    526539# admin : repos2 = admin2 
    527540# admin : repos3 = admin3 
    528 ''', self.authz.compose_acl()) 
     541# admin : 版本库1 = @管理组1 
     542''', repr(self.authz.compose_acl())) 
    529543        pass 
    530544 
    531545    def testAuthzConfAliases(self): 
    532546        al = self.authz.aliaslist 
    533         self.assert_(al.get('admin').username == 'jiangxin', str(al.get('admin'))) 
    534         self.assert_(str(al) == '[aliases]\n007 = james\nadmin = jiangxin\n', repr(str(al))) 
     547        self.assert_(al.get('admin').username == 'jiangxin', unicode(al.get('admin'))) 
     548        self.assert_(unicode(al) == u'[aliases]\n007 = james\nadmin = jiangxin\n别名1 = 用户1\n', repr(unicode(al))) 
    535549        pass 
    536550 
     
    545559                     ['@team1', 'user3', 'user4'], 
    546560                     sorted(gl.get('all').membernames)) 
    547         self.assert_(str(gl) ==  
    548             '''[groups] 
     561        self.assert_(unicode(gl) ==  
     562            u'''[groups] 
    549563admin = &admin, admin1, admin2, admin3 
    550564admins = &007, &admin 
     
    553567team2 = @team3, user2, user22 
    554568team3 = user3, user33 
    555 ''', repr(str(gl))) 
     569管理组1 = &别名1, 蒋鑫 
     570组1 = &别名1, 用户2 
     571''', repr(unicode(gl))) 
    556572 
    557573     
     
    622638        self.assert_(isinstance(self.authz.add_alias('superuser', user), Alias)) 
    623639        self.assert_(isinstance(self.authz.add_alias('root', user), Alias)) 
    624         self.assert_(str(self.authz.aliaslist) == '[aliases]\nroot = jiangxin\nsuperuser = jiangxin\n', repr(str(self.authz.aliaslist))) 
     640        self.assert_(unicode(self.authz.aliaslist) == '[aliases]\nroot = jiangxin\nsuperuser = jiangxin\n', repr(unicode(self.authz.aliaslist))) 
    625641        self.assert_(','.join(map(lambda x:x.name, self.authz.aliaslist)) == 
    626642                     'superuser,root', ','.join(map(lambda x:x.name, 
     
    628644 
    629645        # add_group 
    630         self.assert_(str(self.authz.grouplist) == '[groups]\n', repr(str(self.authz.grouplist))) 
     646        self.assert_(unicode(self.authz.grouplist) == '[groups]\n', repr(unicode(self.authz.grouplist))) 
    631647        self.assert_(isinstance(self.authz.add_group('myteam','user1'), Group)) 
    632         self.assert_(str(self.authz.grouplist) == '[groups]\nmyteam = user1\n', repr(str(self.authz.grouplist))) 
     648        self.assert_(unicode(self.authz.grouplist) == '[groups]\nmyteam = user1\n', repr(unicode(self.authz.grouplist))) 
    633649        self.assert_(isinstance(self.authz.add_group_member('myteam','user2,user3'), Group)) 
    634650        self.assert_(isinstance(self.authz.add_group_member('myteam','user2,user3'), Group)) 
    635         self.assert_(str(self.authz.grouplist) == '[groups]\nmyteam = user1, user2, user3\n', repr(str(self.authz.grouplist))) 
     651        self.assert_(unicode(self.authz.grouplist) == '[groups]\nmyteam = user1, user2, user3\n', repr(unicode(self.authz.grouplist))) 
    636652        self.assert_(','.join(map(lambda x:x.name, self.authz.grouplist)) == 
    637653                     'myteam', ','.join(map(lambda x:x.name, 
     
    643659        self.assert_(isinstance(self.authz.add_group_member('team4','@myteam'),Group)) 
    644660        self.assertRaises(Exception, self.authz.add_group_member, 'myteam','@team3, @team4, @team5') 
    645         self.assert_(str(self.authz.grouplist.get('@myteam')) ==  
     661        self.assert_(unicode(self.authz.grouplist.get('@myteam')) ==  
    646662                     'myteam = $authenticated, *, @team1, @team2, user1, user2, user3',  
    647                      repr(str(self.authz.grouplist.get('@myteam'))))  
     663                     repr(unicode(self.authz.grouplist.get('@myteam'))))  
    648664        self.assert_(isinstance(self.authz.add_group_member('myteam','@team3, @team4, @team5', True),Group)) 
    649         self.assert_(str(self.authz.grouplist.get('@myteam')) ==  
     665        self.assert_(unicode(self.authz.grouplist.get('@myteam')) ==  
    650666                     'myteam = $authenticated, *, @team1, @team2, @team5, user1, user2, user3',  
    651                      repr(str(self.authz.grouplist.get('@myteam'))))  
     667                     repr(unicode(self.authz.grouplist.get('@myteam'))))  
    652668        self.assertRaises(Exception, self.authz.del_group, '@team2') 
    653         self.assert_(str(self.authz.grouplist.get('@team2')) == 'team2 = $authenticated, *',  
     669        self.assert_(unicode(self.authz.grouplist.get('@team2')) == 'team2 = $authenticated, *',  
    654670                     self.authz.grouplist.get('@team2')) 
    655671        self.authz.del_group('@team2',force=True) 
    656672        self.assert_(self.authz.grouplist.get('@team2') == None,  
    657                      str(self.authz.grouplist.get('@team2'))) 
    658         self.assert_(str(self.authz.grouplist.get('@myteam')) ==  
     673                     unicode(self.authz.grouplist.get('@team2'))) 
     674        self.assert_(unicode(self.authz.grouplist.get('@myteam')) ==  
    659675                     'myteam = $authenticated, *, @team1, @team5, user1, user2, user3', 
    660                      repr(str(self.authz.grouplist.get('@myteam'))))  
    661         self.assert_(str(self.authz.grouplist.get('@team1')) == 'team1 = ', 
    662                      repr(str(self.authz.grouplist.get('@team1'))))  
     676                     repr(unicode(self.authz.grouplist.get('@myteam'))))  
     677        self.assert_(unicode(self.authz.grouplist.get('@team1')) == 'team1 = ', 
     678                     repr(unicode(self.authz.grouplist.get('@team1'))))  
    663679 
    664680        # add_rule  
     
    682698        self.assert_(self.authz.add_rules('/', '/trunk/', '&superuser=r; *=rw') == True, self.authz.add_rules('/', '/trunk/', '&superuser=rw')) 
    683699        self.assert_(self.authz.add_rules('/', '/trunk/', '&superuser=rw\n *=r') == True, self.authz.add_rules('/', '/trunk/', '&superuser=rw')) 
    684         self.assert_(str(self.authz.get_module('repos1', '/')) == '[repos1:/]\n* = r\n', repr(str(self.authz.get_module('repos1', '/')))) 
     700        self.assert_(unicode(self.authz.get_module('repos1', '/')) == '[repos1:/]\n* = r\n', repr(unicode(self.authz.get_module('repos1', '/')))) 
    685701        self.assert_(self.authz.add_rules('repos1', '/', ['*=', '@team1=rw']) == True) 
    686         self.assert_(str(self.authz.get_module('repos1', '/')) == '[repos1:/]\n* = \n@team1 = rw\n', repr(str(self.authz.get_module('repos1', '/')))) 
    687         self.assert_(','.join(map(lambda x:str(x), self.authz.rulelist())) == 
     702        self.assert_(unicode(self.authz.get_module('repos1', '/')) == '[repos1:/]\n* = \n@team1 = rw\n', repr(unicode(self.authz.get_module('repos1', '/')))) 
     703        self.assert_(','.join(map(lambda x:unicode(x), self.authz.rulelist())) == 
    688704                     '&superuser = rw,* = r,* = ,@team1 = rw', ','.join(map(lambda 
    689                                                                       x:str(x), 
     705                                                                      x:unicode(x), 
    690706                                                                      self.authz.rulelist()))) 
    691707        self.assertRaises(Exception, self.authz.chk_grp_ref_by_rules, '*') 
     
    695711        self.assert_(self.authz.del_rule('norepos', '/nopath', ['*=rw']) == False) 
    696712        self.assert_(self.authz.del_rule('repos1', '/', ['*=rw']) == True) 
    697         self.assert_(str(self.authz.get_module('repos1', '/')) == '[repos1:/]\n@team1 = rw\n', repr(str(self.authz.get_module('repos1', '/')))) 
     713        self.assert_(unicode(self.authz.get_module('repos1', '/')) == '[repos1:/]\n@team1 = rw\n', repr(unicode(self.authz.get_module('repos1', '/')))) 
    698714        self.assert_(','.join(map(lambda x:x.name, self.authz.grouplist)) == 
    699715                     'myteam,team1,*,$authenticated,team3,team4,team5', 
     
    727743        self.assert_(isinstance(self.authz.add_group_member('myteam','user1,user2,user3'),Group)) 
    728744        self.assert_(self.authz.del_group_member('myteam','user1,user3') == True) 
    729         self.assert_(str(self.authz.grouplist) ==  
     745        self.assert_(unicode(self.authz.grouplist) ==  
    730746                     '[groups]\nmyteam = user2\nteam1 = \nteam3 = @team4\nteam4 = \nteam5 = \n', 
    731                      repr(str(self.authz.grouplist))) 
     747                     repr(unicode(self.authz.grouplist))) 
    732748 
    733749        # del_module 
     
    739755 
    740756        # del_repos 
    741         #self.assert_(str(self.authz) == '', str(self.authz)) 
     757        #self.assert_(unicode(self.authz) == '', unicode(self.authz)) 
    742758        self.assert_(self.authz.get_repos('/').is_blank() == False) 
    743759        self.assert_(self.authz.get_repos('repos2').is_blank() == True) 
     
    751767 
    752768        # output config from __str__ 
    753         self.assert_(str(self.authz) ==  
     769        self.assert_(unicode(self.authz) ==  
    754770                     '# version : 0.0\n# admin : / = admin1, admin2\n\n[groups]\nmyteam = user2\nteam1 = \nteam3 = @team4\nteam4 = \nteam5 = \n\n[aliases]\nsuperuser = jiangxin\n\n',  
    755                      repr(str(self.authz))) 
     771                     repr(unicode(self.authz))) 
    756772 
    757773    def testAuthzConfDefault(self): 
     
    794810        # SvnAuthz __str__ test 
    795811        self.authz.update_revision() 
    796         self.assert_(str(self.authz) == 
    797 """# version : 0.1.3 
     812        self.assert_(unicode(self.authz) == 
     813u"""# version : 0.1.3 
    798814# admin : / = admin1, admin2 
    799815# admin : repos1 = admin1, admin2 
    800816# admin : repos2 = admin2 
    801817# admin : repos3 = admin3 
     818# admin : 版本库1 = @管理组1 
    802819 
    803820[groups] 
     
    808825team2 = @team3, user2, user22 
    809826team3 = user3, user33 
     827管理组1 = &别名1, 蒋鑫 
     828组1 = &别名1, 用户2 
    810829 
    811830[aliases] 
    812831007 = james 
    813832admin = jiangxin 
     833别名1 = 用户1 
    814834 
    815835[/] 
     
    844864user1 =  
    845865 
    846 """, (repr(str(self.authz)))) 
     866[版本库1:/] 
     867* =  
     868@管理组1 = rw 
     869 
     870[版本库1:/项目1] 
     871* =  
     872@组1 = rw 
     873用户3 = r 
     874 
     875""", (repr(unicode(self.authz)))) 
    847876 
    848877        self.assert_(self.authz.check_rights('*','/','/trunk/src/test','r') == False) 
     
    909938 
    910939        self.assert_(self.authz.get_access_map_msgs('  ', abbr=True) ==  
    911 [""" 
     940[u""" 
    912941* => [/] 
    913942---------------------------------------- 
     
    917946 
    918947""",  
    919 """ 
     948u""" 
    920949* => [repos1] 
    921950---------------------------------------- 
     
    925954 
    926955""", 
    927 """ 
     956u""" 
    928957* => [repos2] 
    929958---------------------------------------- 
     
    933962 
    934963""", 
    935 """ 
     964u""" 
    936965* => [repos3] 
    937966---------------------------------------- 
     
    940969XX: /, /branches, /tags, /trunk, /trunk/src 
    941970 
     971""", 
     972u""" 
     973* => [版本库1] 
     974---------------------------------------- 
     975RW:  
     976RO:  
     977XX: /, /branches, /tags, /trunk, /trunk/src, /项目1 
     978 
    942979"""] 
    943980, repr(self.authz.get_access_map_msgs('  ', abbr=True))) 
    944981 
    945982        self.assert_(self.authz.get_path_access_msgs(' ', '*', '/trunk/src/mod1', abbr=True) ==  
    946                      [u'[/:/trunk/src/mod1] * =', u'[repos1:/trunk/src/mod1] * =', u'[repos2:/trunk/src/mod1] * =', u'[repos3:/trunk/src/mod1] * ='], 
     983                     [u'[/:/trunk/src/mod1] * =',  
     984                      u'[repos1:/trunk/src/mod1] * =',  
     985                      u'[repos2:/trunk/src/mod1] * =',  
     986                      u'[repos3:/trunk/src/mod1] * =', 
     987                      u'[版本库1:/trunk/src/mod1] * =',], 
    947988                     self.authz.get_path_access_msgs(' ', '*', '/trunk/src/mod1', abbr=True)) 
    948989 
  • trunk/setup.cfg

    r4 r21  
    6464with-pylons=test.ini 
    6565detailed-errors=1 
     66#with-coverage=1 
    6667#with-doctest=1 
    6768