|
46 | 46 | import java.io.BufferedWriter;
|
47 | 47 | import java.io.Closeable;
|
48 | 48 | import java.io.IOException;
|
| 49 | +import java.io.InputStreamReader; |
49 | 50 | import java.io.OutputStream;
|
50 | 51 | import java.lang.reflect.Constructor;
|
51 | 52 | import java.lang.reflect.Method;
|
@@ -464,6 +465,41 @@ protected Object execute(RootNode node, Env env, Object[] contextArguments, Obje
|
464 | 465 | }
|
465 | 466 | }
|
466 | 467 |
|
| 468 | + @Test |
| 469 | + public void testReadIgnoresLinkOption() { |
| 470 | + Context ctx = cfg.getContext(); |
| 471 | + String configuration = cfg.getName(); |
| 472 | + String path = cfg.getPath().toString(); |
| 473 | + boolean usePublicFile = cfg.usePublicFile; |
| 474 | + boolean canRead = cfg.canRead(); |
| 475 | + AbstractExecutableTestLanguage.evalTestLanguage(ctx, TestReadIgnoresLinkOptionLanguage.class, "", configuration, path, usePublicFile, canRead); |
| 476 | + } |
| 477 | + |
| 478 | + @Registration |
| 479 | + public static final class TestReadIgnoresLinkOptionLanguage extends AbstractExecutableTestLanguage { |
| 480 | + @Override |
| 481 | + @TruffleBoundary |
| 482 | + protected Object execute(RootNode node, Env env, Object[] contextArguments, Object[] frameArguments) throws Exception { |
| 483 | + String configurationName = (String) contextArguments[0]; |
| 484 | + String path = (String) contextArguments[1]; |
| 485 | + boolean usePublicFile = (boolean) contextArguments[2]; |
| 486 | + boolean canRead = (boolean) contextArguments[3]; |
| 487 | + TruffleFile file = resolve(env, usePublicFile, path, FOLDER_EXISTING, FILE_EXISTING); |
| 488 | + try { |
| 489 | + try (BufferedReader in = new BufferedReader(new InputStreamReader(file.newInputStream(LinkOption.NOFOLLOW_LINKS), StandardCharsets.UTF_8))) { |
| 490 | + final String content = in.readLine(); |
| 491 | + Assert.assertTrue(formatErrorMessage("Expected SecurityException", configurationName, path), canRead); |
| 492 | + Assert.assertEquals(formatErrorMessage("Expected file content", configurationName, path), FILE_EXISTING_CONTENT, content); |
| 493 | + } |
| 494 | + } catch (SecurityException se) { |
| 495 | + Assert.assertFalse(formatErrorMessage("Unexpected SecurityException", configurationName, path), canRead); |
| 496 | + } catch (IOException ioe) { |
| 497 | + throw new AssertionError(formatErrorMessage(ioe.getMessage(), configurationName, path), ioe); |
| 498 | + } |
| 499 | + return null; |
| 500 | + } |
| 501 | + } |
| 502 | + |
467 | 503 | @Test
|
468 | 504 | public void testReadUsingStream() {
|
469 | 505 | Context ctx = cfg.getContext();
|
|
0 commit comments