Skip to content
Snippets Groups Projects
Commit ca67d2c4 authored by srosse's avatar srosse
Browse files

Merge remote-tracking branch 'origin/OpenOLAT_14.2'

parents 340b03e3 541a91cb
No related branches found
No related tags found
No related merge requests found
...@@ -356,7 +356,7 @@ public class AuthoringEditAccessAndBookingController extends FormBasicController ...@@ -356,7 +356,7 @@ public class AuthoringEditAccessAndBookingController extends FormBasicController
private void initFormOrganisations(FormItemContainer formLayout, UserSession usess) { private void initFormOrganisations(FormItemContainer formLayout, UserSession usess) {
Roles roles = usess.getRoles(); Roles roles = usess.getRoles();
List<Organisation> organisations = organisationService.getOrganisations(getIdentity(), roles, List<Organisation> organisations = organisationService.getOrganisations(getIdentity(), roles,
OrganisationRoles.administrator, OrganisationRoles.learnresourcemanager); OrganisationRoles.administrator, OrganisationRoles.learnresourcemanager, OrganisationRoles.author);
List<Organisation> organisationList = new ArrayList<>(organisations); List<Organisation> organisationList = new ArrayList<>(organisations);
List<Organisation> reOrganisations = repositoryService.getOrganisations(entry); List<Organisation> reOrganisations = repositoryService.getOrganisations(entry);
......
...@@ -153,6 +153,7 @@ public class WebDAVCommandsTest extends WebDAVTestCase { ...@@ -153,6 +153,7 @@ public class WebDAVCommandsTest extends WebDAVTestCase {
//head file //head file
URI publicUri = conn.getBaseURI().path("webdav").path("home").path("public").path("test_head.txt").build(); URI publicUri = conn.getBaseURI().path("webdav").path("home").path("public").path("test_head.txt").build();
HttpResponse response = conn.head(publicUri); HttpResponse response = conn.head(publicUri);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
Header lengthHeader = response.getFirstHeader("Content-Length"); Header lengthHeader = response.getFirstHeader("Content-Length");
Assert.assertNotNull(lengthHeader); Assert.assertNotNull(lengthHeader);
Assert.assertEquals("10", lengthHeader.getValue()); Assert.assertEquals("10", lengthHeader.getValue());
...@@ -878,6 +879,49 @@ public class WebDAVCommandsTest extends WebDAVTestCase { ...@@ -878,6 +879,49 @@ public class WebDAVCommandsTest extends WebDAVTestCase {
conn.close(); conn.close();
} }
/**
* Default are the following User-Agent forbidden: empty, -
*
* @throws IOException
* @throws URISyntaxException
*/
@Test
public void forbiddenUserAgent()
throws IOException, URISyntaxException {
Identity user = JunitTestHelper.createAndPersistIdentityAsRndUser("webdav-2-");
//create a file
String publicPath = FolderConfig.getUserHomes() + "/" + user.getName() + "/public";
VFSContainer vfsPublic = VFSManager.olatRootContainer(publicPath, null);
createFile(vfsPublic, "test_head.txt");
WebDAVConnection conn = new WebDAVConnection();
URI publicUri = conn.getBaseURI().path("webdav").path("home").path("public").path("test_head.txt").build();
//head file with standard Apache User Agent -> Ok
conn.setCredentials(user.getName(), "A6B7C8");
HttpResponse response = conn.head(publicUri);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
conn.close();
// check with "-" as User-Agent -> Forbidden
WebDAVConnection hyphenConn = new WebDAVConnection("-");
hyphenConn.setCredentials(user.getName(), "A6B7C8");
HttpResponse hyphenResponse = hyphenConn.head(publicUri);
Assert.assertEquals(403, hyphenResponse.getStatusLine().getStatusCode());
EntityUtils.consume(hyphenResponse.getEntity());
hyphenConn.close();
// check with "" as User-Agent -> Forbidden
WebDAVConnection emptyConn = new WebDAVConnection("-");
emptyConn.setCredentials(user.getName(), "A6B7C8");
HttpResponse emptyResponse = emptyConn.head(publicUri);
Assert.assertEquals(403, emptyResponse.getStatusLine().getStatusCode());
EntityUtils.consume(emptyResponse.getEntity());
emptyConn.close();
}
private VFSItem createFile(VFSContainer container, String filename) throws IOException { private VFSItem createFile(VFSContainer container, String filename) throws IOException {
VFSLeaf testLeaf = container.createChildLeaf(filename); VFSLeaf testLeaf = container.createChildLeaf(filename);
try(InputStream in = WebDAVCommandsTest.class.getResourceAsStream("text.txt"); try(InputStream in = WebDAVCommandsTest.class.getResourceAsStream("text.txt");
......
...@@ -39,8 +39,6 @@ import org.apache.http.client.methods.HttpHead; ...@@ -39,8 +39,6 @@ import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpOptions; import org.apache.http.client.methods.HttpOptions;
import org.apache.http.client.methods.HttpPut; import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLContexts;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCookieStore; import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.BasicCredentialsProvider;
...@@ -76,22 +74,25 @@ public class WebDAVConnection implements Closeable { ...@@ -76,22 +74,25 @@ public class WebDAVConnection implements Closeable {
private final CloseableHttpClient httpclient; private final CloseableHttpClient httpclient;
public WebDAVConnection() { public WebDAVConnection() {
this(WebDAVTestCase.PROTOCOL, WebDAVTestCase.HOST, WebDAVTestCase.PORT); this(WebDAVTestCase.PROTOCOL, WebDAVTestCase.HOST, WebDAVTestCase.PORT, null);
} }
public WebDAVConnection(String protocol, String host, int port) { public WebDAVConnection(String userAgent) {
this(WebDAVTestCase.PROTOCOL, WebDAVTestCase.HOST, WebDAVTestCase.PORT, userAgent);
}
public WebDAVConnection(String protocol, String host, int port, String userAgent) {
this.protocol = protocol; this.protocol = protocol;
this.host = host; this.host = host;
this.port = port; this.port = port;
SSLConnectionSocketFactory sslFactory HttpClientBuilder builder = HttpClientBuilder.create()
= new SSLConnectionSocketFactory(SSLContexts.createDefault(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
httpclient = HttpClientBuilder.create()
.setDefaultCookieStore(cookieStore) .setDefaultCookieStore(cookieStore)
.setDefaultCredentialsProvider(provider) .setDefaultCredentialsProvider(provider);
.setSSLSocketFactory(sslFactory) if(userAgent != null) {
.build(); builder.setUserAgent(userAgent);
}
httpclient = builder.build();
} }
public CookieStore getCookieStore() { public CookieStore getCookieStore() {
...@@ -112,9 +113,7 @@ public class WebDAVConnection implements Closeable { ...@@ -112,9 +113,7 @@ public class WebDAVConnection implements Closeable {
public HttpResponse head(URI uri) throws IOException, URISyntaxException { public HttpResponse head(URI uri) throws IOException, URISyntaxException {
HttpHead propfind = new HttpHead(uri); HttpHead propfind = new HttpHead(uri);
HttpResponse response = execute(propfind); return execute(propfind);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
return response;
} }
public String propfind(URI uri, int depth) throws IOException, URISyntaxException { public String propfind(URI uri, int depth) throws IOException, URISyntaxException {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment