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());
}
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);
}
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());
}
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;
}
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());
}
Aggregations