Fix SOCKSv4 and SOCKSv5 proxy. resolves #214 #220

This commit is contained in:
ngosang
2021-12-12 14:29:38 +01:00
parent 642d67b927
commit b1a6ad7688
3 changed files with 59 additions and 15 deletions

View File

@@ -9,6 +9,7 @@ const sessions = require('../services/sessions');
const version: string = 'v' + require('../../package.json').version
const proxyUrl = "http://127.0.0.1:8888"
const proxySocksUrl = "socks5://127.0.0.1:1080"
const googleUrl = "https://www.google.com";
const postUrl = "https://ptsv2.com/t/qv4j3-1634496523";
const cfUrl = "https://pirateiro.com/torrents/?search=harry";
@@ -221,7 +222,7 @@ describe("Test '/v1' path", () => {
expect(solution.userAgent).toBe(null)
});
test("Cmd 'request.get' should return OK with 'proxy' param", async () => {
test("Cmd 'request.get' should return OK with HTTP 'proxy' param", async () => {
/*
To configure TinyProxy in local:
* sudo vim /etc/tinyproxy/tinyproxy.conf
@@ -249,7 +250,7 @@ describe("Test '/v1' path", () => {
});
// todo: credentials are not working
test.skip("Cmd 'request.get' should return OK with 'proxy' param with credentials", async () => {
test.skip("Cmd 'request.get' should return OK with HTTP 'proxy' param with credentials", async () => {
/*
To configure TinyProxy in local:
* sudo vim /etc/tinyproxy/tinyproxy.conf
@@ -279,6 +280,32 @@ describe("Test '/v1' path", () => {
expect(solution.status).toContain(200)
});
test("Cmd 'request.get' should return OK with SOCKSv5 'proxy' param", async () => {
/*
To configure Dante in local:
* https://linuxhint.com/set-up-a-socks5-proxy-on-ubuntu-with-dante/
* sudo vim /etc/sockd.conf
* sudo systemctl restart sockd.service
* curl --socks5 socks5://127.0.0.1:1080 https://www.google.com
*/
const payload = {
"cmd": "request.get",
"url": googleUrl,
"proxy": {
"url": proxySocksUrl
}
}
const response: Response = await request(app).post("/v1").send(payload);
expect(response.statusCode).toBe(200);
const apiResponse: V1ResponseSolution = response.body;
expect(apiResponse.status).toBe("ok");
const solution = apiResponse.solution;
expect(solution.url).toContain(googleUrl)
expect(solution.status).toBe(200);
});
test("Cmd 'request.get' should fail with wrong 'proxy' param", async () => {
const payload = {
"cmd": "request.get",