@@ -15,7 +15,7 @@ import net, { Socket } from "node:net";
15
15
import fs from "node:fs" ;
16
16
import { text } from "node:stream/consumers" ;
17
17
18
- import { assert , assertEquals , fail } from "@std/assert" ;
18
+ import { assert , assertEquals , assertStringIncludes , fail } from "@std/assert" ;
19
19
import { assertSpyCalls , spy } from "@std/testing/mock" ;
20
20
import { fromFileUrl , relative } from "@std/path" ;
21
21
import { retry } from "@std/async/retry" ;
@@ -1916,3 +1916,31 @@ Deno.test("[node/http] supports proxy http request", async () => {
1916
1916
await promise ;
1917
1917
await server . finished ;
1918
1918
} ) ;
1919
+
1920
+ Deno . test ( "[node/http] `request` requires net permission to host and port" , {
1921
+ permissions : { net : [ "localhost:4545" ] } ,
1922
+ } , async ( ) => {
1923
+ const { promise, resolve } = Promise . withResolvers < void > ( ) ;
1924
+ http . request ( "http://localhost:4545/echo.ts" , async ( res ) => {
1925
+ assertEquals ( res . statusCode , 200 ) ;
1926
+ assertStringIncludes ( await text ( res ) , "function echo(" ) ;
1927
+ resolve ( ) ;
1928
+ } ) . end ( ) ;
1929
+ await promise ;
1930
+ } ) ;
1931
+
1932
+ Deno . test (
1933
+ "[node/http] `request` errors with EPERM error when permission is not granted" ,
1934
+ { permissions : { net : [ "localhost:4321" ] } } , // wrong permission
1935
+ async ( ) => {
1936
+ const { promise, resolve } = Promise . withResolvers < void > ( ) ;
1937
+ http . request ( "http://localhost:4545/echo.ts" , async ( ) => { } )
1938
+ . on ( "error" , ( e ) => {
1939
+ assertEquals ( e . message , "getaddrinfo EPERM localhost" ) ;
1940
+ // deno-lint-ignore no-explicit-any
1941
+ assertEquals ( ( e as any ) . code , "EPERM" ) ;
1942
+ resolve ( ) ;
1943
+ } ) . end ( ) ;
1944
+ await promise ;
1945
+ } ,
1946
+ ) ;
0 commit comments