aboutsummaryrefslogtreecommitdiff
path: root/gitosis/test/test_access.py
blob: 9f9d81a5092218016a555670b9ef2533cdff42a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from nose.tools import eq_ as eq
 
from ConfigParser import RawConfigParser
 
from gitosis import access
 
def test_write_no_simple():
    cfg = RawConfigParser()
    eq(access.haveAccess(config=cfg, user='jdoe', mode='writable', path='foo/bar'),
       None)
 
def test_write_yes_simple():
    cfg = RawConfigParser()
    cfg.add_section('group fooers')
    cfg.set('group fooers''members''jdoe')
    cfg.set('group fooers''writable''foo/bar')
    eq(access.haveAccess(config=cfg, user='jdoe', mode='writable', path='foo/bar'),
       ('repositories''foo/bar'))
 
def test_write_no_simple_wouldHaveReadonly():
    cfg = RawConfigParser()
    cfg.add_section('group fooers')
    cfg.set('group fooers''members''jdoe')
    cfg.set('group fooers''readonly''foo/bar')
    eq(access.haveAccess(config=cfg, user='jdoe', mode='writable', path='foo/bar'),
       None)
 
def test_write_yes_map():
    cfg = RawConfigParser()
    cfg.add_section('group fooers')
    cfg.set('group fooers''members''jdoe')
    cfg.set('group fooers''map writable foo/bar''quux/thud')
    eq(access.haveAccess(config=cfg, user='jdoe', mode='writable', path='foo/bar'),
       ('repositories''quux/thud'))
 
def test_write_no_map_wouldHaveReadonly():
    cfg = RawConfigParser()
    cfg.add_section('group fooers')
    cfg.set('group fooers''members''jdoe')
    cfg.set('group fooers''map readonly foo/bar''quux/thud')
    eq(access.haveAccess(config=cfg, user='jdoe', mode='writable', path='foo/bar'),
       None)
 
def test_read_no_simple():
    cfg = RawConfigParser()
    eq(access.haveAccess(config=cfg, user='jdoe', mode='readonly', path='foo/bar'),
       None)
 
def test_read_yes_simple():
    cfg = RawConfigParser()
    cfg.add_section('group fooers')
    cfg.set('group fooers''members''jdoe')
    cfg.set('group fooers''readonly''foo/bar')
    eq(access.haveAccess(config=cfg, user='jdoe', mode='readonly', path='foo/bar'),
       ('repositories''foo/bar'))
 
def test_read_yes_simple_wouldHaveWritable():
    cfg = RawConfigParser()
    cfg.add_section('group fooers')
    cfg.set('group fooers''members''jdoe')
    cfg.set('group fooers''writable''foo/bar')
    eq(access.haveAccess(config=cfg, user='jdoe', mode='readonly', path='foo/bar'),
       None)
 
def test_read_yes_map():
    cfg = RawConfigParser()
    cfg.add_section('group fooers')
    cfg.set('group fooers''members''jdoe')
    cfg.set('group fooers''map readonly foo/bar''quux/thud')
    eq(access.haveAccess(config=cfg, user='jdoe', mode='readonly', path='foo/bar'),
       ('repositories''quux/thud'))
 
def test_read_yes_map_wouldHaveWritable():
    cfg = RawConfigParser()
    cfg.add_section('group fooers')
    cfg.set('group fooers''members''jdoe')
    cfg.set('group fooers''map writable foo/bar''quux/thud')
    eq(access.haveAccess(config=cfg, user='jdoe', mode='readonly', path='foo/bar'),
       None)
 
def test_base_global_absolute():
    cfg = RawConfigParser()
    cfg.add_section('gitosis')
    cfg.set('gitosis''repositories''/a/leading/path')
    cfg.add_section('group fooers')
    cfg.set('group fooers''members''jdoe')
    cfg.set('group fooers''map writable foo/bar''baz/quux/thud')
    eq(access.haveAccess(
        config=cfg, user='jdoe', mode='writable', path='foo/bar'),
       ('/a/leading/path''baz/quux/thud'))
 
def test_base_global_relative():
    cfg = RawConfigParser()
    cfg.add_section('gitosis')
    cfg.set('gitosis''repositories''some/relative/path')
    cfg.add_section('group fooers')
    cfg.set('group fooers''members''jdoe')
    cfg.set('group fooers''map writable foo/bar''baz/quux/thud')
    eq(access.haveAccess(
        config=cfg, user='jdoe', mode='writable', path='foo/bar'),
       ('some/relative/path''baz/quux/thud'))
 
def test_base_global_relative_simple():
    cfg = RawConfigParser()
    cfg.add_section('gitosis')
    cfg.set('gitosis''repositories''some/relative/path')
    cfg.add_section('group fooers')
    cfg.set('group fooers''members''jdoe')
    cfg.set('group fooers''readonly''foo xyzzy bar')
    eq(access.haveAccess(
        config=cfg, user='jdoe', mode='readonly', path='xyzzy'),
       ('some/relative/path''xyzzy'))
 
def test_base_global_unset():
    cfg = RawConfigParser()
    cfg.add_section('gitosis')
    cfg.add_section('group fooers')
    cfg.set('group fooers''members''jdoe')
    cfg.set('group fooers''readonly''foo xyzzy bar')
    eq(access.haveAccess(
        config=cfg, user='jdoe', mode='readonly', path='xyzzy'),
       ('repositories''xyzzy'))
 
def test_base_local():
    cfg = RawConfigParser()
    cfg.add_section('group fooers')
    cfg.set('group fooers''repositories''some/relative/path')
    cfg.set('group fooers''members''jdoe')
    cfg.set('group fooers''map writable foo/bar''baz/quux/thud')
    eq(access.haveAccess(
        config=cfg, user='jdoe', mode='writable', path='foo/bar'),
       ('some/relative/path''baz/quux/thud'))
 
def test_dotgit():
    # a .git extension is always allowed to be added 
    cfg = RawConfigParser()
    cfg.add_section('group fooers')
    cfg.set('group fooers''members''jdoe')
    cfg.set('group fooers''writable''foo/bar')
    eq(access.haveAccess(config=cfg, user='jdoe', mode='writable', path='foo/bar.git'),
       ('repositories''foo/bar'))