@@ -2,7 +2,7 @@ import {Buffer} from 'buffer';
22import test from 'ava' ;
33import { Handler } from 'express' ;
44import nock from 'nock' ;
5- import got , { MaxRedirectsError } from '../source/index.js' ;
5+ import got , { MaxRedirectsError , RequestError } from '../source/index.js' ;
66import withServer , { withHttpsServer } from './helpers/with-server.js' ;
77
88const reachedHandler : Handler = ( _request , response ) => {
@@ -28,6 +28,35 @@ const relativeHandler: Handler = (_request, response) => {
2828 response . end ( ) ;
2929} ;
3030
31+ const unixProtocol : Handler = ( _request , response ) => {
32+ response . writeHead ( 302 , {
33+ location : 'unix:/var/run/docker.sock:/containers/json' ,
34+ } ) ;
35+ response . end ( ) ;
36+ } ;
37+
38+ const unixHostname : Handler = ( _request , response ) => {
39+ response . writeHead ( 302 , {
40+ location : 'http://unix:/var/run/docker.sock:/containers/json' ,
41+ } ) ;
42+ response . end ( ) ;
43+ } ;
44+
45+ test ( 'cannot redirect to unix protocol' , withServer , async ( t , server , got ) => {
46+ server . get ( '/protocol' , unixProtocol ) ;
47+ server . get ( '/hostname' , unixHostname ) ;
48+
49+ await t . throwsAsync ( got ( 'protocol' ) , {
50+ message : 'Cannot redirect to UNIX socket' ,
51+ instanceOf : RequestError ,
52+ } ) ;
53+
54+ await t . throwsAsync ( got ( 'hostname' ) , {
55+ message : 'Cannot redirect to UNIX socket' ,
56+ instanceOf : RequestError ,
57+ } ) ;
58+ } ) ;
59+
3160test ( 'follows redirect' , withServer , async ( t , server , got ) => {
3261 server . get ( '/' , reachedHandler ) ;
3362 server . get ( '/finite' , finiteHandler ) ;
0 commit comments