Merge pull request #6022 from eclipse/jetty-10.0.x-better-xml-path-resolution
Issue #6021 - PoC for resolvePath within XmlConfiguration
This commit is contained in:
commit
1cb0a4978f
|
@ -40,12 +40,10 @@
|
||||||
<Arg>
|
<Arg>
|
||||||
<New id="webappprovider" class="org.eclipse.jetty.deploy.providers.WebAppProvider">
|
<New id="webappprovider" class="org.eclipse.jetty.deploy.providers.WebAppProvider">
|
||||||
<Set name="monitoredDirName">
|
<Set name="monitoredDirName">
|
||||||
<Property>
|
<Call name="resolvePath" class="org.eclipse.jetty.xml.XmlConfiguration">
|
||||||
<Name>jetty.deploy.monitoredPath</Name>
|
<Arg><Property name="jetty.base"/></Arg>
|
||||||
<Default>
|
<Arg><Property name="jetty.deploy.monitoredDir" default="webapps" /></Arg>
|
||||||
<Property name="jetty.base" default="." />/<Property name="jetty.deploy.monitoredDir" default="webapps"/>
|
</Call>
|
||||||
</Default>
|
|
||||||
</Property>
|
|
||||||
</Set>
|
</Set>
|
||||||
<Set name="defaultsDescriptor">
|
<Set name="defaultsDescriptor">
|
||||||
<Property>
|
<Property>
|
||||||
|
|
|
@ -7,12 +7,10 @@
|
||||||
<Arg>
|
<Arg>
|
||||||
<New class="org.eclipse.jetty.deploy.bindings.GlobalWebappConfigBinding">
|
<New class="org.eclipse.jetty.deploy.bindings.GlobalWebappConfigBinding">
|
||||||
<Set name="jettyXml">
|
<Set name="jettyXml">
|
||||||
<Property>
|
<Call name="resolvePath" class="org.eclipse.jetty.xml.XmlConfiguration">
|
||||||
<Name>jetty.deploy.webappCommonConfig</Name>
|
<Arg><Property name="jetty.base"/></Arg>
|
||||||
<Default>
|
<Arg><Property name="jetty.deploy.webappCommonConfig" default="etc/webapp-common.xml"/></Arg>
|
||||||
<Property name="jetty.base"/>/etc/webapp-common.xml
|
</Call>
|
||||||
</Default>
|
|
||||||
</Property>
|
|
||||||
</Set>
|
</Set>
|
||||||
</New>
|
</New>
|
||||||
</Arg>
|
</Arg>
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<Arg>
|
<Arg>
|
||||||
<New class="org.eclipse.jetty.webapp.WebAppContext">
|
<New class="org.eclipse.jetty.webapp.WebAppContext">
|
||||||
<Set name="contextPath">/hawtio</Set>
|
<Set name="contextPath">/hawtio</Set>
|
||||||
<Set name="war"><Property name="jetty.base" default="."/>/lib/hawtio/hawtio.war</Set>
|
<Set name="war"><Property name="jetty.base"/>/lib/hawtio/hawtio.war</Set>
|
||||||
<Set name="extractWAR">true</Set>
|
<Set name="extractWAR">true</Set>
|
||||||
<Set name="copyWebDir">false</Set>
|
<Set name="copyWebDir">false</Set>
|
||||||
<Set name="defaultsDescriptor"><Property name="jetty.home" default="."/>/etc/webdefault.xml</Set>
|
<Set name="defaultsDescriptor"><Property name="jetty.home" default="."/>/etc/webdefault.xml</Set>
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
<Arg>
|
<Arg>
|
||||||
<New class="org.eclipse.jetty.webapp.WebAppContext">
|
<New class="org.eclipse.jetty.webapp.WebAppContext">
|
||||||
<Set name="contextPath">/jamon</Set>
|
<Set name="contextPath">/jamon</Set>
|
||||||
<Set name="war"><Property name="jetty.base" default="."/>/lib/jamon/jamon.war</Set>
|
<Set name="war"><Property name="jetty.base"/>/lib/jamon/jamon.war</Set>
|
||||||
<Set name="extractWAR">true</Set>
|
<Set name="extractWAR">true</Set>
|
||||||
<Set name="copyWebDir">false</Set>
|
<Set name="copyWebDir">false</Set>
|
||||||
<Set name="defaultsDescriptor"><Property name="jetty.home" default="."/>/etc/webdefault.xml</Set>
|
<Set name="defaultsDescriptor"><Property name="jetty.home" default="."/>/etc/webdefault.xml</Set>
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<Arg>
|
<Arg>
|
||||||
<New class="org.eclipse.jetty.webapp.WebAppContext">
|
<New class="org.eclipse.jetty.webapp.WebAppContext">
|
||||||
<Set name="contextPath">/jolokia</Set>
|
<Set name="contextPath">/jolokia</Set>
|
||||||
<Set name="war"><Property name="jetty.base" default="."/>/lib/jolokia/jolokia.war</Set>
|
<Set name="war"><Property name="jetty.base"/>/lib/jolokia/jolokia.war</Set>
|
||||||
<Set name="extractWAR">true</Set>
|
<Set name="extractWAR">true</Set>
|
||||||
<Set name="copyWebDir">false</Set>
|
<Set name="copyWebDir">false</Set>
|
||||||
<Set name="defaultsDescriptor"><Property name="jetty.home" default="."/>/etc/webdefault.xml</Set>
|
<Set name="defaultsDescriptor"><Property name="jetty.home" default="."/>/etc/webdefault.xml</Set>
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
<New id="cacheMgr" class="org.infinispan.manager.DefaultCacheManager">
|
<New id="cacheMgr" class="org.infinispan.manager.DefaultCacheManager">
|
||||||
<Arg>
|
<Arg>
|
||||||
<Property name="jetty.base" default="."/>/etc/infinispan.xml
|
<Property name="jetty.base"/>/etc/infinispan.xml
|
||||||
</Arg>
|
</Arg>
|
||||||
<Get id="defaultConfig" name="defaultCacheConfiguration"/>
|
<Get id="defaultConfig" name="defaultCacheConfiguration"/>
|
||||||
</New>
|
</New>
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<!-- Get a reference to the default local cache. -->
|
<!-- Get a reference to the default local cache. -->
|
||||||
<!-- ===================================================================== -->
|
<!-- ===================================================================== -->
|
||||||
<New id="cacheMgr" class="org.infinispan.manager.DefaultCacheManager">
|
<New id="cacheMgr" class="org.infinispan.manager.DefaultCacheManager">
|
||||||
<Arg><Property name="jetty.base" default="."/>/etc/infinispan.xml</Arg>
|
<Arg><Property name="jetty.base"/>/etc/infinispan.xml</Arg>
|
||||||
<Get id="cache" name="cache"></Get>
|
<Get id="cache" name="cache"></Get>
|
||||||
</New>
|
</New>
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
<Call name="load">
|
<Call name="load">
|
||||||
<Arg>
|
<Arg>
|
||||||
<New class="java.io.FileInputStream">
|
<New class="java.io.FileInputStream">
|
||||||
<Arg><Property name="jetty.base" default="."/>/resources/hotrod-client.properties</Arg>
|
<Arg><Property name="jetty.base"/>/resources/hotrod-client.properties</Arg>
|
||||||
</New>
|
</New>
|
||||||
</Arg>
|
</Arg>
|
||||||
</Call>
|
</Call>
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
<Arg>my.proto</Arg>
|
<Arg>my.proto</Arg>
|
||||||
<Arg>
|
<Arg>
|
||||||
<New class="java.io.File">
|
<New class="java.io.File">
|
||||||
<Arg><Property name="jetty.base" default="."/>/etc/my.proto</Arg>
|
<Arg><Property name="jetty.base"/>/etc/my.proto</Arg>
|
||||||
</New>
|
</New>
|
||||||
</Arg>
|
</Arg>
|
||||||
</Call>
|
</Call>
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<Call name="load">
|
<Call name="load">
|
||||||
<Arg>
|
<Arg>
|
||||||
<New class="java.io.FileInputStream">
|
<New class="java.io.FileInputStream">
|
||||||
<Arg><Property name="jetty.base" default="."/>/resources/hotrod-client.properties</Arg>
|
<Arg><Property name="jetty.base"/>/resources/hotrod-client.properties</Arg>
|
||||||
</New>
|
</New>
|
||||||
</Arg>
|
</Arg>
|
||||||
</Call>
|
</Call>
|
||||||
|
|
|
@ -10,7 +10,12 @@
|
||||||
<!-- ======================================================== -->
|
<!-- ======================================================== -->
|
||||||
<Call class="java.lang.System" name="setProperty">
|
<Call class="java.lang.System" name="setProperty">
|
||||||
<Arg>java.security.auth.login.config</Arg>
|
<Arg>java.security.auth.login.config</Arg>
|
||||||
<Arg><Property name="jetty.base" default="." />/<Property name="jetty.jaas.login.conf" default="etc/login.conf"/></Arg>
|
<Arg>
|
||||||
|
<Call name="resolvePath" class="org.eclipse.jetty.xml.XmlConfiguration">
|
||||||
|
<Arg><Property name="jetty.base"/></Arg>
|
||||||
|
<Arg><Property name="jetty.jaas.login.conf" default="etc/login.conf" /></Arg>
|
||||||
|
</Call>
|
||||||
|
</Arg>
|
||||||
</Call>
|
</Call>
|
||||||
|
|
||||||
</Configure>
|
</Configure>
|
||||||
|
|
|
@ -3,7 +3,12 @@
|
||||||
|
|
||||||
<Configure id="Server" class="org.eclipse.jetty.server.Server">
|
<Configure id="Server" class="org.eclipse.jetty.server.Server">
|
||||||
<Call class="org.eclipse.jetty.keystore.KeystoreGenerator" name="generateTestKeystore">
|
<Call class="org.eclipse.jetty.keystore.KeystoreGenerator" name="generateTestKeystore">
|
||||||
<Arg><Property name="jetty.base" default="." />/<Property name="jetty.sslContext.keyStorePath" default="etc/keystore.p12" /></Arg>
|
<Arg>
|
||||||
|
<Call name="resolvePath" class="org.eclipse.jetty.xml.XmlConfiguration">
|
||||||
|
<Arg><Property name="jetty.base"/></Arg>
|
||||||
|
<Arg><Property name="jetty.sslContext.keyStorePath" default="etc/keystore.p12" /></Arg>
|
||||||
|
</Call>
|
||||||
|
</Arg>
|
||||||
<Arg><Property name="jetty.sslContext.keyStorePassword" /></Arg>
|
<Arg><Property name="jetty.sslContext.keyStorePassword" /></Arg>
|
||||||
</Call>
|
</Call>
|
||||||
</Configure>
|
</Configure>
|
||||||
|
|
|
@ -27,6 +27,3 @@ jetty.webapp.addServerClasses+=,${jetty.base.uri}/lib/bouncycastle/
|
||||||
jetty.sslContext.keyStorePath?=etc/test-keystore.p12
|
jetty.sslContext.keyStorePath?=etc/test-keystore.p12
|
||||||
jetty.sslContext.keyStoreType?=PKCS12
|
jetty.sslContext.keyStoreType?=PKCS12
|
||||||
jetty.sslContext.keyStorePassword?=OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4
|
jetty.sslContext.keyStorePassword?=OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4
|
||||||
jetty.sslContext.trustStorePath?=etc/test-keystore.p12
|
|
||||||
jetty.sslContext.trustStoreType?=PKCS12
|
|
||||||
jetty.sslContext.keyStorePassword?=OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<Arg>
|
<Arg>
|
||||||
<Ref refid="wac" />
|
<Ref refid="wac" />
|
||||||
</Arg>
|
</Arg>
|
||||||
<Arg><Property name="jetty.base" default="."/>/etc/maven.props</Arg>
|
<Arg><Property name="jetty.base"/>/etc/maven.props</Arg>
|
||||||
<Arg>
|
<Arg>
|
||||||
<Ref refid="Server" />
|
<Ref refid="Server" />
|
||||||
</Arg>
|
</Arg>
|
||||||
|
|
|
@ -31,9 +31,9 @@
|
||||||
<!-- ============================================================= -->
|
<!-- ============================================================= -->
|
||||||
<New id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory$Server">
|
<New id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory$Server">
|
||||||
<Set name="Provider"><SystemProperty name="jetty.sslContext.provider"/></Set>
|
<Set name="Provider"><SystemProperty name="jetty.sslContext.provider"/></Set>
|
||||||
<Set name="KeyStorePath"><Property name="jetty.base" default="."/>/<Property name="jetty.sslContext.keyStorePath" default="etc/keystore.p12"/></Set>
|
<Set name="KeyStorePath"><Property name="jetty.base"/>/<Property name="jetty.sslContext.keyStorePath" default="etc/keystore.p12"/></Set>
|
||||||
<Set name="KeyStorePassword"><Property name="jetty.sslContext.keyStorePassword" default="OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"/></Set>
|
<Set name="KeyStorePassword"><Property name="jetty.sslContext.keyStorePassword" default="OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"/></Set>
|
||||||
<Set name="TrustStorePath"><Property name="jetty.base" default="."/>/<Property name="jetty.sslContext.trustStorePath" default="etc/keystore.p12"/></Set>
|
<Set name="TrustStorePath"><Property name="jetty.base"/>/<Property name="jetty.sslContext.trustStorePath" default="etc/keystore.p12"/></Set>
|
||||||
<Set name="TrustStorePassword"><Property name="jetty.sslContext.trustStorePassword" default="OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"/></Set>
|
<Set name="TrustStorePassword"><Property name="jetty.sslContext.trustStorePassword" default="OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"/></Set>
|
||||||
<Set name="NeedClientAuth" property="jetty.sslContext.needClientAuth"/>
|
<Set name="NeedClientAuth" property="jetty.sslContext.needClientAuth"/>
|
||||||
<Set name="WantClientAuth" property="jetty.sslContext.wantClientAuth"/>
|
<Set name="WantClientAuth" property="jetty.sslContext.wantClientAuth"/>
|
||||||
|
|
|
@ -15,11 +15,12 @@
|
||||||
<!-- Writer -->
|
<!-- Writer -->
|
||||||
<Arg>
|
<Arg>
|
||||||
<New class="org.eclipse.jetty.server.AsyncRequestLogWriter">
|
<New class="org.eclipse.jetty.server.AsyncRequestLogWriter">
|
||||||
<Arg><Property name="jetty.base" default="." />/<Property>
|
<Arg>
|
||||||
<Name>jetty.requestlog.filePath</Name>
|
<Call name="resolvePath" class="org.eclipse.jetty.xml.XmlConfiguration">
|
||||||
<Default><Property name="jetty.requestlog.dir" default="logs"/>/yyyy_mm_dd.request.log</Default>
|
<Arg><Property name="jetty.base"/></Arg>
|
||||||
</Property></Arg>
|
<Arg><Property name="jetty.requestlog.dir" default="logs" />/yyyy_mm_dd.request.log</Arg>
|
||||||
<Arg/>
|
</Call>
|
||||||
|
</Arg>
|
||||||
|
|
||||||
<Set name="filenameDateFormat"><Property name="jetty.requestlog.filenameDateFormat" default="yyyy_MM_dd"/></Set>
|
<Set name="filenameDateFormat"><Property name="jetty.requestlog.filenameDateFormat" default="yyyy_MM_dd"/></Set>
|
||||||
<Set name="retainDays"><Property name="jetty.requestlog.retainDays" default="90"/></Set>
|
<Set name="retainDays"><Property name="jetty.requestlog.retainDays" default="90"/></Set>
|
||||||
|
|
|
@ -6,22 +6,20 @@
|
||||||
<New id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory$Server">
|
<New id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory$Server">
|
||||||
<Set name="Provider" property="jetty.sslContext.provider" />
|
<Set name="Provider" property="jetty.sslContext.provider" />
|
||||||
<Set name="KeyStorePath">
|
<Set name="KeyStorePath">
|
||||||
<Property name="jetty.sslContext.keyStoreAbsolutePath">
|
<Call name="resolvePath" class="org.eclipse.jetty.xml.XmlConfiguration">
|
||||||
<Default>
|
<Arg><Property name="jetty.base"/></Arg>
|
||||||
<Property name="jetty.base" default="." />/<Property name="jetty.sslContext.keyStorePath" deprecated="jetty.keystore" default="etc/keystore"/>
|
<Arg><Property name="jetty.sslContext.keyStorePath" deprecated="jetty.sslContext.keyStoreAbsolutePath,jetty.keystore" default="etc/keystore.p12" /></Arg>
|
||||||
</Default>
|
</Call>
|
||||||
</Property>
|
|
||||||
</Set>
|
</Set>
|
||||||
<Set name="KeyStorePassword"><Property name="jetty.sslContext.keyStorePassword" /></Set>
|
<Set name="KeyStorePassword"><Property name="jetty.sslContext.keyStorePassword" /></Set>
|
||||||
<Set name="KeyStoreType" property="jetty.sslContext.keyStoreType" />
|
<Set name="KeyStoreType" property="jetty.sslContext.keyStoreType" />
|
||||||
<Set name="KeyStoreProvider" property="jetty.sslContext.keyStoreProvider" />
|
<Set name="KeyStoreProvider" property="jetty.sslContext.keyStoreProvider" />
|
||||||
<Set name="KeyManagerPassword"><Property name="jetty.sslContext.keyManagerPassword" /></Set>
|
<Set name="KeyManagerPassword"><Property name="jetty.sslContext.keyManagerPassword" /></Set>
|
||||||
<Set name="TrustStorePath">
|
<Set name="TrustStorePath">
|
||||||
<Property name="jetty.sslContext.trustStoreAbsolutePath">
|
<Call name="resolvePath" class="org.eclipse.jetty.xml.XmlConfiguration">
|
||||||
<Default>
|
<Arg><Property name="jetty.base"/></Arg>
|
||||||
<Property name="jetty.base" default="." />/<Property name="jetty.sslContext.trustStorePath" deprecated="jetty.truststore" default="etc/keystore"/>
|
<Arg><Property name="jetty.sslContext.trustStorePath" deprecated="jetty.sslContext.trustStoreAbsolutePath,jetty.truststore" /></Arg>
|
||||||
</Default>
|
</Call>
|
||||||
</Property>
|
|
||||||
</Set>
|
</Set>
|
||||||
<Set name="TrustStorePassword" property="jetty.sslContext.trustStorePassword" />
|
<Set name="TrustStorePassword" property="jetty.sslContext.trustStorePassword" />
|
||||||
<Set name="TrustStoreType" property="jetty.sslContext.trustStoreType" />
|
<Set name="TrustStoreType" property="jetty.sslContext.trustStoreType" />
|
||||||
|
|
|
@ -707,6 +707,12 @@ public abstract class SslContextFactory extends AbstractLifeCycle implements Dum
|
||||||
* @param trustStorePath The file name or URL of the trust store location
|
* @param trustStorePath The file name or URL of the trust store location
|
||||||
*/
|
*/
|
||||||
public void setTrustStorePath(String trustStorePath)
|
public void setTrustStorePath(String trustStorePath)
|
||||||
|
{
|
||||||
|
if (StringUtil.isEmpty(trustStorePath))
|
||||||
|
{
|
||||||
|
_trustStoreResource = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -717,6 +723,7 @@ public abstract class SslContextFactory extends AbstractLifeCycle implements Dum
|
||||||
throw new IllegalArgumentException(e);
|
throw new IllegalArgumentException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The provider of the trust store
|
* @return The provider of the trust store
|
||||||
|
|
|
@ -331,6 +331,22 @@ public class XmlConfiguration
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility method to resolve a provided path against a directory.
|
||||||
|
*
|
||||||
|
* @param dir the directory (should be a directory reference, does not have to exist)
|
||||||
|
* @param destPath the destination path (can be relative or absolute, syntax depends on OS + FileSystem in use,
|
||||||
|
* and does not need to exist)
|
||||||
|
* @return String to resolved and normalized path, or null if dir or destPath is empty.
|
||||||
|
*/
|
||||||
|
public static String resolvePath(String dir, String destPath)
|
||||||
|
{
|
||||||
|
if (StringUtil.isEmpty(dir) || StringUtil.isEmpty(destPath))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return Paths.get(dir).resolve(destPath).normalize().toString();
|
||||||
|
}
|
||||||
|
|
||||||
private static class JettyXmlConfiguration implements ConfigurationProcessor
|
private static class JettyXmlConfiguration implements ConfigurationProcessor
|
||||||
{
|
{
|
||||||
XmlParser.Node _root;
|
XmlParser.Node _root;
|
||||||
|
|
|
@ -31,10 +31,12 @@ import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.eclipse.jetty.logging.JettyLevel;
|
import org.eclipse.jetty.logging.JettyLevel;
|
||||||
import org.eclipse.jetty.logging.JettyLogger;
|
import org.eclipse.jetty.logging.JettyLogger;
|
||||||
import org.eclipse.jetty.logging.StdErrAppender;
|
import org.eclipse.jetty.logging.StdErrAppender;
|
||||||
|
import org.eclipse.jetty.toolchain.test.FS;
|
||||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
|
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
|
||||||
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
|
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
|
||||||
|
@ -43,11 +45,12 @@ import org.eclipse.jetty.util.resource.PathResource;
|
||||||
import org.eclipse.jetty.util.resource.Resource;
|
import org.eclipse.jetty.util.resource.Resource;
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
import org.junit.jupiter.api.Assumptions;
|
import org.junit.jupiter.api.Assumptions;
|
||||||
import org.junit.jupiter.api.Disabled;
|
|
||||||
import org.junit.jupiter.api.RepeatedTest;
|
import org.junit.jupiter.api.RepeatedTest;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.condition.OS;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -1588,6 +1591,129 @@ public class XmlConfigurationTest
|
||||||
assertEquals(6, warnings.size());
|
assertEquals(6, warnings.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Stream<Arguments> resolvePathCases()
|
||||||
|
{
|
||||||
|
String resolvePathCasesJettyBase;
|
||||||
|
|
||||||
|
ArrayList<Arguments> cases = new ArrayList<>();
|
||||||
|
if (OS.WINDOWS.isCurrentOs())
|
||||||
|
{
|
||||||
|
resolvePathCasesJettyBase = "C:\\web\\jetty-base";
|
||||||
|
|
||||||
|
// Not configured, default (in xml) is used.
|
||||||
|
cases.add(Arguments.of(resolvePathCasesJettyBase, null, "C:\\web\\jetty-base\\etc\\keystore.p12"));
|
||||||
|
// Configured using normal relative path
|
||||||
|
cases.add(Arguments.of(resolvePathCasesJettyBase, "alt/keystore", "C:\\web\\jetty-base\\alt\\keystore"));
|
||||||
|
// Configured using navigated path segments
|
||||||
|
cases.add(Arguments.of(resolvePathCasesJettyBase, "../corp/etc/keystore", "C:\\web\\corp\\etc\\keystore"));
|
||||||
|
// Configured using relative to drive-root path
|
||||||
|
cases.add(Arguments.of(resolvePathCasesJettyBase, "/included/keystore", "C:\\included\\keystore"));
|
||||||
|
cases.add(Arguments.of(resolvePathCasesJettyBase, "\\included\\keystore", "C:\\included\\keystore"));
|
||||||
|
// Configured using absolute path
|
||||||
|
cases.add(Arguments.of(resolvePathCasesJettyBase, "D:\\main\\config\\keystore", "D:\\main\\config\\keystore"));
|
||||||
|
cases.add(Arguments.of(resolvePathCasesJettyBase, "E:other\\keystore", "E:other\\keystore"));
|
||||||
|
cases.add(Arguments.of(resolvePathCasesJettyBase, "F:\\\\other\\keystore", "F:\\other\\keystore"));
|
||||||
|
cases.add(Arguments.of(resolvePathCasesJettyBase, "G:///another/keystore", "G:\\another\\keystore"));
|
||||||
|
cases.add(Arguments.of(resolvePathCasesJettyBase, "H:///prod/app/keystore", "H:\\prod\\app\\keystore"));
|
||||||
|
|
||||||
|
resolvePathCasesJettyBase = "\\\\machine\\share\\apps\\jetty-base";
|
||||||
|
|
||||||
|
// Not configured, default (in xml) is used.
|
||||||
|
cases.add(Arguments.of(resolvePathCasesJettyBase, null, "\\\\machine\\share\\apps\\jetty-base\\etc\\keystore.p12"));
|
||||||
|
// Configured using normal relative path
|
||||||
|
cases.add(Arguments.of(resolvePathCasesJettyBase, "alt/keystore", "\\\\machine\\share\\apps\\jetty-base\\alt\\keystore"));
|
||||||
|
// Configured using navigated path segments
|
||||||
|
cases.add(Arguments.of(resolvePathCasesJettyBase, "../corp/etc/keystore", "\\\\machine\\share\\apps\\corp\\etc\\keystore"));
|
||||||
|
// Configured using relative to drive-root path
|
||||||
|
cases.add(Arguments.of(resolvePathCasesJettyBase, "/included/keystore", "\\\\machine\\share\\included\\keystore"));
|
||||||
|
cases.add(Arguments.of(resolvePathCasesJettyBase, "\\included\\keystore", "\\\\machine\\share\\included\\keystore"));
|
||||||
|
// Configured using absolute path
|
||||||
|
cases.add(Arguments.of(resolvePathCasesJettyBase, "D:\\main\\config\\keystore", "D:\\main\\config\\keystore"));
|
||||||
|
cases.add(Arguments.of(resolvePathCasesJettyBase, "E:other\\keystore", "E:other\\keystore"));
|
||||||
|
cases.add(Arguments.of(resolvePathCasesJettyBase, "F:\\\\other\\keystore", "F:\\other\\keystore"));
|
||||||
|
cases.add(Arguments.of(resolvePathCasesJettyBase, "G:///another/keystore", "G:\\another\\keystore"));
|
||||||
|
cases.add(Arguments.of(resolvePathCasesJettyBase, "H:///prod/app/keystore", "H:\\prod\\app\\keystore"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
resolvePathCasesJettyBase = "/var/lib/jetty-base";
|
||||||
|
|
||||||
|
// Not configured, default (in xml) is used.
|
||||||
|
cases.add(Arguments.of(resolvePathCasesJettyBase, null, "/var/lib/jetty-base/etc/keystore.p12"));
|
||||||
|
// Configured using normal relative path
|
||||||
|
cases.add(Arguments.of(resolvePathCasesJettyBase, "alt/keystore", "/var/lib/jetty-base/alt/keystore"));
|
||||||
|
// Configured using navigated path segments
|
||||||
|
cases.add(Arguments.of(resolvePathCasesJettyBase, "../corp/etc/keystore", "/var/lib/corp/etc/keystore"));
|
||||||
|
// Configured using absolute path
|
||||||
|
cases.add(Arguments.of(resolvePathCasesJettyBase, "/opt/jetty/etc/keystore", "/opt/jetty/etc/keystore"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return cases.stream();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource("resolvePathCases")
|
||||||
|
public void testCallResolvePath(String jettyBasePath, String configValue, String expectedPath) throws Exception
|
||||||
|
{
|
||||||
|
Path war = MavenTestingUtils.getTargetPath("no.war");
|
||||||
|
XmlConfiguration configuration =
|
||||||
|
asXmlConfiguration(
|
||||||
|
"<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" +
|
||||||
|
" <Set name=\"TestString\">" +
|
||||||
|
" <Call name=\"resolvePath\" class=\"org.eclipse.jetty.xml.XmlConfiguration\">" +
|
||||||
|
" <Arg><Property name=\"jetty.base\"/></Arg>" +
|
||||||
|
" <Arg><Property name=\"jetty.sslContext.keyStorePath\" default=\"etc/keystore.p12\" /></Arg>" +
|
||||||
|
" </Call>" +
|
||||||
|
" </Set>" +
|
||||||
|
"</Configure>");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
configuration.setJettyStandardIdsAndProperties(null, Resource.newResource(war));
|
||||||
|
configuration.getProperties().put("jetty.base", jettyBasePath);
|
||||||
|
if (configValue != null)
|
||||||
|
configuration.getProperties().put("jetty.sslContext.keyStorePath", configValue);
|
||||||
|
|
||||||
|
TestConfiguration tc = new TestConfiguration();
|
||||||
|
configuration.configure(tc);
|
||||||
|
|
||||||
|
assertThat(tc.getTestString(), is(expectedPath));
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
// cleanup after myself
|
||||||
|
configuration.getProperties().remove("jetty.base");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testResolvePathRelative()
|
||||||
|
{
|
||||||
|
Path testPath = MavenTestingUtils.getTargetTestingPath("testResolvePathRelative");
|
||||||
|
FS.ensureDirExists(testPath);
|
||||||
|
String resolved = XmlConfiguration.resolvePath(testPath.toString(), "etc/keystore");
|
||||||
|
assertEquals(testPath.resolve("etc/keystore").toString(), resolved);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testResolvePathAbsolute()
|
||||||
|
{
|
||||||
|
Path testPath = MavenTestingUtils.getTargetTestingPath("testResolvePathRelative");
|
||||||
|
FS.ensureDirExists(testPath);
|
||||||
|
String resolved = XmlConfiguration.resolvePath(testPath.toString(), "/tmp/etc/keystore");
|
||||||
|
assertEquals(testPath.resolve("/tmp/etc/keystore").toString(), resolved);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testResolvePathInvalidBase()
|
||||||
|
{
|
||||||
|
Path testPath = MavenTestingUtils.getTargetTestingPath("testResolvePathRelative");
|
||||||
|
FS.ensureDeleted(testPath);
|
||||||
|
Path baseDir = testPath.resolve("bogus");
|
||||||
|
String resolved = XmlConfiguration.resolvePath(baseDir.toString(), "etc/keystore");
|
||||||
|
assertEquals(baseDir.resolve("etc/keystore").toString(), resolved);
|
||||||
|
}
|
||||||
|
|
||||||
private ByteArrayOutputStream captureLoggingBytes(ThrowableAction action) throws Exception
|
private ByteArrayOutputStream captureLoggingBytes(ThrowableAction action) throws Exception
|
||||||
{
|
{
|
||||||
Logger slf4jLogger = LoggerFactory.getLogger(XmlConfiguration.class);
|
Logger slf4jLogger = LoggerFactory.getLogger(XmlConfiguration.class);
|
||||||
|
|
Loading…
Reference in New Issue