Skip to content

Commit

Permalink
Issue #8973 - Scanner should follow its own linkOptions setting
Browse files Browse the repository at this point in the history
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
  • Loading branch information
joakime committed Dec 7, 2022
1 parent f8cfb65 commit ad03e45
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
4 changes: 2 additions & 2 deletions jetty-util/src/main/java/org/eclipse/jetty/util/Scanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ public void addFile(Path path)
try
{
// Always follow links when check ultimate type of the path
Path real = path.toRealPath();
Path real = path.toRealPath(_linkOptions);
if (!Files.exists(real) || Files.isDirectory(real))
throw new IllegalStateException("Not file or doesn't exist: " + path);

Expand Down Expand Up @@ -452,7 +452,7 @@ public IncludeExcludeSet<PathMatcher, Path> addDirectory(Path p)
try
{
// Check status of the real path
Path real = p.toRealPath();
Path real = p.toRealPath(_linkOptions);
if (!Files.exists(real) || !Files.isDirectory(real))
throw new IllegalStateException("Not directory or doesn't exist: " + p);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,60 @@ public void testReloadChangingLinkTargetOfSymbolicLink() throws Exception
assertThat(getExpiryYear(cert2), is(2020));
}

/**
* Test a keystore, where the monitored directory is a symlink.
*/
@Test
public void testSymlinkedMonitoredDirectory() throws Exception
{
assumeFileSystemSupportsSymlink();
Path oldKeyStoreSrc = MavenTestingUtils.getTestResourcePathFile("oldKeyStore");
Path newKeyStoreSrc = MavenTestingUtils.getTestResourcePathFile("newKeyStore");

Path dataLinkDir = keystoreDir.resolve("data_symlink");
Path dataDir = keystoreDir.resolve("data");
Path etcDir = keystoreDir.resolve("etc");
Path dataLinkKeystore = dataLinkDir.resolve("keystore");
Path dataKeystore = dataDir.resolve("keystore");
Path etcKeystore = etcDir.resolve("keystore");

start(sslContextFactory ->
{
// What we want is ..
// (link) data_symlink/ -> data/
// (link) data/keystore -> etc/keystore
// (file) etc/keystore (actual certificate)

FS.ensureEmpty(etcDir);
FS.ensureEmpty(dataDir);
Files.copy(oldKeyStoreSrc, etcKeystore);
Files.createSymbolicLink(dataLinkDir, dataDir);
Files.createSymbolicLink(dataKeystore, etcKeystore);

sslContextFactory.setKeyStorePath(dataLinkKeystore.toString());
sslContextFactory.setKeyStorePassword("storepwd");
sslContextFactory.setKeyManagerPassword("keypwd");
});

// Check the original certificate expiry.
X509Certificate cert1 = getCertificateFromServer();
assertThat(getExpiryYear(cert1), is(2015));

// Update etc/keystore
Files.copy(newKeyStoreSrc, etcKeystore, StandardCopyOption.REPLACE_EXISTING);
System.err.println("### Triggering scan");
keyStoreScanner.scan(5000);

// The scanner should have detected the updated keystore, expiry should be renewed.
X509Certificate cert2 = getCertificateFromServer();
assertThat(getExpiryYear(cert2), is(2020));
}

/**
* Test a doubly-linked keystore, and refreshing by only modifying the middle symlink.
*/
@Test
public void testDoublySymlinked() throws Exception
public void testDoublySymlinkedTimestampedDir() throws Exception
{
assumeFileSystemSupportsSymlink();
Path oldKeyStoreSrc = MavenTestingUtils.getTestResourcePathFile("oldKeyStore");
Expand Down

0 comments on commit ad03e45

Please sign in to comment.