Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,26 @@ void checkPathRegister(
WatchEvent.Modifier... modifiers
);

// URLConnection

void check$sun_net_www_protocol_file_FileURLConnection$connect(Class<?> callerClass, java.net.URLConnection that);

void check$sun_net_www_protocol_file_FileURLConnection$getHeaderFields(Class<?> callerClass, java.net.URLConnection that);

void check$sun_net_www_protocol_file_FileURLConnection$getHeaderField(Class<?> callerClass, java.net.URLConnection that, String name);

void check$sun_net_www_protocol_file_FileURLConnection$getHeaderField(Class<?> callerClass, java.net.URLConnection that, int n);

void check$sun_net_www_protocol_file_FileURLConnection$getContentLength(Class<?> callerClass, java.net.URLConnection that);

void check$sun_net_www_protocol_file_FileURLConnection$getContentLengthLong(Class<?> callerClass, java.net.URLConnection that);

void check$sun_net_www_protocol_file_FileURLConnection$getHeaderFieldKey(Class<?> callerClass, java.net.URLConnection that, int n);

void check$sun_net_www_protocol_file_FileURLConnection$getLastModified(Class<?> callerClass, java.net.URLConnection that);

void check$sun_net_www_protocol_file_FileURLConnection$getInputStream(Class<?> callerClass, java.net.URLConnection that);

////////////////////
//
// Thread management
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,9 @@ public static Path createTempSymbolicLink() throws IOException {
public static URLConnection createHttpURLConnection() throws IOException {
return URI.create("http://127.0.0.1:12345/").toURL().openConnection();
}

public static URLConnection createFileURLConnection() throws IOException {
var fileUrl = createTempFileForWrite().toUri().toURL();
return fileUrl.openConnection();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ static CheckAction alwaysDenied(CheckedRunnable<Exception> action) {
getTestEntries(PathActions.class),
getTestEntries(SpiActions.class),
getTestEntries(SystemActions.class),
getTestEntries(URLConnectionFileActions.class),
getTestEntries(URLConnectionNetworkActions.class)
)
.flatMap(Function.identity())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

package org.elasticsearch.entitlement.qa.test;

import org.elasticsearch.core.CheckedConsumer;
import org.elasticsearch.entitlement.qa.entitled.EntitledActions;

import java.io.IOException;
import java.net.URLConnection;

import static org.elasticsearch.entitlement.qa.test.EntitlementTest.ExpectedAccess.PLUGINS;

class URLConnectionFileActions {

private static void withJdkFileConnection(CheckedConsumer<URLConnection, Exception> connectionConsumer) throws Exception {
var conn = EntitledActions.createFileURLConnection();
// Be sure we got the connection implementation we want
assert conn.getClass().getSimpleName().equals("FileURLConnection");
try {
connectionConsumer.accept(conn);
} catch (IOException e) {
// It's OK, it means we passed entitlement checks, and we tried to perform some operation
}
}

@EntitlementTest(expectedAccess = PLUGINS)
static void sunFileURLConnectionConnect() throws Exception {
withJdkFileConnection(URLConnection::connect);
}

@EntitlementTest(expectedAccess = PLUGINS)
static void sunFileURLConnectionGetHeaderFields() throws Exception {
withJdkFileConnection(URLConnection::getHeaderFields);
}

@EntitlementTest(expectedAccess = PLUGINS)
static void sunFileURLConnectionGetHeaderFieldWithName() throws Exception {
withJdkFileConnection(urlConnection -> urlConnection.getHeaderField("date"));
}

@EntitlementTest(expectedAccess = PLUGINS)
static void sunFileURLConnectionGetHeaderFieldWithIndex() throws Exception {
withJdkFileConnection(urlConnection -> urlConnection.getHeaderField(0));
}

@EntitlementTest(expectedAccess = PLUGINS)
static void sunFileURLConnectionGetContentLength() throws Exception {
withJdkFileConnection(URLConnection::getContentLength);
}

@EntitlementTest(expectedAccess = PLUGINS)
static void sunFileURLConnectionGetContentLengthLong() throws Exception {
withJdkFileConnection(URLConnection::getContentLengthLong);
}

@EntitlementTest(expectedAccess = PLUGINS)
static void sunFileURLConnectionGetHeaderFieldKey() throws Exception {
withJdkFileConnection(urlConnection -> urlConnection.getHeaderFieldKey(0));
}

@EntitlementTest(expectedAccess = PLUGINS)
static void sunFileURLConnectionGetLastModified() throws Exception {
withJdkFileConnection(URLConnection::getLastModified);
}

@EntitlementTest(expectedAccess = PLUGINS)
static void sunFileURLConnectionGetInputStream() throws Exception {
withJdkFileConnection(URLConnection::getInputStream);
}

@EntitlementTest(expectedAccess = PLUGINS)
static void sunFileURLConnectionGetContentType() throws Exception {
withJdkFileConnection(URLConnection::getContentType);
}

@EntitlementTest(expectedAccess = PLUGINS)
static void sunFileURLConnectionGetContentEncoding() throws Exception {
withJdkFileConnection(URLConnection::getContentEncoding);
}

@EntitlementTest(expectedAccess = PLUGINS)
static void sunFileURLConnectionGetExpiration() throws Exception {
withJdkFileConnection(URLConnection::getExpiration);
}

@EntitlementTest(expectedAccess = PLUGINS)
static void sunFileURLConnectionGetDate() throws Exception {
withJdkFileConnection(URLConnection::getDate);
}

@EntitlementTest(expectedAccess = PLUGINS)
static void sunFileURLConnectionGetHeaderFieldInt() throws Exception {
withJdkFileConnection(conn -> conn.getHeaderFieldInt("field", 0));
}

@EntitlementTest(expectedAccess = PLUGINS)
static void sunFileURLConnectionGetHeaderFieldLong() throws Exception {
withJdkFileConnection(conn -> conn.getHeaderFieldLong("field", 0));
}

@EntitlementTest(expectedAccess = PLUGINS)
static void sunFileURLConnectionGetContent() throws Exception {
withJdkFileConnection(URLConnection::getContent);
}

@EntitlementTest(expectedAccess = PLUGINS)
static void sunFileURLConnectionGetContentWithClasses() throws Exception {
withJdkFileConnection(conn -> conn.getContent(new Class<?>[] { String.class }));
}
}
Loading