|
25 | 25 | import java.net.URL; |
26 | 26 | import java.net.URLConnection; |
27 | 27 |
|
| 28 | +import javax.net.ssl.HttpsURLConnection; |
| 29 | + |
28 | 30 | import static org.elasticsearch.entitlement.qa.test.EntitlementTest.ExpectedAccess.PLUGINS; |
29 | 31 |
|
30 | 32 | @SuppressWarnings("unused") // everything is called via reflection |
@@ -79,6 +81,17 @@ private static void withJdkHttpConnection(CheckedConsumer<HttpURLConnection, Exc |
79 | 81 | } |
80 | 82 | } |
81 | 83 |
|
| 84 | + private static void withJdkHttpsConnection(CheckedConsumer<HttpsURLConnection, Exception> connectionConsumer) throws Exception { |
| 85 | + var conn = EntitledActions.createHttpsURLConnection(); |
| 86 | + // Be sure we got the connection implementation we want |
| 87 | + assert HttpsURLConnection.class.isAssignableFrom(conn.getClass()); |
| 88 | + try { |
| 89 | + connectionConsumer.accept((HttpsURLConnection) conn); |
| 90 | + } catch (java.net.ConnectException e) { |
| 91 | + // It's OK, it means we passed entitlement checks, and we tried to connect |
| 92 | + } |
| 93 | + } |
| 94 | + |
82 | 95 | private static void withJdkFtpConnection(CheckedConsumer<URLConnection, Exception> connectionConsumer) throws Exception { |
83 | 96 | var conn = EntitledActions.createFtpURLConnection(); |
84 | 97 | // Be sure we got the connection implementation we want |
@@ -302,4 +315,118 @@ static void sunHttpURLConnectionGetHeaderFieldWithIndex() throws Exception { |
302 | 315 | static void sunHttpURLConnectionGetHeaderFieldKey() throws Exception { |
303 | 316 | withJdkHttpConnection(conn -> conn.getHeaderFieldKey(0)); |
304 | 317 | } |
| 318 | + |
| 319 | + // https |
| 320 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 321 | + static void sunHttpsURLConnectionImplConnect() throws Exception { |
| 322 | + withJdkHttpsConnection(HttpsURLConnection::connect); |
| 323 | + } |
| 324 | + |
| 325 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 326 | + static void sunHttpsURLConnectionImplGetOutputStream() throws Exception { |
| 327 | + withJdkHttpsConnection(httpsURLConnection -> { |
| 328 | + httpsURLConnection.setDoOutput(true); |
| 329 | + httpsURLConnection.getOutputStream(); |
| 330 | + }); |
| 331 | + } |
| 332 | + |
| 333 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 334 | + static void sunHttpsURLConnectionImplGetInputStream() throws Exception { |
| 335 | + withJdkHttpsConnection(HttpsURLConnection::getInputStream); |
| 336 | + } |
| 337 | + |
| 338 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 339 | + static void sunHttpsURLConnectionImplGetErrorStream() throws Exception { |
| 340 | + withJdkHttpsConnection(HttpsURLConnection::getErrorStream); |
| 341 | + } |
| 342 | + |
| 343 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 344 | + static void sunHttpsURLConnectionImplGetHeaderFieldWithName() throws Exception { |
| 345 | + withJdkHttpsConnection(httpsURLConnection -> httpsURLConnection.getHeaderField("date")); |
| 346 | + } |
| 347 | + |
| 348 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 349 | + static void sunHttpsURLConnectionImplGetHeaderFields() throws Exception { |
| 350 | + withJdkHttpsConnection(HttpsURLConnection::getHeaderFields); |
| 351 | + } |
| 352 | + |
| 353 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 354 | + static void sunHttpsURLConnectionImplGetHeaderFieldWithIndex() throws Exception { |
| 355 | + withJdkHttpsConnection(httpsURLConnection -> httpsURLConnection.getHeaderField(0)); |
| 356 | + } |
| 357 | + |
| 358 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 359 | + static void sunHttpsURLConnectionImplGetHeaderFieldKey() throws Exception { |
| 360 | + withJdkHttpsConnection(httpsURLConnection -> httpsURLConnection.getHeaderFieldKey(0)); |
| 361 | + } |
| 362 | + |
| 363 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 364 | + static void sunHttpsURLConnectionImplGetResponseCode() throws Exception { |
| 365 | + withJdkHttpsConnection(HttpsURLConnection::getResponseCode); |
| 366 | + } |
| 367 | + |
| 368 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 369 | + static void sunHttpsURLConnectionImplGetResponseMessage() throws Exception { |
| 370 | + withJdkHttpsConnection(HttpsURLConnection::getResponseMessage); |
| 371 | + } |
| 372 | + |
| 373 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 374 | + static void sunHttpsURLConnectionImplGetContentLength() throws Exception { |
| 375 | + withJdkHttpsConnection(HttpsURLConnection::getContentLength); |
| 376 | + } |
| 377 | + |
| 378 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 379 | + static void sunHttpsURLConnectionImpl$getContentLengthLong() throws Exception { |
| 380 | + withJdkHttpsConnection(HttpsURLConnection::getContentLengthLong); |
| 381 | + } |
| 382 | + |
| 383 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 384 | + static void sunHttpsURLConnectionImplGetContentType() throws Exception { |
| 385 | + withJdkHttpsConnection(HttpsURLConnection::getContentType); |
| 386 | + } |
| 387 | + |
| 388 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 389 | + static void sunHttpsURLConnectionImplGetContentEncoding() throws Exception { |
| 390 | + withJdkHttpsConnection(HttpsURLConnection::getContentEncoding); |
| 391 | + } |
| 392 | + |
| 393 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 394 | + static void sunHttpsURLConnectionImplGetExpiration() throws Exception { |
| 395 | + withJdkHttpsConnection(HttpsURLConnection::getExpiration); |
| 396 | + } |
| 397 | + |
| 398 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 399 | + static void sunHttpsURLConnectionImplGetDate() throws Exception { |
| 400 | + withJdkHttpsConnection(HttpsURLConnection::getDate); |
| 401 | + } |
| 402 | + |
| 403 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 404 | + static void sunHttpsURLConnectionImplGetLastModified() throws Exception { |
| 405 | + withJdkHttpsConnection(HttpsURLConnection::getLastModified); |
| 406 | + } |
| 407 | + |
| 408 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 409 | + static void sunHttpsURLConnectionImplGetHeaderFieldInt() throws Exception { |
| 410 | + withJdkHttpsConnection(httpsURLConnection -> httpsURLConnection.getHeaderFieldInt("content-length", -1)); |
| 411 | + } |
| 412 | + |
| 413 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 414 | + static void sunHttpsURLConnectionImplGetHeaderFieldLong() throws Exception { |
| 415 | + withJdkHttpsConnection(httpsURLConnection -> httpsURLConnection.getHeaderFieldLong("content-length", -1)); |
| 416 | + } |
| 417 | + |
| 418 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 419 | + static void sunHttpsURLConnectionImplGetHeaderFieldDate() throws Exception { |
| 420 | + withJdkHttpsConnection(httpsURLConnection -> httpsURLConnection.getHeaderFieldDate("date", 0)); |
| 421 | + } |
| 422 | + |
| 423 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 424 | + static void sunHttpsURLConnectionImplGetContent() throws Exception { |
| 425 | + withJdkHttpsConnection(HttpsURLConnection::getContent); |
| 426 | + } |
| 427 | + |
| 428 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 429 | + static void sunHttpsURLConnectionImplGetContentWithClasses() throws Exception { |
| 430 | + withJdkHttpsConnection(httpsURLConnection -> httpsURLConnection.getContent(new Class<?>[] { String.class })); |
| 431 | + } |
305 | 432 | } |
0 commit comments