test/unittest_ruleset.py
author Mahlon E. Smith <mahlon@martini.nu>
Wed, 31 Oct 2018 13:21:37 -0700
changeset 377 18869fcfbc92
parent 372 80f78674c56e
permissions -rw-r--r--
Merge a41e4382ea6e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
371
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
     1
import os.path as osp
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
     2
from unittest import TestCase
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
     3
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
     4
from mercurialserver import ruleset
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
     5
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
     6
class _RuleSetBaseTC(TestCase):
372
80f78674c56e Add support for phases
David Douard <david.douard@logilab.fr>
parents: 371
diff changeset
     7
    alllevels = ["init", "publish", "write", "read", "deny", "none"]
371
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
     8
    levels = alllevels[:-1]
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
     9
    def setUp(self):
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    10
        self.rs = ruleset.Ruleset()
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    11
        self.rs.buildrules(self.accessrules.splitlines())
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    12
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    13
    def check_level(self, level, **kw):
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    14
        idx = self.alllevels.index(level)
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    15
        msg = ", ".join(["%s=%s"%item for item in self.rs.preset.items()])
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    16
        msg = msg + ": "
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    17
        if idx > 0:
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    18
            prevlevel = self.levels[idx-1]
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    19
            self.assertFalse(self.rs.allow(prevlevel, **kw), msg+prevlevel)
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    20
        if level != "none":
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    21
            self.assertTrue(self.rs.allow(level, **kw), msg+level)
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    22
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    23
class RuleSetDefaultTC(_RuleSetBaseTC):
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    24
    accessrules = '''
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    25
init user=root/**
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    26
deny repo=hgadmin
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    27
write user=users/**
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    28
'''
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    29
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    30
    def test_norules(self):
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    31
        for level in self.levels:
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    32
            self.assertFalse(self.rs.allow(level), level)
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    33
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    34
    def test_root(self):
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    35
        self.rs.set(user='root/key')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    36
        for level in self.levels:
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    37
            self.assertTrue(self.rs.allow(level), level)
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    38
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    39
    def test_user_norepo(self):
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    40
        self.rs.set(user='user/key')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    41
        for level in self.levels:
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    42
            self.assertFalse(self.rs.allow(level), level)
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    43
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    44
    def test_user(self):
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    45
        self.rs.set(user='users/key')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    46
        self.rs.set(repo='some/repo')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    47
        self.check_level('write')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    48
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    49
    def test_user_kwargs(self):
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    50
        self.check_level('write', user='users/key', repo='some/repo')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    51
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    52
class RuleSet2TC(_RuleSetBaseTC):
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    53
    accessrules = '''
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    54
init user=root/**
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    55
deny repo=hgadmin
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    56
init user=users/toto/* repo=toto
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    57
write user=users/toto/* repo=pub/**
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    58
write user=users/w/*
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    59
write repo=allpub/**
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    60
read user=users/**
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    61
'''
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    62
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    63
    def test_hgadmin(self):
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    64
        self.rs.set(repo='hgadmin')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    65
        self.check_level('deny', user='users/key')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    66
        self.check_level('deny', user='key')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    67
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    68
    def test_user(self):
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    69
        self.check_level('read', user='users/key', repo='some/repo')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    70
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    71
    def test_repo(self):
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    72
        self.check_level('init', user='users/toto/key', repo='toto')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    73
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    74
    def test_write(self):
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    75
        self.rs.set(repo='toto')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    76
        self.check_level('read', user='users/w')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    77
        self.check_level('write', user='users/w/key')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    78
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    79
        self.rs.set(repo='pub/stuff')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    80
        self.check_level('read', user='users/w')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    81
        self.check_level('write', user='users/w/key')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    82
        self.check_level('read', user='users/toto')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    83
        self.check_level('write', user='users/toto/key')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    84
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    85
        self.rs.set(repo='other/repo')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    86
        self.check_level('read', user='users/toto')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    87
        self.check_level('read', user='users/toto/key')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    88
        self.check_level('read', user='users/w')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    89
        self.check_level('write', user='users/w/key')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    90
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    91
        self.rs.set(repo='allpub/repo')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    92
        self.check_level('write', user='users/toto')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    93
        self.check_level('write', user='users/toto/key')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    94
        self.check_level('write', user='users/w')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    95
        self.check_level('write', user='users/w/key')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    96
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    97
        self.rs.set(repo='hgadmin')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    98
        self.check_level('deny', user='users/toto')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
    99
        self.check_level('deny', user='users/toto/key')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   100
        self.check_level('deny', user='users/w')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   101
        self.check_level('deny', user='users/w/key')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   102
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   103
    def test_init(self):
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   104
        self.rs.set(repo='toto')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   105
        self.check_level('read', user='users/toto')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   106
        self.check_level('init', user='users/toto/key')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   107
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   108
class RuleSet3TC(_RuleSetBaseTC):
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   109
    accessrules = '''
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   110
read  user=users/w/* repo=toto
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   111
deny  user=users/w/* repo=no
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   112
write user=users/w/*
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   113
read  user=users/**
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   114
'''
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   115
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   116
    def test_user_w(self):
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   117
        self.rs.set(user='users/w/key')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   118
        self.check_level('read', repo='toto')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   119
        self.check_level('deny', repo='no')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   120
        self.check_level('write', repo='other')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   121
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   122
    def test_user_k(self):
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   123
        self.rs.set(user='users/k/key')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   124
        self.check_level('read', repo='toto')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   125
        self.check_level('read', repo='no')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   126
        self.check_level('read', repo='other')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   127
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   128
    def test_otheruser(self):
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   129
        self.rs.set(user='jay/key')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   130
        self.check_level('none', repo='toto')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   131
        self.check_level('none', repo='no')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   132
        self.check_level('none', repo='other')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   133
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   134
class RuleSet4TC(_RuleSetBaseTC):
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   135
    accessrules = '''
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   136
read  user=users/w/* repo=toto
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   137
write user=users/w/*
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   138
deny  user=users/w/* repo=no
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   139
read  user=users/**
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   140
'''
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   141
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   142
    def test_user_w(self):
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   143
        self.rs.set(user='users/w/key')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   144
        self.check_level('read', repo='toto')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   145
        # deny has no effect here, write match first
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   146
        self.check_level('write', repo='no')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   147
        self.check_level('write', repo='other')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   148
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   149
class RuleSet5TC(_RuleSetBaseTC):
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   150
    accessrules = '''
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   151
read  user=users/w/* repo=toto
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   152
deny  user=users/w/* repo=no
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   153
write user=users/w/*
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   154
read  user=users/**
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   155
'''
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   156
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   157
    def test_user_w(self):
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   158
        self.rs.set(user='users/w/key')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   159
        self.check_level('read', repo='toto')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   160
        # deny takes effect here
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   161
        self.check_level('deny', repo='no')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   162
        self.check_level('write', repo='other')
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   163
372
80f78674c56e Add support for phases
David Douard <david.douard@logilab.fr>
parents: 371
diff changeset
   164
