Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions xwiki-platform-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@
</revapi.differences>
-->



</analysisConfiguration>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.commons.io.IOUtils;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
Expand Down Expand Up @@ -98,20 +98,20 @@ void validateAttachment(TestUtils setup, TestReference testReference, TestConfig
assertEquals("File image.gif is too large (194 bytes). Max file size: 10 bytes.", errorSize.getText());

// Check if the attachment validators are also executed when uploading attachment through the rest API.
PutMethod putMethodText = restUploadImage(setup, subPage, TEXT_FILE_NAME);
assertEquals(415, putMethodText.getStatusCode());
CloseableHttpResponse testResponse = restUploadImage(setup, subPage, TEXT_FILE_NAME);
assertEquals(415, testResponse.getCode());
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> mapResult = objectMapper.readValue(putMethodText.getResponseBodyAsStream(), Map.class);
Map<String, Object> mapResult = objectMapper.readValue(testResponse.getEntity().getContent(), Map.class);
Map<String, Object> expectedMap = Map.of(
"message", "Invalid mimetype [text/plain]",
"translationKey", "attachment.validation.mimetype.rejected",
"translationParameters", List.of(List.of("image/*"), List.of())
);
assertEquals(expectedMap, mapResult);

PutMethod putMethodImage = restUploadImage(setup, subPage, IMAGE_FILE_NAME);
assertEquals(413, putMethodImage.getStatusCode());
mapResult = objectMapper.readValue(putMethodImage.getResponseBodyAsStream(), Map.class);
CloseableHttpResponse imageResponse = restUploadImage(setup, subPage, IMAGE_FILE_NAME);
assertEquals(413, imageResponse.getCode());
mapResult = objectMapper.readValue(imageResponse.getEntity().getContent(), Map.class);
expectedMap = Map.of(
"message", "File size too big",
"translationKey", "attachment.validation.filesize.rejected",
Expand All @@ -124,7 +124,8 @@ void validateAttachment(TestUtils setup, TestReference testReference, TestConfig
assertEquals(0, attachmentsPane.getNumberOfAttachments());
}

private PutMethod restUploadImage(TestUtils setup, DocumentReference subPage, String imageFileName) throws Exception
private CloseableHttpResponse restUploadImage(TestUtils setup, DocumentReference subPage, String imageFileName)
throws Exception
{
return setup.rest().executePut(AttachmentResource.class,
IOUtils.toByteArray(this.getClass().getResourceAsStream("/" + imageFileName)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.io.IOUtils;
import org.xwiki.component.namespace.Namespace;
import org.xwiki.extension.ExtensionId;
import org.xwiki.http.internal.XWikiCredentials;
import org.xwiki.model.reference.LocalDocumentReference;
import org.xwiki.test.ui.TestUtils;

Expand Down Expand Up @@ -60,7 +60,7 @@ public class ExtensionTestUtils

private final Map<Integer, Boolean> initialized = new ConcurrentHashMap<>();

private UsernamePasswordCredentials adminCredentials = TestUtils.SUPER_ADMIN_CREDENTIALS;
private XWikiCredentials adminCredentials = TestUtils.SUPER_ADMIN_CREDENTIALS;

/**
* Creates a new instance.
Expand All @@ -78,7 +78,7 @@ public ExtensionTestUtils(TestUtils utils)
* @param utils the generic test utility methods
* @param adminCredentials the admin credentials to use
*/
public ExtensionTestUtils(TestUtils utils, UsernamePasswordCredentials adminCredentials)
public ExtensionTestUtils(TestUtils utils, XWikiCredentials adminCredentials)
{
this.utils = utils;
this.adminCredentials = adminCredentials;
Expand All @@ -92,7 +92,7 @@ private void checkinit() throws Exception
// Create the service page if it does not exist
try (InputStream extensionTestService = this.getClass().getResourceAsStream("/extensionTestService.wiki")) {
// Make sure to save the service with superadmin
UsernamePasswordCredentials currentCredentials =
XWikiCredentials currentCredentials =
this.utils.setDefaultCredentials(this.adminCredentials);

// Save the service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

import java.net.URI;

import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.lang3.StringUtils;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.xwiki.test.docker.junit5.UITest;
Expand All @@ -45,10 +45,8 @@ void pathTraversal(TestUtils setup) throws Exception
URI uri = new URI(StringUtils.removeEnd(setup.rest().getBaseURL(), "rest")
+ "webjars/wiki%3Axwiki/..%2F..%2F..%2F..%2F..%2FWEB-INF%2Fxwiki.cfg");

GetMethod response = setup.rest().executeGet(uri);

assertNotEquals(200, response.getStatusCode());

response.releaseConnection();
try (CloseableHttpResponse response = setup.rest().executeGet(uri)) {
assertNotEquals(200, response.getCode());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import javax.ws.rs.core.UriBuilder;
import javax.xml.bind.JAXBContext;

import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -54,7 +54,7 @@ class IconThemesRestIT
@BeforeEach
void setUp(TestUtils testUtils)
{
// Login as superadmin to define the preferences.
// Login as superadmin to define the preferences.
testUtils.loginAsSuperAdmin();
DocumentReference documentReference = new DocumentReference("xwiki", "XWiki", "XWikiPreferences");
testUtils.updateObject(documentReference, "XWiki.XWikiPreferences", 0, "iconTheme", "IconThemes.FontAwesome");
Expand All @@ -67,9 +67,7 @@ void setUp(TestUtils testUtils)
void iconsNoParamKeys(TestUtils testUtils) throws Exception
{
URI rootIconThemeURI = testUtils.rest().createUri(IconThemesResource.class, new HashMap<>(), "xwiki");
GetMethod getMethod =
testUtils.rest().executeGet(UriBuilder.fromUri(rootIconThemeURI).segment("icons").build());
String body = getMethod.getResponseBodyAsString();
String body = testUtils.rest().getString(UriBuilder.fromUri(rootIconThemeURI).segment("icons").build());
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
+ "<icons xmlns=\"http://www.xwiki.org/icon\"/>", body);
}
Expand All @@ -79,10 +77,11 @@ void iconsNoParamKeys(TestUtils testUtils) throws Exception
void iconsUnknownWiki(TestUtils testUtils) throws Exception
{
URI rootIconThemeURI = testUtils.rest().createUri(IconThemesResource.class, new HashMap<>(), "nowiki");
GetMethod getMethod =
testUtils.rest().executeGet(UriBuilder.fromUri(rootIconThemeURI).segment("icons").build());
int statusCode = getMethod.getStatusCode();
assertEquals(NOT_FOUND.getStatusCode(), statusCode);
try (CloseableHttpResponse response =
testUtils.rest().executeGet(UriBuilder.fromUri(rootIconThemeURI).segment("icons").build())) {
int statusCode = response.getCode();
assertEquals(NOT_FOUND.getStatusCode(), statusCode);
}
}

@Test
Expand All @@ -91,12 +90,10 @@ void icons(TestUtils testUtils) throws Exception
{
URI rootIconThemeURI = testUtils.rest().createUri(IconThemesResource.class, new HashMap<>(), "xwiki");

URI uri = UriBuilder.fromUri(rootIconThemeURI)
.segment("icons")
.queryParam("name", "add", "unknown", "arrow_undo")
.build();
GetMethod getMethod = testUtils.rest().executeGet(uri);
String body = getMethod.getResponseBodyAsString();
URI uri = UriBuilder.fromUri(rootIconThemeURI).segment("icons")
.queryParam("name", "add", "unknown", "arrow_undo").build();
String body = testUtils.rest().getString(uri);
// @formatter:off
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
+ "<icons xmlns=\"http://www.xwiki.org/icon\">"
+ "<icon>"
Expand All @@ -111,7 +108,9 @@ void icons(TestUtils testUtils) throws Exception
+ "<iconSetName>Font Awesome</iconSetName>"
+ "<cssClass>fa fa-undo</cssClass>"
+ "</icon>"
+ "<missingIcons>unknown</missingIcons></icons>", body);
+ "<missingIcons>unknown</missingIcons></icons>"
, body);
// @formatter:on
}

@Test
Expand All @@ -120,14 +119,12 @@ void iconsUnknownTheme(TestUtils testUtils) throws Exception
{
URI rootIconThemeURI = testUtils.rest().createUri(IconThemesResource.class, new HashMap<>(), "xwiki");

URI uri = UriBuilder.fromUri(rootIconThemeURI)
.segment("notheme")
.segment("icons")
.queryParam("name", "add", "unknown", "arrow_undo")
.build();
GetMethod getMethod = testUtils.rest().executeGet(uri);
int statusCode = getMethod.getStatusCode();
assertEquals(NOT_FOUND.getStatusCode(), statusCode);
URI uri = UriBuilder.fromUri(rootIconThemeURI).segment("notheme").segment("icons")
.queryParam("name", "add", "unknown", "arrow_undo").build();
try (CloseableHttpResponse response = testUtils.rest().executeGet(uri)) {
int statusCode = response.getCode();
assertEquals(NOT_FOUND.getStatusCode(), statusCode);
}
}

@Test
Expand All @@ -136,16 +133,12 @@ void iconsWithTheme(TestUtils testUtils) throws Exception
{
URI rootIconThemeURI = testUtils.rest().createUri(IconThemesResource.class, new HashMap<>(), "xwiki");

URI uri = UriBuilder.fromUri(rootIconThemeURI)
.segment("Silk")
.segment("icons")
.queryParam("name", "add", "unknown", "arrow_undo")
.build();
GetMethod getMethod = testUtils.rest().executeGet(uri);
String body = getMethod.getResponseBodyAsString();
URI uri = UriBuilder.fromUri(rootIconThemeURI).segment("Silk").segment("icons")
.queryParam("name", "add", "unknown", "arrow_undo").build();
String body = testUtils.rest().getString(uri);
JAXBContext jaxbContext = JAXBContext.newInstance(Icons.class);

// We need to parse the response body to analyse the icons attributes more finely. This is useful in
// We need to parse the response body to analyse the icons attributes more finely. This is useful in
// particular to assert the icon's url attribute while ignoring the cache-version get parameter value.
Icons icons = (Icons) jaxbContext.createUnmarshaller().unmarshal(new StringReader(body));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import javax.ws.rs.core.UriBuilder;

import org.apache.commons.httpclient.methods.GetMethod;
import org.junit.jupiter.params.ParameterizedTest;
import org.xwiki.image.style.rest.ImageStylesResource;
import org.xwiki.image.style.test.po.ImageStyleAdministrationPage;
Expand Down Expand Up @@ -54,10 +53,8 @@
class ImageStyleIT
{
@ParameterizedTest
@WikisSource(extensions = {
"org.xwiki.platform:xwiki-platform-image-style-ui",
"org.xwiki.platform:xwiki-platform-administration-ui"
})
@WikisSource(extensions = {"org.xwiki.platform:xwiki-platform-image-style-ui",
"org.xwiki.platform:xwiki-platform-administration-ui"})
void imageStyleAdministration(WikiReference wikiReference, TestUtils testUtils) throws Exception
{
testUtils.loginAsSuperAdmin();
Expand All @@ -69,24 +66,23 @@ void imageStyleAdministration(WikiReference wikiReference, TestUtils testUtils)
String defaultPrettyName = String.format("Default-%s", wikiName);
String type = String.format("default-class-%s", wikiName);

testUtils.deletePage(
new DocumentReference(wikiName, List.of("Image", "Style", "Code", "ImageStyles"), defaultName));
testUtils
.deletePage(new DocumentReference(wikiName, List.of("Image", "Style", "Code", "ImageStyles"), defaultName));
testUtils.updateObject(new DocumentReference(wikiName, List.of("Image", "Style", "Code"), "Configuration"),
"Image.Style.Code.ConfigurationClass", 0, "defaultStyle", "");

assertEquals(Map.of(), getDefaultFromRest(testUtils, wikiReference));

assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
+ "<styles xmlns=\"http://www.xwiki.org/imageStyle\"/>", getImageStylesFromRest(testUtils, wikiReference));
assertEquals(
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
+ "<styles xmlns=\"http://www.xwiki.org/imageStyle\"/>",
getImageStylesFromRest(testUtils, wikiReference));

ImageStyleAdministrationPage imageStyleAdministrationPage =
ImageStyleAdministrationPage.getToAdminPage(wikiReference);
ImageStyleConfigurationForm imageStyleConfigurationForm =
imageStyleAdministrationPage.submitNewImageStyleForm(defaultName);
imageStyleConfigurationForm
.setPrettyName(defaultPrettyName)
.setType(type)
.clickSaveAndView(true);
imageStyleConfigurationForm.setPrettyName(defaultPrettyName).setType(type).clickSaveAndView(true);
imageStyleAdministrationPage = imageStyleConfigurationForm.clickBackToTheAdministration();
assertEquals("", imageStyleAdministrationPage.getDefaultStyle());
imageStyleAdministrationPage.submitDefaultStyleForm(defaultName);
Expand All @@ -101,6 +97,7 @@ void imageStyleAdministration(WikiReference wikiReference, TestUtils testUtils)
assertEquals(Map.of("forceDefaultStyle", "false", "defaultStyle", defaultName),
getDefaultFromRest(testUtils, wikiReference));

// @formatter:off
assertEquals(String.format("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
+ "<styles xmlns=\"http://www.xwiki.org/imageStyle\">"
+ "<imageStyle>"
Expand All @@ -118,25 +115,23 @@ void imageStyleAdministration(WikiReference wikiReference, TestUtils testUtils)
+ "<defaultTextWrap>false</defaultTextWrap>"
+ "</imageStyle>"
+ "</styles>", defaultName, defaultPrettyName, type), getImageStylesFromRest(testUtils, wikiReference));
// @formatter:on
}

private Map<?, ?> getDefaultFromRest(TestUtils testUtils, WikiReference wikiReference) throws Exception
{
URI imageStylesResourceURI =
testUtils.rest().createUri(ImageStylesResource.class, new HashMap<>(), wikiReference.getName());
GetMethod getMethod = testUtils.rest().executeGet(UriBuilder.fromUri(imageStylesResourceURI)
.segment("default")
.queryParam("media", "json")
.build());
return new ObjectMapper().readValue(getMethod.getResponseBodyAsString(), Map.class);
String body = testUtils.rest().getString(
UriBuilder.fromUri(imageStylesResourceURI).segment("default").queryParam("media", "json").build());
return new ObjectMapper().readValue(body, Map.class);
}

private String getImageStylesFromRest(TestUtils testUtils, WikiReference wikiReference) throws Exception
{
URI imageStylesResourceURI =
testUtils.rest().createUri(ImageStylesResource.class, new HashMap<>(), wikiReference.getName());
GetMethod getMethod =
testUtils.rest().executeGet(imageStylesResourceURI);
return getMethod.getResponseBodyAsString().trim();
String body = testUtils.rest().getString(imageStylesResourceURI);
return body.trim();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<xwiki.jacoco.instructionRatio>0.00</xwiki.jacoco.instructionRatio>
<!-- TODO: Remove once the tests have been fixed to not output anything to the console! -->
<xwiki.surefire.captureconsole.skip>true</xwiki.surefire.captureconsole.skip>

<!-- We still have a deprecated API exposing HTTPClient 3 as an API -->
<xwiki.enforcer.enforce-apache-http5.skip>true</xwiki.enforcer.enforce-apache-http5.skip>
</properties>
<dependencies>
<!-- Trigger xwiki-platform-oldcore dependencies (but without xwiki-platform-oldcore jar itself) -->
Expand Down Expand Up @@ -101,6 +104,12 @@
<artifactId>commons-net</artifactId>
</dependency>

<!-- Some HTTP Client 3 classes are exposed in the API -->
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
</dependency>

<!-- Testing dependencies -->
<dependency>
<groupId>org.xwiki.platform</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.net.smtp.SMTPClient;
import org.apache.commons.net.smtp.SMTPReply;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -1500,4 +1504,36 @@ public privileged aspect XWikiCompatibilityAspect
{
return addTooltip(html, message, "this.WIDTH='300'", context);
}

@Deprecated(since = "17.5.0RC1")
public static HttpClient XWiki.getHttpClient(int timeout, String userAgent)
{
HttpClient client = new HttpClient();

if (timeout != 0) {
client.getParams().setSoTimeout(timeout);
client.getParams().setParameter("http.connection.timeout", Integer.valueOf(timeout));
}

client.getParams().setParameter("http.useragent", userAgent);

String proxyHost = System.getProperty("http.proxyHost");
String proxyPort = System.getProperty("http.proxyPort");
if ((proxyHost != null) && (!proxyHost.equals(""))) {
int port = 3128;
if ((proxyPort != null) && (!proxyPort.equals(""))) {
port = Integer.parseInt(proxyPort);
}
client.getHostConfiguration().setProxy(proxyHost, port);
}

String proxyUser = System.getProperty("http.proxyUser");
if ((proxyUser != null) && (!proxyUser.equals(""))) {
String proxyPassword = System.getProperty("http.proxyPassword");
Credentials defaultcreds = new UsernamePasswordCredentials(proxyUser, proxyPassword);
client.getState().setProxyCredentials(AuthScope.ANY, defaultcreds);
}

return client;
}
}
Loading