Search in sources :

Example 51 with TestEngine

use of org.apache.wiki.TestEngine in project jspwiki by apache.

the class RPCHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    CacheManager.getInstance().removeAllCaches();
    m_engine = new TestEngine(m_props);
    m_handler = new RPCHandler();
    WikiContext ctx = new WikiContext(m_engine, new WikiPage(m_engine, "Dummy"));
    m_handler.initialize(ctx);
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) TestEngine(org.apache.wiki.TestEngine) Before(org.junit.Before)

Example 52 with TestEngine

use of org.apache.wiki.TestEngine in project jspwiki by apache.

the class AttachmentManagerTest method setUp.

@Before
public void setUp() throws Exception {
    CacheManager m_cacheManager = CacheManager.getInstance();
    m_cacheManager.clearAll();
    m_cacheManager.removeAllCaches();
    m_engine = new TestEngine(props);
    m_manager = m_engine.getAttachmentManager();
    m_engine.saveText(NAME1, "Foobar");
    m_engine.saveText(NAMEU, "Foobar");
}
Also used : CacheManager(net.sf.ehcache.CacheManager) TestEngine(org.apache.wiki.TestEngine) Before(org.junit.Before)

Example 53 with TestEngine

use of org.apache.wiki.TestEngine in project jspwiki by apache.

the class AuthenticationManagerTest method testCustomAuthorizer.

/**
 * Tests a dummy WebAuthorizer that is guaranteed to return true for one
 * role for each of the two <code>isInRole</code> methods.
 *
 * @throws Exception
 */
@Test
public void testCustomAuthorizer() throws Exception {
    Properties props = TestEngine.getTestProperties();
    props.put(AuthorizationManager.PROP_AUTHORIZER, "org.apache.wiki.auth.AuthenticationManagerTest$DummyAuthorizer");
    m_engine = new TestEngine(props);
    // Start a session without any container roles: DummyAuthorizer should ALWAYS allow AuthorizerRole
    WikiSession session = WikiSessionTest.authenticatedSession(m_engine, Users.JANNE, Users.JANNE_PASS);
    Assert.assertTrue(session.hasPrincipal(Role.ALL));
    Assert.assertTrue(session.hasPrincipal(Role.AUTHENTICATED));
    Assert.assertTrue(session.hasPrincipal(new WikiPrincipal(Users.JANNE, WikiPrincipal.LOGIN_NAME)));
    Assert.assertTrue(session.hasPrincipal(new WikiPrincipal("JanneJalkanen", WikiPrincipal.WIKI_NAME)));
    Assert.assertTrue(session.hasPrincipal(new WikiPrincipal("Janne Jalkanen", WikiPrincipal.FULL_NAME)));
    Assert.assertTrue(session.hasPrincipal(new Role("AuthorizerRole")));
    Assert.assertFalse(session.hasPrincipal(new Role("ContainerRole")));
    Assert.assertFalse(session.hasPrincipal(new Role("DummyRole")));
    // Try again with a container-authenticated session: DummyAuthorizer should ALSO allow ContainerRole
    session = WikiSessionTest.containerAuthenticatedSession(m_engine, Users.JANNE, new Principal[0]);
    Assert.assertTrue(session.hasPrincipal(Role.ALL));
    Assert.assertTrue(session.hasPrincipal(Role.AUTHENTICATED));
    Assert.assertTrue(session.hasPrincipal(new WikiPrincipal(Users.JANNE, WikiPrincipal.LOGIN_NAME)));
    Assert.assertTrue(session.hasPrincipal(new WikiPrincipal("JanneJalkanen", WikiPrincipal.WIKI_NAME)));
    Assert.assertTrue(session.hasPrincipal(new WikiPrincipal("Janne Jalkanen", WikiPrincipal.FULL_NAME)));
    Assert.assertTrue(session.hasPrincipal(new Role("AuthorizerRole")));
    Assert.assertTrue(session.hasPrincipal(new Role("ContainerRole")));
    Assert.assertFalse(session.hasPrincipal(new Role("DummyRole")));
}
Also used : Role(org.apache.wiki.auth.authorize.Role) WikiSession(org.apache.wiki.WikiSession) TestEngine(org.apache.wiki.TestEngine) Properties(java.util.Properties) Principal(java.security.Principal) WikiSessionTest(org.apache.wiki.WikiSessionTest) Test(org.junit.Test)

