Skip to content

update permissions samples on testing.md #1664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions runtime/fundamentals/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Deno.test("async test", async () => {

Deno.test({
name: "read file test",
permissions: { read: true },
fn: () => {
const data = Deno.readTextFileSync("./somefile.txt");
assertEquals(data, "expected content");
Expand Down Expand Up @@ -97,7 +96,7 @@ deno test my_test.ts -- -e --foo --bar

# Provide permission for deno to read from the filesystem, which is necessary
# for the final test above to pass
deno test --allow-read my_test.ts
deno test --allow-read=. my_test.ts
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit of a personal preference, but I have a strong desire to promote the practice of not granting broad permissions too easily.

```

## Test Steps
Expand Down Expand Up @@ -611,7 +610,7 @@ import getFileText from "./main.ts";

Deno.test({
name: "File reader gets text with permission",
permissions: { read: true },
// no `permissions` means "inherit"
fn: async () => {
const result = await getFileText();
console.log(result);
Expand Down Expand Up @@ -640,11 +639,10 @@ The permissions object supports detailed configuration:
```ts
Deno.test({
name: "permission configuration example",
// permissions: { read: true } // Grant all read permissions and deny all others
// OR
permissions: {
read: true, // Grant all read permissions
// OR
read: ["./data", "./config"], // Grant read to specific paths only

write: false, // Explicitly deny write permissions
net: ["example.com:443"], // Allow specific host:port combinations
env: ["API_KEY"], // Allow access to specific env variables
Expand Down
Loading