1 from nose
.tools
import eq_
as eq
4 from ConfigParser
import RawConfigParser
6 from gitosis
import access
8 def test_write_no_simple():
9 cfg
= RawConfigParser()
10 eq(access
.haveAccess(config
=cfg
, user
='jdoe', mode
='writable', path
='foo/bar'),
13 def test_write_yes_simple():
14 cfg
= RawConfigParser()
15 cfg
.add_section('group fooers')
16 cfg
.set('group fooers', 'members', 'jdoe')
17 cfg
.set('group fooers', 'writable', 'foo/bar')
18 eq(access
.haveAccess(config
=cfg
, user
='jdoe', mode
='writable', path
='foo/bar'),
19 ('repositories', 'foo/bar'))
21 def test_write_no_simple_wouldHaveReadonly():
22 cfg
= RawConfigParser()
23 cfg
.add_section('group fooers')
24 cfg
.set('group fooers', 'members', 'jdoe')
25 cfg
.set('group fooers', 'readonly', 'foo/bar')
26 eq(access
.haveAccess(config
=cfg
, user
='jdoe', mode
='writable', path
='foo/bar'),
29 def test_write_yes_map():
30 cfg
= RawConfigParser()
31 cfg
.add_section('group fooers')
32 cfg
.set('group fooers', 'members', 'jdoe')
33 cfg
.set('group fooers', 'map writable foo/bar', 'quux/thud')
34 eq(access
.haveAccess(config
=cfg
, user
='jdoe', mode
='writable', path
='foo/bar'),
35 ('repositories', 'quux/thud'))
37 def test_write_no_map_wouldHaveReadonly():
38 cfg
= RawConfigParser()
39 cfg
.add_section('group fooers')
40 cfg
.set('group fooers', 'members', 'jdoe')
41 cfg
.set('group fooers', 'map readonly foo/bar', 'quux/thud')
42 eq(access
.haveAccess(config
=cfg
, user
='jdoe', mode
='writable', path
='foo/bar'),
45 def test_read_no_simple():
46 cfg
= RawConfigParser()
47 eq(access
.haveAccess(config
=cfg
, user
='jdoe', mode
='readonly', path
='foo/bar'),
50 def test_read_yes_simple():
51 cfg
= RawConfigParser()
52 cfg
.add_section('group fooers')
53 cfg
.set('group fooers', 'members', 'jdoe')
54 cfg
.set('group fooers', 'readonly', 'foo/bar')
55 eq(access
.haveAccess(config
=cfg
, user
='jdoe', mode
='readonly', path
='foo/bar'),
56 ('repositories', 'foo/bar'))
58 def test_read_yes_simple_wouldHaveWritable():
59 cfg
= RawConfigParser()
60 cfg
.add_section('group fooers')
61 cfg
.set('group fooers', 'members', 'jdoe')
62 cfg
.set('group fooers', 'writable', 'foo/bar')
63 eq(access
.haveAccess(config
=cfg
, user
='jdoe', mode
='readonly', path
='foo/bar'),
66 def test_read_yes_map():
67 cfg
= RawConfigParser()
68 cfg
.add_section('group fooers')
69 cfg
.set('group fooers', 'members', 'jdoe')
70 cfg
.set('group fooers', 'map readonly foo/bar', 'quux/thud')
71 eq(access
.haveAccess(config
=cfg
, user
='jdoe', mode
='readonly', path
='foo/bar'),
72 ('repositories', 'quux/thud'))
74 def test_read_yes_map_wouldHaveWritable():
75 cfg
= RawConfigParser()
76 cfg
.add_section('group fooers')
77 cfg
.set('group fooers', 'members', 'jdoe')
78 cfg
.set('group fooers', 'map writable foo/bar', 'quux/thud')
79 eq(access
.haveAccess(config
=cfg
, user
='jdoe', mode
='readonly', path
='foo/bar'),
82 def test_read_yes_all():
83 cfg
= RawConfigParser()
84 cfg
.add_section('group fooers')
85 cfg
.set('group fooers', 'members', '@all')
86 cfg
.set('group fooers', 'readonly', 'foo/bar')
87 eq(access
.haveAccess(config
=cfg
, user
='jdoe', mode
='readonly', path
='foo/bar'),
88 ('repositories', 'foo/bar'))
90 def test_base_global_absolute():
91 cfg
= RawConfigParser()
92 cfg
.add_section('gitosis')
93 cfg
.set('gitosis', 'repositories', '/a/leading/path')
94 cfg
.add_section('group fooers')
95 cfg
.set('group fooers', 'members', 'jdoe')
96 cfg
.set('group fooers', 'map writable foo/bar', 'baz/quux/thud')
98 config
=cfg
, user
='jdoe', mode
='writable', path
='foo/bar'),
99 ('/a/leading/path', 'baz/quux/thud'))
101 def test_base_global_relative():
102 cfg
= RawConfigParser()
103 cfg
.add_section('gitosis')
104 cfg
.set('gitosis', 'repositories', 'some/relative/path')
105 cfg
.add_section('group fooers')
106 cfg
.set('group fooers', 'members', 'jdoe')
107 cfg
.set('group fooers', 'map writable foo/bar', 'baz/quux/thud')
108 eq(access
.haveAccess(
109 config
=cfg
, user
='jdoe', mode
='writable', path
='foo/bar'),
110 ('some/relative/path', 'baz/quux/thud'))
112 def test_base_global_relative_simple():
113 cfg
= RawConfigParser()
114 cfg
.add_section('gitosis')
115 cfg
.set('gitosis', 'repositories', 'some/relative/path')
116 cfg
.add_section('group fooers')
117 cfg
.set('group fooers', 'members', 'jdoe')
118 cfg
.set('group fooers', 'readonly', 'foo xyzzy bar')
119 eq(access
.haveAccess(
120 config
=cfg
, user
='jdoe', mode
='readonly', path
='xyzzy'),
121 ('some/relative/path', 'xyzzy'))
123 def test_base_global_unset():
124 cfg
= RawConfigParser()
125 cfg
.add_section('gitosis')
126 cfg
.add_section('group fooers')
127 cfg
.set('group fooers', 'members', 'jdoe')
128 cfg
.set('group fooers', 'readonly', 'foo xyzzy bar')
129 eq(access
.haveAccess(
130 config
=cfg
, user
='jdoe', mode
='readonly', path
='xyzzy'),
131 ('repositories', 'xyzzy'))
134 cfg
= RawConfigParser()
135 cfg
.add_section('user jdoe')
136 cfg
.set('user jdoe', 'readonly', 'foo xyzzy bar')
137 eq(access
.haveAccess(
138 config
=cfg
, user
='jdoe', mode
='readonly', path
='xyzzy'),
139 ('repositories', 'xyzzy'))
141 def test_base_local():
142 cfg
= RawConfigParser()
143 cfg
.add_section('group fooers')
144 cfg
.set('group fooers', 'repositories', 'some/relative/path')
145 cfg
.set('group fooers', 'members', 'jdoe')
146 cfg
.set('group fooers', 'map writable foo/bar', 'baz/quux/thud')
147 eq(access
.haveAccess(
148 config
=cfg
, user
='jdoe', mode
='writable', path
='foo/bar'),
149 ('some/relative/path', 'baz/quux/thud'))
152 cfg
= RawConfigParser()
153 cfg
.add_section('group fooers')
154 cfg
.set('group fooers', 'members', 'jdoe')
155 cfg
.set('group fooers', 'map writable foo/bar', 'baz/quux/thud')
156 cfg
.add_section('group mooers')
157 cfg
.set('group mooers', 'readonly', 'baz/quux/thud')
160 access
.listAccess(cfg
,'writable','baz/quux/thud',users
,groups
)
161 eq(sorted(groups
), ['fooers'])
162 eq(sorted(users
), [])
164 def test_list_read():
165 cfg
= RawConfigParser()
166 cfg
.add_section('group fooers')
167 cfg
.set('group fooers', 'members', 'jdoe')
168 cfg
.set('group fooers', 'map writable foo/bar', 'baz/quux/thud')
169 cfg
.add_section('group mooers')
170 cfg
.set('group mooers', 'readonly', 'baz/quux/thud')
171 cfg
.add_section('user jdoe')
172 cfg
.set('user jdoe', 'readonly', 'baz/quux/thud')
175 access
.listAccess(cfg
,'readonly','baz/quux/thud',users
,groups
)
176 eq(sorted(groups
), ['mooers'])
177 eq(sorted(users
), ['jdoe'])
180 cfg
= RawConfigParser()
181 cfg
.add_section('group fooers')
182 cfg
.set('group fooers', 'members', 'jdoe')
183 cfg
.set('group fooers', 'map writable foo/bar', 'baz/quux/thud')
184 cfg
.add_section('group mooers')
185 cfg
.set('group mooers', 'members', '@fooers')
186 cfg
.set('group mooers', 'readonly', 'baz/quux/thud')
187 (users
, groups
, all_refs
) = access
.getAllAccess(cfg
,'baz/quux/thud',['readonly'])
188 eq(sorted(users
), [])
189 eq(sorted(groups
), ['mooers'])
190 eq(sorted(all_refs
), ['@fooers','@mooers','jdoe'])
193 # a .git extension is always allowed to be added
194 cfg
= RawConfigParser()
195 cfg
.add_section('group fooers')
196 cfg
.set('group fooers', 'members', 'jdoe')
197 cfg
.set('group fooers', 'writable', 'foo/bar')
198 eq(access
.haveAccess(config
=cfg
, user
='jdoe', mode
='writable', path
='foo/bar.git'),
199 ('repositories', 'foo/bar'))