1 /*
2 * Copyright (c) 2003
3 * Information Desire GmbH
4 * All rights reserved.
5 */
6 package com.infodesire.infobit;
7
8 import junit.framework.TestCase;
9 import junit.framework.TestSuite;
10
11 import com.infodesire.infobit.data.Acl;
12 import com.infodesire.infobit.data.Capability;
13
14 /***
15 * test for creation and modification of ACLs and capabilities
16 *
17 * @author konstantin
18 * @created August 8, 2003
19 * @version $Revision: 1.7 $
20 */
21 public class AclTest extends InfobitTestBase {
22
23 /***
24 * constructor for test suite.
25 *
26 * @param name test suite name
27 */
28 public AclTest(String name) {
29 super(name);
30 }
31
32
33 /***
34 * test creation and manipulation of acl.
35 *
36 * @exception Exception Description of Exception
37 */
38 public void testAclCreation() throws Exception {
39 InfobitPool pool = _configuration.getPool("superuser_pool");
40 AclManager manager = pool.getAclManager();
41
42 Acl acl = manager.createAcl("blabla");
43 // flish pool before artifically creating exception
44 pool.flush();
45 assertEquals(acl.getName(), "blabla");
46 Acl acl2 = manager.getAcl("blabla");
47 assertEquals(acl, acl2);
48 assertEquals(acl.hashCode(), acl2.hashCode());
49 assertEquals(1, manager.listAcl().size());
50
51 boolean bombed = false;
52 try {
53 manager.createAcl("blabla");
54 } catch (InfobitException ie) {
55 bombed = true;
56 }
57 assertTrue("allowed creation of duplicate acl", bombed);
58
59 }
60
61
62 /***
63 * A unit test for JUnit
64 *
65 * @exception Exception Description of Exception
66 */
67 public void testAclRemoval() throws Exception {
68 InfobitPool pool = _configuration.getPool("superuser_pool");
69 AclManager manager = pool.getAclManager();
70 Acl acl = manager.createAcl("blabla");
71 manager.removeAcl(acl);
72 assertNull(manager.getAcl("blabla"));
73
74 assertTrue(manager.listAcl().isEmpty());
75 }
76
77
78 /***
79 * we test that it's impossible to modify acl without proper security role
80 *
81 * @exception Exception junit likes to throw exceptions...
82 */
83 public void testAclSecurity() throws Exception {
84 boolean bombed = false;
85 InfobitPool pool = _configuration.getPool("pool_one");
86 InfobitPool supool = _configuration.getPool("superuser_pool");
87 supool.getAclManager().createAcl("foobar");
88 pool.flush();
89 try {
90 pool.getAclManager().createAcl("foobar");
91 } catch (InfobitSecurityException ex) {
92 bombed = true;
93 }
94
95 assertTrue("Allowed ACL creaton without proper permissions", bombed);
96 bombed = false;
97
98 Acl foobar = pool.getAclManager().getAcl("foobar");
99 try {
100 pool.getAclManager().updateAcl(foobar);
101 } catch (InfobitSecurityException ex) {
102 bombed = true;
103 }
104 assertTrue("Allowed acl update without proper permissions", bombed);
105 bombed = false;
106
107 try {
108 pool.getAclManager().removeAcl(foobar);
109 } catch (InfobitSecurityException ex) {
110 bombed = true;
111 }
112
113 assertTrue("Allowed acl removal without proper permissions", bombed);
114
115 }
116
117 }
This page was automatically generated by Maven