Example 54 with TestEngine

use of org.apache.wiki.TestEngine in project jspwiki by apache.

the class AuthenticationManagerTest method testCustomJAASLoginModuleOptions.

@Test
public void testCustomJAASLoginModuleOptions() throws Exception {
    Properties props = TestEngine.getTestProperties();
    // Supply a custom LoginModule options
    props.put("jspwiki.loginModule.options.key1", "value1");
    props.put("jspwiki.loginModule.options.key2", "value2");
    props.put("jspwiki.loginModule.options.key3", "value3");
    // Init the engine and verify that we initialized with the correct
    // options
    WikiEngine engine = new TestEngine(props);
    AuthenticationManager authMgr = engine.getAuthenticationManager();
    Map<String, String> options = authMgr.m_loginModuleOptions;
    Assert.assertEquals(3, options.size());
    Assert.assertTrue(options.containsKey("key1"));
    Assert.assertTrue(options.containsKey("key2"));
    Assert.assertTrue(options.containsKey("key3"));
    Assert.assertEquals("value1", options.get("key1"));
    Assert.assertEquals("value2", options.get("key2"));
    Assert.assertEquals("value3", options.get("key3"));
}
Also used : TestEngine(org.apache.wiki.TestEngine) Properties(java.util.Properties) WikiEngine(org.apache.wiki.WikiEngine) WikiSessionTest(org.apache.wiki.WikiSessionTest) Test(org.junit.Test)

Example 55 with TestEngine

use of org.apache.wiki.TestEngine in project jspwiki by apache.

the class AuthenticationManagerTest method testCustomJAASLoginModule.

@Test
public void testCustomJAASLoginModule() throws Exception {
    Properties props = TestEngine.getTestProperties();
    // Supply a custom LoginModule class
    props.put("jspwiki.loginModule.class", "org.apache.wiki.auth.login.CookieAssertionLoginModule");
    // Init the engine and verify that we initialized with a custom auth
    // login module
    WikiEngine engine = new TestEngine(props);
    AuthenticationManager authMgr = engine.getAuthenticationManager();
    Assert.assertEquals(CookieAssertionLoginModule.class, authMgr.m_loginModuleClass);
}
Also used : TestEngine(org.apache.wiki.TestEngine) Properties(java.util.Properties) WikiEngine(org.apache.wiki.WikiEngine) WikiSessionTest(org.apache.wiki.WikiSessionTest) Test(org.junit.Test)

Aggregations

TestEngine (org.apache.wiki.TestEngine)70 Before (org.junit.Before)49 Properties (java.util.Properties)42 WikiPage (org.apache.wiki.WikiPage)15 Test (org.junit.Test)15 WikiContext (org.apache.wiki.WikiContext)11 WikiEngine (org.apache.wiki.WikiEngine)8 File (java.io.File)4 Subject (javax.security.auth.Subject)4 WikiSessionTest (org.apache.wiki.WikiSessionTest)4 NoRequiredPropertyException (org.apache.wiki.api.exceptions.NoRequiredPropertyException)4 XMLUserDatabase (org.apache.wiki.auth.user.XMLUserDatabase)4 Attachment (org.apache.wiki.attachment.Attachment)3 WikiPrincipal (org.apache.wiki.auth.WikiPrincipal)3 StringReader (java.io.StringReader)2 Principal (java.security.Principal)2 WikiSession (org.apache.wiki.WikiSession)2 GroupPrincipal (org.apache.wiki.auth.GroupPrincipal)2 Group (org.apache.wiki.auth.authorize.Group)2 BufferedReader (java.io.BufferedReader)1