|
22 | 22 | import java.io.FileWriter; |
23 | 23 | import java.io.IOException; |
24 | 24 | import java.io.RandomAccessFile; |
| 25 | +import java.net.http.HttpRequest; |
| 26 | +import java.net.http.HttpResponse; |
25 | 27 | import java.nio.charset.StandardCharsets; |
26 | 28 | import java.nio.file.Path; |
27 | 29 | import java.nio.file.Paths; |
28 | 30 | import java.security.GeneralSecurityException; |
29 | 31 | import java.security.KeyStore; |
30 | 32 | import java.util.Scanner; |
31 | 33 | import java.util.jar.JarFile; |
| 34 | +import java.util.logging.FileHandler; |
32 | 35 | import java.util.zip.ZipException; |
33 | 36 | import java.util.zip.ZipFile; |
34 | 37 |
|
35 | 38 | import static java.nio.charset.Charset.defaultCharset; |
| 39 | +import static java.nio.file.StandardOpenOption.CREATE; |
| 40 | +import static java.nio.file.StandardOpenOption.WRITE; |
36 | 41 | import static java.util.zip.ZipFile.OPEN_DELETE; |
37 | 42 | import static java.util.zip.ZipFile.OPEN_READ; |
38 | 43 | import static org.elasticsearch.entitlement.qa.entitled.EntitledActions.createTempFileForWrite; |
@@ -477,5 +482,86 @@ static void createScannerFileWithCharsetName() throws FileNotFoundException { |
477 | 482 | new Scanner(readFile().toFile(), "UTF-8"); |
478 | 483 | } |
479 | 484 |
|
| 485 | + @EntitlementTest(expectedAccess = ALWAYS_DENIED) |
| 486 | + static void fileHandler() throws IOException { |
| 487 | + new FileHandler(); |
| 488 | + } |
| 489 | + |
| 490 | + @EntitlementTest(expectedAccess = ALWAYS_DENIED) |
| 491 | + static void fileHandler_String() throws IOException { |
| 492 | + new FileHandler(readFile().toString()); |
| 493 | + } |
| 494 | + |
| 495 | + @EntitlementTest(expectedAccess = ALWAYS_DENIED) |
| 496 | + static void fileHandler_StringBoolean() throws IOException { |
| 497 | + new FileHandler(readFile().toString(), false); |
| 498 | + } |
| 499 | + |
| 500 | + @EntitlementTest(expectedAccess = ALWAYS_DENIED) |
| 501 | + static void fileHandler_StringIntInt() throws IOException { |
| 502 | + new FileHandler(readFile().toString(), 1, 2); |
| 503 | + } |
| 504 | + |
| 505 | + @EntitlementTest(expectedAccess = ALWAYS_DENIED) |
| 506 | + static void fileHandler_StringIntIntBoolean() throws IOException { |
| 507 | + new FileHandler(readFile().toString(), 1, 2, false); |
| 508 | + } |
| 509 | + |
| 510 | + @EntitlementTest(expectedAccess = ALWAYS_DENIED) |
| 511 | + static void fileHandler_StringLongIntBoolean() throws IOException { |
| 512 | + new FileHandler(readFile().toString(), 1L, 2, false); |
| 513 | + } |
| 514 | + |
| 515 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 516 | + static void httpRequestBodyPublishersOfFile() throws IOException { |
| 517 | + HttpRequest.BodyPublishers.ofFile(readFile()); |
| 518 | + } |
| 519 | + |
| 520 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 521 | + static void httpResponseBodyHandlersOfFile() { |
| 522 | + HttpResponse.BodyHandlers.ofFile(readWriteFile()); |
| 523 | + } |
| 524 | + |
| 525 | + @EntitlementTest(expectedAccess = ALWAYS_DENIED) |
| 526 | + static void httpResponseBodyHandlersOfFile_readOnly() { |
| 527 | + HttpResponse.BodyHandlers.ofFile(readFile()); |
| 528 | + } |
| 529 | + |
| 530 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 531 | + static void httpResponseBodyHandlersOfFileDownload() { |
| 532 | + HttpResponse.BodyHandlers.ofFileDownload(readWriteDir()); |
| 533 | + } |
| 534 | + |
| 535 | + @EntitlementTest(expectedAccess = ALWAYS_DENIED) |
| 536 | + static void httpResponseBodyHandlersOfFileDownload_readOnly() { |
| 537 | + HttpResponse.BodyHandlers.ofFileDownload(readDir()); |
| 538 | + } |
| 539 | + |
| 540 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 541 | + static void httpResponseBodySubscribersOfFile_File() { |
| 542 | + HttpResponse.BodySubscribers.ofFile(readWriteFile()); |
| 543 | + } |
| 544 | + |
| 545 | + @EntitlementTest(expectedAccess = ALWAYS_DENIED) |
| 546 | + static void httpResponseBodySubscribersOfFile_File_readOnly() { |
| 547 | + HttpResponse.BodySubscribers.ofFile(readFile()); |
| 548 | + } |
| 549 | + |
| 550 | + @EntitlementTest(expectedAccess = PLUGINS) |
| 551 | + static void httpResponseBodySubscribersOfFile_FileOpenOptions() { |
| 552 | + // Note that, unlike other methods like BodyHandlers.ofFile, this is indeed |
| 553 | + // an overload distinct from ofFile with no OpenOptions, and so it needs its |
| 554 | + // own instrumentation and its own test. |
| 555 | + HttpResponse.BodySubscribers.ofFile(readWriteFile(), CREATE, WRITE); |
| 556 | + } |
| 557 | + |
| 558 | + @EntitlementTest(expectedAccess = ALWAYS_DENIED) |
| 559 | + static void httpResponseBodySubscribersOfFile_FileOpenOptions_readOnly() { |
| 560 | + // Note that, unlike other methods like BodyHandlers.ofFile, this is indeed |
| 561 | + // an overload distinct from ofFile with no OpenOptions, and so it needs its |
| 562 | + // own instrumentation and its own test. |
| 563 | + HttpResponse.BodySubscribers.ofFile(readFile(), CREATE, WRITE); |
| 564 | + } |
| 565 | + |
480 | 566 | private FileCheckActions() {} |
481 | 567 | } |
0 commit comments