-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tests for socks, README improvements (#541)
- Loading branch information
1 parent
a586b3e
commit 1ef5588
Showing
3 changed files
with
76 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
const portastic = require('portastic'); | ||
const socksv5 = require('socksv5'); | ||
const { gotScraping } = require('got-scraping'); | ||
const { expect } = require('chai'); | ||
const ProxyChain = require('../src/index'); | ||
|
||
describe('SOCKS protocol', () => { | ||
let socksServer; | ||
let proxyServer; | ||
|
||
afterEach(() => { | ||
if (socksServer) socksServer.close(); | ||
if (proxyServer) proxyServer.close(); | ||
}); | ||
|
||
it('works without auth', (done) => { | ||
portastic.find({ min: 50000, max: 50250 }).then((ports) => { | ||
const [socksPort, proxyPort] = ports; | ||
socksServer = socksv5.createServer((info, accept) => { | ||
accept(); | ||
}); | ||
socksServer.listen(socksPort, 'localhost'); | ||
socksServer.useAuth(socksv5.auth.None()); | ||
|
||
proxyServer = new ProxyChain.Server({ | ||
port: proxyPort, | ||
prepareRequestFunction() { | ||
return { | ||
upstreamProxyUrl: `socks://localhost:${socksPort}`, | ||
}; | ||
}, | ||
}); | ||
proxyServer.listen(); | ||
|
||
gotScraping.get({ url: 'https://example.com', proxyUrl: `http://127.0.0.1:${proxyPort}` }) | ||
.then((response) => { | ||
expect(response.body).to.contain('Example Domain'); | ||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
}).timeout(5 * 1000); | ||
|
||
it('work with auth', (done) => { | ||
portastic.find({ min: 50250, max: 50500 }).then((ports) => { | ||
const [socksPort, proxyPort] = ports; | ||
socksServer = socksv5.createServer((info, accept) => { | ||
accept(); | ||
}); | ||
socksServer.listen(socksPort, 'localhost'); | ||
socksServer.useAuth(socksv5.auth.UserPassword((user, password, cb) => { | ||
cb(user === 'proxy-chain' && password === 'rules!'); | ||
})); | ||
|
||
proxyServer = new ProxyChain.Server({ | ||
port: proxyPort, | ||
prepareRequestFunction() { | ||
return { | ||
upstreamProxyUrl: `socks://proxy-chain:rules!@localhost:${socksPort}`, | ||
}; | ||
}, | ||
}); | ||
proxyServer.listen(); | ||
|
||
gotScraping.get({ url: 'https://example.com', proxyUrl: `http://127.0.0.1:${proxyPort}` }) | ||
.then((response) => { | ||
expect(response.body).to.contain('Example Domain'); | ||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
}).timeout(5 * 1000); | ||
}); |