@@ -2,7 +2,6 @@ import * as http from 'http'
2
2
import * as httpm from '../_out'
3
3
import * as pm from '../_out/proxy'
4
4
import * as proxy from 'proxy'
5
- import * as url from 'url'
6
5
7
6
let _proxyConnects : string [ ]
8
7
let _proxyServer : http . Server
@@ -39,107 +38,107 @@ describe('proxy', () => {
39
38
} )
40
39
41
40
it ( 'getProxyUrl does not return proxyUrl if variables not set' , ( ) => {
42
- let proxyUrl = pm . getProxyUrl ( url . parse ( 'https://github.com' ) )
41
+ let proxyUrl = pm . getProxyUrl ( new URL ( 'https://github.com' ) )
43
42
expect ( proxyUrl ) . toBeUndefined ( )
44
43
} )
45
44
46
45
it ( 'getProxyUrl returns proxyUrl if https_proxy set for https url' , ( ) => {
47
46
process . env [ 'https_proxy' ] = 'https://myproxysvr'
48
- let proxyUrl = pm . getProxyUrl ( url . parse ( 'https://github.com' ) )
47
+ let proxyUrl = pm . getProxyUrl ( new URL ( 'https://github.com' ) )
49
48
expect ( proxyUrl ) . toBeDefined ( )
50
49
} )
51
50
52
51
it ( 'getProxyUrl does not return proxyUrl if http_proxy set for https url' , ( ) => {
53
52
process . env [ 'http_proxy' ] = 'https://myproxysvr'
54
- let proxyUrl = pm . getProxyUrl ( url . parse ( 'https://github.com' ) )
53
+ let proxyUrl = pm . getProxyUrl ( new URL ( 'https://github.com' ) )
55
54
expect ( proxyUrl ) . toBeUndefined ( )
56
55
} )
57
56
58
57
it ( 'getProxyUrl returns proxyUrl if http_proxy set for http url' , ( ) => {
59
58
process . env [ 'http_proxy' ] = 'http://myproxysvr'
60
- let proxyUrl = pm . getProxyUrl ( url . parse ( 'http://github.com' ) )
59
+ let proxyUrl = pm . getProxyUrl ( new URL ( 'http://github.com' ) )
61
60
expect ( proxyUrl ) . toBeDefined ( )
62
61
} )
63
62
64
63
it ( 'getProxyUrl does not return proxyUrl if https_proxy set and in no_proxy list' , ( ) => {
65
64
process . env [ 'https_proxy' ] = 'https://myproxysvr'
66
65
process . env [ 'no_proxy' ] = 'otherserver,myserver,anotherserver:8080'
67
- let proxyUrl = pm . getProxyUrl ( url . parse ( 'https://myserver' ) )
66
+ let proxyUrl = pm . getProxyUrl ( new URL ( 'https://myserver' ) )
68
67
expect ( proxyUrl ) . toBeUndefined ( )
69
68
} )
70
69
71
70
it ( 'getProxyUrl returns proxyUrl if https_proxy set and not in no_proxy list' , ( ) => {
72
71
process . env [ 'https_proxy' ] = 'https://myproxysvr'
73
72
process . env [ 'no_proxy' ] = 'otherserver,myserver,anotherserver:8080'
74
- let proxyUrl = pm . getProxyUrl ( url . parse ( 'https://github.com' ) )
73
+ let proxyUrl = pm . getProxyUrl ( new URL ( 'https://github.com' ) )
75
74
expect ( proxyUrl ) . toBeDefined ( )
76
75
} )
77
76
78
77
it ( 'getProxyUrl does not return proxyUrl if http_proxy set and in no_proxy list' , ( ) => {
79
78
process . env [ 'http_proxy' ] = 'http://myproxysvr'
80
79
process . env [ 'no_proxy' ] = 'otherserver,myserver,anotherserver:8080'
81
- let proxyUrl = pm . getProxyUrl ( url . parse ( 'http://myserver' ) )
80
+ let proxyUrl = pm . getProxyUrl ( new URL ( 'http://myserver' ) )
82
81
expect ( proxyUrl ) . toBeUndefined ( )
83
82
} )
84
83
85
84
it ( 'getProxyUrl returns proxyUrl if http_proxy set and not in no_proxy list' , ( ) => {
86
85
process . env [ 'http_proxy' ] = 'http://myproxysvr'
87
86
process . env [ 'no_proxy' ] = 'otherserver,myserver,anotherserver:8080'
88
- let proxyUrl = pm . getProxyUrl ( url . parse ( 'http://github.com' ) )
87
+ let proxyUrl = pm . getProxyUrl ( new URL ( 'http://github.com' ) )
89
88
expect ( proxyUrl ) . toBeDefined ( )
90
89
} )
91
90
92
91
it ( 'checkBypass returns true if host as no_proxy list' , ( ) => {
93
92
process . env [ 'no_proxy' ] = 'myserver'
94
- let bypass = pm . checkBypass ( url . parse ( 'https://myserver' ) )
93
+ let bypass = pm . checkBypass ( new URL ( 'https://myserver' ) )
95
94
expect ( bypass ) . toBeTruthy ( )
96
95
} )
97
96
98
97
it ( 'checkBypass returns true if host in no_proxy list' , ( ) => {
99
98
process . env [ 'no_proxy' ] = 'otherserver,myserver,anotherserver:8080'
100
- let bypass = pm . checkBypass ( url . parse ( 'https://myserver' ) )
99
+ let bypass = pm . checkBypass ( new URL ( 'https://myserver' ) )
101
100
expect ( bypass ) . toBeTruthy ( )
102
101
} )
103
102
104
103
it ( 'checkBypass returns true if host in no_proxy list with spaces' , ( ) => {
105
104
process . env [ 'no_proxy' ] = 'otherserver, myserver ,anotherserver:8080'
106
- let bypass = pm . checkBypass ( url . parse ( 'https://myserver' ) )
105
+ let bypass = pm . checkBypass ( new URL ( 'https://myserver' ) )
107
106
expect ( bypass ) . toBeTruthy ( )
108
107
} )
109
108
110
109
it ( 'checkBypass returns true if host in no_proxy list with port' , ( ) => {
111
110
process . env [ 'no_proxy' ] = 'otherserver, myserver:8080 ,anotherserver'
112
- let bypass = pm . checkBypass ( url . parse ( 'https://myserver:8080' ) )
111
+ let bypass = pm . checkBypass ( new URL ( 'https://myserver:8080' ) )
113
112
expect ( bypass ) . toBeTruthy ( )
114
113
} )
115
114
116
115
it ( 'checkBypass returns true if host with port in no_proxy list without port' , ( ) => {
117
116
process . env [ 'no_proxy' ] = 'otherserver, myserver ,anotherserver'
118
- let bypass = pm . checkBypass ( url . parse ( 'https://myserver:8080' ) )
117
+ let bypass = pm . checkBypass ( new URL ( 'https://myserver:8080' ) )
119
118
expect ( bypass ) . toBeTruthy ( )
120
119
} )
121
120
122
121
it ( 'checkBypass returns true if host in no_proxy list with default https port' , ( ) => {
123
122
process . env [ 'no_proxy' ] = 'otherserver, myserver:443 ,anotherserver'
124
- let bypass = pm . checkBypass ( url . parse ( 'https://myserver' ) )
123
+ let bypass = pm . checkBypass ( new URL ( 'https://myserver' ) )
125
124
expect ( bypass ) . toBeTruthy ( )
126
125
} )
127
126
128
127
it ( 'checkBypass returns true if host in no_proxy list with default http port' , ( ) => {
129
128
process . env [ 'no_proxy' ] = 'otherserver, myserver:80 ,anotherserver'
130
- let bypass = pm . checkBypass ( url . parse ( 'http://myserver' ) )
129
+ let bypass = pm . checkBypass ( new URL ( 'http://myserver' ) )
131
130
expect ( bypass ) . toBeTruthy ( )
132
131
} )
133
132
134
133
it ( 'checkBypass returns false if host not in no_proxy list' , ( ) => {
135
134
process . env [ 'no_proxy' ] = 'otherserver, myserver ,anotherserver:8080'
136
- let bypass = pm . checkBypass ( url . parse ( 'https://github.com' ) )
135
+ let bypass = pm . checkBypass ( new URL ( 'https://github.com' ) )
137
136
expect ( bypass ) . toBeFalsy ( )
138
137
} )
139
138
140
139
it ( 'checkBypass returns false if empty no_proxy' , ( ) => {
141
140
process . env [ 'no_proxy' ] = ''
142
- let bypass = pm . checkBypass ( url . parse ( 'https://github.com' ) )
141
+ let bypass = pm . checkBypass ( new URL ( 'https://github.com' ) )
143
142
expect ( bypass ) . toBeFalsy ( )
144
143
} )
145
144
0 commit comments