Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de70a45
commit 81438eb
Showing
6 changed files
with
80 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { req, json } from 'agent-base'; | ||
import { HttpsProxyAgent } from '../src'; | ||
|
||
interface NordVPNServer { | ||
name: string; | ||
domain: string; | ||
flag: string; | ||
features: { [key: string]: boolean }; | ||
} | ||
|
||
jest.setTimeout(30000); | ||
|
||
async function findNordVpnServer(): Promise<NordVPNServer> { | ||
const res = await req('https://nordvpn.com/api/server'); | ||
const body = await json(res); | ||
const server = (body as NordVPNServer[]).find((s) => s.features.proxy_ssl); | ||
if (!server) { | ||
throw new Error('Could not find `https` proxy server from NordVPN'); | ||
} | ||
return server; | ||
} | ||
|
||
async function getRealIP(): Promise<string> { | ||
const res = await req('https://dump.n8.io'); | ||
const body = await json(res); | ||
return body.request.headers['x-real-ip']; | ||
} | ||
|
||
describe('HttpsProxyAgent', () => { | ||
it('should work over NordVPN proxy', async () => { | ||
const { NORDVPN_USERNAME, NORDVPN_PASSWORD } = process.env; | ||
if (!NORDVPN_USERNAME) { | ||
throw new Error('`NORDVPN_USERNAME` env var is not defined'); | ||
} | ||
if (!NORDVPN_PASSWORD) { | ||
throw new Error('`NORDVPN_PASSWORD` env var is not defined'); | ||
} | ||
|
||
const [realIp, server] = await Promise.all([ | ||
getRealIP(), | ||
findNordVpnServer(), | ||
]); | ||
console.log( | ||
`Using NordVPN HTTPS proxy server: ${server.name} (${server.domain})` | ||
); | ||
|
||
const username = encodeURIComponent(NORDVPN_USERNAME); | ||
const password = encodeURIComponent(NORDVPN_PASSWORD); | ||
|
||
// NordVPN runs their HTTPS proxy servers on port 89 | ||
// https://www.reddit.com/r/nordvpn/comments/hvz48h/nordvpn_https_proxy/ | ||
const agent = new HttpsProxyAgent( | ||
`https://${username}:${password}@${server.domain}:89` | ||
); | ||
|
||
const res = await req('https://dump.n8.io', { agent }); | ||
const body = await json(res); | ||
expect(body.request.headers['x-real-ip']).not.toEqual(realIp); | ||
expect(body.request.headers['x-vercel-ip-country']).toEqual( | ||
server.flag | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"include": ["test.ts"] | ||
"include": ["*.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters