summaryrefslogtreecommitdiff
path: root/cli/tests/unit/ffi_test.ts
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2022-03-25 12:29:54 +0100
committerGitHub <noreply@github.com>2022-03-25 12:29:54 +0100
commit25b73a366f8b114d05add8b93aa52beb321dcb6e (patch)
treeede00e70b8a2b523c8e8014401b009aa0e8f7bce /cli/tests/unit/ffi_test.ts
parent3462d8750344743b7b0cdbedcbff6c4b98a383ba (diff)
fix(ext/ffi): enforce unstable check on ops (#14115)
Diffstat (limited to 'cli/tests/unit/ffi_test.ts')
-rw-r--r--cli/tests/unit/ffi_test.ts51
1 files changed, 51 insertions, 0 deletions
diff --git a/cli/tests/unit/ffi_test.ts b/cli/tests/unit/ffi_test.ts
index b7772e8e2..22da88d27 100644
--- a/cli/tests/unit/ffi_test.ts
+++ b/cli/tests/unit/ffi_test.ts
@@ -23,3 +23,54 @@ Deno.test({ permissions: { ffi: true } }, function dlopenInvalidArguments() {
Deno.dlopen(filename);
}, TypeError);
});
+
+Deno.test({ permissions: { ffi: false } }, function ffiPermissionDenied() {
+ assertThrows(() => {
+ Deno.dlopen("/usr/lib/libc.so.6", {});
+ }, Deno.errors.PermissionDenied);
+ const ptr = new Deno.UnsafePointer(0n);
+ const fnptr = new Deno.UnsafeFnPointer(
+ ptr,
+ {
+ parameters: ["u32", "pointer"],
+ result: "void",
+ } as const,
+ );
+ assertThrows(() => {
+ fnptr.call(123, null);
+ }, Deno.errors.PermissionDenied);
+ assertThrows(() => {
+ Deno.UnsafePointer.of(new Uint8Array(0));
+ }, Deno.errors.PermissionDenied);
+ const ptrView = new Deno.UnsafePointerView(ptr);
+ assertThrows(() => {
+ ptrView.copyInto(new Uint8Array(0));
+ }, Deno.errors.PermissionDenied);
+ assertThrows(() => {
+ ptrView.getCString();
+ }, Deno.errors.PermissionDenied);
+ assertThrows(() => {
+ ptrView.getUint8();
+ }, Deno.errors.PermissionDenied);
+ assertThrows(() => {
+ ptrView.getInt8();
+ }, Deno.errors.PermissionDenied);
+ assertThrows(() => {
+ ptrView.getUint16();
+ }, Deno.errors.PermissionDenied);
+ assertThrows(() => {
+ ptrView.getInt16();
+ }, Deno.errors.PermissionDenied);
+ assertThrows(() => {
+ ptrView.getUint32();
+ }, Deno.errors.PermissionDenied);
+ assertThrows(() => {
+ ptrView.getInt32();
+ }, Deno.errors.PermissionDenied);
+ assertThrows(() => {
+ ptrView.getFloat32();
+ }, Deno.errors.PermissionDenied);
+ assertThrows(() => {
+ ptrView.getFloat64();
+ }, Deno.errors.PermissionDenied);
+});