2019-10-27 05:29:49 +01:00
|
|
|
import path from 'path'
|
|
|
|
import ProxyConfiguration from '~/src/main/proxy'
|
|
|
|
import { ManualProxy, ProxyProtocol } from '~/src/types/proxy'
|
|
|
|
|
|
|
|
const preferencesDBPath = path.resolve(__dirname, '../../preferences.json')
|
|
|
|
const proxyConfiguration = new ProxyConfiguration(preferencesDBPath)
|
|
|
|
|
2019-12-04 15:09:11 +01:00
|
|
|
jest.mock('electron', () => ({
|
2020-04-11 11:00:32 +02:00
|
|
|
app: {
|
|
|
|
// getVersion is used by electron-log
|
|
|
|
getVersion: jest.fn(),
|
|
|
|
// getName is used by electron-json-storage
|
|
|
|
getName: jest.fn()
|
|
|
|
}
|
2019-12-04 15:09:11 +01:00
|
|
|
}))
|
|
|
|
|
2019-10-27 05:29:49 +01:00
|
|
|
describe('Parser', () => {
|
|
|
|
it('do not use proxy', () => {
|
|
|
|
proxyConfiguration.setSystemProxy('DIRECT')
|
|
|
|
const proxy = proxyConfiguration.parseSystemProxy()
|
|
|
|
expect(proxy).toEqual(false)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('HTTP and HTTPS proxy', () => {
|
|
|
|
proxyConfiguration.setSystemProxy('PROXY hoge.example.com:8080')
|
|
|
|
const proxy = proxyConfiguration.parseSystemProxy()
|
|
|
|
expect(proxy).not.toBe(false)
|
|
|
|
const manualProxy = proxy as ManualProxy
|
|
|
|
expect(manualProxy.protocol).toEqual(ProxyProtocol.http)
|
|
|
|
expect(manualProxy.host).toEqual('hoge.example.com')
|
|
|
|
expect(manualProxy.port).toEqual('8080')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('SOCKS4 proxy', () => {
|
|
|
|
proxyConfiguration.setSystemProxy('SOCKS4 hoge.example.com:8080')
|
|
|
|
const proxy = proxyConfiguration.parseSystemProxy()
|
|
|
|
expect(proxy).not.toBe(false)
|
|
|
|
const manualProxy = proxy as ManualProxy
|
|
|
|
expect(manualProxy.protocol).toEqual(ProxyProtocol.socks4)
|
|
|
|
})
|
|
|
|
it('SOCKS4A proxy', () => {
|
|
|
|
proxyConfiguration.setSystemProxy('SOCKS4A hoge.example.com:8080')
|
|
|
|
const proxy = proxyConfiguration.parseSystemProxy()
|
|
|
|
expect(proxy).not.toBe(false)
|
|
|
|
const manualProxy = proxy as ManualProxy
|
|
|
|
expect(manualProxy.protocol).toEqual(ProxyProtocol.socks4a)
|
|
|
|
})
|
|
|
|
it('SOCKS5 proxy', () => {
|
|
|
|
proxyConfiguration.setSystemProxy('SOCKS5 hoge.example.com:8080')
|
|
|
|
const proxy = proxyConfiguration.parseSystemProxy()
|
|
|
|
expect(proxy).not.toBe(false)
|
|
|
|
const manualProxy = proxy as ManualProxy
|
|
|
|
expect(manualProxy.protocol).toEqual(ProxyProtocol.socks5)
|
|
|
|
})
|
|
|
|
it('SOCKS5H proxy', () => {
|
|
|
|
proxyConfiguration.setSystemProxy('SOCKS5H hoge.example.com:8080')
|
|
|
|
const proxy = proxyConfiguration.parseSystemProxy()
|
|
|
|
expect(proxy).not.toBe(false)
|
|
|
|
const manualProxy = proxy as ManualProxy
|
|
|
|
expect(manualProxy.protocol).toEqual(ProxyProtocol.socks5h)
|
|
|
|
})
|
|
|
|
it('SOCKS proxy', () => {
|
|
|
|
proxyConfiguration.setSystemProxy('SOCKS hoge.example.com:8080')
|
|
|
|
const proxy = proxyConfiguration.parseSystemProxy()
|
|
|
|
expect(proxy).not.toBe(false)
|
|
|
|
const manualProxy = proxy as ManualProxy
|
|
|
|
expect(manualProxy.protocol).toEqual(ProxyProtocol.socks5)
|
|
|
|
})
|
|
|
|
})
|