@actions/http-client 1.0.10 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,228 +0,0 @@
1
- import * as http from 'http'
2
- import * as httpm from '../_out'
3
- import * as pm from '../_out/proxy'
4
- import * as proxy from 'proxy'
5
- import * as tunnelm from 'tunnel'
6
-
7
- let _proxyConnects: string[]
8
- let _proxyServer: http.Server
9
- let _proxyUrl = 'http://127.0.0.1:8080'
10
-
11
- describe('proxy', () => {
12
- beforeAll(async () => {
13
- // Start proxy server
14
- _proxyServer = proxy()
15
- await new Promise(resolve => {
16
- const port = Number(_proxyUrl.split(':')[2])
17
- _proxyServer.listen(port, () => resolve())
18
- })
19
- _proxyServer.on('connect', req => {
20
- _proxyConnects.push(req.url)
21
- })
22
- })
23
-
24
- beforeEach(() => {
25
- _proxyConnects = []
26
- _clearVars()
27
- })
28
-
29
- afterEach(() => {})
30
-
31
- afterAll(async () => {
32
- _clearVars()
33
-
34
- // Stop proxy server
35
- await new Promise(resolve => {
36
- _proxyServer.once('close', () => resolve())
37
- _proxyServer.close()
38
- })
39
- })
40
-
41
- it('getProxyUrl does not return proxyUrl if variables not set', () => {
42
- let proxyUrl = pm.getProxyUrl(new URL('https://github.com'))
43
- expect(proxyUrl).toBeUndefined()
44
- })
45
-
46
- it('getProxyUrl returns proxyUrl if https_proxy set for https url', () => {
47
- process.env['https_proxy'] = 'https://myproxysvr'
48
- let proxyUrl = pm.getProxyUrl(new URL('https://github.com'))
49
- expect(proxyUrl).toBeDefined()
50
- })
51
-
52
- it('getProxyUrl does not return proxyUrl if http_proxy set for https url', () => {
53
- process.env['http_proxy'] = 'https://myproxysvr'
54
- let proxyUrl = pm.getProxyUrl(new URL('https://github.com'))
55
- expect(proxyUrl).toBeUndefined()
56
- })
57
-
58
- it('getProxyUrl returns proxyUrl if http_proxy set for http url', () => {
59
- process.env['http_proxy'] = 'http://myproxysvr'
60
- let proxyUrl = pm.getProxyUrl(new URL('http://github.com'))
61
- expect(proxyUrl).toBeDefined()
62
- })
63
-
64
- it('getProxyUrl does not return proxyUrl if https_proxy set and in no_proxy list', () => {
65
- process.env['https_proxy'] = 'https://myproxysvr'
66
- process.env['no_proxy'] = 'otherserver,myserver,anotherserver:8080'
67
- let proxyUrl = pm.getProxyUrl(new URL('https://myserver'))
68
- expect(proxyUrl).toBeUndefined()
69
- })
70
-
71
- it('getProxyUrl returns proxyUrl if https_proxy set and not in no_proxy list', () => {
72
- process.env['https_proxy'] = 'https://myproxysvr'
73
- process.env['no_proxy'] = 'otherserver,myserver,anotherserver:8080'
74
- let proxyUrl = pm.getProxyUrl(new URL('https://github.com'))
75
- expect(proxyUrl).toBeDefined()
76
- })
77
-
78
- it('getProxyUrl does not return proxyUrl if http_proxy set and in no_proxy list', () => {
79
- process.env['http_proxy'] = 'http://myproxysvr'
80
- process.env['no_proxy'] = 'otherserver,myserver,anotherserver:8080'
81
- let proxyUrl = pm.getProxyUrl(new URL('http://myserver'))
82
- expect(proxyUrl).toBeUndefined()
83
- })
84
-
85
- it('getProxyUrl returns proxyUrl if http_proxy set and not in no_proxy list', () => {
86
- process.env['http_proxy'] = 'http://myproxysvr'
87
- process.env['no_proxy'] = 'otherserver,myserver,anotherserver:8080'
88
- let proxyUrl = pm.getProxyUrl(new URL('http://github.com'))
89
- expect(proxyUrl).toBeDefined()
90
- })
91
-
92
- it('checkBypass returns true if host as no_proxy list', () => {
93
- process.env['no_proxy'] = 'myserver'
94
- let bypass = pm.checkBypass(new URL('https://myserver'))
95
- expect(bypass).toBeTruthy()
96
- })
97
-
98
- it('checkBypass returns true if host in no_proxy list', () => {
99
- process.env['no_proxy'] = 'otherserver,myserver,anotherserver:8080'
100
- let bypass = pm.checkBypass(new URL('https://myserver'))
101
- expect(bypass).toBeTruthy()
102
- })
103
-
104
- it('checkBypass returns true if host in no_proxy list with spaces', () => {
105
- process.env['no_proxy'] = 'otherserver, myserver ,anotherserver:8080'
106
- let bypass = pm.checkBypass(new URL('https://myserver'))
107
- expect(bypass).toBeTruthy()
108
- })
109
-
110
- it('checkBypass returns true if host in no_proxy list with port', () => {
111
- process.env['no_proxy'] = 'otherserver, myserver:8080 ,anotherserver'
112
- let bypass = pm.checkBypass(new URL('https://myserver:8080'))
113
- expect(bypass).toBeTruthy()
114
- })
115
-
116
- it('checkBypass returns true if host with port in no_proxy list without port', () => {
117
- process.env['no_proxy'] = 'otherserver, myserver ,anotherserver'
118
- let bypass = pm.checkBypass(new URL('https://myserver:8080'))
119
- expect(bypass).toBeTruthy()
120
- })
121
-
122
- it('checkBypass returns true if host in no_proxy list with default https port', () => {
123
- process.env['no_proxy'] = 'otherserver, myserver:443 ,anotherserver'
124
- let bypass = pm.checkBypass(new URL('https://myserver'))
125
- expect(bypass).toBeTruthy()
126
- })
127
-
128
- it('checkBypass returns true if host in no_proxy list with default http port', () => {
129
- process.env['no_proxy'] = 'otherserver, myserver:80 ,anotherserver'
130
- let bypass = pm.checkBypass(new URL('http://myserver'))
131
- expect(bypass).toBeTruthy()
132
- })
133
-
134
- it('checkBypass returns false if host not in no_proxy list', () => {
135
- process.env['no_proxy'] = 'otherserver, myserver ,anotherserver:8080'
136
- let bypass = pm.checkBypass(new URL('https://github.com'))
137
- expect(bypass).toBeFalsy()
138
- })
139
-
140
- it('checkBypass returns false if empty no_proxy', () => {
141
- process.env['no_proxy'] = ''
142
- let bypass = pm.checkBypass(new URL('https://github.com'))
143
- expect(bypass).toBeFalsy()
144
- })
145
-
146
- it('HttpClient does basic http get request through proxy', async () => {
147
- process.env['http_proxy'] = _proxyUrl
148
- const httpClient = new httpm.HttpClient()
149
- let res: httpm.HttpClientResponse = await httpClient.get(
150
- 'http://httpbin.org/get'
151
- )
152
- expect(res.message.statusCode).toBe(200)
153
- let body: string = await res.readBody()
154
- let obj: any = JSON.parse(body)
155
- expect(obj.url).toBe('http://httpbin.org/get')
156
- expect(_proxyConnects).toEqual(['httpbin.org:80'])
157
- })
158
-
159
- it('HttoClient does basic http get request when bypass proxy', async () => {
160
- process.env['http_proxy'] = _proxyUrl
161
- process.env['no_proxy'] = 'httpbin.org'
162
- const httpClient = new httpm.HttpClient()
163
- let res: httpm.HttpClientResponse = await httpClient.get(
164
- 'http://httpbin.org/get'
165
- )
166
- expect(res.message.statusCode).toBe(200)
167
- let body: string = await res.readBody()
168
- let obj: any = JSON.parse(body)
169
- expect(obj.url).toBe('http://httpbin.org/get')
170
- expect(_proxyConnects).toHaveLength(0)
171
- })
172
-
173
- it('HttpClient does basic https get request through proxy', async () => {
174
- process.env['https_proxy'] = _proxyUrl
175
- const httpClient = new httpm.HttpClient()
176
- let res: httpm.HttpClientResponse = await httpClient.get(
177
- 'https://httpbin.org/get'
178
- )
179
- expect(res.message.statusCode).toBe(200)
180
- let body: string = await res.readBody()
181
- let obj: any = JSON.parse(body)
182
- expect(obj.url).toBe('https://httpbin.org/get')
183
- expect(_proxyConnects).toEqual(['httpbin.org:443'])
184
- })
185
-
186
- it('HttpClient does basic https get request when bypass proxy', async () => {
187
- process.env['https_proxy'] = _proxyUrl
188
- process.env['no_proxy'] = 'httpbin.org'
189
- const httpClient = new httpm.HttpClient()
190
- let res: httpm.HttpClientResponse = await httpClient.get(
191
- 'https://httpbin.org/get'
192
- )
193
- expect(res.message.statusCode).toBe(200)
194
- let body: string = await res.readBody()
195
- let obj: any = JSON.parse(body)
196
- expect(obj.url).toBe('https://httpbin.org/get')
197
- expect(_proxyConnects).toHaveLength(0)
198
- })
199
-
200
- it('proxyAuth not set in tunnel agent when authentication is not provided', async () => {
201
- process.env['https_proxy'] = 'http://127.0.0.1:8080'
202
- const httpClient = new httpm.HttpClient()
203
- let agent: tunnelm.TunnelingAgent = httpClient.getAgent('https://some-url')
204
- console.log(agent)
205
- expect(agent.proxyOptions.host).toBe('127.0.0.1')
206
- expect(agent.proxyOptions.port).toBe('8080')
207
- expect(agent.proxyOptions.proxyAuth).toBe(undefined)
208
- })
209
-
210
- it('proxyAuth is set in tunnel agent when authentication is provided', async () => {
211
- process.env['https_proxy'] = 'http://user:password@127.0.0.1:8080'
212
- const httpClient = new httpm.HttpClient()
213
- let agent: tunnelm.TunnelingAgent = httpClient.getAgent('https://some-url')
214
- console.log(agent)
215
- expect(agent.proxyOptions.host).toBe('127.0.0.1')
216
- expect(agent.proxyOptions.port).toBe('8080')
217
- expect(agent.proxyOptions.proxyAuth).toBe('user:password')
218
- })
219
- })
220
-
221
- function _clearVars() {
222
- delete process.env.http_proxy
223
- delete process.env.HTTP_PROXY
224
- delete process.env.https_proxy
225
- delete process.env.HTTPS_PROXY
226
- delete process.env.no_proxy
227
- delete process.env.NO_PROXY
228
- }
package/auth.ts DELETED
@@ -1,86 +0,0 @@
1
- import ifm = require('./interfaces')
2
-
3
- export class BasicCredentialHandler implements ifm.IRequestHandler {
4
- username: string
5
- password: string
6
-
7
- constructor(username: string, password: string) {
8
- this.username = username
9
- this.password = password
10
- }
11
-
12
- prepareRequest(options: any): void {
13
- options.headers['Authorization'] =
14
- 'Basic ' +
15
- Buffer.from(this.username + ':' + this.password).toString('base64')
16
- }
17
-
18
- // This handler cannot handle 401
19
- canHandleAuthentication(response: ifm.IHttpClientResponse): boolean {
20
- return false
21
- }
22
-
23
- handleAuthentication(
24
- httpClient: ifm.IHttpClient,
25
- requestInfo: ifm.IRequestInfo,
26
- objs
27
- ): Promise<ifm.IHttpClientResponse> {
28
- return null
29
- }
30
- }
31
-
32
- export class BearerCredentialHandler implements ifm.IRequestHandler {
33
- token: string
34
-
35
- constructor(token: string) {
36
- this.token = token
37
- }
38
-
39
- // currently implements pre-authorization
40
- // TODO: support preAuth = false where it hooks on 401
41
- prepareRequest(options: any): void {
42
- options.headers['Authorization'] = 'Bearer ' + this.token
43
- }
44
-
45
- // This handler cannot handle 401
46
- canHandleAuthentication(response: ifm.IHttpClientResponse): boolean {
47
- return false
48
- }
49
-
50
- handleAuthentication(
51
- httpClient: ifm.IHttpClient,
52
- requestInfo: ifm.IRequestInfo,
53
- objs
54
- ): Promise<ifm.IHttpClientResponse> {
55
- return null
56
- }
57
- }
58
-
59
- export class PersonalAccessTokenCredentialHandler
60
- implements ifm.IRequestHandler {
61
- token: string
62
-
63
- constructor(token: string) {
64
- this.token = token
65
- }
66
-
67
- // currently implements pre-authorization
68
- // TODO: support preAuth = false where it hooks on 401
69
- prepareRequest(options: any): void {
70
- options.headers['Authorization'] =
71
- 'Basic ' + Buffer.from('PAT:' + this.token).toString('base64')
72
- }
73
-
74
- // This handler cannot handle 401
75
- canHandleAuthentication(response: ifm.IHttpClientResponse): boolean {
76
- return false
77
- }
78
-
79
- handleAuthentication(
80
- httpClient: ifm.IHttpClient,
81
- requestInfo: ifm.IRequestInfo,
82
- objs
83
- ): Promise<ifm.IHttpClientResponse> {
84
- return null
85
- }
86
- }