-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
58 lines (46 loc) · 1.39 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const debug = require('debug')('get-windows-proxy')
const os = require('os')
const registry = require('@cypress/registry-js')
const findByName = (values, name) => {
return values.find((value) => {
return value && value.name === name
})
}
module.exports = function getWindowsProxy () {
if (!registry || os.platform() !== 'win32') {
return
}
debug('scanning Windows registry for proxy setting')
const values = registry.enumerateValues(
registry.HKEY.HKEY_CURRENT_USER,
'Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings'
)
const proxyEnabled = findByName(values, 'ProxyEnable')
const proxyServer = findByName(values, 'ProxyServer')
if (
!proxyEnabled ||
!proxyEnabled.data ||
!proxyServer ||
!proxyServer.data
) {
debug('windows proxy disabled or no proxy defined')
return
}
const proxyOverride = findByName(values, 'ProxyOverride')
let noProxy
if (proxyOverride && proxyOverride.data) {
noProxy = proxyOverride.data
.split(';')
.join(',')
// Windows registry inserts <local> if a user indicates to not proxy localhost stuff
// on Linux/Mac, this is the equivalent
.replace('<local>', 'localhost,127.0.0.0/8,::1')
}
const httpProxy = `http://${proxyServer.data}`
debug(
'found HTTP proxy %s and "no proxy" %s from registry key',
httpProxy,
noProxy
)
return { httpProxy, noProxy }
}