Merge branch 'jetty-9.4.x' of github.com:eclipse/jetty.project into jetty-9.4.x
This commit is contained in:
commit
505595508c
|
@ -128,14 +128,21 @@ public class FileSessionDataStore extends AbstractSessionDataStore
|
|||
{
|
||||
if (dir != _storeDir)
|
||||
return false;
|
||||
|
||||
String s = name.substring(0, name.indexOf('_'));
|
||||
long expiry = (s==null?0:Long.parseLong(s));
|
||||
|
||||
if (expiry > 0 && expiry < now)
|
||||
return true;
|
||||
else
|
||||
|
||||
//dir may contain files that don't match our naming pattern
|
||||
int index = name.indexOf('_');
|
||||
if (index < 0)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
long expiry = Long.parseLong(name.substring(0, index));
|
||||
return expiry > 0 && expiry < now;
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.server.session;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
|
@ -195,4 +196,52 @@ public class FileSessionManagerTest
|
|||
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIrregularFilenames() throws Exception
|
||||
{
|
||||
Server server = new Server();
|
||||
SessionHandler handler = new SessionHandler();
|
||||
handler.setServer(server);
|
||||
final DefaultSessionIdManager idmgr = new DefaultSessionIdManager(server);
|
||||
idmgr.setServer(server);
|
||||
server.setSessionIdManager(idmgr);
|
||||
|
||||
FileSessionDataStore ds = new FileSessionDataStore();
|
||||
ds.setDeleteUnrestorableFiles(true);
|
||||
DefaultSessionCache ss = new DefaultSessionCache(handler);
|
||||
handler.setSessionCache(ss);
|
||||
ss.setSessionDataStore(ds);
|
||||
//manager.setLazyLoad(true);
|
||||
File testDir = MavenTestingUtils.getTargetTestingDir("hashes");
|
||||
testDir.mkdirs();
|
||||
ds.setStoreDir(testDir);
|
||||
handler.setSessionIdManager(idmgr);
|
||||
handler.start();
|
||||
|
||||
//Create a file in the session storeDir that has no underscore.
|
||||
File noUnderscore = new File(testDir, "spuriousFile");
|
||||
noUnderscore.createNewFile();
|
||||
try
|
||||
{
|
||||
Assert.assertTrue("Expired should be empty!", ds.getExpired(Collections.emptySet()).isEmpty());
|
||||
}
|
||||
finally
|
||||
{
|
||||
noUnderscore.delete();
|
||||
}
|
||||
|
||||
//Create a file that starts with a non-number before an underscore
|
||||
File nonNumber = new File(testDir, "nonNumber_0.0.0.0_spuriousFile");
|
||||
nonNumber.createNewFile();
|
||||
try
|
||||
{
|
||||
Assert.assertTrue("Expired should be empty!", ds.getExpired(Collections.emptySet()).isEmpty());
|
||||
}
|
||||
finally
|
||||
{
|
||||
nonNumber.delete();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue