summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2023-04-26 21:23:28 +0100
committerGitHub <noreply@github.com>2023-04-26 16:23:28 -0400
commit3d8a4d3b81e107bbb152ad69047f64d16ca800f3 (patch)
tree52c8d5e655e3b4bc51aabee1bbfe428a3b7b394a /cli/tests
parentc2f5c096925e2fc303f6ea1c36cdba38748c9217 (diff)
feat(cli): don't check permissions for statically analyzable dynamic imports (#18713)
Closes #17697 Closes #17658
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration/run_tests.rs5
-rw-r--r--cli/tests/testdata/dynamic_import/empty_1.ts0
-rw-r--r--cli/tests/testdata/dynamic_import/empty_2.ts0
-rw-r--r--cli/tests/testdata/dynamic_import/permissions_remote_remote.ts2
-rw-r--r--cli/tests/testdata/dynamic_import/static_analysis_no_permissions.ts13
-rw-r--r--cli/tests/testdata/dynamic_import/static_analysis_no_permissions.ts.out2
-rw-r--r--cli/tests/testdata/run/error_015_dynamic_import_permissions.js2
-rw-r--r--cli/tests/testdata/run/error_015_dynamic_import_permissions.out2
-rw-r--r--cli/tests/testdata/workers/dynamic_remote.ts2
-rw-r--r--cli/tests/testdata/workers/permissions_dynamic_remote.ts.out2
10 files changed, 25 insertions, 5 deletions
diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs
index cc37cf523..d946b6a1c 100644
--- a/cli/tests/integration/run_tests.rs
+++ b/cli/tests/integration/run_tests.rs
@@ -2661,6 +2661,11 @@ mod permissions {
});
}
+ itest!(dynamic_import_static_analysis_no_permissions {
+ args: "run --quiet --reload --no-prompt dynamic_import/static_analysis_no_permissions.ts",
+ output: "dynamic_import/static_analysis_no_permissions.ts.out",
+ });
+
itest!(dynamic_import_permissions_remote_remote {
args: "run --quiet --reload --allow-net=localhost:4545 dynamic_import/permissions_remote_remote.ts",
output: "dynamic_import/permissions_remote_remote.ts.out",
diff --git a/cli/tests/testdata/dynamic_import/empty_1.ts b/cli/tests/testdata/dynamic_import/empty_1.ts
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/cli/tests/testdata/dynamic_import/empty_1.ts
diff --git a/cli/tests/testdata/dynamic_import/empty_2.ts b/cli/tests/testdata/dynamic_import/empty_2.ts
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/cli/tests/testdata/dynamic_import/empty_2.ts
diff --git a/cli/tests/testdata/dynamic_import/permissions_remote_remote.ts b/cli/tests/testdata/dynamic_import/permissions_remote_remote.ts
index 0033bcccc..65a254191 100644
--- a/cli/tests/testdata/dynamic_import/permissions_remote_remote.ts
+++ b/cli/tests/testdata/dynamic_import/permissions_remote_remote.ts
@@ -1,3 +1,3 @@
await import(
- "http://localhost:4545/dynamic_import/static_remote.ts"
+ "" + "http://localhost:4545/dynamic_import/static_remote.ts"
);
diff --git a/cli/tests/testdata/dynamic_import/static_analysis_no_permissions.ts b/cli/tests/testdata/dynamic_import/static_analysis_no_permissions.ts
new file mode 100644
index 000000000..de75ba87b
--- /dev/null
+++ b/cli/tests/testdata/dynamic_import/static_analysis_no_permissions.ts
@@ -0,0 +1,13 @@
+try {
+ await import("./empty_1.ts");
+ console.log("✅ Succeeded importing statically analyzable specifier");
+} catch {
+ console.log("❌ Failed importing statically analyzable specifier");
+}
+
+try {
+ await import("" + "./empty_2.ts");
+ console.log("❌ Succeeded importing non-statically analyzable specifier");
+} catch {
+ console.log("✅ Failed importing non-statically analyzable specifier");
+}
diff --git a/cli/tests/testdata/dynamic_import/static_analysis_no_permissions.ts.out b/cli/tests/testdata/dynamic_import/static_analysis_no_permissions.ts.out
new file mode 100644
index 000000000..ba9249ab0
--- /dev/null
+++ b/cli/tests/testdata/dynamic_import/static_analysis_no_permissions.ts.out
@@ -0,0 +1,2 @@
+✅ Succeeded importing statically analyzable specifier
+✅ Failed importing non-statically analyzable specifier
diff --git a/cli/tests/testdata/run/error_015_dynamic_import_permissions.js b/cli/tests/testdata/run/error_015_dynamic_import_permissions.js
index 73da56fd8..47961cf63 100644
--- a/cli/tests/testdata/run/error_015_dynamic_import_permissions.js
+++ b/cli/tests/testdata/run/error_015_dynamic_import_permissions.js
@@ -1,3 +1,3 @@
(async () => {
- await import("http://localhost:4545/subdir/mod4.js");
+ await import("" + "http://localhost:4545/subdir/mod4.js");
})();
diff --git a/cli/tests/testdata/run/error_015_dynamic_import_permissions.out b/cli/tests/testdata/run/error_015_dynamic_import_permissions.out
index ef54f331b..87ce43e9c 100644
--- a/cli/tests/testdata/run/error_015_dynamic_import_permissions.out
+++ b/cli/tests/testdata/run/error_015_dynamic_import_permissions.out
@@ -1,4 +1,4 @@
error: Uncaught (in promise) TypeError: Requires net access to "localhost:4545", run again with the --allow-net flag
- await import("http://localhost:4545/subdir/mod4.js");
+ await import("" + "http://localhost:4545/subdir/mod4.js");
^
at async file://[WILDCARD]/error_015_dynamic_import_permissions.js:2:3
diff --git a/cli/tests/testdata/workers/dynamic_remote.ts b/cli/tests/testdata/workers/dynamic_remote.ts
index 381c7f374..54e4a4714 100644
--- a/cli/tests/testdata/workers/dynamic_remote.ts
+++ b/cli/tests/testdata/workers/dynamic_remote.ts
@@ -1,2 +1,2 @@
// This file doesn't really exist, but it doesn't matter, a "PermissionsDenied" error should be thrown.
-await import("https://example.com/some/file.ts");
+await import("" + "https://example.com/some/file.ts");
diff --git a/cli/tests/testdata/workers/permissions_dynamic_remote.ts.out b/cli/tests/testdata/workers/permissions_dynamic_remote.ts.out
index cd1884c7e..91f3cc6d5 100644
--- a/cli/tests/testdata/workers/permissions_dynamic_remote.ts.out
+++ b/cli/tests/testdata/workers/permissions_dynamic_remote.ts.out
@@ -1,5 +1,5 @@
error: Uncaught (in worker "") (in promise) TypeError: Requires net access to "example.com", run again with the --allow-net flag
-await import("https://example.com/some/file.ts");
+await import("" + "https://example.com/some/file.ts");
^
at async http://localhost:4545/workers/dynamic_remote.ts:2:1
[WILDCARD]error: Uncaught (in promise) Error: Unhandled error in child worker.