1 22 package org.jboss.test.security.test; 23 24 import java.io.FilePermission ; 25 import java.net.URL ; 26 import java.security.CodeSource ; 27 import java.security.Permission ; 28 import java.security.PermissionCollection ; 29 import java.security.Policy ; 30 31 38 public class NamespacePermissionsUnitTestCase 39 extends junit.framework.TestCase 40 { 41 PermissionCollection pc; 42 43 public NamespacePermissionsUnitTestCase(String name) 44 { 45 super(name); 46 } 47 48 protected void setUp() throws Exception 49 { 50 pc = new NamespacePermissionCollection(); 51 NamespacePermission p = new NamespacePermission("starksm/Project1", "r---"); 52 pc.add(p); 53 p = new NamespacePermission("starksm/Project1/Documents/readme.html", "rw--"); 54 pc.add(p); 55 p = new NamespacePermission("starksm/Project1/Documents/Public", "rw--"); 56 pc.add(p); 57 p = new NamespacePermission("starksm/Project1/Documents/Public/Private", "----"); 58 pc.add(p); 59 p = new NamespacePermission("Project1/Documents/Public", "r---"); 60 pc.add(p); 61 p = new NamespacePermission("Project1/Documents/Public/starksm", "----"); 62 pc.add(p); 63 } 64 protected void tearDown() 65 { 66 pc = null; 67 } 68 69 78 79 83 public void testImplied() 84 { 85 NamespacePermission p = new NamespacePermission("Project1/Documents/Public/view1.jpg", "r---"); 86 boolean implied = pc.implies(p); 87 assertEquals(p.toString(), true, implied); 88 89 p = new NamespacePermission("starksm/Project1", "r---"); 90 implied = pc.implies(p); 91 assertEquals(p.toString(), true, implied); 92 p = new NamespacePermission("starksm/Project1/Documents/Folder1", "r---"); 93 implied = pc.implies(p); 94 assertEquals(p.toString(), true, implied); 95 p = new NamespacePermission("starksm/Project1/Documents/readme.html", "r---"); 96 implied = pc.implies(p); 97 assertEquals(p.toString(), true, implied); 98 p = new NamespacePermission("starksm/Project1/Documents/readme.html", "rw--"); 99 implied = pc.implies(p); 100 assertEquals(p.toString(), true, implied); 101 p = new NamespacePermission("starksm/Project1/Documents/readme.html", "-w--"); 102 implied = pc.implies(p); 103 assertEquals(p.toString(), true, implied); 104 p = new NamespacePermission("starksm/Project1/Documents/Public/readme.html", "r---"); 105 implied = pc.implies(p); 106 assertEquals(p.toString(), true, implied); 107 p = new NamespacePermission("starksm/Project1/Documents/Public/readme.html", "rw--"); 108 implied = pc.implies(p); 109 } 111 112 116 public void testNotImplied() 117 { 118 NamespacePermission p = new NamespacePermission("Project1/Drawings/view1.jpg", "r---"); 119 boolean implied = pc.implies(p); 120 assertEquals(p.toString(), false, implied); 121 p = new NamespacePermission("Project1/Documents/view1.jpg", "r---"); 122 implied = pc.implies(p); 123 assertEquals(p.toString(), false, implied); 124 p = new NamespacePermission("starksm/Project1/Documents/readme.html", "rw-d"); 125 implied = pc.implies(p); 126 assertEquals(p.toString(), false, implied); 127 p = new NamespacePermission("starksm/Project1/Documents", "rw--"); 128 implied = pc.implies(p); 129 assertEquals(p.toString(), false, implied); 130 p = new NamespacePermission("starksm/Project1/Documents/Public/Private/readme.html", "r---"); 131 implied = pc.implies(p); 132 assertEquals(p.toString(), false, implied); 133 p = new NamespacePermission("starksm/Project1/Documents/Public/Private/readme.html", "rw--"); 134 implied = pc.implies(p); 135 assertEquals(p.toString(), false, implied); 136 p = new NamespacePermission("starksm/Project1/Documents/Folder1/readme.html", "rw--"); 137 implied = pc.implies(p); 138 assertEquals(p.toString(), false, implied); 139 p = new NamespacePermission("Project1/Documents/Public/starksm/.bashrc", "r---"); 140 implied = pc.implies(p); 141 assertEquals(p.toString(), false, implied); 142 } 143 144 public static void main(String [] args) throws Exception 145 { 146 NamespacePermissionsUnitTestCase tst = new NamespacePermissionsUnitTestCase("main"); 147 tst.setUp(); 148 tst.testImplied(); 149 tst.testNotImplied(); 150 } 151 } 152 | Popular Tags |