class RuleSetPublishTC(_RuleSetBaseTC):
80f78674c56e Add support for phases
David Douard <david.douard@logilab.fr>
parents: 371
diff changeset
   165
    accessrules = '''
80f78674c56e Add support for phases
David Douard <david.douard@logilab.fr>
parents: 371
diff changeset
   166
init user=root/**
80f78674c56e Add support for phases
David Douard <david.douard@logilab.fr>
parents: 371
diff changeset
   167
deny repo=hgadmin
80f78674c56e Add support for phases
David Douard <david.douard@logilab.fr>
parents: 371
diff changeset
   168
init user=users/toto/* repo=toto
80f78674c56e Add support for phases
David Douard <david.douard@logilab.fr>
parents: 371
diff changeset
   169
publish user=users/toto/* repo=pub/**
80f78674c56e Add support for phases
David Douard <david.douard@logilab.fr>
parents: 371
diff changeset
   170
publish repo=allpub/**
80f78674c56e Add support for phases
David Douard <david.douard@logilab.fr>
parents: 371
diff changeset
   171
write user=users/w/*
80f78674c56e Add support for phases
David Douard <david.douard@logilab.fr>
parents: 371
diff changeset
   172
read user=users/**
80f78674c56e Add support for phases
David Douard <david.douard@logilab.fr>
parents: 371
diff changeset
   173
'''
80f78674c56e Add support for phases
David Douard <david.douard@logilab.fr>
parents: 371
diff changeset
   174
    def test_publish(self):
80f78674c56e Add support for phases
David Douard <david.douard@logilab.fr>
parents: 371
diff changeset
   175
        self.rs.set(user='users/w/key')
80f78674c56e Add support for phases
David Douard <david.douard@logilab.fr>
parents: 371
diff changeset
   176
        self.check_level('publish', repo='allpub/stuff')
80f78674c56e Add support for phases
David Douard <david.douard@logilab.fr>
parents: 371
diff changeset
   177
        self.check_level('write', repo='toto')
80f78674c56e Add support for phases
David Douard <david.douard@logilab.fr>
parents: 371
diff changeset
   178
        self.check_level('write', repo='other/stuff')
80f78674c56e Add support for phases
David Douard <david.douard@logilab.fr>
parents: 371
diff changeset
   179
80f78674c56e Add support for phases
David Douard <david.douard@logilab.fr>
parents: 371
diff changeset
   180
        self.rs.set(repo='pub/stuff')
80f78674c56e Add support for phases
David Douard <david.douard@logilab.fr>
parents: 371
diff changeset
   181
        self.check_level('write', user='users/w/key')
80f78674c56e Add support for phases
David Douard <david.douard@logilab.fr>
parents: 371
diff changeset
   182
        self.check_level('publish', user='users/toto/key')
80f78674c56e Add support for phases
David Douard <david.douard@logilab.fr>
parents: 371
diff changeset
   183
80f78674c56e Add support for phases
David Douard <david.douard@logilab.fr>
parents: 371
diff changeset
   184
371
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   185
if __name__ == '__main__':
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   186
    from unittest import main
e9ce904b62a9 [test] add unit tests for ruleset
David Douard <david.douard@logilab.fr>
parents:
diff changeset
   187
    main()