diff options
author | LinuxWizard42 <computerwizard@linuxmail.org> | 2022-10-12 22:54:37 +0300 |
---|---|---|
committer | LinuxWizard42 <computerwizard@linuxmail.org> | 2022-10-12 22:54:37 +0300 |
commit | 703e03aba33f234712206769f57717ba7d92d23d (patch) | |
tree | 0041f04ccb75bd5379c764e9fe42249fffe75fc3 /node_modules/global-tunnel-ng/test/end-to-end.js | |
parent | ab6e257e6e9d9a483d7e86f220d8b209a2cd7753 (diff) | |
download | FlashRunner-703e03aba33f234712206769f57717ba7d92d23d.tar.gz FlashRunner-703e03aba33f234712206769f57717ba7d92d23d.tar.zst |
Added export_allowed file to make repository visible in cgit
Diffstat (limited to 'node_modules/global-tunnel-ng/test/end-to-end.js')
-rw-r--r-- | node_modules/global-tunnel-ng/test/end-to-end.js | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/node_modules/global-tunnel-ng/test/end-to-end.js b/node_modules/global-tunnel-ng/test/end-to-end.js new file mode 100644 index 0000000..be91f7d --- /dev/null +++ b/node_modules/global-tunnel-ng/test/end-to-end.js @@ -0,0 +1,71 @@ +// Use this tests for troubleshooting, you'll need a proxy runnig at an endpoint +// The idea is to make sure the tests pass if the proxy is turned on, that means the requests are resolving +// And also the tests should fail if the proxy is turned off, that means the requests are actually being proxied + +const globalTunnel = require('../index'); +const assert = require('chai').assert; +const request = require('request'); +const http = require('http'); +const https = require('https'); + +// You need to have a proxy running at the Proxy URL. +const proxyUrl = 'http://localhost:8080'; +const resourceUrl = 'www.google.com'; + +describe.skip('end-to-end tests', () => { + beforeEach(() => { + globalTunnel.initialize(proxyUrl); + }); + + const httpResourceUrl = (secure = false) => `http${secure ? 's' : ''}://${resourceUrl}`; + + const testHttp = (httpMethod = 'request') => (secure = false) => () => + new Promise((resolve, reject) => { + const request = (secure ? https : http)[httpMethod]( + httpResourceUrl(secure), + response => { + assert.isAtLeast(response.statusCode, 200); + assert.isBelow(response.statusCode, 300); + + let buffer = Buffer.alloc(0); + + response.on('data', chunk => { + buffer = Buffer.concat([buffer, chunk]); + }); + response.on('end', () => { + assert.isNotEmpty(buffer.toString()); + resolve(); + }); + } + ); + + request.on('error', reject); + + if (httpMethod === 'request') { + request.end(); + } + }); + + const testHttpRequest = testHttp(); + const testHttpGet = testHttp('get'); + + it('proxies http.get', testHttpGet()); + it('proxies https.get', testHttpGet(true)); + it('proxies http.request', testHttpRequest()); + it('proxies https.request', testHttpRequest(true)); + + it('proxies request', () => + new Promise((resolve, reject) => { + request.get({ url: httpResourceUrl(true) }, err => { + if (err) { + reject(err); + } else { + resolve(); + } + }); + })); + + afterEach(() => { + globalTunnel.end(); + }); +}); |