Merge branch 'jetty-8'

This commit is contained in:
Jesse McConnell 2013-01-25 16:53:46 -06:00
commit 2cbb630f8e
3 changed files with 59 additions and 7 deletions

View File

@ -469,6 +469,8 @@ public class HashSessionManager extends AbstractSessionManager
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public void setStoreDirectory (File dir) throws IOException public void setStoreDirectory (File dir) throws IOException
{ {
// CanonicalFile is used to capture the base store directory in a way that will
// work on Windows. Case differences may through off later checks using this directory.
_storeDir=dir.getCanonicalFile(); _storeDir=dir.getCanonicalFile();
} }

View File

@ -22,14 +22,37 @@ import java.io.File;
import junit.framework.Assert; import junit.framework.Assert;
import org.eclipse.jetty.server.SessionManager;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.StdErrLog;
import org.junit.After;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
public class HashSessionManagerTest public class HashSessionManagerTest
{ {
@After
public void enableStacks()
{
enableStacks(true);
}
@Before
public void quietStacks()
{
enableStacks(false);
}
protected void enableStacks(boolean enabled)
{
StdErrLog log = (StdErrLog)Log.getLogger("org.eclipse.jetty.server.session");
log.setHideStacks(!enabled);
}
@Test @Test
public void testDangerousSessionId() throws Exception public void testDangerousSessionIdRemoval() throws Exception
{ {
final HashSessionManager manager = new HashSessionManager(); final HashSessionManager manager = new HashSessionManager();
manager.setDeleteUnrestorableSessions(true); manager.setDeleteUnrestorableSessions(true);
@ -47,4 +70,24 @@ public class HashSessionManagerTest
Assert.assertTrue("File should exist!", MavenTestingUtils.getTargetFile("dangerFile.session").exists()); Assert.assertTrue("File should exist!", MavenTestingUtils.getTargetFile("dangerFile.session").exists());
} }
@Test
public void testValidSessionIdRemoval() throws Exception
{
final HashSessionManager manager = new HashSessionManager();
manager.setDeleteUnrestorableSessions(true);
manager.setLazyLoad(true);
File testDir = MavenTestingUtils.getTargetTestingDir("hashes");
testDir.mkdirs();
manager.setStoreDirectory(testDir);
new File(testDir, "validFile.session").createNewFile();
Assert.assertTrue("File should exist!", new File(testDir, "validFile.session").exists());
manager.getSession("validFile.session");
Assert.assertTrue("File shouldn't exist!", !new File(testDir,"validFile.session").exists());
}
} }

View File

@ -64,10 +64,17 @@ public class IdleSessionTest
@Override @Override
public SessionManager newSessionManager() public SessionManager newSessionManager()
{ {
HashSessionManager manager = (HashSessionManager)super.newSessionManager(); try
manager.setStoreDirectory(_storeDir); {
manager.setIdleSavePeriod(_idlePeriod); HashSessionManager manager = (HashSessionManager)super.newSessionManager();
return manager; manager.setStoreDirectory(_storeDir);
manager.setIdleSavePeriod(_idlePeriod);
return manager;
}
catch ( IOException e)
{
return null;
}
} }