Issue #2556 - bad "file:" scheme present in Xml usage of "jetty.base" and "jetty.home" properties

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
Joakim Erdfelt 2018-05-22 13:34:26 -05:00
parent 65748093bd
commit 6b0652c499
2 changed files with 78 additions and 20 deletions

View File

@ -31,6 +31,8 @@ import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.AccessController;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
@ -134,20 +136,21 @@ public class XmlConfiguration
{
if (server!=null)
getIdMap().put("Server", server);
Resource home = Resource.newResource(System.getProperty("jetty.home","."));
getProperties().put("jetty.home",home.toString());
getProperties().put("jetty.home.uri",normalizeURI(home.getURI().toString()));
Resource base = Resource.newResource(System.getProperty("jetty.base",home.toString()));
Path home = Paths.get(System.getProperty("jetty.home", "."));
getProperties().put("jetty.home",home.toString());
getProperties().put("jetty.home.uri",normalizeURI(home.toUri().toASCIIString()));
Path base = Paths.get(System.getProperty("jetty.base", home.toString()));
getProperties().put("jetty.base",base.toString());
getProperties().put("jetty.base.uri",normalizeURI(base.getURI().toString()));
getProperties().put("jetty.base.uri",normalizeURI(base.toUri().toASCIIString()));
if (webapp!=null)
{
getProperties().put("jetty.webapp",webapp.toString());
getProperties().put("jetty.webapps",webapp.getFile().toPath().getParent().toString());
getProperties().put("jetty.webapps.uri",normalizeURI(webapp.getURI().toString()));
Path webappPath = webapp.getFile().toPath().toAbsolutePath();
getProperties().put("jetty.webapp", webappPath.toString());
getProperties().put("jetty.webapps", webappPath.getParent().toString());
getProperties().put("jetty.webapps.uri", normalizeURI(webapp.getURI().toString()));
}
}
catch(Exception e)

View File

@ -18,28 +18,27 @@
package org.eclipse.jetty.xml;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicInteger;
import org.eclipse.jetty.util.log.Log;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public class XmlConfigurationTest
{
protected String[] _configure=new String [] {"org/eclipse/jetty/xml/configureWithAttr.xml","org/eclipse/jetty/xml/configureWithElements.xml"};
@ -937,4 +936,60 @@ public class XmlConfigurationTest
DefaultTestConfiguration config = (DefaultTestConfiguration)xmlConfiguration.configure();
assertEquals(value, config.getFirst());
}
@Test
public void testJettyStandardIdsAndProperties_JettyHome_JettyBase() throws Exception
{
String propNames[] = new String[] {
"jetty.base",
"jetty.home"
};
for(String propName: propNames)
{
XmlConfiguration configuration =
new XmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" +
" <Set name=\"TestString\">" +
" <Property name=\"" + propName + "\"/>" +
" </Set>" +
"</Configure>");
configuration.setJettyStandardIdsAndProperties(null, null);
TestConfiguration tc = new TestConfiguration();
configuration.configure(tc);
assertThat(propName, tc.getTestString(), is(notNullValue()));
assertThat(propName, tc.getTestString(), not(startsWith("file:")));
}
}
@Test
public void testJettyStandardIdsAndProperties_JettyHomeUri_JettyBaseUri() throws Exception
{
String propNames[] = new String[] {
"jetty.base.uri",
"jetty.home.uri"
};
for(String propName: propNames)
{
XmlConfiguration configuration =
new XmlConfiguration("" +
"<Configure class=\"org.eclipse.jetty.xml.TestConfiguration\">" +
" <Set name=\"TestString\">" +
" <Property name=\"" + propName + "\"/>" +
" </Set>" +
"</Configure>");
configuration.setJettyStandardIdsAndProperties(null, null);
TestConfiguration tc = new TestConfiguration();
configuration.configure(tc);
assertThat(propName, tc.getTestString(), is(notNullValue()));
assertThat(propName, tc.getTestString(), startsWith("file:"));
}
}
}