-
Notifications
You must be signed in to change notification settings - Fork 147
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
9f210ee
commit eddf358
Showing
2 changed files
with
21 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ const http = require('http'); | |
const proxy = require('proxy'); | ||
|
||
const { createTunnel, closeTunnel } = require('../src/index'); | ||
const { expectThrowsAsync } = require('./utils/throws_async'); | ||
|
||
const destroySocket = (socket) => new Promise((resolve, reject) => { | ||
if (!socket || socket.destroyed) return resolve(); | ||
|
@@ -42,16 +43,16 @@ const closeServer = (server, connections) => new Promise((resolve, reject) => { | |
|
||
describe('tcp_tunnel.createTunnel', () => { | ||
it('throws error if proxyUrl is not in correct format', () => { | ||
assert.throws(() => { createTunnel('socks://user:[email protected]:123', 'localhost:9000'); }, /must have the "http" protocol/); | ||
assert.throws(() => { createTunnel('socks5://user:[email protected]', 'localhost:9000'); }, /must have the "http" protocol/); | ||
expectThrowsAsync(async () => { await createTunnel('socks://user:[email protected]:123', 'localhost:9000'); }, /must have the "http" protocol/); | ||
expectThrowsAsync(async () => { await createTunnel('socks5://user:[email protected]', 'localhost:9000'); }, /must have the "http" protocol/); | ||
}); | ||
it('throws error if target is not in correct format', () => { | ||
assert.throws(() => { createTunnel('http://user:[email protected]:12'); }, 'Missing target hostname'); | ||
assert.throws(() => { createTunnel('http://user:[email protected]:12', null); }, 'Missing target hostname'); | ||
assert.throws(() => { createTunnel('http://user:[email protected]:12', ''); }, 'Missing target hostname'); | ||
assert.throws(() => { createTunnel('http://user:[email protected]:12', 'whatever'); }, 'Missing target port'); | ||
assert.throws(() => { createTunnel('http://user:[email protected]:12', 'whatever:'); }, 'Missing target port'); | ||
assert.throws(() => { createTunnel('http://user:[email protected]:12', ':whatever'); }, /Invalid URL/); | ||
expectThrowsAsync(async () => { await createTunnel('http://user:[email protected]:12'); }, 'Missing target hostname'); | ||
expectThrowsAsync(async () => { await createTunnel('http://user:[email protected]:12', null); }, 'Missing target hostname'); | ||
expectThrowsAsync(async () => { await createTunnel('http://user:[email protected]:12', ''); }, 'Missing target hostname'); | ||
expectThrowsAsync(async () => { await createTunnel('http://user:[email protected]:12', 'whatever'); }, 'Missing target port'); | ||
expectThrowsAsync(async () => { await createTunnel('http://user:[email protected]:12', 'whatever:'); }, 'Missing target port'); | ||
expectThrowsAsync(async () => { await createTunnel('http://user:[email protected]:12', ':whatever'); }, /Invalid URL/); | ||
}); | ||
it('correctly tunnels to tcp service and then is able to close the connection', () => { | ||
const proxyServerConnections = []; | ||
|
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