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 13, 2003
19 * @version $Revision: 1.3 $
20 */
21 public class CapabilityTest extends InfobitTestBase {
22
23 /***
24 * constructor for test suite.
25 *
26 * @param name test suite name
27 */
28 public CapabilityTest(String name) {
29 super(name);
30 }
31
32
33 /***
34 * test creation and manipulation of capabilities
35 *
36 * @exception Exception Description of Exception
37 */
38 public void testCapabilityCreation() throws Exception {
39 InfobitPool pool = _configuration.getPool("superuser_pool");
40 AclManager manager = pool.getAclManager();
41
42 Capability cap = manager.createCapability("blabla");
43 assertEquals(cap.getName(), "blabla");
44 cap.setDescription("blurge");
45 manager.updateCapability(cap);
46
47 cap = manager.getCapability("blabla");
48 assertEquals("blurge", cap.getDescription());
49 Capability cap2 = manager.getCapability("blabla");
50 assertEquals(cap, cap2);
51 assertEquals(1, manager.listCapabilities().size());
52
53 boolean bombed = false;
54 try {
55 manager.createCapability("blabla");
56 } catch (InfobitException ie) {
57 bombed = true;
58 }
59 assertTrue("allowed creation of duplicate capability", bombed);
60
61 }
62
63
64 /***
65 * A unit test for JUnit
66 *
67 * @exception Exception Description of Exception
68 */
69 public void testCapabilityRemoval() throws Exception {
70 InfobitPool pool = _configuration.getPool("superuser_pool");
71 AclManager manager = pool.getAclManager();
72
73 Capability cap = manager.createCapability("blabla");
74 assertEquals(1, manager.listCapabilities().size());
75
76 manager.removeCapability(cap);
77 assertNull(manager.getCapability("blabla"));
78 assertTrue(manager.listCapabilities().isEmpty());
79
80 }
81
82
83 /***
84 * we test that it's impossible to modify acl without proper security role
85 *
86 * @exception Exception junit likes to throw exceptions...
87 */
88 public void testSecurity() throws Exception {
89 boolean bombed = false;
90 InfobitPool pool = _configuration.getPool("pool_one");
91 InfobitPool supool = _configuration.getPool("superuser_pool");
92 supool.getAclManager().createAcl("foobar");
93 try {
94 pool.getAclManager().createCapability("foobar");
95 } catch (InfobitSecurityException ex) {
96 bombed = true;
97 }
98
99 assertTrue("Allowed Capability creaton without proper permissions", bombed);
100 bombed = false;
101
102 Capability foobar = pool.getAclManager().getCapability("foobar");
103 try {
104 pool.getAclManager().updateCapability(foobar);
105 } catch (InfobitSecurityException ex) {
106 bombed = true;
107 }
108 assertTrue("Allowed acl update without proper permissions", bombed);
109 bombed = false;
110
111 try {
112 pool.getAclManager().removeCapability(foobar);
113 } catch (InfobitSecurityException ex) {
114 bombed = true;
115 }
116
117 assertTrue("Allowed acl removal without proper permissions", bombed);
118
119 }
120
121 }
This page was automatically generated by Maven