1 31 32 package org.opencms.security; 33 34 import org.opencms.db.CmsDbEntryNotFoundException; 35 import org.opencms.file.CmsObject; 36 import org.opencms.main.CmsException; 37 import org.opencms.main.OpenCms; 38 import org.opencms.test.OpenCmsTestCase; 39 import org.opencms.test.OpenCmsTestProperties; 40 41 import junit.extensions.TestSetup; 42 import junit.framework.Test; 43 import junit.framework.TestSuite; 44 45 48 public class TestCmsPrincipal extends OpenCmsTestCase { 49 50 55 public TestCmsPrincipal(String arg0) { 56 57 super(arg0); 58 } 59 60 65 public static Test suite() { 66 OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH); 67 68 TestSuite suite = new TestSuite(); 69 suite.setName(TestCmsPrincipal.class.getName()); 70 71 suite.addTest(new TestCmsPrincipal("testBasicReadOperation")); 72 73 TestSetup wrapper = new TestSetup(suite) { 74 75 protected void setUp() { 76 setupOpenCms("simpletest", "/sites/default/"); 77 } 78 79 protected void tearDown() { 80 removeOpenCms(); 81 } 82 }; 83 84 return wrapper; 85 } 86 87 92 public void testBasicReadOperation() throws Exception { 93 94 echo("Testing basic principal read operation"); 95 CmsObject cms = getCmsObject(); 96 97 I_CmsPrincipal principal; 98 String prefixedName; 99 100 prefixedName = CmsPrincipal.getPrefixedUser(OpenCms.getDefaultUsers().getUserAdmin()); 101 principal = CmsPrincipal.readPrefixedPrincipal(cms, prefixedName); 102 assertTrue(principal.isUser()); 103 assertFalse(principal.isGroup()); 104 assertEquals(prefixedName, principal.getPrefixedName()); 105 106 prefixedName = CmsPrincipal.getPrefixedGroup(OpenCms.getDefaultUsers().getGroupAdministrators()); 107 principal = CmsPrincipal.readPrefixedPrincipal(cms, prefixedName); 108 assertFalse(principal.isUser()); 109 assertTrue(principal.isGroup()); 110 assertEquals(prefixedName, principal.getPrefixedName()); 111 112 prefixedName = "kaputt"; 114 CmsException caught = null; 115 try { 116 principal = CmsPrincipal.readPrefixedPrincipal(cms, prefixedName); 117 } catch (CmsException e) { 118 caught = e; 119 } 120 assertNotNull(caught); 121 assertTrue(caught instanceof CmsSecurityException); 122 assertSame(Messages.ERR_INVALID_PRINCIPAL_1, caught.getMessageContainer().getKey()); 123 124 prefixedName = CmsPrincipal.getPrefixedUser("kaputt"); 126 caught = null; 127 try { 128 principal = CmsPrincipal.readPrefixedPrincipal(cms, prefixedName); 129 } catch (CmsException e) { 130 caught = e; 131 } 132 assertNotNull(caught); 133 assertTrue(caught instanceof CmsDbEntryNotFoundException); 134 assertSame(org.opencms.db.Messages.ERR_READ_USER_FOR_NAME_1, caught.getMessageContainer().getKey()); 135 136 prefixedName = CmsPrincipal.getPrefixedGroup("kaputt"); 138 caught = null; 139 try { 140 principal = CmsPrincipal.readPrefixedPrincipal(cms, prefixedName); 141 } catch (CmsException e) { 142 caught = e; 143 } 144 assertNotNull(caught); 145 assertTrue(caught instanceof CmsDbEntryNotFoundException); 146 assertSame(org.opencms.db.Messages.ERR_READ_GROUP_FOR_NAME_1, caught.getMessageContainer().getKey()); 147 148 } 149 } | Popular Tags |