Merge branch '2.0' of github.com:jenkinsci/jenkins

This commit is contained in:
Daniel Beck committed 2016-04-07 11:52:44 +02:00
commit 1fe9cf7b7a
708 files changed
+13947 -4305

No files matched your search

@@ -0,0 +1,69 @@
/*
* The MIT License
*
* Copyright (c) 2015, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson;
import hudson.util.VersionNumber;
import org.junit.Assert;
import org.junit.Test;
import java.util.List;
import static hudson.ClassicPluginStrategy.DetachedPlugin;
/**
* @author <a href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
*/
public class ClassicPluginStrategyTest {
@Test
public void test_getDetachedPlugins() {
List<DetachedPlugin> list = ClassicPluginStrategy.getDetachedPlugins(new VersionNumber("1.296"));
Assert.assertTrue(list.size() >= 14); // There were 14 at the time of writing this test
Assert.assertNotNull(findPlugin("maven-plugin", list));
Assert.assertNotNull(findPlugin("subversion", list));
// Narrow the list to since "1.310" (the subversion detach version).
list = ClassicPluginStrategy.getDetachedPlugins(new VersionNumber("1.310"));
// Maven should no longer be in the list, but subversion should.
Assert.assertNull(findPlugin("maven-plugin", list));
Assert.assertNotNull(findPlugin("subversion", list));
// Narrow the list to since "1.311" (after the subversion detach version).
list = ClassicPluginStrategy.getDetachedPlugins(new VersionNumber("1.311"));
// Neither Maven or subversion should be in the list.
Assert.assertNull(findPlugin("maven-plugin", list));
Assert.assertNull(findPlugin("subversion", list));
}
private DetachedPlugin findPlugin(String shortName, List<DetachedPlugin> list) {
for (DetachedPlugin detachedPlugin : list) {
if (detachedPlugin.getShortName().equals(shortName)) {
return detachedPlugin;
}
}
return null;
}
}
@@ -0,0 +1,56 @@
/*
* The MIT License
*
* Copyright (c) 2015, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.util;
import net.sf.json.JSONObject;
import org.junit.Assert;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
/**
* @author <a href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
*/
public class JSONObjectResponseTest {
@Test
public void test() {
Map<String, String> data = new HashMap<>();
data.put("val_1", "1");
HttpResponses.JSONObjectResponse response = new HttpResponses.JSONObjectResponse(data);
JSONObject payload = response.getJsonObject();
Assert.assertEquals("ok", payload.getString("status"));
JSONObject payloadData = payload.getJSONObject("data");
Assert.assertEquals("1", payloadData.getString("val_1"));
// change it to an error
response.error("a message");
Assert.assertEquals("error", payload.getString("status"));
Assert.assertEquals("a message", payload.getString("message"));
}
}
@@ -0,0 +1,69 @@
/*
* The MIT License
*
* Copyright (c) 2015, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package jenkins.util;
import net.sf.json.JSONObject;
import org.junit.Assert;
import org.junit.Test;
import java.util.Locale;
import java.util.MissingResourceException;
/**
* @author <a href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
*/
public class ResourceBundleUtilTest {
/**
* Test resource bundle loading for a defined locale.
*/
@Test
public void test_known_locale() {
JSONObject bundle = ResourceBundleUtil.getBundle("hudson.logging.Messages", Locale.GERMAN);
Assert.assertEquals("Initialisiere Log-Rekorder", bundle.getString("LogRecorderManager.init"));
bundle = ResourceBundleUtil.getBundle("hudson.logging.Messages", new Locale("pt"));
Assert.assertEquals("Inicializando registros de log", bundle.getString("LogRecorderManager.init"));
// Test caching - should get the same bundle instance back...
Assert.assertTrue(ResourceBundleUtil.getBundle("hudson.logging.Messages", new Locale("pt")) == bundle);
}
/**
* Test that we get the "default" bundle for an unknown locale.
*/
@Test
public void test_unknown_locale() {
JSONObject bundle = ResourceBundleUtil.getBundle("hudson.logging.Messages", new Locale("kok")); // konkani
Assert.assertEquals("Initialing log recorders", bundle.getString("LogRecorderManager.init"));
}
/**
* Test unknown bundle.
*/
@Test(expected = MissingResourceException.class)
public void test_unknown_bundle() {
ResourceBundleUtil.getBundle("hudson.blah.Whatever");
}
}
@@ -26,17 +26,24 @@ package jenkins.xml;
import jenkins.util.xml.XMLUtils;
import org.junit.Assert;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.net.URL;
import javax.xml.transform.TransformerException;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import javax.xml.xpath.XPathExpressionException;
import static org.hamcrest.core.StringContains.containsString;
import static org.junit.Assert.assertThat;
import org.jvnet.hudson.test.Issue;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
public class XMLUtilsTest {
@@ -97,4 +104,30 @@ public class XMLUtilsTest {
assertThat(stringWriter.toString(), containsString("<description>&amp;</description>"));
}
/**
* Tests getValue() directly. Tests the parse methods too (indirectly - yeah, a purest would have
* tests for each).
*/
@Test
public void testGetValue() throws XPathExpressionException, SAXException, IOException {
URL configUrl = getClass().getResource("/jenkins/xml/config.xml");
File configFile = new File(configUrl.getFile());
Assert.assertEquals("1.480.1", XMLUtils.getValue("/hudson/version", configFile));
Assert.assertEquals("", XMLUtils.getValue("/hudson/unknown-element", configFile));
}
@Test
public void testParse_with_XXE() throws IOException, XPathExpressionException {
try {
Document doc = XMLUtils.parse(new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<!DOCTYPE foo [\n" +
" <!ELEMENT foo ANY >\n" +
" <!ENTITY xxe SYSTEM \"http://abc.com/temp/test.jsp\" >]> " +
"<foo>&xxe;</foo>"));
Assert.fail("Expecting SAXException for XXE.");
} catch (SAXException e) {
assertThat(e.getMessage(), containsString("DOCTYPE is disallowed"));
}
}
}