James Moger
2012-10-10 5d7545652a6529c9076f67acd75f7a977c8a44a6
commit | author | age
20714a 1 /*
JM 2  * Copyright 2012 gitblit.com.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.gitblit.tests;
17
18 import java.util.Date;
19
20 import junit.framework.Assert;
21
22 import org.junit.Test;
23
24 import com.gitblit.Constants.AccessPermission;
25 import com.gitblit.Constants.AccessRestrictionType;
26 import com.gitblit.Constants.AuthorizationControl;
27 import com.gitblit.models.RepositoryModel;
28 import com.gitblit.models.TeamModel;
29 import com.gitblit.models.UserModel;
30
31 /**
32  * Comprehensive, brute-force test of all permutations of discrete permissions.
33  * 
34  * @author James Moger
35  *
36  */
37 public class PermissionsTest extends Assert {
38
39     /**
40      * Admin access rights/permissions
41      */
42     @Test
43     public void testAdmin() throws Exception {
44         UserModel user = new UserModel("admin");
45         user.canAdmin = true;
46         
47         for (AccessRestrictionType ar : AccessRestrictionType.values()) {
48             RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
49             repository.authorizationControl = AuthorizationControl.NAMED;
50             repository.accessRestriction = ar;
51                 
52             assertTrue("admin CAN NOT view!", user.canView(repository));
53             assertTrue("admin CAN NOT clone!", user.canClone(repository));
54             assertTrue("admin CAN NOT push!", user.canPush(repository));
55             
56             assertTrue("admin CAN NOT create ref!", user.canCreateRef(repository));
57             assertTrue("admin CAN NOT delete ref!", user.canDeleteRef(repository));
58             assertTrue("admin CAN NOT rewind ref!", user.canRewindRef(repository));
59             
60             assertTrue("admin CAN NOT fork!", user.canFork(repository));
61             
62             assertTrue("admin CAN NOT delete!", user.canDelete(repository));
63             assertTrue("admin CAN NOT edit!", user.canEdit(repository));
64         }
65     }
66     
67     /**
68      * Anonymous access rights/permissions 
69      */
70     @Test
71     public void testAnonymous_NONE() throws Exception {
72         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
73         repository.authorizationControl = AuthorizationControl.NAMED;
74         repository.accessRestriction = AccessRestrictionType.NONE;
75         
76         UserModel user = UserModel.ANONYMOUS;
77         
78         // all permissions, except fork
79         assertTrue("anonymous CAN NOT view!", user.canView(repository));
80         assertTrue("anonymous CAN NOT clone!", user.canClone(repository));
81         assertTrue("anonymous CAN NOT push!", user.canPush(repository));
82         
83         assertTrue("anonymous CAN NOT create ref!", user.canCreateRef(repository));
84         assertTrue("anonymous CAN NOT delete ref!", user.canDeleteRef(repository));
85         assertTrue("anonymous CAN NOT rewind ref!", user.canRewindRef(repository));
86
87         repository.allowForks = false;
88         assertFalse("anonymous CAN fork!", user.canFork(repository));
89         repository.allowForks = true;
90         assertFalse("anonymous CAN fork!", user.canFork(repository));
91         
92         assertFalse("anonymous CAN delete!", user.canDelete(repository));
93         assertFalse("anonymous CAN edit!", user.canEdit(repository));
94     }
95     
96     @Test
97     public void testAnonymous_PUSH() throws Exception {
98         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
99         repository.authorizationControl = AuthorizationControl.NAMED;
100         repository.accessRestriction = AccessRestrictionType.PUSH;
101
102         UserModel user = UserModel.ANONYMOUS;
103
104         assertTrue("anonymous CAN NOT view!", user.canView(repository));
105         assertTrue("anonymous CAN NOT clone!", user.canClone(repository));
106         assertFalse("anonymous CAN push!", user.canPush(repository));
107         
108         assertFalse("anonymous CAN create ref!", user.canCreateRef(repository));
109         assertFalse("anonymous CAN delete ref!", user.canDeleteRef(repository));
110         assertFalse("anonymous CAN rewind ref!", user.canRewindRef(repository));
111         
112         repository.allowForks = false;
113         assertFalse("anonymous CAN fork!", user.canFork(repository));
114         repository.allowForks = true;
115         assertFalse("anonymous CAN fork!", user.canFork(repository));
116     }
117     
118     @Test
119     public void testAnonymous_CLONE() throws Exception {
120         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
121         repository.authorizationControl = AuthorizationControl.NAMED;
122         repository.accessRestriction = AccessRestrictionType.CLONE;
123
124         UserModel user = UserModel.ANONYMOUS;
125
126         assertTrue("anonymous CAN NOT view!", user.canView(repository));
127         assertFalse("anonymous CAN clone!", user.canClone(repository));
128         assertFalse("anonymous CAN push!", user.canPush(repository));
129         
130         assertFalse("anonymous CAN create ref!", user.canCreateRef(repository));
131         assertFalse("anonymous CAN delete ref!", user.canDeleteRef(repository));
132         assertFalse("anonymous CAN rewind ref!", user.canRewindRef(repository));
133
134         repository.allowForks = false;
135         assertFalse("anonymous CAN fork!", user.canFork(repository));
136         repository.allowForks = true;
137         assertFalse("anonymous CAN fork!", user.canFork(repository));
138     }
139     
140     @Test
141     public void testAnonymous_VIEW() throws Exception {
142         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
143         repository.authorizationControl = AuthorizationControl.NAMED;
144         repository.accessRestriction = AccessRestrictionType.VIEW;
145         
146         UserModel user = UserModel.ANONYMOUS;
147
148         assertFalse("anonymous CAN view!", user.canView(repository));
149         assertFalse("anonymous CAN clone!", user.canClone(repository));
150         assertFalse("anonymous CAN push!", user.canPush(repository));
151         
152         assertFalse("anonymous CAN create ref!", user.canCreateRef(repository));
153         assertFalse("anonymous CAN delete ref!", user.canDeleteRef(repository));
154         assertFalse("anonymous CAN rewind ref!", user.canRewindRef(repository));
155
156         repository.allowForks = false;
157         assertFalse("anonymous CAN fork!", user.canFork(repository));
158         repository.allowForks = true;
159         assertFalse("anonymous CAN fork!", user.canFork(repository));
160     }
161     
162     /**
163      * Authenticated access rights/permissions 
164      */
165     @Test
166     public void testAuthenticated_NONE() throws Exception {
167         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
168         repository.authorizationControl = AuthorizationControl.AUTHENTICATED;
169         repository.accessRestriction = AccessRestrictionType.NONE;
170         
171         UserModel user = new UserModel("test");
172         
173         // all permissions, except fork
174         assertTrue("authenticated CAN NOT view!", user.canView(repository));
175         assertTrue("authenticated CAN NOT clone!", user.canClone(repository));
176         assertTrue("authenticated CAN NOT push!", user.canPush(repository));
177         
178         assertTrue("authenticated CAN NOT create ref!", user.canCreateRef(repository));
179         assertTrue("authenticated CAN NOT delete ref!", user.canDeleteRef(repository));
180         assertTrue("authenticated CAN NOT rewind ref!", user.canRewindRef(repository));
181
182         user.canFork = false;
183         repository.allowForks = false;
184         assertFalse("authenticated CAN fork!", user.canFork(repository));
185         repository.allowForks = true;
186         assertFalse("authenticated CAN fork!", user.canFork(repository));
187         user.canFork = true;
188         assertTrue("authenticated CAN NOT fork!", user.canFork(repository));
189         
190         assertFalse("authenticated CAN delete!", user.canDelete(repository));
191         assertFalse("authenticated CAN edit!", user.canEdit(repository));
192     }
193
194     @Test
195     public void testAuthenticated_PUSH() throws Exception {
196         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
197         repository.authorizationControl = AuthorizationControl.AUTHENTICATED;
198         repository.accessRestriction = AccessRestrictionType.PUSH;
199         
200         UserModel user = new UserModel("test");
201
202         assertTrue("authenticated CAN NOT view!", user.canView(repository));
203         assertTrue("authenticated CAN NOT clone!", user.canClone(repository));
204         assertTrue("authenticated CAN NOT push!", user.canPush(repository));
205         
206         assertTrue("authenticated CAN NOT create ref!", user.canCreateRef(repository));
207         assertTrue("authenticated CAN NOT delete ref!", user.canDeleteRef(repository));
208         assertTrue("authenticated CAN NOT rewind ref!", user.canRewindRef(repository));
209
210         user.canFork = false;
211         repository.allowForks = false;
212         assertFalse("authenticated CAN fork!", user.canFork(repository));
213         repository.allowForks = true;
214         assertFalse("authenticated CAN fork!", user.canFork(repository));
215         user.canFork = true;
216         assertTrue("authenticated CAN NOT fork!", user.canFork(repository));
217     }
218     
219     @Test
220     public void testAuthenticated_CLONE() throws Exception {
221         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
222         repository.authorizationControl = AuthorizationControl.AUTHENTICATED;
223         repository.accessRestriction = AccessRestrictionType.CLONE;
224             
225         UserModel user = new UserModel("test");
226
227         assertTrue("authenticated CAN NOT view!", user.canView(repository));
228         assertTrue("authenticated CAN NOT clone!", user.canClone(repository));
229         assertTrue("authenticated CAN NOT push!", user.canPush(repository));
230         
231         assertTrue("authenticated CAN NOT create ref!", user.canCreateRef(repository));
232         assertTrue("authenticated CAN NOT delete ref!", user.canDeleteRef(repository));
233         assertTrue("authenticated CAN NOT rewind ref!", user.canRewindRef(repository));
234
235         user.canFork = false;
236         repository.allowForks = false;
237         assertFalse("authenticated CAN fork!", user.canFork(repository));
238         repository.allowForks = true;
239         assertFalse("authenticated CAN fork!", user.canFork(repository));
240         user.canFork = true;
241         assertTrue("authenticated CAN NOT fork!", user.canFork(repository));
242     }
243     
244     @Test
245     public void testAuthenticated_VIEW() throws Exception {
246         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
247         repository.authorizationControl = AuthorizationControl.AUTHENTICATED;
248         repository.accessRestriction = AccessRestrictionType.VIEW;
249             
250         UserModel user = new UserModel("test");
251
252         assertTrue("authenticated CAN NOT view!", user.canView(repository));
253         assertTrue("authenticated CAN NOT clone!", user.canClone(repository));
254         assertTrue("authenticated CAN NOT push!", user.canPush(repository));
255         
256         assertTrue("authenticated CAN NOT create ref!", user.canCreateRef(repository));
257         assertTrue("authenticated CAN NOT delete ref!", user.canDeleteRef(repository));
258         assertTrue("authenticated CAN NOT rewind ref!", user.canRewindRef(repository));
259
260         user.canFork = false;
261         repository.allowForks = false;
262         assertFalse("authenticated CAN fork!", user.canFork(repository));
263         repository.allowForks = true;
264         assertFalse("authenticated CAN fork!", user.canFork(repository));
265         user.canFork = true;
266         assertTrue("authenticated CAN NOT fork!", user.canFork(repository));
267     }
268     
269     /**
270      * NONE_NONE = NO access restriction, NO access permission
271      */
272     @Test
273     public void testNamed_NONE_NONE() throws Exception {
274         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
275         repository.authorizationControl = AuthorizationControl.NAMED;
276         repository.accessRestriction = AccessRestrictionType.NONE;
277
278         UserModel user = new UserModel("test");
279         
280         assertTrue("named CAN NOT view!", user.canView(repository));
281         assertTrue("named CAN NOT clone!", user.canClone(repository));
282         assertTrue("named CAN NOT push!", user.canPush(repository));
283         
284         assertTrue("named CAN NOT create ref!", user.canCreateRef(repository));
285         assertTrue("named CAN NOT delete ref!", user.canDeleteRef(repository));
286         assertTrue("named CAN NOT rewind ref!", user.canRewindRef(repository));
287         
288         repository.allowForks = false;
289         user.canFork = false;
290         assertFalse("named CAN fork!", user.canFork(repository));
291         user.canFork = true;
292         assertFalse("named CAN fork!", user.canFork(repository));
293         repository.allowForks = true;
294         assertTrue("named CAN NOT fork!", user.canFork(repository));
295         
296         assertFalse("named CAN delete!", user.canDelete(repository));
297         assertFalse("named CAN edit!", user.canEdit(repository));
298     }
299     
300     /**
301      * PUSH_NONE = PUSH access restriction, NO access permission
302      */
303     @Test
304     public void testNamed_PUSH_NONE() throws Exception {
305         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
306         repository.authorizationControl = AuthorizationControl.NAMED;
307         repository.accessRestriction = AccessRestrictionType.PUSH;
308         
309         UserModel user = new UserModel("test");
310         
311         assertTrue("named CAN NOT view!", user.canView(repository));
312         assertTrue("named CAN NOT clone!", user.canClone(repository));
313         assertFalse("named CAN push!", user.canPush(repository));
314         
315         assertFalse("named CAN create ref!", user.canCreateRef(repository));
316         assertFalse("named CAN delete ref!", user.canDeleteRef(repository));
317         assertFalse("named CAN rewind ref!", user.canRewindRef(repository));
318
319         repository.allowForks = false;
320         user.canFork = false;
321         assertFalse("named CAN fork!", user.canFork(repository));
322         user.canFork = true;
323         assertFalse("named CAN fork!", user.canFork(repository));
324         repository.allowForks = true;
325         assertTrue("named CAN NOT fork!", user.canFork(repository));
326     }
327     
328     /**
329      * CLONE_NONE = CLONE access restriction, NO access permission
330      */
331     @Test
332     public void testNamed_CLONE_NONE() throws Exception {
333         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
334         repository.authorizationControl = AuthorizationControl.NAMED;
335         repository.accessRestriction = AccessRestrictionType.CLONE;
336         
337         UserModel user = new UserModel("test");
338         
339         assertTrue("named CAN NOT view!", user.canView(repository));
340         assertFalse("named CAN clone!", user.canClone(repository));
341         assertFalse("named CAN push!", user.canPush(repository));
342         
343         assertFalse("named CAN create ref!", user.canCreateRef(repository));
344         assertFalse("named CAN delete ref!", user.canDeleteRef(repository));
345         assertFalse("named CAN rewind ref!", user.canRewindRef(repository));
346
347         repository.allowForks = false;
348         user.canFork = false;
349         assertFalse("named CAN fork!", user.canFork(repository));
350         user.canFork = true;
351         assertFalse("named CAN fork!", user.canFork(repository));
352         repository.allowForks = true;
353         assertFalse("named CAN NOT fork!", user.canFork(repository));
354     }
355     
356     /**
357      * VIEW_NONE = VIEW access restriction, NO access permission
358      */
359     @Test
360     public void testNamed_VIEW_NONE() throws Exception {
361         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
362         repository.authorizationControl = AuthorizationControl.NAMED;
363         repository.accessRestriction = AccessRestrictionType.VIEW;
364         
365         UserModel user = new UserModel("test");
366         
367         assertFalse("named CAN view!", user.canView(repository));
368         assertFalse("named CAN clone!", user.canClone(repository));
369         assertFalse("named CAN push!", user.canPush(repository));
370         
371         assertFalse("named CAN create ref!", user.canCreateRef(repository));
372         assertFalse("named CAN delete ref!", user.canDeleteRef(repository));
373         assertFalse("named CAN rewind ref!", user.canRewindRef(repository));
374         
375         repository.allowForks = false;
376         user.canFork = false;
377         assertFalse("named CAN fork!", user.canFork(repository));
378         user.canFork = true;
379         assertFalse("named CAN fork!", user.canFork(repository));
380         repository.allowForks = true;
381         assertFalse("named CAN NOT fork!", user.canFork(repository));
382     }
383
384     
385     /**
386      * NONE_VIEW = NO access restriction, VIEW access permission.
387      * (not useful scenario)
388      */
389     @Test
390     public void testNamed_NONE_VIEW() throws Exception {
391         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
392         repository.authorizationControl = AuthorizationControl.NAMED;
393         repository.accessRestriction = AccessRestrictionType.NONE;
394
395         UserModel user = new UserModel("test");
396         user.setRepositoryPermission(repository.name, AccessPermission.VIEW);
397         
398         assertTrue("named CAN NOT view!", user.canView(repository));
399         assertTrue("named CAN NOT clone!", user.canClone(repository));
400         assertTrue("named CAN NOT push!", user.canPush(repository));
401         
402         assertTrue("named CAN NOT create ref!", user.canCreateRef(repository));
403         assertTrue("named CAN NOT delete ref!", user.canDeleteRef(repository));
404         assertTrue("named CAN NOT rewind ref!", user.canRewindRef(repository));
405         
406         repository.allowForks = false;
407         user.canFork = false;
408         assertFalse("named CAN fork!", user.canFork(repository));
409         user.canFork = true;
410         assertFalse("named CAN fork!", user.canFork(repository));
411         repository.allowForks = true;
412         assertTrue("named CAN NOT fork!", user.canFork(repository));
413     }
414     
415     /**
416      * PUSH_VIEW = PUSH access restriction, VIEW access permission
417      */
418     @Test
419     public void testNamed_PUSH_VIEW() throws Exception {
420         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
421         repository.authorizationControl = AuthorizationControl.NAMED;
422         repository.accessRestriction = AccessRestrictionType.PUSH;
423         
424         UserModel user = new UserModel("test");
425         user.setRepositoryPermission(repository.name, AccessPermission.VIEW);
426         
427         assertTrue("named CAN NOT view!", user.canView(repository));
428         assertTrue("named CAN NOT clone!", user.canClone(repository));
429         assertFalse("named CAN push!", user.canPush(repository));
430         
431         assertFalse("named CAN create ref!", user.canCreateRef(repository));
432         assertFalse("named CAN delete ref!", user.canDeleteRef(repository));
433         assertFalse("named CAN rewind ref!", user.canRewindRef(repository));
434
435         repository.allowForks = false;
436         user.canFork = false;
437         assertFalse("named CAN fork!", user.canFork(repository));
438         user.canFork = true;
439         assertFalse("named CAN fork!", user.canFork(repository));
440         repository.allowForks = true;
441         assertTrue("named CAN NOT fork!", user.canFork(repository));
442     }
443     
444     /**
445      * CLONE_VIEW = CLONE access restriction, VIEW access permission
446      */
447     @Test
448     public void testNamed_CLONE_VIEW() throws Exception {
449         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
450         repository.authorizationControl = AuthorizationControl.NAMED;
451         repository.accessRestriction = AccessRestrictionType.CLONE;
452         
453         UserModel user = new UserModel("test");
454         user.setRepositoryPermission(repository.name, AccessPermission.VIEW);
455
456         assertTrue("named CAN NOT view!", user.canView(repository));
457         assertFalse("named CAN clone!", user.canClone(repository));
458         assertFalse("named CAN push!", user.canPush(repository));
459         
460         assertFalse("named CAN create ref!", user.canCreateRef(repository));
461         assertFalse("named CAN delete ref!", user.canDeleteRef(repository));
462         assertFalse("named CAN rewind ref!", user.canRewindRef(repository));
463
464         repository.allowForks = false;
465         user.canFork = false;
466         assertFalse("named CAN fork!", user.canFork(repository));
467         user.canFork = true;
468         assertFalse("named CAN fork!", user.canFork(repository));
469         repository.allowForks = true;
470         assertFalse("named CAN NOT fork!", user.canFork(repository));
471     }
472     
473     /**
474      * VIEW_VIEW = VIEW access restriction, VIEW access permission
475      */
476     @Test
477     public void testNamed_VIEW_VIEW() throws Exception {
478         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
479         repository.authorizationControl = AuthorizationControl.NAMED;
480         repository.accessRestriction = AccessRestrictionType.VIEW;
481         
482         UserModel user = new UserModel("test");
483         user.setRepositoryPermission(repository.name, AccessPermission.VIEW);
484
485         assertTrue("named CAN NOT view!", user.canView(repository));
486         assertFalse("named CAN clone!", user.canClone(repository));
487         assertFalse("named CAN push!", user.canPush(repository));
488         
489         assertFalse("named CAN create ref!", user.canCreateRef(repository));
490         assertFalse("named CAN delete ref!", user.canDeleteRef(repository));
491         assertFalse("named CAN rewind ref!", user.canRewindRef(repository));
492         
493         repository.allowForks = false;
494         user.canFork = false;
495         assertFalse("named CAN fork!", user.canFork(repository));
496         user.canFork = true;
497         assertFalse("named CAN fork!", user.canFork(repository));
498         repository.allowForks = true;
499         assertFalse("named CAN NOT fork!", user.canFork(repository));
500     }
501     
502     /**
503      * NONE_CLONE = NO access restriction, CLONE access permission.
504      * (not useful scenario)
505      */
506     @Test
507     public void testNamed_NONE_CLONE() throws Exception {
508         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
509         repository.authorizationControl = AuthorizationControl.NAMED;
510         repository.accessRestriction = AccessRestrictionType.NONE;
511
512         UserModel user = new UserModel("test");
513         user.setRepositoryPermission(repository.name, AccessPermission.CLONE);
514         
515         assertTrue("named CAN NOT view!", user.canView(repository));
516         assertTrue("named CAN NOT clone!", user.canClone(repository));
517         assertTrue("named CAN NOT push!", user.canPush(repository));
518         
519         assertTrue("named CAN NOT create ref!", user.canCreateRef(repository));
520         assertTrue("named CAN NOT delete ref!", user.canDeleteRef(repository));
521         assertTrue("named CAN NOT rewind ref!", user.canRewindRef(repository));
522         
523         repository.allowForks = false;
524         user.canFork = false;
525         assertFalse("named CAN fork!", user.canFork(repository));
526         user.canFork = true;
527         assertFalse("named CAN fork!", user.canFork(repository));
528         repository.allowForks = true;
529         assertTrue("named CAN NOT fork!", user.canFork(repository));
530     }
531     
532     /**
533      * PUSH_CLONE = PUSH access restriction, CLONE access permission
534      */
535     @Test
536     public void testNamed_PUSH_READ() throws Exception {
537         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
538         repository.authorizationControl = AuthorizationControl.NAMED;
539         repository.accessRestriction = AccessRestrictionType.PUSH;
540         
541         UserModel user = new UserModel("test");
542         user.setRepositoryPermission(repository.name, AccessPermission.CLONE);
543         
544         assertTrue("named CAN NOT view!", user.canView(repository));
545         assertTrue("named CAN NOT clone!", user.canClone(repository));
546         assertFalse("named CAN push!", user.canPush(repository));
547         
548         assertFalse("named CAN create ref!", user.canCreateRef(repository));
549         assertFalse("named CAN delete ref!", user.canDeleteRef(repository));
550         assertFalse("named CAN rewind ref!", user.canRewindRef(repository));
551
552         repository.allowForks = false;
553         user.canFork = false;
554         assertFalse("named CAN fork!", user.canFork(repository));
555         user.canFork = true;
556         assertFalse("named CAN fork!", user.canFork(repository));
557         repository.allowForks = true;
558         assertTrue("named CAN NOT fork!", user.canFork(repository));
559     }
560     
561     /**
562      * CLONE_CLONE = CLONE access restriction, CLONE access permission
563      */
564     @Test
565     public void testNamed_CLONE_CLONE() throws Exception {
566         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
567         repository.authorizationControl = AuthorizationControl.NAMED;
568         repository.accessRestriction = AccessRestrictionType.CLONE;
569         
570         UserModel user = new UserModel("test");
571         user.setRepositoryPermission(repository.name, AccessPermission.CLONE);
572
573         assertTrue("named CAN NOT view!", user.canView(repository));
574         assertTrue("named CAN NOT clone!", user.canClone(repository));
575         assertFalse("named CAN push!", user.canPush(repository));
576         
577         assertFalse("named CAN create ref!", user.canCreateRef(repository));
578         assertFalse("named CAN delete ref!", user.canDeleteRef(repository));
579         assertFalse("named CAN rewind ref!", user.canRewindRef(repository));
580
581         repository.allowForks = false;
582         user.canFork = false;
583         assertFalse("named CAN fork!", user.canFork(repository));
584         user.canFork = true;
585         assertFalse("named CAN fork!", user.canFork(repository));
586         repository.allowForks = true;
587         assertTrue("named CAN NOT fork!", user.canFork(repository));
588     }
589     
590     /**
591      * VIEW_CLONE = VIEW access restriction, CLONE access permission
592      */
593     @Test
594     public void testNamed_VIEW_CLONE() throws Exception {
595         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
596         repository.authorizationControl = AuthorizationControl.NAMED;
597         repository.accessRestriction = AccessRestrictionType.VIEW;
598         
599         UserModel user = new UserModel("test");
600         user.setRepositoryPermission(repository.name, AccessPermission.CLONE);
601
602         assertTrue("named CAN NOT view!", user.canView(repository));
603         assertTrue("named CAN NOT clone!", user.canClone(repository));
604         assertFalse("named CAN push!", user.canPush(repository));
605         
606         assertFalse("named CAN create ref!", user.canCreateRef(repository));
607         assertFalse("named CAN delete ref!", user.canDeleteRef(repository));
608         assertFalse("named CAN rewind ref!", user.canRewindRef(repository));
609         
610         repository.allowForks = false;
611         user.canFork = false;
612         assertFalse("named CAN fork!", user.canFork(repository));
613         user.canFork = true;
614         assertFalse("named CAN fork!", user.canFork(repository));
615         repository.allowForks = true;
616         assertTrue("named CAN NOT fork!", user.canFork(repository));
617     }    
618
619     /**
620      * NONE_PUSH = NO access restriction, PUSH access permission.
621      * (not useful scenario)
622      */
623     @Test
624     public void testNamed_NONE_PUSH() throws Exception {
625         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
626         repository.authorizationControl = AuthorizationControl.NAMED;
627         repository.accessRestriction = AccessRestrictionType.NONE;
628
629         UserModel user = new UserModel("test");
630         user.setRepositoryPermission(repository.name, AccessPermission.PUSH);
631         
632         assertTrue("named CAN NOT view!", user.canView(repository));
633         assertTrue("named CAN NOT clone!", user.canClone(repository));
634         assertTrue("named CAN NOT push!", user.canPush(repository));
635         
636         assertTrue("named CAN NOT create ref!", user.canCreateRef(repository));
637         assertTrue("named CAN NOT delete ref!", user.canDeleteRef(repository));
638         assertTrue("named CAN NOT rewind ref!", user.canRewindRef(repository));
639         
640         repository.allowForks = false;
641         user.canFork = false;
642         assertFalse("named CAN fork!", user.canFork(repository));
643         user.canFork = true;
644         assertFalse("named CAN fork!", user.canFork(repository));
645         repository.allowForks = true;
646         assertTrue("named CAN NOT fork!", user.canFork(repository));
647     }
648     
649     /**
650      * PUSH_PUSH = PUSH access restriction, PUSH access permission
651      */
652     @Test
653     public void testNamed_PUSH_PUSH() throws Exception {
654         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
655         repository.authorizationControl = AuthorizationControl.NAMED;
656         repository.accessRestriction = AccessRestrictionType.PUSH;
657         
658         UserModel user = new UserModel("test");
659         user.setRepositoryPermission(repository.name, AccessPermission.PUSH);
660         
661         assertTrue("named CAN NOT view!", user.canView(repository));
662         assertTrue("named CAN NOT clone!", user.canClone(repository));
663         assertTrue("named CAN NOT push!", user.canPush(repository));
664         
665         assertFalse("named CAN create ref!", user.canCreateRef(repository));
666         assertFalse("named CAN delete ref!", user.canDeleteRef(repository));
667         assertFalse("named CAN rewind ref!", user.canRewindRef(repository));
668
669         repository.allowForks = false;
670         user.canFork = false;
671         assertFalse("named CAN fork!", user.canFork(repository));
672         user.canFork = true;
673         assertFalse("named CAN fork!", user.canFork(repository));
674         repository.allowForks = true;
675         assertTrue("named CAN NOT fork!", user.canFork(repository));
676     }
677     
678     /**
679      * CLONE_PUSH = CLONE access restriction, PUSH access permission
680      */
681     @Test
682     public void testNamed_CLONE_PUSH() throws Exception {
683         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
684         repository.authorizationControl = AuthorizationControl.NAMED;
685         repository.accessRestriction = AccessRestrictionType.CLONE;
686         
687         UserModel user = new UserModel("test");
688         user.setRepositoryPermission(repository.name, AccessPermission.PUSH);
689
690         assertTrue("named CAN NOT view!", user.canView(repository));
691         assertTrue("named CAN NOT clone!", user.canClone(repository));
692         assertTrue("named CAN NOT push!", user.canPush(repository));
693         
694         assertFalse("named CAN create ref!", user.canCreateRef(repository));
695         assertFalse("named CAN delete red!", user.canDeleteRef(repository));
696         assertFalse("named CAN rewind ref!", user.canRewindRef(repository));
697
698         repository.allowForks = false;
699         user.canFork = false;
700         assertFalse("named CAN fork!", user.canFork(repository));
701         user.canFork = true;
702         assertFalse("named CAN fork!", user.canFork(repository));
703         repository.allowForks = true;
704         assertTrue("named CAN NOT fork!", user.canFork(repository));
705     }
706     
707     /**
708      * VIEW_PUSH = VIEW access restriction, PUSH access permission
709      */
710     @Test
711     public void testNamed_VIEW_PUSH() throws Exception {
712         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
713         repository.authorizationControl = AuthorizationControl.NAMED;
714         repository.accessRestriction = AccessRestrictionType.VIEW;
715         
716         UserModel user = new UserModel("test");
717         user.setRepositoryPermission(repository.name, AccessPermission.PUSH);
718
719         assertTrue("named CAN NOT view!", user.canView(repository));
720         assertTrue("named CAN NOT clone!", user.canClone(repository));
721         assertTrue("named CAN not push!", user.canPush(repository));
722         
723         assertFalse("named CAN create ref!", user.canCreateRef(repository));
724         assertFalse("named CAN delete ref!", user.canDeleteRef(repository));
725         assertFalse("named CAN rewind ref!", user.canRewindRef(repository));
726         
727         repository.allowForks = false;
728         user.canFork = false;
729         assertFalse("named CAN fork!", user.canFork(repository));
730         user.canFork = true;
731         assertFalse("named CAN fork!", user.canFork(repository));
732         repository.allowForks = true;
733         assertTrue("named CAN NOT fork!", user.canFork(repository));
734     }
735
736     /**
737      * NONE_CREATE = NO access restriction, CREATE access permission.
738      * (not useful scenario)
739      */
740     @Test
741     public void testNamed_NONE_CREATE() throws Exception {
742         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
743         repository.authorizationControl = AuthorizationControl.NAMED;
744         repository.accessRestriction = AccessRestrictionType.NONE;
745
746         UserModel user = new UserModel("test");
747         user.setRepositoryPermission(repository.name, AccessPermission.CREATE);
748         
749         assertTrue("named CAN NOT view!", user.canView(repository));
750         assertTrue("named CAN NOT clone!", user.canClone(repository));
751         assertTrue("named CAN NOT push!", user.canPush(repository));
752         
753         assertTrue("named CAN NOT create ref!", user.canCreateRef(repository));
754         assertTrue("named CAN NOT delete ref!", user.canDeleteRef(repository));
755         assertTrue("named CAN NOT rewind ref!", user.canRewindRef(repository));
756         
757         repository.allowForks = false;
758         user.canFork = false;
759         assertFalse("named CAN fork!", user.canFork(repository));
760         user.canFork = true;
761         assertFalse("named CAN fork!", user.canFork(repository));
762         repository.allowForks = true;
763         assertTrue("named CAN NOT fork!", user.canFork(repository));
764     }
765     
766     /**
767      * PUSH_CREATE = PUSH access restriction, CREATE access permission
768      */
769     @Test
770     public void testNamed_PUSH_CREATE() throws Exception {
771         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
772         repository.authorizationControl = AuthorizationControl.NAMED;
773         repository.accessRestriction = AccessRestrictionType.PUSH;
774         
775         UserModel user = new UserModel("test");
776         user.setRepositoryPermission(repository.name, AccessPermission.CREATE);
777         
778         assertTrue("named CAN NOT view!", user.canView(repository));
779         assertTrue("named CAN NOT clone!", user.canClone(repository));
780         assertTrue("named CAN NOT push!", user.canPush(repository));
781         
782         assertTrue("named CAN NOT create ref!", user.canCreateRef(repository));
783         assertFalse("named CAN delete ref!", user.canDeleteRef(repository));
784         assertFalse("named CAN rewind ref!", user.canRewindRef(repository));
785
786         repository.allowForks = false;
787         user.canFork = false;
788         assertFalse("named CAN fork!", user.canFork(repository));
789         user.canFork = true;
790         assertFalse("named CAN fork!", user.canFork(repository));
791         repository.allowForks = true;
792         assertTrue("named CAN NOT fork!", user.canFork(repository));
793     }
794     
795     /**
796      * CLONE_CREATE = CLONE access restriction, CREATE access permission
797      */
798     @Test
799     public void testNamed_CLONE_CREATE() throws Exception {
800         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
801         repository.authorizationControl = AuthorizationControl.NAMED;
802         repository.accessRestriction = AccessRestrictionType.CLONE;
803         
804         UserModel user = new UserModel("test");
805         user.setRepositoryPermission(repository.name, AccessPermission.CREATE);
806
807         assertTrue("named CAN NOT view!", user.canView(repository));
808         assertTrue("named CAN NOT clone!", user.canClone(repository));
809         assertTrue("named CAN NOT push!", user.canPush(repository));
810         
811         assertTrue("named CAN NOT create ref!", user.canCreateRef(repository));
812         assertFalse("named CAN delete red!", user.canDeleteRef(repository));
813         assertFalse("named CAN rewind ref!", user.canRewindRef(repository));
814
815         repository.allowForks = false;
816         user.canFork = false;
817         assertFalse("named CAN fork!", user.canFork(repository));
818         user.canFork = true;
819         assertFalse("named CAN fork!", user.canFork(repository));
820         repository.allowForks = true;
821         assertTrue("named CAN NOT fork!", user.canFork(repository));
822     }
823     
824     /**
825      * VIEW_CREATE = VIEW access restriction, CREATE access permission
826      */
827     @Test
828     public void testNamed_VIEW_CREATE() throws Exception {
829         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
830         repository.authorizationControl = AuthorizationControl.NAMED;
831         repository.accessRestriction = AccessRestrictionType.VIEW;
832         
833         UserModel user = new UserModel("test");
834         user.setRepositoryPermission(repository.name, AccessPermission.CREATE);
835
836         assertTrue("named CAN NOT view!", user.canView(repository));
837         assertTrue("named CAN NOT clone!", user.canClone(repository));
838         assertTrue("named CAN not push!", user.canPush(repository));
839         
840         assertTrue("named CAN NOT create ref!", user.canCreateRef(repository));
841         assertFalse("named CAN delete ref!", user.canDeleteRef(repository));
842         assertFalse("named CAN rewind ref!", user.canRewindRef(repository));
843         
844         repository.allowForks = false;
845         user.canFork = false;
846         assertFalse("named CAN fork!", user.canFork(repository));
847         user.canFork = true;
848         assertFalse("named CAN fork!", user.canFork(repository));
849         repository.allowForks = true;
850         assertTrue("named CAN NOT fork!", user.canFork(repository));
851     }
852
853     /**
854      * NONE_DELETE = NO access restriction, DELETE access permission.
855      * (not useful scenario)
856      */
857     @Test
858     public void testNamed_NONE_DELETE() throws Exception {
859         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
860         repository.authorizationControl = AuthorizationControl.NAMED;
861         repository.accessRestriction = AccessRestrictionType.NONE;
862
863         UserModel user = new UserModel("test");
864         user.setRepositoryPermission(repository.name, AccessPermission.DELETE);
865         
866         assertTrue("named CAN NOT view!", user.canView(repository));
867         assertTrue("named CAN NOT clone!", user.canClone(repository));
868         assertTrue("named CAN NOT push!", user.canPush(repository));
869         
870         assertTrue("named CAN NOT create ref!", user.canCreateRef(repository));
871         assertTrue("named CAN NOT delete ref!", user.canDeleteRef(repository));
872         assertTrue("named CAN NOT rewind ref!", user.canRewindRef(repository));
873         
874         repository.allowForks = false;
875         user.canFork = false;
876         assertFalse("named CAN fork!", user.canFork(repository));
877         user.canFork = true;
878         assertFalse("named CAN fork!", user.canFork(repository));
879         repository.allowForks = true;
880         assertTrue("named CAN NOT fork!", user.canFork(repository));
881     }
882     
883     /**
884      * PUSH_DELETE = PUSH access restriction, DELETE access permission
885      */
886     @Test
887     public void testNamed_PUSH_DELETE() throws Exception {
888         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
889         repository.authorizationControl = AuthorizationControl.NAMED;
890         repository.accessRestriction = AccessRestrictionType.PUSH;
891         
892         UserModel user = new UserModel("test");
893         user.setRepositoryPermission(repository.name, AccessPermission.DELETE);
894         
895         assertTrue("named CAN NOT view!", user.canView(repository));
896         assertTrue("named CAN NOT clone!", user.canClone(repository));
897         assertTrue("named CAN NOT push!", user.canPush(repository));
898         
899         assertTrue("named CAN NOT create ref!", user.canCreateRef(repository));
900         assertTrue("named CAN NOT delete ref!", user.canDeleteRef(repository));
901         assertFalse("named CAN rewind ref!", user.canRewindRef(repository));
902
903         repository.allowForks = false;
904         user.canFork = false;
905         assertFalse("named CAN fork!", user.canFork(repository));
906         user.canFork = true;
907         assertFalse("named CAN fork!", user.canFork(repository));
908         repository.allowForks = true;
909         assertTrue("named CAN NOT fork!", user.canFork(repository));
910     }
911     
912     /**
913      * CLONE_DELETE = CLONE access restriction, DELETE access permission
914      */
915     @Test
916     public void testNamed_CLONE_DELETE() throws Exception {
917         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
918         repository.authorizationControl = AuthorizationControl.NAMED;
919         repository.accessRestriction = AccessRestrictionType.CLONE;
920         
921         UserModel user = new UserModel("test");
922         user.setRepositoryPermission(repository.name, AccessPermission.DELETE);
923
924         assertTrue("named CAN NOT view!", user.canView(repository));
925         assertTrue("named CAN NOT clone!", user.canClone(repository));
926         assertTrue("named CAN NOT push!", user.canPush(repository));
927         
928         assertTrue("named CAN NOT create ref!", user.canCreateRef(repository));
929         assertTrue("named CAN NOT delete red!", user.canDeleteRef(repository));
930         assertFalse("named CAN rewind ref!", user.canRewindRef(repository));
931
932         repository.allowForks = false;
933         user.canFork = false;
934         assertFalse("named CAN fork!", user.canFork(repository));
935         user.canFork = true;
936         assertFalse("named CAN fork!", user.canFork(repository));
937         repository.allowForks = true;
938         assertTrue("named CAN NOT fork!", user.canFork(repository));
939     }
940     
941     /**
942      * VIEW_DELETE = VIEW access restriction, DELETE access permission
943      */
944     @Test
945     public void testNamed_VIEW_DELETE() throws Exception {
946         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
947         repository.authorizationControl = AuthorizationControl.NAMED;
948         repository.accessRestriction = AccessRestrictionType.VIEW;
949         
950         UserModel user = new UserModel("test");
951         user.setRepositoryPermission(repository.name, AccessPermission.DELETE);
952
953         assertTrue("named CAN NOT view!", user.canView(repository));
954         assertTrue("named CAN NOT clone!", user.canClone(repository));
955         assertTrue("named CAN not push!", user.canPush(repository));
956         
957         assertTrue("named CAN NOT create ref!", user.canCreateRef(repository));
958         assertTrue("named CAN NOT delete ref!", user.canDeleteRef(repository));
959         assertFalse("named CAN rewind ref!", user.canRewindRef(repository));
960         
961         repository.allowForks = false;
962         user.canFork = false;
963         assertFalse("named CAN fork!", user.canFork(repository));
964         user.canFork = true;
965         assertFalse("named CAN fork!", user.canFork(repository));
966         repository.allowForks = true;
967         assertTrue("named CAN NOT fork!", user.canFork(repository));
968     }
969     
970     /**
971      * NONE_REWIND = NO access restriction, REWIND access permission.
972      * (not useful scenario)
973      */
974     @Test
975     public void testNamed_NONE_REWIND() throws Exception {
976         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
977         repository.authorizationControl = AuthorizationControl.NAMED;
978         repository.accessRestriction = AccessRestrictionType.NONE;
979
980         UserModel user = new UserModel("test");
981         user.setRepositoryPermission(repository.name, AccessPermission.REWIND);
982         
983         assertTrue("named CAN NOT view!", user.canView(repository));
984         assertTrue("named CAN NOT clone!", user.canClone(repository));
985         assertTrue("named CAN NOT push!", user.canPush(repository));
986         
987         assertTrue("named CAN NOT create ref!", user.canCreateRef(repository));
988         assertTrue("named CAN NOT delete ref!", user.canDeleteRef(repository));
989         assertTrue("named CAN NOT rewind ref!", user.canRewindRef(repository));
990         
991         repository.allowForks = false;
992         user.canFork = false;
993         assertFalse("named CAN fork!", user.canFork(repository));
994         user.canFork = true;
995         assertFalse("named CAN fork!", user.canFork(repository));
996         repository.allowForks = true;
997         assertTrue("named CAN NOT fork!", user.canFork(repository));
998     }
999     
1000     /**
1001      * PUSH_REWIND = PUSH access restriction, REWIND access permission
1002      */
1003     @Test
1004     public void testNamed_PUSH_REWIND() throws Exception {
1005         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1006         repository.authorizationControl = AuthorizationControl.NAMED;
1007         repository.accessRestriction = AccessRestrictionType.PUSH;
1008         
1009         UserModel user = new UserModel("test");
1010         user.setRepositoryPermission(repository.name, AccessPermission.REWIND);
1011         
1012         assertTrue("named CAN NOT view!", user.canView(repository));
1013         assertTrue("named CAN NOT clone!", user.canClone(repository));
1014         assertTrue("named CAN NOT push!", user.canPush(repository));
1015         
1016         assertTrue("named CAN NOT create ref!", user.canCreateRef(repository));
1017         assertTrue("named CAN NOT delete ref!", user.canDeleteRef(repository));
1018         assertTrue("named CAN NOT rewind ref!", user.canRewindRef(repository));
1019
1020         repository.allowForks = false;
1021         user.canFork = false;
1022         assertFalse("named CAN fork!", user.canFork(repository));
1023         user.canFork = true;
1024         assertFalse("named CAN fork!", user.canFork(repository));
1025         repository.allowForks = true;
1026         assertTrue("named CAN NOT fork!", user.canFork(repository));
1027     }
1028     
1029     /**
1030      * CLONE_REWIND = CLONE access restriction, REWIND access permission
1031      */
1032     @Test
1033     public void testNamed_CLONE_REWIND() throws Exception {
1034         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1035         repository.authorizationControl = AuthorizationControl.NAMED;
1036         repository.accessRestriction = AccessRestrictionType.CLONE;
1037         
1038         UserModel user = new UserModel("test");
1039         user.setRepositoryPermission(repository.name, AccessPermission.REWIND);
1040
1041         assertTrue("named CAN NOT view!", user.canView(repository));
1042         assertTrue("named CAN NOT clone!", user.canClone(repository));
1043         assertTrue("named CAN NOT push!", user.canPush(repository));
1044         
1045         assertTrue("named CAN NOT create ref!", user.canCreateRef(repository));
1046         assertTrue("named CAN NOT delete ref!", user.canDeleteRef(repository));
1047         assertTrue("named CAN NOT rewind ref!", user.canRewindRef(repository));
1048
1049         repository.allowForks = false;
1050         user.canFork = false;
1051         assertFalse("named CAN fork!", user.canFork(repository));
1052         user.canFork = true;
1053         assertFalse("named CAN fork!", user.canFork(repository));
1054         repository.allowForks = true;
1055         assertTrue("named CAN NOT fork!", user.canFork(repository));
1056     }
1057     
1058     /**
1059      * VIEW_REWIND = VIEW access restriction, REWIND access permission
1060      */
1061     @Test
1062     public void testNamed_VIEW_REWIND() throws Exception {
1063         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1064         repository.authorizationControl = AuthorizationControl.NAMED;
1065         repository.accessRestriction = AccessRestrictionType.VIEW;
1066         
1067         UserModel user = new UserModel("test");
1068         user.setRepositoryPermission(repository.name, AccessPermission.REWIND);
1069
1070         assertTrue("named CAN NOT view!", user.canView(repository));
1071         assertTrue("named CAN NOT clone!", user.canClone(repository));
1072         assertTrue("named CAN NOT push!", user.canPush(repository));
1073         
1074         assertTrue("named CAN NOT create ref!", user.canCreateRef(repository));
1075         assertTrue("named CAN NOT delete ref!", user.canDeleteRef(repository));
1076         assertTrue("named CAN NOT rewind ref!", user.canRewindRef(repository));
1077         
1078         repository.allowForks = false;
1079         user.canFork = false;
1080         assertFalse("named CAN fork!", user.canFork(repository));
1081         user.canFork = true;
1082         assertFalse("named CAN fork!", user.canFork(repository));
1083         repository.allowForks = true;
1084         assertTrue("named CAN NOT fork!", user.canFork(repository));
1085     }
1086     
1087     /**
1088      * NONE_NONE = NO access restriction, NO access permission
1089      */
1090     @Test
1091     public void testTeam_NONE_NONE() throws Exception {
1092         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1093         repository.authorizationControl = AuthorizationControl.NAMED;
1094         repository.accessRestriction = AccessRestrictionType.NONE;
1095
1096         TeamModel team = new TeamModel("test");
1097         
1098         assertTrue("team CAN NOT view!", team.canView(repository));
1099         assertTrue("team CAN NOT clone!", team.canClone(repository));
1100         assertTrue("team CAN NOT push!", team.canPush(repository));
1101         
1102         assertTrue("team CAN NOT create ref!", team.canCreateRef(repository));
1103         assertTrue("team CAN NOT delete ref!", team.canDeleteRef(repository));
1104         assertTrue("team CAN NOT rewind ref!", team.canRewindRef(repository));
1105     }
1106     
1107     /**
1108      * PUSH_NONE = PUSH access restriction, NO access permission
1109      */
1110     @Test
1111     public void testTeam_PUSH_NONE() throws Exception {
1112         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1113         repository.authorizationControl = AuthorizationControl.NAMED;
1114         repository.accessRestriction = AccessRestrictionType.PUSH;
1115
1116         TeamModel team = new TeamModel("test");
1117         
1118         assertTrue("team CAN NOT view!", team.canView(repository));
1119         assertTrue("team CAN NOT clone!", team.canClone(repository));
1120         assertFalse("team CAN push!", team.canPush(repository));
1121         
1122         assertFalse("team CAN create ref!", team.canCreateRef(repository));
1123         assertFalse("team CAN delete ref!", team.canDeleteRef(repository));
1124         assertFalse("team CAN rewind ref!", team.canRewindRef(repository));
1125     }
1126
1127     /**
1128      * CLONE_NONE = CLONE access restriction, NO access permission
1129      */
1130     @Test
1131     public void testTeam_CLONE_NONE() throws Exception {
1132         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1133         repository.authorizationControl = AuthorizationControl.NAMED;
1134         repository.accessRestriction = AccessRestrictionType.CLONE;
1135
1136         TeamModel team = new TeamModel("test");
1137         
1138         assertTrue("team CAN NOT view!", team.canView(repository));
1139         assertFalse("team CAN clone!", team.canClone(repository));
1140         assertFalse("team CAN push!", team.canPush(repository));
1141         
1142         assertFalse("team CAN create ref!", team.canCreateRef(repository));
1143         assertFalse("team CAN delete ref!", team.canDeleteRef(repository));
1144         assertFalse("team CAN rewind ref!", team.canRewindRef(repository));
1145     }
1146
1147     /**
1148      * VIEW_NONE = VIEW access restriction, NO access permission
1149      */
1150     @Test
1151     public void testTeam_VIEW_NONE() throws Exception {
1152         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1153         repository.authorizationControl = AuthorizationControl.NAMED;
1154         repository.accessRestriction = AccessRestrictionType.VIEW;
1155
1156         TeamModel team = new TeamModel("test");
1157         
1158         assertFalse("team CAN view!", team.canView(repository));
1159         assertFalse("team CAN clone!", team.canClone(repository));
1160         assertFalse("team CAN push!", team.canPush(repository));
1161         
1162         assertFalse("team CAN create ref!", team.canCreateRef(repository));
1163         assertFalse("team CAN delete ref!", team.canDeleteRef(repository));
1164         assertFalse("team CAN rewind ref!", team.canRewindRef(repository));
1165     }
1166     
1167     /**
1168      * NONE_PUSH = NO access restriction, PUSH access permission
1169      * (not useful scenario)
1170      */
1171     @Test
1172     public void testTeam_NONE_PUSH() throws Exception {
1173         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1174         repository.authorizationControl = AuthorizationControl.NAMED;
1175         repository.accessRestriction = AccessRestrictionType.NONE;
1176
1177         TeamModel team = new TeamModel("test");
1178         team.setRepositoryPermission(repository.name, AccessPermission.PUSH);
1179         
1180         assertTrue("team CAN NOT view!", team.canView(repository));
1181         assertTrue("team CAN NOT clone!", team.canClone(repository));
1182         assertTrue("team CAN NOT push!", team.canPush(repository));
1183         
1184         assertTrue("team CAN NOT create ref!", team.canCreateRef(repository));
1185         assertTrue("team CAN NOT delete ref!", team.canDeleteRef(repository));
1186         assertTrue("team CAN NOT rewind ref!", team.canRewindRef(repository));
1187     }
1188     
1189     /**
1190      * PUSH_PUSH = PUSH access restriction, PUSH access permission
1191      */
1192     @Test
1193     public void testTeam_PUSH_PUSH() throws Exception {
1194         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1195         repository.authorizationControl = AuthorizationControl.NAMED;
1196         repository.accessRestriction = AccessRestrictionType.PUSH;
1197
1198         TeamModel team = new TeamModel("test");
1199         team.setRepositoryPermission(repository.name, AccessPermission.PUSH);
1200         
1201         assertTrue("team CAN NOT view!", team.canView(repository));
1202         assertTrue("team CAN NOT clone!", team.canClone(repository));
1203         assertTrue("team CAN NOT push!", team.canPush(repository));
1204         
1205         assertFalse("team CAN create ref!", team.canCreateRef(repository));
1206         assertFalse("team CAN delete ref!", team.canDeleteRef(repository));
1207         assertFalse("team CAN rewind ref!", team.canRewindRef(repository));
1208     }
1209     
1210     /**
1211      * CLONE_PUSH = CLONE access restriction, PUSH access permission
1212      */
1213     @Test
1214     public void testTeam_CLONE_PUSH() throws Exception {
1215         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1216         repository.authorizationControl = AuthorizationControl.NAMED;
1217         repository.accessRestriction = AccessRestrictionType.CLONE;
1218
1219         TeamModel team = new TeamModel("test");
1220         team.setRepositoryPermission(repository.name, AccessPermission.PUSH);
1221         
1222         assertTrue("team CAN NOT view!", team.canView(repository));
1223         assertTrue("team CAN NOT clone!", team.canClone(repository));
1224         assertTrue("team CAN NOT push!", team.canPush(repository));
1225         
1226         assertFalse("team CAN create ref!", team.canCreateRef(repository));
1227         assertFalse("team CAN delete ref!", team.canDeleteRef(repository));
1228         assertFalse("team CAN rewind ref!", team.canRewindRef(repository));
1229     }
1230     
1231     /**
1232      * VIEW_PUSH = VIEW access restriction, PUSH access permission
1233      */
1234     @Test
1235     public void testTeam_VIEW_PUSH() throws Exception {
1236         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1237         repository.authorizationControl = AuthorizationControl.NAMED;
1238         repository.accessRestriction = AccessRestrictionType.VIEW;
1239
1240         TeamModel team = new TeamModel("test");
1241         team.setRepositoryPermission(repository.name, AccessPermission.PUSH);
1242         
1243         assertTrue("team CAN NOT view!", team.canView(repository));
1244         assertTrue("team CAN NOT clone!", team.canClone(repository));
1245         assertTrue("team CAN NOT push!", team.canPush(repository));
1246         
1247         assertFalse("team CAN create ref!", team.canCreateRef(repository));
1248         assertFalse("team CAN delete ref!", team.canDeleteRef(repository));
1249         assertFalse("team CAN rewind ref!", team.canRewindRef(repository));
1250     }
1251     
1252     /**
1253      * NONE_CREATE = NO access restriction, CREATE access permission
1254      * (not useful scenario)
1255      */
1256     @Test
1257     public void testTeam_NONE_CREATE() throws Exception {
1258         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1259         repository.authorizationControl = AuthorizationControl.NAMED;
1260         repository.accessRestriction = AccessRestrictionType.NONE;
1261
1262         TeamModel team = new TeamModel("test");
1263         team.setRepositoryPermission(repository.name, AccessPermission.CREATE);
1264         
1265         assertTrue("team CAN NOT view!", team.canView(repository));
1266         assertTrue("team CAN NOT clone!", team.canClone(repository));
1267         assertTrue("team CAN NOT push!", team.canPush(repository));
1268         
1269         assertTrue("team CAN NOT create ref!", team.canCreateRef(repository));
1270         assertTrue("team CAN NOT delete ref!", team.canDeleteRef(repository));
1271         assertTrue("team CAN NOT rewind ref!", team.canRewindRef(repository));
1272     }
1273     
1274     /**
1275      * PUSH_CREATE = PUSH access restriction, CREATE access permission
1276      */
1277     @Test
1278     public void testTeam_PUSH_CREATE() throws Exception {
1279         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1280         repository.authorizationControl = AuthorizationControl.NAMED;
1281         repository.accessRestriction = AccessRestrictionType.PUSH;
1282
1283         TeamModel team = new TeamModel("test");
1284         team.setRepositoryPermission(repository.name, AccessPermission.CREATE);
1285         
1286         assertTrue("team CAN NOT view!", team.canView(repository));
1287         assertTrue("team CAN NOT clone!", team.canClone(repository));
1288         assertTrue("team CAN NOT push!", team.canPush(repository));
1289         
1290         assertTrue("team CAN NOT create ref!", team.canCreateRef(repository));
1291         assertFalse("team CAN delete ref!", team.canDeleteRef(repository));
1292         assertFalse("team CAN rewind ref!", team.canRewindRef(repository));
1293     }
1294     
1295     /**
1296      * CLONE_CREATE = CLONE access restriction, CREATE access permission
1297      */
1298     @Test
1299     public void testTeam_CLONE_CREATE() throws Exception {
1300         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1301         repository.authorizationControl = AuthorizationControl.NAMED;
1302         repository.accessRestriction = AccessRestrictionType.CLONE;
1303
1304         TeamModel team = new TeamModel("test");
1305         team.setRepositoryPermission(repository.name, AccessPermission.CREATE);
1306         
1307         assertTrue("team CAN NOT view!", team.canView(repository));
1308         assertTrue("team CAN NOT clone!", team.canClone(repository));
1309         assertTrue("team CAN NOT push!", team.canPush(repository));
1310         
1311         assertTrue("team CAN NOT create ref!", team.canCreateRef(repository));
1312         assertFalse("team CAN delete ref!", team.canDeleteRef(repository));
1313         assertFalse("team CAN rewind ref!", team.canRewindRef(repository));
1314     }
1315     
1316     /**
1317      * VIEW_CREATE = VIEW access restriction, CREATE access permission
1318      */
1319     @Test
1320     public void testTeam_VIEW_CREATE() throws Exception {
1321         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1322         repository.authorizationControl = AuthorizationControl.NAMED;
1323         repository.accessRestriction = AccessRestrictionType.VIEW;
1324
1325         TeamModel team = new TeamModel("test");
1326         team.setRepositoryPermission(repository.name, AccessPermission.CREATE);
1327         
1328         assertTrue("team CAN NOT view!", team.canView(repository));
1329         assertTrue("team CAN NOT clone!", team.canClone(repository));
1330         assertTrue("team CAN NOT push!", team.canPush(repository));
1331         
1332         assertTrue("team CAN NOT create ref!", team.canCreateRef(repository));
1333         assertFalse("team CAN delete ref!", team.canDeleteRef(repository));
1334         assertFalse("team CAN rewind ref!", team.canRewindRef(repository));
1335     }
1336
1337     /**
1338      * NONE_DELETE = NO access restriction, DELETE access permission
1339      * (not useful scenario)
1340      */
1341     @Test
1342     public void testTeam_NONE_DELETE() throws Exception {
1343         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1344         repository.authorizationControl = AuthorizationControl.NAMED;
1345         repository.accessRestriction = AccessRestrictionType.NONE;
1346
1347         TeamModel team = new TeamModel("test");
1348         team.setRepositoryPermission(repository.name, AccessPermission.DELETE);
1349         
1350         assertTrue("team CAN NOT view!", team.canView(repository));
1351         assertTrue("team CAN NOT clone!", team.canClone(repository));
1352         assertTrue("team CAN NOT push!", team.canPush(repository));
1353         
1354         assertTrue("team CAN NOT create ref!", team.canCreateRef(repository));
1355         assertTrue("team CAN NOT delete ref!", team.canDeleteRef(repository));
1356         assertTrue("team CAN NOT rewind ref!", team.canRewindRef(repository));
1357     }
1358     
1359     /**
1360      * PUSH_DELETE = PUSH access restriction, DELETE access permission
1361      */
1362     @Test
1363     public void testTeam_PUSH_DELETE() throws Exception {
1364         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1365         repository.authorizationControl = AuthorizationControl.NAMED;
1366         repository.accessRestriction = AccessRestrictionType.PUSH;
1367
1368         TeamModel team = new TeamModel("test");
1369         team.setRepositoryPermission(repository.name, AccessPermission.DELETE);
1370         
1371         assertTrue("team CAN NOT view!", team.canView(repository));
1372         assertTrue("team CAN NOT clone!", team.canClone(repository));
1373         assertTrue("team CAN NOT push!", team.canPush(repository));
1374         
1375         assertTrue("team CAN NOT create ref!", team.canCreateRef(repository));
1376         assertTrue("team CAN NOT delete ref!", team.canDeleteRef(repository));
1377         assertFalse("team CAN rewind ref!", team.canRewindRef(repository));
1378     }
1379     
1380     /**
1381      * CLONE_DELETE = CLONE access restriction, DELETE access permission
1382      */
1383     @Test
1384     public void testTeam_CLONE_DELETE() throws Exception {
1385         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1386         repository.authorizationControl = AuthorizationControl.NAMED;
1387         repository.accessRestriction = AccessRestrictionType.CLONE;
1388
1389         TeamModel team = new TeamModel("test");
1390         team.setRepositoryPermission(repository.name, AccessPermission.DELETE);
1391         
1392         assertTrue("team CAN NOT view!", team.canView(repository));
1393         assertTrue("team CAN NOT clone!", team.canClone(repository));
1394         assertTrue("team CAN NOT push!", team.canPush(repository));
1395         
1396         assertTrue("team CAN NOT create ref!", team.canCreateRef(repository));
1397         assertTrue("team CAN NOT delete ref!", team.canDeleteRef(repository));
1398         assertFalse("team CAN rewind ref!", team.canRewindRef(repository));
1399     }
1400     
1401     /**
1402      * VIEW_DELETE = VIEW access restriction, DELETE access permission
1403      */
1404     @Test
1405     public void testTeam_VIEW_DELETE() throws Exception {
1406         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1407         repository.authorizationControl = AuthorizationControl.NAMED;
1408         repository.accessRestriction = AccessRestrictionType.VIEW;
1409
1410         TeamModel team = new TeamModel("test");
1411         team.setRepositoryPermission(repository.name, AccessPermission.DELETE);
1412         
1413         assertTrue("team CAN NOT view!", team.canView(repository));
1414         assertTrue("team CAN NOT clone!", team.canClone(repository));
1415         assertTrue("team CAN NOT push!", team.canPush(repository));
1416         
1417         assertTrue("team CAN NOT create ref!", team.canCreateRef(repository));
1418         assertTrue("team CAN NOT delete ref!", team.canDeleteRef(repository));
1419         assertFalse("team CAN rewind ref!", team.canRewindRef(repository));
1420     }
1421     
1422     /**
1423      * NONE_REWIND = NO access restriction, REWIND access permission
1424      * (not useful scenario)
1425      */
1426     @Test
1427     public void testTeam_NONE_REWIND() throws Exception {
1428         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1429         repository.authorizationControl = AuthorizationControl.NAMED;
1430         repository.accessRestriction = AccessRestrictionType.NONE;
1431
1432         TeamModel team = new TeamModel("test");
1433         team.setRepositoryPermission(repository.name, AccessPermission.REWIND);
1434         
1435         assertTrue("team CAN NOT view!", team.canView(repository));
1436         assertTrue("team CAN NOT clone!", team.canClone(repository));
1437         assertTrue("team CAN NOT push!", team.canPush(repository));
1438         
1439         assertTrue("team CAN NOT create ref!", team.canCreateRef(repository));
1440         assertTrue("team CAN NOT delete ref!", team.canDeleteRef(repository));
1441         assertTrue("team CAN NOT rewind ref!", team.canRewindRef(repository));
1442     }
1443     
1444     /**
1445      * PUSH_REWIND = PUSH access restriction, REWIND access permission
1446      */
1447     @Test
1448     public void testTeam_PUSH_REWIND() throws Exception {
1449         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1450         repository.authorizationControl = AuthorizationControl.NAMED;
1451         repository.accessRestriction = AccessRestrictionType.PUSH;
1452
1453         TeamModel team = new TeamModel("test");
1454         team.setRepositoryPermission(repository.name, AccessPermission.REWIND);
1455         
1456         assertTrue("team CAN NOT view!", team.canView(repository));
1457         assertTrue("team CAN NOT clone!", team.canClone(repository));
1458         assertTrue("team CAN NOT push!", team.canPush(repository));
1459         
1460         assertTrue("team CAN NOT create ref!", team.canCreateRef(repository));
1461         assertTrue("team CAN NOT delete ref!", team.canDeleteRef(repository));
1462         assertTrue("team CAN NOT rewind ref!", team.canRewindRef(repository));
1463     }
1464     
1465     /**
1466      * CLONE_REWIND = CLONE access restriction, REWIND access permission
1467      */
1468     @Test
1469     public void testTeam_CLONE_REWIND() throws Exception {
1470         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1471         repository.authorizationControl = AuthorizationControl.NAMED;
1472         repository.accessRestriction = AccessRestrictionType.CLONE;
1473
1474         TeamModel team = new TeamModel("test");
1475         team.setRepositoryPermission(repository.name, AccessPermission.REWIND);
1476         
1477         assertTrue("team CAN NOT view!", team.canView(repository));
1478         assertTrue("team CAN NOT clone!", team.canClone(repository));
1479         assertTrue("team CAN NOT push!", team.canPush(repository));
1480         
1481         assertTrue("team CAN NOT create ref!", team.canCreateRef(repository));
1482         assertTrue("team CAN NOT delete ref!", team.canDeleteRef(repository));
1483         assertTrue("team CAN NOT rewind ref!", team.canRewindRef(repository));
1484     }
1485     
1486     /**
1487      * VIEW_REWIND = VIEW access restriction, REWIND access permission
1488      */
1489     @Test
1490     public void testTeam_VIEW_REWIND() throws Exception {
1491         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1492         repository.authorizationControl = AuthorizationControl.NAMED;
1493         repository.accessRestriction = AccessRestrictionType.VIEW;
1494
1495         TeamModel team = new TeamModel("test");
1496         team.setRepositoryPermission(repository.name, AccessPermission.REWIND);
1497         
1498         assertTrue("team CAN NOT view!", team.canView(repository));
1499         assertTrue("team CAN NOT clone!", team.canClone(repository));
1500         assertTrue("team CAN NOT push!", team.canPush(repository));
1501         
1502         assertTrue("team CAN NOT create ref!", team.canCreateRef(repository));
1503         assertTrue("team CAN NOT delete ref!", team.canDeleteRef(repository));
1504         assertTrue("team CAN NOT rewind ref!", team.canRewindRef(repository));
1505     }
1506     
1507     /**
1508      * NONE_CLONE = NO access restriction, CLONE access permission
1509      * (not useful scenario)
1510      */
1511     @Test
1512     public void testTeam_NONE_CLONE() throws Exception {
1513         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1514         repository.authorizationControl = AuthorizationControl.NAMED;
1515         repository.accessRestriction = AccessRestrictionType.NONE;
1516
1517         TeamModel team = new TeamModel("test");
1518         team.setRepositoryPermission(repository.name, AccessPermission.CLONE);
1519         
1520         assertTrue("team CAN NOT view!", team.canView(repository));
1521         assertTrue("team CAN NOT clone!", team.canClone(repository));
1522         assertTrue("team CAN NOT push!", team.canPush(repository));
1523         
1524         assertTrue("team CAN NOT create ref!", team.canCreateRef(repository));
1525         assertTrue("team CAN NOT delete ref!", team.canDeleteRef(repository));
1526         assertTrue("team CAN NOT rewind ref!", team.canRewindRef(repository));
1527     }
1528
1529     /**
1530      * PUSH_CLONE = PUSH access restriction, CLONE access permission
1531      */
1532     @Test
1533     public void testTeam_PUSH_CLONE() throws Exception {
1534         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1535         repository.authorizationControl = AuthorizationControl.NAMED;
1536         repository.accessRestriction = AccessRestrictionType.PUSH;
1537
1538         TeamModel team = new TeamModel("test");
1539         team.setRepositoryPermission(repository.name, AccessPermission.CLONE);
1540         
1541         assertTrue("team CAN NOT view!", team.canView(repository));
1542         assertTrue("team CAN NOT clone!", team.canClone(repository));
1543         assertFalse("team CAN push!", team.canPush(repository));
1544         
1545         assertFalse("team CAN create ref!", team.canCreateRef(repository));
1546         assertFalse("team CAN delete ref!", team.canDeleteRef(repository));
1547         assertFalse("team CAN rewind ref!", team.canRewindRef(repository));
1548     }
1549
1550     /**
1551      * CLONE_CLONE = CLONE access restriction, CLONE access permission
1552      */
1553     @Test
1554     public void testTeam_CLONE_CLONE() throws Exception {
1555         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1556         repository.authorizationControl = AuthorizationControl.NAMED;
1557         repository.accessRestriction = AccessRestrictionType.CLONE;
1558
1559         TeamModel team = new TeamModel("test");
1560         team.setRepositoryPermission(repository.name, AccessPermission.CLONE);
1561         
1562         assertTrue("team CAN NOT view!", team.canView(repository));
1563         assertTrue("team CAN NOT clone!", team.canClone(repository));
1564         assertFalse("team CAN push!", team.canPush(repository));
1565         
1566         assertFalse("team CAN create ref!", team.canCreateRef(repository));
1567         assertFalse("team CAN delete ref!", team.canDeleteRef(repository));
1568         assertFalse("team CAN rewind ref!", team.canRewindRef(repository));
1569     }
1570     
1571     /**
1572      * VIEW_CLONE = VIEW access restriction, CLONE access permission
1573      */
1574     @Test
1575     public void testTeam_VIEW_CLONE() throws Exception {
1576         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1577         repository.authorizationControl = AuthorizationControl.NAMED;
1578         repository.accessRestriction = AccessRestrictionType.VIEW;
1579
1580         TeamModel team = new TeamModel("test");
1581         team.setRepositoryPermission(repository.name, AccessPermission.CLONE);
1582         
1583         assertTrue("team CAN NOT view!", team.canView(repository));
1584         assertTrue("team CAN NOT clone!", team.canClone(repository));
1585         assertFalse("team CAN push!", team.canPush(repository));
1586         
1587         assertFalse("team CAN create ref!", team.canCreateRef(repository));
1588         assertFalse("team CAN delete ref!", team.canDeleteRef(repository));
1589         assertFalse("team CAN rewind ref!", team.canRewindRef(repository));
1590     }
1591
1592     /**
1593      * NONE_VIEW = NO access restriction, VIEW access permission
1594      * (not useful scenario)
1595      */
1596     @Test
1597     public void testTeam_NONE_VIEW() throws Exception {
1598         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1599         repository.authorizationControl = AuthorizationControl.NAMED;
1600         repository.accessRestriction = AccessRestrictionType.NONE;
1601
1602         TeamModel team = new TeamModel("test");
1603         team.setRepositoryPermission(repository.name, AccessPermission.VIEW);
1604         
1605         assertTrue("team CAN NOT view!", team.canView(repository));
1606         assertTrue("team CAN NOT clone!", team.canClone(repository));
1607         assertTrue("team CAN NOT push!", team.canPush(repository));
1608         
1609         assertTrue("team CAN NOT create ref!", team.canCreateRef(repository));
1610         assertTrue("team CAN NOT delete ref!", team.canDeleteRef(repository));
1611         assertTrue("team CAN NOT rewind ref!", team.canRewindRef(repository));
1612     }
1613
1614     /**
1615      * PUSH_VIEW = PUSH access restriction, VIEW access permission
1616      */
1617     @Test
1618     public void testTeam_PUSH_VIEW() throws Exception {
1619         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1620         repository.authorizationControl = AuthorizationControl.NAMED;
1621         repository.accessRestriction = AccessRestrictionType.PUSH;
1622
1623         TeamModel team = new TeamModel("test");
1624         team.setRepositoryPermission(repository.name, AccessPermission.VIEW);
1625         
1626         assertTrue("team CAN NOT view!", team.canView(repository));
1627         assertTrue("team CAN NOT clone!", team.canClone(repository));
1628         assertFalse("team CAN push!", team.canPush(repository));
1629         
1630         assertFalse("team CAN create ref!", team.canCreateRef(repository));
1631         assertFalse("team CAN delete ref!", team.canDeleteRef(repository));
1632         assertFalse("team CAN rewind ref!", team.canRewindRef(repository));
1633     }
1634     
1635     /**
1636      * CLONE_VIEW = CLONE access restriction, VIEW access permission
1637      */
1638     @Test
1639     public void testTeam_CLONE_VIEW() throws Exception {
1640         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1641         repository.authorizationControl = AuthorizationControl.NAMED;
1642         repository.accessRestriction = AccessRestrictionType.CLONE;
1643
1644         TeamModel team = new TeamModel("test");
1645         team.setRepositoryPermission(repository.name, AccessPermission.VIEW);
1646         
1647         assertTrue("team CAN NOT view!", team.canView(repository));
1648         assertFalse("team CAN clone!", team.canClone(repository));
1649         assertFalse("team CAN push!", team.canPush(repository));
1650         
1651         assertFalse("team CAN create ref!", team.canCreateRef(repository));
1652         assertFalse("team CAN delete ref!", team.canDeleteRef(repository));
1653         assertFalse("team CAN rewind ref!", team.canRewindRef(repository));
1654     }
1655     
1656     /**
1657      * VIEW_VIEW = VIEW access restriction, VIEW access permission
1658      */
1659     @Test
1660     public void testTeam_VIEW_VIEW() throws Exception {
1661         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1662         repository.authorizationControl = AuthorizationControl.NAMED;
1663         repository.accessRestriction = AccessRestrictionType.VIEW;
1664
1665         TeamModel team = new TeamModel("test");
1666         team.setRepositoryPermission(repository.name, AccessPermission.VIEW);
1667         
1668         assertTrue("team CAN NOT view!", team.canView(repository));
1669         assertFalse("team CAN clone!", team.canClone(repository));
1670         assertFalse("team CAN push!", team.canPush(repository));
1671         
1672         assertFalse("team CAN create ref!", team.canCreateRef(repository));
1673         assertFalse("team CAN delete ref!", team.canDeleteRef(repository));
1674         assertFalse("team CAN rewind ref!", team.canRewindRef(repository));
1675     }
1676     
1677     /**
1678      * NONE_NONE = NO access restriction, NO access permission
1679      */
1680     @Test
1681     public void testTeamMember_NONE_NONE() throws Exception {
1682         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1683         repository.authorizationControl = AuthorizationControl.NAMED;
1684         repository.accessRestriction = AccessRestrictionType.NONE;
1685
1686         TeamModel team = new TeamModel("test");
1687         UserModel user = new UserModel("test");
1688         user.teams.add(team);
1689         
1690         assertTrue("team member CAN NOT view!", user.canView(repository));
1691         assertTrue("team member CAN NOT clone!", user.canClone(repository));
1692         assertTrue("team member CAN NOT push!", user.canPush(repository));
1693         
1694         assertTrue("team member CAN NOT create ref!", user.canCreateRef(repository));
1695         assertTrue("team member CAN NOT delete ref!", user.canDeleteRef(repository));
1696         assertTrue("team member CAN NOT rewind ref!", user.canRewindRef(repository));
1697     }
1698     
1699     /**
1700      * PUSH_NONE = PUSH access restriction, NO access permission
1701      */
1702     @Test
1703     public void testTeamMember_PUSH_NONE() throws Exception {
1704         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1705         repository.authorizationControl = AuthorizationControl.NAMED;
1706         repository.accessRestriction = AccessRestrictionType.PUSH;
1707
1708         TeamModel team = new TeamModel("test");
1709         UserModel user = new UserModel("test");
1710         user.teams.add(team);
1711         
1712         assertTrue("team member CAN NOT view!", user.canView(repository));
1713         assertTrue("team member CAN NOT clone!", user.canClone(repository));
1714         assertFalse("team member CAN push!", user.canPush(repository));
1715         
1716         assertFalse("team member CAN create ref!", user.canCreateRef(repository));
1717         assertFalse("team member CAN delete ref!", user.canDeleteRef(repository));
1718         assertFalse("team member CAN rewind ref!", user.canRewindRef(repository));
1719     }
1720
1721     /**
1722      * CLONE_NONE = CLONE access restriction, NO access permission
1723      */
1724     @Test
1725     public void testTeamMember_CLONE_NONE() throws Exception {
1726         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1727         repository.authorizationControl = AuthorizationControl.NAMED;
1728         repository.accessRestriction = AccessRestrictionType.CLONE;
1729
1730         TeamModel team = new TeamModel("test");
1731         UserModel user = new UserModel("test");
1732         user.teams.add(team);
1733         
1734         assertTrue("team member CAN NOT view!", user.canView(repository));
1735         assertFalse("team member CAN clone!", user.canClone(repository));
1736         assertFalse("team member CAN push!", user.canPush(repository));
1737         
1738         assertFalse("team member CAN create ref!", user.canCreateRef(repository));
1739         assertFalse("team member CAN delete ref!", user.canDeleteRef(repository));
1740         assertFalse("team member CAN rewind ref!", user.canRewindRef(repository));
1741     }
1742
1743     /**
1744      * VIEW_NONE = VIEW access restriction, NO access permission
1745      */
1746     @Test
1747     public void testTeamMember_VIEW_NONE() throws Exception {
1748         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1749         repository.authorizationControl = AuthorizationControl.NAMED;
1750         repository.accessRestriction = AccessRestrictionType.VIEW;
1751
1752         TeamModel team = new TeamModel("test");
1753         UserModel user = new UserModel("test");
1754         user.teams.add(team);
1755         
1756         assertFalse("team member CAN view!", user.canView(repository));
1757         assertFalse("team member CAN clone!", user.canClone(repository));
1758         assertFalse("team member CAN push!", user.canPush(repository));
1759         
1760         assertFalse("team member CAN create ref!", user.canCreateRef(repository));
1761         assertFalse("team member CAN delete ref!", user.canDeleteRef(repository));
1762         assertFalse("team member CAN rewind ref!", user.canRewindRef(repository));
1763     }
1764     
1765     /**
1766      * NONE_PUSH = NO access restriction, PUSH access permission
1767      * (not useful scenario)
1768      */
1769     @Test
1770     public void testTeamMember_NONE_PUSH() throws Exception {
1771         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1772         repository.authorizationControl = AuthorizationControl.NAMED;
1773         repository.accessRestriction = AccessRestrictionType.NONE;
1774
1775         TeamModel team = new TeamModel("test");
1776         team.setRepositoryPermission(repository.name, AccessPermission.PUSH);
1777         UserModel user = new UserModel("test");
1778         user.teams.add(team);
1779         
1780         assertTrue("team member CAN NOT view!", user.canView(repository));
1781         assertTrue("team member CAN NOT clone!", user.canClone(repository));
1782         assertTrue("team member CAN NOT push!", user.canPush(repository));
1783         
1784         assertTrue("team member CAN NOT create ref!", user.canCreateRef(repository));
1785         assertTrue("team member CAN NOT delete ref!", user.canDeleteRef(repository));
1786         assertTrue("team member CAN NOT rewind ref!", user.canRewindRef(repository));
1787     }
1788     
1789     /**
1790      * PUSH_PUSH = PUSH access restriction, PUSH access permission
1791      */
1792     @Test
1793     public void testTeamMember_PUSH_PUSH() throws Exception {
1794         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1795         repository.authorizationControl = AuthorizationControl.NAMED;
1796         repository.accessRestriction = AccessRestrictionType.PUSH;
1797
1798         TeamModel team = new TeamModel("test");
1799         team.setRepositoryPermission(repository.name, AccessPermission.PUSH);
1800         UserModel user = new UserModel("test");
1801         user.teams.add(team);
1802
1803         assertTrue("team member CAN NOT view!", user.canView(repository));
1804         assertTrue("team member CAN NOT clone!", user.canClone(repository));
1805         assertTrue("team member CAN NOT push!", user.canPush(repository));
1806         
1807         assertFalse("team member CAN create ref!", user.canCreateRef(repository));
1808         assertFalse("team member CAN delete ref!", user.canDeleteRef(repository));
1809         assertFalse("team member CAN rewind ref!", user.canRewindRef(repository));
1810     }
1811     
1812     /**
1813      * CLONE_PUSH = CLONE access restriction, PUSH access permission
1814      */
1815     @Test
1816     public void testTeamMember_CLONE_PUSH() throws Exception {
1817         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1818         repository.authorizationControl = AuthorizationControl.NAMED;
1819         repository.accessRestriction = AccessRestrictionType.CLONE;
1820
1821         TeamModel team = new TeamModel("test");
1822         team.setRepositoryPermission(repository.name, AccessPermission.PUSH);
1823         UserModel user = new UserModel("test");
1824         user.teams.add(team);
1825
1826         assertTrue("team member CAN NOT view!", user.canView(repository));
1827         assertTrue("team member CAN NOT clone!", user.canClone(repository));
1828         assertTrue("team member CAN NOT push!", user.canPush(repository));
1829         
1830         assertFalse("team member CAN create ref!", user.canCreateRef(repository));
1831         assertFalse("team member CAN delete ref!", user.canDeleteRef(repository));
1832         assertFalse("team member CAN rewind ref!", user.canRewindRef(repository));
1833     }
1834     
1835     /**
1836      * VIEW_PUSH = VIEW access restriction, PUSH access permission
1837      */
1838     @Test
1839     public void testTeamMember_VIEW_PUSH() throws Exception {
1840         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1841         repository.authorizationControl = AuthorizationControl.NAMED;
1842         repository.accessRestriction = AccessRestrictionType.VIEW;
1843
1844         TeamModel team = new TeamModel("test");
1845         team.setRepositoryPermission(repository.name, AccessPermission.PUSH);
1846         UserModel user = new UserModel("test");
1847         user.teams.add(team);
1848
1849         assertTrue("team member CAN NOT view!", user.canView(repository));
1850         assertTrue("team member CAN NOT clone!", user.canClone(repository));
1851         assertTrue("team member CAN NOT push!", user.canPush(repository));
1852         
1853         assertFalse("team member CAN create ref!", user.canCreateRef(repository));
1854         assertFalse("team member CAN delete ref!", user.canDeleteRef(repository));
1855         assertFalse("team member CAN rewind ref!", user.canRewindRef(repository));
1856     }
1857     
1858     /**
1859      * NONE_CREATE = NO access restriction, CREATE access permission
1860      * (not useful scenario)
1861      */
1862     @Test
1863     public void testTeamMember_NONE_CREATE() throws Exception {
1864         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1865         repository.authorizationControl = AuthorizationControl.NAMED;
1866         repository.accessRestriction = AccessRestrictionType.NONE;
1867
1868         TeamModel team = new TeamModel("test");
1869         team.setRepositoryPermission(repository.name, AccessPermission.CREATE);
1870         UserModel user = new UserModel("test");
1871         user.teams.add(team);
1872         
1873         assertTrue("team member CAN NOT view!", user.canView(repository));
1874         assertTrue("team member CAN NOT clone!", user.canClone(repository));
1875         assertTrue("team member CAN NOT push!", user.canPush(repository));
1876         
1877         assertTrue("team member CAN NOT create ref!", user.canCreateRef(repository));
1878         assertTrue("team member CAN NOT delete ref!", user.canDeleteRef(repository));
1879         assertTrue("team member CAN NOT rewind ref!", user.canRewindRef(repository));
1880     }
1881     
1882     /**
1883      * PUSH_CREATE = PUSH access restriction, CREATE access permission
1884      */
1885     @Test
1886     public void testTeamMember_PUSH_CREATE() throws Exception {
1887         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1888         repository.authorizationControl = AuthorizationControl.NAMED;
1889         repository.accessRestriction = AccessRestrictionType.PUSH;
1890
1891         TeamModel team = new TeamModel("test");
1892         team.setRepositoryPermission(repository.name, AccessPermission.CREATE);
1893         UserModel user = new UserModel("test");
1894         user.teams.add(team);
1895
1896         assertTrue("team member CAN NOT view!", user.canView(repository));
1897         assertTrue("team member CAN NOT clone!", user.canClone(repository));
1898         assertTrue("team member CAN NOT push!", user.canPush(repository));
1899         
1900         assertTrue("team member CAN NOT create ref!", user.canCreateRef(repository));
1901         assertFalse("team member CAN delete ref!", user.canDeleteRef(repository));
1902         assertFalse("team member CAN rewind ref!", user.canRewindRef(repository));
1903     }
1904     
1905     /**
1906      * CLONE_CREATE = CLONE access restriction, CREATE access permission
1907      */
1908     @Test
1909     public void testTeamMember_CLONE_CREATE() throws Exception {
1910         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1911         repository.authorizationControl = AuthorizationControl.NAMED;
1912         repository.accessRestriction = AccessRestrictionType.CLONE;
1913
1914         TeamModel team = new TeamModel("test");
1915         team.setRepositoryPermission(repository.name, AccessPermission.CREATE);
1916         UserModel user = new UserModel("test");
1917         user.teams.add(team);
1918
1919         assertTrue("team member CAN NOT view!", user.canView(repository));
1920         assertTrue("team member CAN NOT clone!", user.canClone(repository));
1921         assertTrue("team member CAN NOT push!", user.canPush(repository));
1922         
1923         assertTrue("team member CAN NOT create ref!", user.canCreateRef(repository));
1924         assertFalse("team member CAN delete ref!", user.canDeleteRef(repository));
1925         assertFalse("team member CAN rewind ref!", user.canRewindRef(repository));
1926     }
1927     
1928     /**
1929      * VIEW_CREATE = VIEW access restriction, CREATE access permission
1930      */
1931     @Test
1932     public void testTeamMember_VIEW_CREATE() throws Exception {
1933         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1934         repository.authorizationControl = AuthorizationControl.NAMED;
1935         repository.accessRestriction = AccessRestrictionType.VIEW;
1936
1937         TeamModel team = new TeamModel("test");
1938         team.setRepositoryPermission(repository.name, AccessPermission.CREATE);
1939         UserModel user = new UserModel("test");
1940         user.teams.add(team);
1941
1942         assertTrue("team member CAN NOT view!", user.canView(repository));
1943         assertTrue("team member CAN NOT clone!", user.canClone(repository));
1944         assertTrue("team member CAN NOT push!", user.canPush(repository));
1945         
1946         assertTrue("team member CAN NOT create ref!", user.canCreateRef(repository));
1947         assertFalse("team member CAN delete ref!", user.canDeleteRef(repository));
1948         assertFalse("team member CAN rewind ref!", user.canRewindRef(repository));
1949     }
1950
1951     /**
1952      * NONE_DELETE = NO access restriction, DELETE access permission
1953      * (not useful scenario)
1954      */
1955     @Test
1956     public void testTeamMember_NONE_DELETE() throws Exception {
1957         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1958         repository.authorizationControl = AuthorizationControl.NAMED;
1959         repository.accessRestriction = AccessRestrictionType.NONE;
1960
1961         TeamModel team = new TeamModel("test");
1962         team.setRepositoryPermission(repository.name, AccessPermission.DELETE);
1963         UserModel user = new UserModel("test");
1964         user.teams.add(team);
1965         
1966         assertTrue("team member CAN NOT view!", user.canView(repository));
1967         assertTrue("team member CAN NOT clone!", user.canClone(repository));
1968         assertTrue("team member CAN NOT push!", user.canPush(repository));
1969         
1970         assertTrue("team member CAN NOT create ref!", user.canCreateRef(repository));
1971         assertTrue("team member CAN NOT delete ref!", user.canDeleteRef(repository));
1972         assertTrue("team member CAN NOT rewind ref!", user.canRewindRef(repository));
1973     }
1974     
1975     /**
1976      * PUSH_DELETE = PUSH access restriction, DELETE access permission
1977      */
1978     @Test
1979     public void testTeamMember_PUSH_DELETE() throws Exception {
1980         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
1981         repository.authorizationControl = AuthorizationControl.NAMED;
1982         repository.accessRestriction = AccessRestrictionType.PUSH;
1983
1984         TeamModel team = new TeamModel("test");
1985         team.setRepositoryPermission(repository.name, AccessPermission.DELETE);
1986         UserModel user = new UserModel("test");
1987         user.teams.add(team);
1988
1989         assertTrue("team member CAN NOT view!", user.canView(repository));
1990         assertTrue("team member CAN NOT clone!", user.canClone(repository));
1991         assertTrue("team member CAN NOT push!", user.canPush(repository));
1992         
1993         assertTrue("team member CAN NOT create ref!", user.canCreateRef(repository));
1994         assertTrue("team member CAN NOT delete ref!", user.canDeleteRef(repository));
1995         assertFalse("team member CAN rewind ref!", user.canRewindRef(repository));
1996     }
1997     
1998     /**
1999      * CLONE_DELETE = CLONE access restriction, DELETE access permission
2000      */
2001     @Test
2002     public void testTeamMember_CLONE_DELETE() throws Exception {
2003         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
2004         repository.authorizationControl = AuthorizationControl.NAMED;
2005         repository.accessRestriction = AccessRestrictionType.CLONE;
2006
2007         TeamModel team = new TeamModel("test");
2008         team.setRepositoryPermission(repository.name, AccessPermission.DELETE);
2009         UserModel user = new UserModel("test");
2010         user.teams.add(team);
2011
2012         assertTrue("team member CAN NOT view!", user.canView(repository));
2013         assertTrue("team member CAN NOT clone!", user.canClone(repository));
2014         assertTrue("team member CAN NOT push!", user.canPush(repository));
2015         
2016         assertTrue("team member CAN NOT create ref!", user.canCreateRef(repository));
2017         assertTrue("team member CAN NOT delete ref!", user.canDeleteRef(repository));
2018         assertFalse("team member CAN rewind ref!", user.canRewindRef(repository));
2019     }
2020     
2021     /**
2022      * VIEW_DELETE = VIEW access restriction, DELETE access permission
2023      */
2024     @Test
2025     public void testTeamMember_VIEW_DELETE() throws Exception {
2026         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
2027         repository.authorizationControl = AuthorizationControl.NAMED;
2028         repository.accessRestriction = AccessRestrictionType.VIEW;
2029
2030         TeamModel team = new TeamModel("test");
2031         team.setRepositoryPermission(repository.name, AccessPermission.DELETE);
2032         UserModel user = new UserModel("test");
2033         user.teams.add(team);
2034
2035         assertTrue("team member CAN NOT view!", user.canView(repository));
2036         assertTrue("team member CAN NOT clone!", user.canClone(repository));
2037         assertTrue("team member CAN NOT push!", user.canPush(repository));
2038         
2039         assertTrue("team member CAN NOT create ref!", user.canCreateRef(repository));
2040         assertTrue("team member CAN NOT delete ref!", user.canDeleteRef(repository));
2041         assertFalse("team member CAN rewind ref!", user.canRewindRef(repository));
2042     }
2043
2044     /**
2045      * NONE_REWIND = NO access restriction, REWIND access permission
2046      * (not useful scenario)
2047      */
2048     @Test
2049     public void testTeamMember_NONE_REWIND() throws Exception {
2050         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
2051         repository.authorizationControl = AuthorizationControl.NAMED;
2052         repository.accessRestriction = AccessRestrictionType.NONE;
2053
2054         TeamModel team = new TeamModel("test");
2055         team.setRepositoryPermission(repository.name, AccessPermission.REWIND);
2056         UserModel user = new UserModel("test");
2057         user.teams.add(team);
2058         
2059         assertTrue("team member CAN NOT view!", user.canView(repository));
2060         assertTrue("team member CAN NOT clone!", user.canClone(repository));
2061         assertTrue("team member CAN NOT push!", user.canPush(repository));
2062         
2063         assertTrue("team member CAN NOT create ref!", user.canCreateRef(repository));
2064         assertTrue("team member CAN NOT delete ref!", user.canDeleteRef(repository));
2065         assertTrue("team member CAN NOT rewind ref!", user.canRewindRef(repository));
2066     }
2067     
2068     /**
2069      * PUSH_REWIND = PUSH access restriction, REWIND access permission
2070      */
2071     @Test
2072     public void testTeamMember_PUSH_REWIND() throws Exception {
2073         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
2074         repository.authorizationControl = AuthorizationControl.NAMED;
2075         repository.accessRestriction = AccessRestrictionType.PUSH;
2076
2077         TeamModel team = new TeamModel("test");
2078         team.setRepositoryPermission(repository.name, AccessPermission.REWIND);
2079         UserModel user = new UserModel("test");
2080         user.teams.add(team);
2081
2082         assertTrue("team member CAN NOT view!", user.canView(repository));
2083         assertTrue("team member CAN NOT clone!", user.canClone(repository));
2084         assertTrue("team member CAN NOT push!", user.canPush(repository));
2085         
2086         assertTrue("team member CAN NOT create ref!", user.canCreateRef(repository));
2087         assertTrue("team member CAN NOT delete ref!", user.canDeleteRef(repository));
2088         assertTrue("team member CAN NOT rewind ref!", user.canRewindRef(repository));
2089     }
2090     
2091     /**
2092      * CLONE_REWIND = CLONE access restriction, REWIND access permission
2093      */
2094     @Test
2095     public void testTeamMember_CLONE_REWIND() throws Exception {
2096         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
2097         repository.authorizationControl = AuthorizationControl.NAMED;
2098         repository.accessRestriction = AccessRestrictionType.CLONE;
2099
2100         TeamModel team = new TeamModel("test");
2101         team.setRepositoryPermission(repository.name, AccessPermission.REWIND);
2102         UserModel user = new UserModel("test");
2103         user.teams.add(team);
2104
2105         assertTrue("team member CAN NOT view!", user.canView(repository));
2106         assertTrue("team member CAN NOT clone!", user.canClone(repository));
2107         assertTrue("team member CAN NOT push!", user.canPush(repository));
2108         
2109         assertTrue("team member CAN NOT create ref!", user.canCreateRef(repository));
2110         assertTrue("team member CAN NOT delete ref!", user.canDeleteRef(repository));
2111         assertTrue("team member CAN NOT rewind ref!", user.canRewindRef(repository));
2112     }
2113     
2114     /**
2115      * VIEW_REWIND = VIEW access restriction, REWIND access permission
2116      */
2117     @Test
2118     public void testTeamMember_VIEW_REWIND() throws Exception {
2119         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
2120         repository.authorizationControl = AuthorizationControl.NAMED;
2121         repository.accessRestriction = AccessRestrictionType.VIEW;
2122
2123         TeamModel team = new TeamModel("test");
2124         team.setRepositoryPermission(repository.name, AccessPermission.REWIND);
2125         UserModel user = new UserModel("test");
2126         user.teams.add(team);
2127
2128         assertTrue("team member CAN NOT view!", user.canView(repository));
2129         assertTrue("team member CAN NOT clone!", user.canClone(repository));
2130         assertTrue("team member CAN NOT push!", user.canPush(repository));
2131         
2132         assertTrue("team member CAN NOT create ref!", user.canCreateRef(repository));
2133         assertTrue("team member CAN NOT delete ref!", user.canDeleteRef(repository));
2134         assertTrue("team member CAN NOT rewind ref!", user.canRewindRef(repository));
2135     }
2136     
2137     /**
2138      * NONE_CLONE = NO access restriction, CLONE access permission
2139      * (not useful scenario)
2140      */
2141     @Test
2142     public void testTeamMember_NONE_CLONE() throws Exception {
2143         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
2144         repository.authorizationControl = AuthorizationControl.NAMED;
2145         repository.accessRestriction = AccessRestrictionType.NONE;
2146
2147         TeamModel team = new TeamModel("test");
2148         team.setRepositoryPermission(repository.name, AccessPermission.CLONE);
2149         UserModel user = new UserModel("test");
2150         user.teams.add(team);
2151
2152         assertTrue("team member CAN NOT view!", user.canView(repository));
2153         assertTrue("team member CAN NOT clone!", user.canClone(repository));
2154         assertTrue("team member CAN NOT push!", user.canPush(repository));
2155         
2156         assertTrue("team member CAN NOT create ref!", user.canCreateRef(repository));
2157         assertTrue("team member CAN NOT delete ref!", user.canDeleteRef(repository));
2158         assertTrue("team member CAN NOT rewind ref!", user.canRewindRef(repository));
2159     }
2160
2161     /**
2162      * PUSH_CLONE = PUSH access restriction, CLONE access permission
2163      */
2164     @Test
2165     public void testTeamMember_PUSH_CLONE() throws Exception {
2166         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
2167         repository.authorizationControl = AuthorizationControl.NAMED;
2168         repository.accessRestriction = AccessRestrictionType.PUSH;
2169
2170         TeamModel team = new TeamModel("test");
2171         team.setRepositoryPermission(repository.name, AccessPermission.CLONE);
2172         UserModel user = new UserModel("test");
2173         user.teams.add(team);
2174
2175         assertTrue("team member CAN NOT view!", user.canView(repository));
2176         assertTrue("team member CAN NOT clone!", user.canClone(repository));
2177         assertFalse("team member CAN push!", user.canPush(repository));
2178         
2179         assertFalse("team member CAN create ref!", user.canCreateRef(repository));
2180         assertFalse("team member CAN delete ref!", user.canDeleteRef(repository));
2181         assertFalse("team member CAN rewind ref!", user.canRewindRef(repository));
2182     }
2183
2184     /**
2185      * CLONE_CLONE = CLONE access restriction, CLONE access permission
2186      */
2187     @Test
2188     public void testTeamMember_CLONE_CLONE() throws Exception {
2189         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
2190         repository.authorizationControl = AuthorizationControl.NAMED;
2191         repository.accessRestriction = AccessRestrictionType.CLONE;
2192
2193         TeamModel team = new TeamModel("test");
2194         team.setRepositoryPermission(repository.name, AccessPermission.CLONE);
2195         UserModel user = new UserModel("test");
2196         user.teams.add(team);
2197
2198         assertTrue("team member CAN NOT view!", user.canView(repository));
2199         assertTrue("team member CAN NOT clone!", user.canClone(repository));
2200         assertFalse("team member CAN push!", user.canPush(repository));
2201         
2202         assertFalse("team member CAN create ref!", user.canCreateRef(repository));
2203         assertFalse("team member CAN delete ref!", user.canDeleteRef(repository));
2204         assertFalse("team member CAN rewind ref!", user.canRewindRef(repository));
2205     }
2206     
2207     /**
2208      * VIEW_CLONE = VIEW access restriction, CLONE access permission
2209      */
2210     @Test
2211     public void testTeamMember_VIEW_CLONE() throws Exception {
2212         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
2213         repository.authorizationControl = AuthorizationControl.NAMED;
2214         repository.accessRestriction = AccessRestrictionType.VIEW;
2215
2216         TeamModel team = new TeamModel("test");
2217         team.setRepositoryPermission(repository.name, AccessPermission.CLONE);
2218         UserModel user = new UserModel("test");
2219         user.teams.add(team);
2220
2221         assertTrue("team member CAN NOT view!", user.canView(repository));
2222         assertTrue("team member CAN NOT clone!", user.canClone(repository));
2223         assertFalse("team member CAN push!", user.canPush(repository));
2224         
2225         assertFalse("team member CAN create ref!", user.canCreateRef(repository));
2226         assertFalse("team member CAN delete ref!", user.canDeleteRef(repository));
2227         assertFalse("team member CAN rewind ref!", user.canRewindRef(repository));
2228     }
2229
2230     /**
2231      * NONE_VIEW = NO access restriction, VIEW access permission
2232      * (not useful scenario)
2233      */
2234     @Test
2235     public void testTeamMember_NONE_VIEW() throws Exception {
2236         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
2237         repository.authorizationControl = AuthorizationControl.NAMED;
2238         repository.accessRestriction = AccessRestrictionType.NONE;
2239
2240         TeamModel team = new TeamModel("test");
2241         team.setRepositoryPermission(repository.name, AccessPermission.VIEW);
2242         UserModel user = new UserModel("test");
2243         user.teams.add(team);
2244
2245         assertTrue("team member CAN NOT view!", user.canView(repository));
2246         assertTrue("team member CAN NOT clone!", user.canClone(repository));
2247         assertTrue("team member CAN NOT push!", user.canPush(repository));
2248         
2249         assertTrue("team member CAN NOT create ref!", user.canCreateRef(repository));
2250         assertTrue("team member CAN NOT delete ref!", user.canDeleteRef(repository));
2251         assertTrue("team member CAN NOT rewind ref!", user.canRewindRef(repository));
2252     }
2253
2254     /**
2255      * PUSH_VIEW = PUSH access restriction, VIEW access permission
2256      */
2257     @Test
2258     public void testTeamMember_PUSH_VIEW() throws Exception {
2259         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
2260         repository.authorizationControl = AuthorizationControl.NAMED;
2261         repository.accessRestriction = AccessRestrictionType.PUSH;
2262
2263         TeamModel team = new TeamModel("test");
2264         team.setRepositoryPermission(repository.name, AccessPermission.VIEW);
2265         UserModel user = new UserModel("test");
2266         user.teams.add(team);
2267
2268         assertTrue("team member CAN NOT view!", user.canView(repository));
2269         assertTrue("team member CAN NOT clone!", user.canClone(repository));
2270         assertFalse("team member CAN push!", user.canPush(repository));
2271         
2272         assertFalse("team member CAN create ref!", user.canCreateRef(repository));
2273         assertFalse("team member CAN delete ref!", user.canDeleteRef(repository));
2274         assertFalse("team member CAN rewind ref!", user.canRewindRef(repository));
2275     }
2276     
2277     /**
2278      * CLONE_VIEW = CLONE access restriction, VIEW access permission
2279      */
2280     @Test
2281     public void testTeamMember_CLONE_VIEW() throws Exception {
2282         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
2283         repository.authorizationControl = AuthorizationControl.NAMED;
2284         repository.accessRestriction = AccessRestrictionType.CLONE;
2285
2286         TeamModel team = new TeamModel("test");
2287         team.setRepositoryPermission(repository.name, AccessPermission.VIEW);
2288         UserModel user = new UserModel("test");
2289         user.teams.add(team);
2290
2291         assertTrue("team member CAN NOT view!", user.canView(repository));
2292         assertFalse("team member CAN clone!", user.canClone(repository));
2293         assertFalse("team member CAN push!", user.canPush(repository));
2294         
2295         assertFalse("team member CAN create ref!", user.canCreateRef(repository));
2296         assertFalse("team member CAN delete ref!", user.canDeleteRef(repository));
2297         assertFalse("team member CAN rewind ref!", user.canRewindRef(repository));
2298     }
2299     
2300     /**
2301      * VIEW_VIEW = VIEW access restriction, VIEW access permission
2302      */
2303     @Test
2304     public void testTeamMember_VIEW_VIEW() throws Exception {
2305         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
2306         repository.authorizationControl = AuthorizationControl.NAMED;
2307         repository.accessRestriction = AccessRestrictionType.VIEW;
2308
2309         TeamModel team = new TeamModel("test");
2310         team.setRepositoryPermission(repository.name, AccessPermission.VIEW);
2311         UserModel user = new UserModel("test");
2312         user.teams.add(team);
2313
2314         assertTrue("team member CAN NOT view!", user.canView(repository));
2315         assertFalse("team member CAN clone!", user.canClone(repository));
2316         assertFalse("team member CAN push!", user.canPush(repository));
2317         
2318         assertFalse("team member CAN create ref!", user.canCreateRef(repository));
2319         assertFalse("team member CAN delete ref!", user.canDeleteRef(repository));
2320         assertFalse("team member CAN rewind ref!", user.canRewindRef(repository));
2321     }
2322     
2323     @Test
2324     public void testOwner() throws Exception {
2325         RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
2326         repository.authorizationControl = AuthorizationControl.NAMED;
2327         repository.accessRestriction = AccessRestrictionType.VIEW;
2328
2329         UserModel user = new UserModel("test");
2330         repository.owner = user.username;
2331
2332         assertTrue("owner CAN NOT view!", user.canView(repository));
2333         assertTrue("owner CAN NOT clone!", user.canClone(repository));
2334         assertTrue("owner CAN NOT push!", user.canPush(repository));
2335         
2336         assertTrue("owner CAN NOT create ref!", user.canCreateRef(repository));
2337         assertTrue("owner CAN NOT delete ref!", user.canDeleteRef(repository));
2338         assertTrue("owner CAN NOT rewind ref!", user.canRewindRef(repository));
2339
2340         assertTrue("owner CAN NOT fork!", user.canFork(repository));
2341         
2342         assertFalse("owner CAN NOT delete!", user.canDelete(repository));
2343         assertTrue("owner CAN NOT edit!", user.canEdit(repository));
2344     }
2345     
2346     @Test
2347     public void testOwnerPersonalRepository() throws Exception {
2348         RepositoryModel repository = new RepositoryModel("~test/myrepo.git", null, null, new Date());
2349         repository.authorizationControl = AuthorizationControl.NAMED;
2350         repository.accessRestriction = AccessRestrictionType.VIEW;
2351
2352         UserModel user = new UserModel("test");
2353         repository.owner = user.username;
2354
2355         assertTrue("user CAN NOT view!", user.canView(repository));
2356         assertTrue("user CAN NOT clone!", user.canClone(repository));
2357         assertTrue("user CAN NOT push!", user.canPush(repository));
2358         
2359         assertTrue("user CAN NOT create ref!", user.canCreateRef(repository));
2360         assertTrue("user CAN NOT delete ref!", user.canDeleteRef(repository));
2361         assertTrue("user CAN NOT rewind ref!", user.canRewindRef(repository));
2362
2363         assertFalse("user CAN fork!", user.canFork(repository));
2364         
2365         assertTrue("user CAN NOT delete!", user.canDelete(repository));
2366         assertTrue("user CAN NOT edit!", user.canEdit(repository));
2367     }
2368
2369     @Test
2370     public void testVisitorPersonalRepository() throws Exception {
2371         RepositoryModel repository = new RepositoryModel("~test/myrepo.git", null, null, new Date());
2372         repository.authorizationControl = AuthorizationControl.NAMED;
2373         repository.accessRestriction = AccessRestrictionType.VIEW;
2374
2375         UserModel user = new UserModel("visitor");
2376         repository.owner = "test";
2377
2378         assertFalse("user CAN view!", user.canView(repository));
2379         assertFalse("user CAN clone!", user.canClone(repository));
2380         assertFalse("user CAN push!", user.canPush(repository));
2381         
2382         assertFalse("user CAN create ref!", user.canCreateRef(repository));
2383         assertFalse("user CAN delete ref!", user.canDeleteRef(repository));
2384         assertFalse("user CAN rewind ref!", user.canRewindRef(repository));
2385
2386         assertFalse("user CAN fork!", user.canFork(repository));
2387         
2388         assertFalse("user CAN delete!", user.canDelete(repository));
2389         assertFalse("user CAN edit!", user.canEdit(repository));
2390     }
5d7545 2391     
JM 2392     @Test
2393     public void testWildcardMatching() throws Exception {
2394         RepositoryModel repository = new RepositoryModel("ubercool/_my-r/e~po.git", null, null, new Date());
2395         repository.authorizationControl = AuthorizationControl.NAMED;
2396         repository.accessRestriction = AccessRestrictionType.VIEW;
2397
2398         UserModel user = new UserModel("test");
2399         user.setRepositoryPermission("ubercool/[A-Za-z0-9-~_\\./]+", AccessPermission.CLONE);
2400
2401         assertTrue("user CAN NOT view!", user.canView(repository));
2402         assertTrue("user CAN NOT clone!", user.canClone(repository));
2403         assertFalse("user CAN push!", user.canPush(repository));
2404         
2405         assertFalse("user CAN create ref!", user.canCreateRef(repository));
2406         assertFalse("user CAN delete ref!", user.canDeleteRef(repository));
2407         assertFalse("user CAN rewind ref!", user.canRewindRef(repository));
2408
2409         assertFalse("user CAN fork!", user.canFork(repository));
2410         
2411         assertFalse("user CAN delete!", user.canDelete(repository));
2412         assertFalse("user CAN edit!", user.canEdit(repository));
2413
2414     }
20714a 2415 }