summaryrefslogtreecommitdiff
path: root/cli/dts/lib.deno.unstable.d.ts
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2021-04-26 05:38:59 +0800
committerGitHub <noreply@github.com>2021-04-25 23:38:59 +0200
commitf3751e498faabd524494a4b70c49b1f53fe5ebdd (patch)
tree9f3cf5b15fc10d0ef12f78c984fbbb59554343ef /cli/dts/lib.deno.unstable.d.ts
parent7063e449f11ab2cff492ba90314da7a0bcd994a6 (diff)
feat(cli): add test permissions to Deno.test (#10188)
This commits adds adds "permissions" option to the test definitions which allows tests to run with different permission sets than the process's permission. The change will only be in effect within the test function, once the test has completed the original process permission set is restored. Test permissions cannot exceed the process's permission. You can only narrow or drop permissions, failure to acquire a permission results in an error being thrown and the test case will fail.
Diffstat (limited to 'cli/dts/lib.deno.unstable.d.ts')
-rw-r--r--cli/dts/lib.deno.unstable.d.ts134
1 files changed, 134 insertions, 0 deletions
diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts
index d955a825f..76d90b10d 100644
--- a/cli/dts/lib.deno.unstable.d.ts
+++ b/cli/dts/lib.deno.unstable.d.ts
@@ -1181,6 +1181,140 @@ declare namespace Deno {
* then the underlying HttpConn resource is closed automatically.
*/
export function serveHttp(conn: Conn): HttpConn;
+
+ /** **UNSTABLE**: New option, yet to be vetted. */
+ export interface TestDefinition {
+ /** Specifies the permissions that should be used to run the test.
+ * Set this to "inherit" to keep the calling thread's permissions.
+ * Set this to "none" to revoke all permissions.
+ *
+ * Defaults to "inherit".
+ */
+ permissions?: "inherit" | "none" | {
+ /** Specifies if the `net` permission should be requested or revoked.
+ * If set to `"inherit"`, the current `env` permission will be inherited.
+ * If set to `true`, the global `net` permission will be requested.
+ * If set to `false`, the global `net` permission will be revoked.
+ *
+ * Defaults to "inherit".
+ */
+ env?: "inherit" | boolean;
+
+ /** Specifies if the `hrtime` permission should be requested or revoked.
+ * If set to `"inherit"`, the current `hrtime` permission will be inherited.
+ * If set to `true`, the global `hrtime` permission will be requested.
+ * If set to `false`, the global `hrtime` permission will be revoked.
+ *
+ * Defaults to "inherit".
+ */
+ hrtime?: "inherit" | boolean;
+
+ /** Specifies if the `net` permission should be requested or revoked.
+ * if set to `"inherit"`, the current `net` permission will be inherited.
+ * if set to `true`, the global `net` permission will be requested.
+ * if set to `false`, the global `net` permission will be revoked.
+ * if set to `string[]`, the `net` permission will be requested with the
+ * specified host strings with the format `"<host>[:<port>]`.
+ *
+ * Defaults to "inherit".
+ *
+ * Examples:
+ *
+ * ```
+ * Deno.test({
+ * name: "inherit",
+ * permissions: {
+ * net: "inherit",
+ * },
+ * async fn() {
+ * const status = await Deno.permissions.query({ name: "net" })
+ * assertEquals(status.state, "granted");
+ * },
+ * };
+ * ```
+ *
+ * ```
+ * Deno.test({
+ * name: "true",
+ * permissions: {
+ * net: true,
+ * },
+ * async fn() {
+ * const status = await Deno.permissions.query({ name: "net" });
+ * assertEquals(status.state, "granted");
+ * },
+ * };
+ * ```
+ *
+ * ```
+ * Deno.test({
+ * name: "false",
+ * permissions: {
+ * net: false,
+ * },
+ * async fn() {
+ * const status = await Deno.permissions.query({ name: "net" });
+ * assertEquals(status.state, "denied");
+ * },
+ * };
+ * ```
+ *
+ * ```
+ * Deno.test({
+ * name: "localhost:8080",
+ * permissions: {
+ * net: ["localhost:8080"],
+ * },
+ * async fn() {
+ * const status = await Deno.permissions.query({ name: "net", host: "localhost:8080" });
+ * assertEquals(status.state, "granted");
+ * },
+ * };
+ * ```
+ */
+ net?: "inherit" | boolean | string[];
+
+ /** Specifies if the `plugin` permission should be requested or revoked.
+ * If set to `"inherit"`, the current `plugin` permission will be inherited.
+ * If set to `true`, the global `plugin` permission will be requested.
+ * If set to `false`, the global `plugin` permission will be revoked.
+ *
+ * Defaults to "inherit".
+ */
+ plugin?: "inherit" | boolean;
+
+ /** Specifies if the `read` permission should be requested or revoked.
+ * If set to `"inherit"`, the current `read` permission will be inherited.
+ * If set to `true`, the global `read` permission will be requested.
+ * If set to `false`, the global `read` permission will be revoked.
+ * If set to `Array<string | URL>`, the `read` permission will be requested with the
+ * specified file paths.
+ *
+ * Defaults to "inherit".
+ */
+ read?: "inherit" | boolean | Array<string | URL>;
+
+ /** Specifies if the `run` permission should be requested or revoked.
+ * If set to `"inherit"`, the current `run` permission will be inherited.
+ * If set to `true`, the global `run` permission will be requested.
+ * If set to `false`, the global `run` permission will be revoked.
+ *
+ * Defaults to "inherit".
+ */
+ run?: "inherit" | boolean;
+
+ /** Specifies if the `write` permission should be requested or revoked.
+ * If set to `"inherit"`, the current `write` permission will be inherited.
+ * If set to `true`, the global `write` permission will be requested.
+ * If set to `false`, the global `write` permission will be revoked.
+ * If set to `Array<string | URL>`, the `write` permission will be requested with the
+ * specified file paths.
+ *
+ * Defaults to "inherit".
+ */
+ write?: "inherit" | boolean | Array<string | URL>;
+ };
+ }
}
declare function fetch(