Search in sources :

Example 6 with TesterContext

use of org.apache.tomcat.unittest.TesterContext in project tomcat by apache.

the class TestRealmBase method doTestDigestDigestPasswords.

private void doTestDigestDigestPasswords(String password, String digest, String digestedPassword) throws Exception {
    Context context = new TesterContext();
    TesterMapRealm realm = new TesterMapRealm();
    realm.setContainer(context);
    MessageDigestCredentialHandler ch = new MessageDigestCredentialHandler();
    ch.setAlgorithm(digest);
    realm.setCredentialHandler(ch);
    realm.start();
    realm.addUser(USER1, digestedPassword);
    Principal p = realm.authenticate(USER1, password);
    Assert.assertNotNull(p);
    Assert.assertEquals(USER1, p.getName());
}
Also used : Context(org.apache.catalina.Context) TesterContext(org.apache.tomcat.unittest.TesterContext) TesterMapRealm(org.apache.catalina.startup.TesterMapRealm) TesterContext(org.apache.tomcat.unittest.TesterContext) Principal(java.security.Principal)

Example 7 with TesterContext

use of org.apache.tomcat.unittest.TesterContext in project tomcat by apache.

the class FileStoreTest method setup.

@BeforeClass
public static void setup() {
    TesterContext testerContext = new TesterContext();
    testerContext.setServletContext(new TesterServletContext());
    manager.setContext(testerContext);
    fileStore = new FileStore();
    fileStore.setManager(manager);
}
Also used : TesterServletContext(org.apache.tomcat.unittest.TesterServletContext) TesterContext(org.apache.tomcat.unittest.TesterContext) BeforeClass(org.junit.BeforeClass)

Example 8 with TesterContext

use of org.apache.tomcat.unittest.TesterContext in project tomcat70 by apache.

the class TestDigestAuthenticator method bug54521.

@Test
public void bug54521() throws LifecycleException {
    DigestAuthenticator digestAuthenticator = new DigestAuthenticator();
    digestAuthenticator.setContainer(new TesterContext());
    digestAuthenticator.start();
    Request request = new TesterRequest();
    final int count = 1000;
    Set<String> nonces = new HashSet<String>();
    for (int i = 0; i < count; i++) {
        nonces.add(digestAuthenticator.generateNonce(request));
    }
    Assert.assertEquals(count, nonces.size());
}
Also used : Request(org.apache.catalina.connector.Request) TesterContext(org.apache.tomcat.unittest.TesterContext) SecurityConstraint(org.apache.catalina.deploy.SecurityConstraint) HashSet(java.util.HashSet) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 9 with TesterContext

use of org.apache.tomcat.unittest.TesterContext in project tomcat70 by apache.

the class TestJNDIRealm method buildRealm.

private JNDIRealm buildRealm(String password, String digest) throws javax.naming.NamingException, NoSuchFieldException, IllegalAccessException, LifecycleException {
    Context context = new TesterContext();
    JNDIRealm realm = new JNDIRealm();
    realm.setContainer(context);
    realm.setUserSearch("");
    realm.setDigest(digest);
    Field field = JNDIRealm.class.getDeclaredField("context");
    field.setAccessible(true);
    field.set(realm, mockDirContext(mockSearchResults(password)));
    realm.start();
    return realm;
}
Also used : DirContext(javax.naming.directory.DirContext) Context(org.apache.catalina.Context) InitialDirContext(javax.naming.directory.InitialDirContext) TesterContext(org.apache.tomcat.unittest.TesterContext) Field(java.lang.reflect.Field) TesterContext(org.apache.tomcat.unittest.TesterContext)

Example 10 with TesterContext

use of org.apache.tomcat.unittest.TesterContext in project tomcat70 by apache.

the class TestPersistentManager method testBug62175.

@Test
public void testBug62175() throws Exception {
    final PersistentManager manager = new PersistentManager();
    final AtomicInteger sessionExpireCounter = new AtomicInteger();
    Store mockStore = EasyMock.createNiceMock(Store.class);
    EasyMock.expect(mockStore.load(EasyMock.anyString())).andAnswer(new IAnswer<Session>() {

        @Override
        public Session answer() throws Throwable {
            return timedOutSession(manager, sessionExpireCounter);
        }
    }).anyTimes();
    EasyMock.replay(mockStore);
    manager.setStore(mockStore);
    Host host = new TesterHost();
    final RequestCachingSessionListener requestCachingSessionListener = new RequestCachingSessionListener();
    final Context context = new TesterContext() {

        @Override
        public Object[] getApplicationLifecycleListeners() {
            return new Object[] { requestCachingSessionListener };
        }

        @Override
        public Manager getManager() {
            return manager;
        }
    };
    context.setParent(host);
    Request req = new Request();
    req.setContext(context);
    req.setRequestedSessionId("invalidSession");
    HttpServletRequest request = new RequestFacade(req);
    requestCachingSessionListener.request = request;
    manager.setContainer(context);
    manager.start();
    Assert.assertNull(request.getSession(false));
    EasyMock.verify(mockStore);
    Assert.assertEquals(1, sessionExpireCounter.get());
}
Also used : Context(org.apache.catalina.Context) TesterContext(org.apache.tomcat.unittest.TesterContext) Request(org.apache.catalina.connector.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) Store(org.apache.catalina.Store) TesterHost(org.apache.tomcat.unittest.TesterHost) Host(org.apache.catalina.Host) RequestFacade(org.apache.catalina.connector.RequestFacade) HttpServletRequest(javax.servlet.http.HttpServletRequest) IAnswer(org.easymock.IAnswer) TesterHost(org.apache.tomcat.unittest.TesterHost) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TesterContext(org.apache.tomcat.unittest.TesterContext) Test(org.junit.Test)

Aggregations

TesterContext (org.apache.tomcat.unittest.TesterContext)18 Context (org.apache.catalina.Context)15 Test (org.junit.Test)8 Request (org.apache.catalina.connector.Request)7 TesterRequest (org.apache.tomcat.unittest.TesterRequest)6 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)4 Host (org.apache.catalina.Host)4 TesterMapRealm (org.apache.catalina.startup.TesterMapRealm)4 TesterHost (org.apache.tomcat.unittest.TesterHost)4 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)3 DirContext (javax.naming.directory.DirContext)3 InitialDirContext (javax.naming.directory.InitialDirContext)3 Response (org.apache.catalina.connector.Response)3 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)3 Field (java.lang.reflect.Field)2 Principal (java.security.Principal)2 HashSet (java.util.HashSet)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Store (org.apache.catalina.Store)2