@testim/testim-cli 3.289.0 → 3.290.1-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.js +22390 -122
- package/cli.js.map +1 -0
- package/npm-shrinkwrap.json +1169 -12846
- package/package.json +16 -10
- package/OverrideTestDataBuilder.js +0 -117
- package/agent/routers/cliJsCode/index.js +0 -13
- package/agent/routers/cliJsCode/router.js +0 -63
- package/agent/routers/cliJsCode/service.js +0 -705
- package/agent/routers/codim/router.js +0 -69
- package/agent/routers/codim/router.test.js +0 -60
- package/agent/routers/codim/service.js +0 -193
- package/agent/routers/general/index.js +0 -36
- package/agent/routers/hybrid/registerRoutes.js +0 -81
- package/agent/routers/index.js +0 -56
- package/agent/routers/playground/router.js +0 -77
- package/agent/routers/playground/service.js +0 -96
- package/agent/routers/standalone-browser/registerRoutes.js +0 -47
- package/agent/server.js +0 -150
- package/cdpTestRunner.js +0 -86
- package/chromiumInstaller.js +0 -91
- package/cli/isCiRun.js +0 -10
- package/cli/onExit.js +0 -65
- package/cli/writeStackTrace.js +0 -27
- package/cliAgentMode.js +0 -384
- package/codim/codim-cli.js +0 -91
- package/codim/codim-npm-package/index.ts +0 -427
- package/codim/codim-npm-package/package-lock.json +0 -14
- package/codim/codim-npm-package/package.json +0 -14
- package/codim/hybrid-utils.js +0 -28
- package/codim/measure-perf.js +0 -41
- package/codim/template.js/.idea/workspace.xml +0 -57
- package/codim/template.js/.vscode/launch.json +0 -53
- package/codim/template.ts/.idea/workspace.xml +0 -57
- package/codim/template.ts/.vscode/launch.json +0 -55
- package/commons/AbortError.js +0 -12
- package/commons/SeleniumPerfStats.js +0 -58
- package/commons/chrome-launcher.js +0 -15
- package/commons/chromedriverWrapper.js +0 -70
- package/commons/config.js +0 -39
- package/commons/constants.js +0 -67
- package/commons/detectDebugger.js +0 -19
- package/commons/featureAvailabilityService.js +0 -26
- package/commons/featureFlags.js +0 -132
- package/commons/getSessionPlayerRequire.js +0 -28
- package/commons/httpRequest.js +0 -261
- package/commons/httpRequestCounters.js +0 -98
- package/commons/httpRequestCounters.test.js +0 -38
- package/commons/initializeUserWithAuth.js +0 -55
- package/commons/lazyRequire.js +0 -105
- package/commons/logUtils.js +0 -15
- package/commons/logUtils.test.js +0 -21
- package/commons/logger.js +0 -178
- package/commons/mockNetworkRuleFileSchema.json +0 -140
- package/commons/npmWrapper.js +0 -174
- package/commons/npmWrapper.test.js +0 -374
- package/commons/performance-logger.js +0 -71
- package/commons/preloadTests.js +0 -29
- package/commons/prepareRunner.js +0 -85
- package/commons/prepareRunner.test.js +0 -144
- package/commons/prepareRunnerAndTestimStartUtils.js +0 -198
- package/commons/prepareRunnerAndTestimStartUtils.test.js +0 -73
- package/commons/requireWithFallback.js +0 -25
- package/commons/runnerFileCache.js +0 -204
- package/commons/socket/baseSocketServiceSocketIO.js +0 -197
- package/commons/socket/realDataService.js +0 -59
- package/commons/socket/realDataServiceSocketIO.js +0 -33
- package/commons/socket/remoteStepService.js +0 -55
- package/commons/socket/remoteStepServiceSocketIO.js +0 -61
- package/commons/socket/socketService.js +0 -175
- package/commons/socket/testResultService.js +0 -62
- package/commons/socket/testResultServiceSocketIO.js +0 -64
- package/commons/testimAnalytics.js +0 -40
- package/commons/testimCloudflare.js +0 -83
- package/commons/testimCloudflare.test.js +0 -185
- package/commons/testimCustomToken.js +0 -124
- package/commons/testimDesiredCapabilitiesBuilder.js +0 -647
- package/commons/testimNgrok.js +0 -90
- package/commons/testimNgrok.test.js +0 -140
- package/commons/testimServicesApi.js +0 -631
- package/commons/testimTunnel.js +0 -73
- package/commons/testimTunnel.test.js +0 -172
- package/commons/xhr2.js +0 -897
- package/coverage/SummaryToObjectReport.js +0 -19
- package/coverage/jsCoverage.js +0 -252
- package/credentialsManager.js +0 -142
- package/errors.js +0 -161
- package/executionQueue.js +0 -37
- package/fixLocalBuild.js +0 -24
- package/inputFileUtils.js +0 -103
- package/lib/coralogix-winston.transport.js +0 -99
- package/player/SeleniumProtocolError.js +0 -100
- package/player/WebDriverHttpRequest.js +0 -177
- package/player/WebdriverioWebDriverApi.js +0 -671
- package/player/appiumTestPlayer.js +0 -90
- package/player/chromeLauncherTestPlayer.js +0 -67
- package/player/constants.js +0 -332
- package/player/extensionTestPlayer.js +0 -32
- package/player/findElementStrategy.js +0 -154
- package/player/scripts/isElementDisplayed.js +0 -252
- package/player/seleniumTestPlayer.js +0 -140
- package/player/services/frameLocator.js +0 -170
- package/player/services/mobileFrameLocatorMock.js +0 -32
- package/player/services/playbackTimeoutCalculator.js +0 -175
- package/player/services/portSelector.js +0 -19
- package/player/services/tabService.js +0 -551
- package/player/services/tabServiceMock.js +0 -167
- package/player/services/windowCreationListener.js +0 -8
- package/player/stepActions/RefreshStepAction.js +0 -16
- package/player/stepActions/apiStepAction.js +0 -89
- package/player/stepActions/baseCliJsStepAction.js +0 -51
- package/player/stepActions/baseJsStepAction.js +0 -277
- package/player/stepActions/cliConditionStepAction.js +0 -11
- package/player/stepActions/cliJsStepAction.js +0 -11
- package/player/stepActions/dropFileStepAction.js +0 -34
- package/player/stepActions/evaluateExpressionStepAction.js +0 -52
- package/player/stepActions/extensionOnlyStepAction.js +0 -12
- package/player/stepActions/extractTextStepAction.js +0 -19
- package/player/stepActions/hoverStepAction.js +0 -55
- package/player/stepActions/inputFileStepAction.js +0 -199
- package/player/stepActions/jsCodeStepAction.js +0 -11
- package/player/stepActions/jsConditionStepAction.js +0 -11
- package/player/stepActions/locateStepAction.js +0 -159
- package/player/stepActions/mouseStepAction.js +0 -370
- package/player/stepActions/navigationStepAction.js +0 -29
- package/player/stepActions/nodePackageStepAction.js +0 -47
- package/player/stepActions/pixelValidationStepAction.js +0 -39
- package/player/stepActions/scripts/dispatchEvents.js +0 -282
- package/player/stepActions/scripts/doClick.js +0 -221
- package/player/stepActions/scripts/doDragPath.js +0 -225
- package/player/stepActions/scripts/doubleClick.js +0 -119
- package/player/stepActions/scripts/dropEvent.js +0 -63
- package/player/stepActions/scripts/focusElement.js +0 -46
- package/player/stepActions/scripts/html5dragAction.js +0 -56
- package/player/stepActions/scripts/html5dragActionV2.js +0 -312
- package/player/stepActions/scripts/runCode.js +0 -147
- package/player/stepActions/scripts/scroll.js +0 -90
- package/player/stepActions/scripts/selectOption.js +0 -51
- package/player/stepActions/scripts/setText.js +0 -415
- package/player/stepActions/scripts/wheel.js +0 -61
- package/player/stepActions/scrollStepAction.js +0 -96
- package/player/stepActions/selectOptionStepAction.js +0 -49
- package/player/stepActions/sfdcRecordedStepAction.js +0 -24
- package/player/stepActions/sfdcStepAction.js +0 -28
- package/player/stepActions/sleepStepAction.js +0 -12
- package/player/stepActions/specialKeyStepAction.js +0 -52
- package/player/stepActions/stepAction.js +0 -73
- package/player/stepActions/stepActionRegistrar.js +0 -111
- package/player/stepActions/submitStepAction.js +0 -12
- package/player/stepActions/tdkHybridStepAction.js +0 -18
- package/player/stepActions/textStepAction.js +0 -110
- package/player/stepActions/textValidationStepAction.js +0 -64
- package/player/stepActions/wheelStepAction.js +0 -41
- package/player/utils/cookieUtils.js +0 -39
- package/player/utils/eyeSdkService.js +0 -250
- package/player/utils/imageCaptureUtils.js +0 -267
- package/player/utils/screenshotUtils.js +0 -68
- package/player/utils/stepActionUtils.js +0 -90
- package/player/utils/windowUtils.js +0 -195
- package/player/webDriverUtils.js +0 -40
- package/player/webDriverUtils.test.js +0 -116
- package/player/webdriver.js +0 -976
- package/polyfills/Array.prototype.at.js +0 -13
- package/polyfills/index.js +0 -13
- package/processHandler.js +0 -79
- package/processHandler.test.js +0 -55
- package/reports/chromeReporter.js +0 -17
- package/reports/consoleReporter.js +0 -190
- package/reports/debugReporter.js +0 -82
- package/reports/jsonReporter.js +0 -55
- package/reports/junitReporter.js +0 -183
- package/reports/reporter.js +0 -166
- package/reports/reporterUtils.js +0 -54
- package/reports/teamCityReporter.js +0 -73
- package/runOptions.d.ts +0 -305
- package/runOptions.js +0 -1288
- package/runOptionsAgentFlow.js +0 -87
- package/runOptionsUtils.js +0 -60
- package/runner.js +0 -355
- package/runners/ParallelWorkerManager.js +0 -284
- package/runners/TestPlanRunner.js +0 -419
- package/runners/buildCodeTests.js +0 -159
- package/runners/runnerUtils.js +0 -81
- package/services/analyticsService.js +0 -96
- package/services/branchService.js +0 -29
- package/services/gridService.js +0 -357
- package/services/gridService.test.js +0 -357
- package/services/labFeaturesService.js +0 -64
- package/services/lambdatestService.js +0 -227
- package/services/lambdatestService.test.js +0 -353
- package/services/localRCASaver.js +0 -124
- package/stepPlayers/cliJsStepPlayback.js +0 -40
- package/stepPlayers/hybridStepPlayback.js +0 -140
- package/stepPlayers/nodePackageStepPlayback.js +0 -28
- package/stepPlayers/playwrightHybridStepPlayback.js +0 -61
- package/stepPlayers/puppeteerHybridStepPlayback.js +0 -76
- package/stepPlayers/remoteStepPlayback.js +0 -80
- package/stepPlayers/seleniumHybridStepPlayback.js +0 -84
- package/stepPlayers/tdkHybridStepPlayback.js +0 -112
- package/testRunHandler.js +0 -603
- package/testRunStatus.js +0 -567
- package/testimNpmDriver.js +0 -52
- package/utils/argsUtils.js +0 -91
- package/utils/argsUtils.test.js +0 -32
- package/utils/fsUtils.js +0 -174
- package/utils/index.js +0 -197
- package/utils/promiseUtils.js +0 -85
- package/utils/stringUtils.js +0 -98
- package/utils/stringUtils.test.js +0 -22
- package/utils/timeUtils.js +0 -25
- package/utils/utils.test.js +0 -27
- package/workers/BaseWorker.js +0 -498
- package/workers/BaseWorker.test.js +0 -186
- package/workers/WorkerAppium.js +0 -180
- package/workers/WorkerExtension.js +0 -192
- package/workers/WorkerExtensionSingleBrowser.js +0 -77
- package/workers/WorkerSelenium.js +0 -253
- package/workers/workerUtils.js +0 -20
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const BaseSocketService = require('./baseSocketServiceSocketIO');
|
|
4
|
-
|
|
5
|
-
class TestResultServiceSocketIO extends BaseSocketService {
|
|
6
|
-
init(projectId) {
|
|
7
|
-
super.init(projectId, 'testResult');
|
|
8
|
-
this.listerers = {};
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
listenToTestResult(resultId, testId, onTestResultStatus) {
|
|
12
|
-
if (this.listerers[resultId]) {
|
|
13
|
-
this._socket.off('testResult:updated', this.listerers[resultId]);
|
|
14
|
-
delete this.listerers[resultId];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
this.listerers[resultId] = data => {
|
|
18
|
-
if (data.resultId === resultId && data.testId === testId) {
|
|
19
|
-
onTestResultStatus(data.testResult);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
this._socket.on('testResult:updated', this.listerers[resultId]);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
emitJoinRoom(resultId, testId) {
|
|
27
|
-
return this.emitPromise('testResult:join', {
|
|
28
|
-
resultId,
|
|
29
|
-
testId,
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
joinToTestResult(resultId, testId) {
|
|
34
|
-
if (this.rooms[resultId]) {
|
|
35
|
-
return Promise.resolve();
|
|
36
|
-
}
|
|
37
|
-
this.joinRoom(resultId, testId);
|
|
38
|
-
return this.emitJoinRoom(resultId, testId);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
emitLeaveRoom(resultId, testId) {
|
|
42
|
-
return this.emitPromise('testResult:leave', {
|
|
43
|
-
resultId,
|
|
44
|
-
testId,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
leaveTestResult(resultId, testId) {
|
|
49
|
-
if (!this.listerers[resultId]) {
|
|
50
|
-
return Promise.resolve();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
this.leaveRoom(resultId);
|
|
54
|
-
this._socket.off('testResult:updated', this.listerers[resultId]);
|
|
55
|
-
delete this.listerers[resultId];
|
|
56
|
-
return this.emitLeaveRoom(resultId, testId);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
getSocket() {
|
|
60
|
-
return this._socket;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
module.exports = new TestResultServiceSocketIO();
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/* segment.io */
|
|
4
|
-
const config = require('./config');
|
|
5
|
-
const Analytics = require('analytics-node');
|
|
6
|
-
|
|
7
|
-
const analytics = new Analytics('sJOSIGKa5x5rJEGsaOlCjrgozAf7FnVY', { flushAt: 1 });
|
|
8
|
-
|
|
9
|
-
const anonymousId = require('crypto').randomBytes(20).toString('hex');
|
|
10
|
-
|
|
11
|
-
function identify(data) {
|
|
12
|
-
if (config.IS_ON_PREM) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
if (!data || !data.userId) {
|
|
16
|
-
data = { anonymousId };
|
|
17
|
-
}
|
|
18
|
-
analytics.identify(data);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function trackWithCIUser(eventName, properties) {
|
|
22
|
-
return track('ci', eventName, properties);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function track(userId, eventName, properties) {
|
|
26
|
-
if (config.IS_ON_PREM) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
const id = userId ? { userId } : { anonymousId };
|
|
30
|
-
analytics.track(Object.assign(id, {
|
|
31
|
-
event: eventName,
|
|
32
|
-
properties,
|
|
33
|
-
}));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
module.exports = {
|
|
37
|
-
identify,
|
|
38
|
-
track,
|
|
39
|
-
trackWithCIUser,
|
|
40
|
-
};
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const os = require('os');
|
|
4
|
-
const childProcess = require('child_process');
|
|
5
|
-
const fse = require('fs-extra');
|
|
6
|
-
const utils = require('../utils');
|
|
7
|
-
const servicesApi = require('./testimServicesApi.js');
|
|
8
|
-
|
|
9
|
-
const TUNNEL_BINARY_ORIGIN = 'https://github.com/cloudflare/cloudflared/releases/download/2022.4.1/';
|
|
10
|
-
const TUNNEL_BINARY_PATHNAME = {
|
|
11
|
-
win32ia32: { path: 'cloudflared-windows-386.exe' },
|
|
12
|
-
win32x64: { path: 'cloudflared-windows-amd64.exe' },
|
|
13
|
-
darwinx64: { path: 'cloudflared-darwin-amd64.tgz', extract: true },
|
|
14
|
-
linuxia32: { path: 'cloudflared-linux-386' },
|
|
15
|
-
linuxx64: { path: 'cloudflared-linux-amd64' },
|
|
16
|
-
};
|
|
17
|
-
const TUNNEL_BINARY_DIRECTORY = os.tmpdir();
|
|
18
|
-
const TUNNEL_BINARY_LOCATION = `${TUNNEL_BINARY_DIRECTORY}/cloudflared`;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
let tunnelId = null;
|
|
22
|
-
let tunnelProcess = null;
|
|
23
|
-
|
|
24
|
-
async function prepareTunnel() {
|
|
25
|
-
const isBinaryExist = await fse.pathExists(TUNNEL_BINARY_LOCATION);
|
|
26
|
-
if (isBinaryExist) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const downloadUrl = TUNNEL_BINARY_PATHNAME[os.platform() + os.arch()];
|
|
31
|
-
if (!downloadUrl) {
|
|
32
|
-
throw new Error(`tunnel on ${os.platform() + os.arch()} platform is not supported.`);
|
|
33
|
-
}
|
|
34
|
-
const destination = downloadUrl.extract ? TUNNEL_BINARY_DIRECTORY + downloadUrl.path : TUNNEL_BINARY_LOCATION;
|
|
35
|
-
await utils.downloadAndSave(`${TUNNEL_BINARY_ORIGIN}/${downloadUrl.path}`, destination);
|
|
36
|
-
if (downloadUrl.extract) {
|
|
37
|
-
await utils.unzipFile(destination, TUNNEL_BINARY_DIRECTORY);
|
|
38
|
-
}
|
|
39
|
-
await fse.chmodSync(TUNNEL_BINARY_LOCATION, '755');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const connectTunnel = async (options) => {
|
|
43
|
-
const tunnelBaseUrl = options.baseUrl || `http://localhost:${options.tunnelPort || 80}`;
|
|
44
|
-
const tunnelRoutes = options.tunnelRoutes || [tunnelBaseUrl];
|
|
45
|
-
const [result] = await Promise.all([
|
|
46
|
-
servicesApi.getCloudflareTunnel(options.company.companyId, tunnelRoutes),
|
|
47
|
-
module.exports.prepareTunnel(),
|
|
48
|
-
]);
|
|
49
|
-
tunnelId = result._id;
|
|
50
|
-
tunnelProcess = childProcess.spawn(TUNNEL_BINARY_LOCATION, ['tunnel', '--no-autoupdate', 'run', '--force', '--token', result.token], { stdio: 'inherit' });
|
|
51
|
-
await servicesApi.forceUpdateCloudflareTunnelRoutes(options.company.companyId, tunnelId);
|
|
52
|
-
|
|
53
|
-
if (options.tunnelRoutesOutput) {
|
|
54
|
-
await fse.writeFileSync(options.tunnelRoutesOutput, JSON.stringify(result.routesMapping, null, 2));
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
options.baseUrl = `${options.tunnelUseHttpAddress ? 'http' : 'https'}://${result.routesMapping[tunnelBaseUrl]}`;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const disconnectTunnel = async (options) => {
|
|
61
|
-
const promises = [];
|
|
62
|
-
if (tunnelId) {
|
|
63
|
-
promises.push(servicesApi.deleteCloudflareTunnel(options.company.companyId, tunnelId));
|
|
64
|
-
}
|
|
65
|
-
if (tunnelProcess) {
|
|
66
|
-
promises.push(new Promise((resolve, reject) => {
|
|
67
|
-
tunnelProcess.on('close', (code) => {
|
|
68
|
-
if (code) {
|
|
69
|
-
reject(new Error(`tunnel process exited with code ${code}`));
|
|
70
|
-
}
|
|
71
|
-
resolve();
|
|
72
|
-
});
|
|
73
|
-
tunnelProcess.kill();
|
|
74
|
-
}));
|
|
75
|
-
}
|
|
76
|
-
return await Promise.all(promises);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
module.exports = {
|
|
80
|
-
connectTunnel,
|
|
81
|
-
disconnectTunnel,
|
|
82
|
-
prepareTunnel,
|
|
83
|
-
};
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
const { sinon, expect } = require('../../test/utils/testUtils');
|
|
6
|
-
const testimCloudflare = require('./testimCloudflare');
|
|
7
|
-
const servicesApi = require('./testimServicesApi.js');
|
|
8
|
-
const utils = require('../utils');
|
|
9
|
-
const fse = require('fs-extra');
|
|
10
|
-
const os = require('os');
|
|
11
|
-
const childProcess = require('child_process');
|
|
12
|
-
const EventEmitter = require('events');
|
|
13
|
-
|
|
14
|
-
class Process extends EventEmitter {
|
|
15
|
-
constructor() {
|
|
16
|
-
super();
|
|
17
|
-
}
|
|
18
|
-
setCode(code) {
|
|
19
|
-
this.code = code;
|
|
20
|
-
}
|
|
21
|
-
kill() {
|
|
22
|
-
this.emit('close', this.code);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
describe('testimCloudflare', () => {
|
|
27
|
-
let sandbox;
|
|
28
|
-
beforeEach(() => {
|
|
29
|
-
sandbox = sinon.createSandbox();
|
|
30
|
-
});
|
|
31
|
-
afterEach(() => {
|
|
32
|
-
sandbox.restore();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe('disconnectTunnel', () => {
|
|
36
|
-
let deleteCloudflareTunnelStub;
|
|
37
|
-
let processMock;
|
|
38
|
-
let killStub;
|
|
39
|
-
|
|
40
|
-
beforeEach(() => {
|
|
41
|
-
deleteCloudflareTunnelStub = sandbox.stub(servicesApi, 'deleteCloudflareTunnel');
|
|
42
|
-
processMock = new Process();
|
|
43
|
-
killStub = sandbox.stub(processMock, 'kill').callThrough();
|
|
44
|
-
sandbox.stub(childProcess, 'spawn').returns(processMock);
|
|
45
|
-
sandbox.stub(testimCloudflare, 'prepareTunnel');
|
|
46
|
-
sandbox.stub(servicesApi, 'getCloudflareTunnel').resolves({ _id: utils.guid(), routesMapping: {} });
|
|
47
|
-
sandbox.stub(servicesApi, 'forceUpdateCloudflareTunnelRoutes');
|
|
48
|
-
sandbox.stub(fse, 'writeFileSync');
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('should do nothing when no tunnel', async () => {
|
|
52
|
-
await testimCloudflare.disconnectTunnel({ company: {} });
|
|
53
|
-
sinon.assert.notCalled(deleteCloudflareTunnelStub);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should delete the tunnel', async () => {
|
|
57
|
-
await testimCloudflare.connectTunnel({ company: {} });
|
|
58
|
-
await testimCloudflare.disconnectTunnel({ company: {} });
|
|
59
|
-
sinon.assert.calledOnce(deleteCloudflareTunnelStub);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('should kill the tunnel', async () => {
|
|
63
|
-
await testimCloudflare.connectTunnel({ company: {} });
|
|
64
|
-
await testimCloudflare.disconnectTunnel({ company: {} });
|
|
65
|
-
sinon.assert.calledOnce(killStub);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should reject when killing the tunnel fails', async () => {
|
|
69
|
-
processMock.setCode(1);
|
|
70
|
-
await testimCloudflare.connectTunnel({ company: {} });
|
|
71
|
-
await expect(testimCloudflare.disconnectTunnel({ company: {} })).to.be.rejectedWith(Error);
|
|
72
|
-
sinon.assert.calledOnce(killStub);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
describe('prepareTunnel', () => {
|
|
77
|
-
it('should do nothing when cloudflared binary already exists', async () => {
|
|
78
|
-
sandbox.stub(fse, 'pathExists').resolves(true);
|
|
79
|
-
const chmod = sandbox.stub(fse, 'chmodSync');
|
|
80
|
-
await testimCloudflare.prepareTunnel();
|
|
81
|
-
expect(chmod).not.to.have.been.called;
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('should throw when unsupported os', async () => {
|
|
85
|
-
sandbox.stub(fse, 'pathExists').resolves(false);
|
|
86
|
-
sandbox.stub(os, 'platform').returns('wtf');
|
|
87
|
-
sandbox.stub(os, 'arch').returns('wtf');
|
|
88
|
-
|
|
89
|
-
await expect(testimCloudflare.prepareTunnel()).to.be.rejectedWith(Error, 'tunnel on wtfwtf platform is not supported.');
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('should download cloudflared binary', async () => {
|
|
93
|
-
sandbox.stub(fse, 'pathExists').resolves(false);
|
|
94
|
-
sandbox.stub(os, 'platform').returns('win32');
|
|
95
|
-
sandbox.stub(os, 'arch').returns('x64');
|
|
96
|
-
|
|
97
|
-
const chmod = sandbox.stub(fse, 'chmodSync');
|
|
98
|
-
const download = sandbox.stub(utils, 'downloadAndSave');
|
|
99
|
-
|
|
100
|
-
await testimCloudflare.prepareTunnel();
|
|
101
|
-
sinon.assert.calledOnce(chmod);
|
|
102
|
-
sinon.assert.calledOnce(download);
|
|
103
|
-
expect(download.args[0][0]).to.startWith('https://github.com/cloudflare/cloudflared/releases/download');
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('should extract tgz file', async () => {
|
|
107
|
-
sandbox.stub(fse, 'pathExists').resolves(false);
|
|
108
|
-
sandbox.stub(os, 'platform').returns('darwin');
|
|
109
|
-
sandbox.stub(os, 'arch').returns('x64');
|
|
110
|
-
sandbox.stub(fse, 'chmodSync');
|
|
111
|
-
|
|
112
|
-
sandbox.stub(utils, 'downloadAndSave').resolves();
|
|
113
|
-
const unzip = sandbox.stub(utils, 'unzipFile').resolves();
|
|
114
|
-
await testimCloudflare.prepareTunnel();
|
|
115
|
-
|
|
116
|
-
sinon.assert.calledOnce(unzip);
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
describe('connectTunnel', () => {
|
|
121
|
-
let prepareTunnelStub;
|
|
122
|
-
let getCloudflareTunnelStub;
|
|
123
|
-
let forceUpdateCloudflareTunnelRoutesStub;
|
|
124
|
-
let writeFileSyncStub;
|
|
125
|
-
let spawnStub;
|
|
126
|
-
|
|
127
|
-
let tunnelData;
|
|
128
|
-
|
|
129
|
-
beforeEach(() => {
|
|
130
|
-
tunnelData = { _id: utils.guid(), token: utils.guid(), routesMapping: {} };
|
|
131
|
-
prepareTunnelStub = sandbox.stub(testimCloudflare, 'prepareTunnel');
|
|
132
|
-
getCloudflareTunnelStub = sandbox.stub(servicesApi, 'getCloudflareTunnel').resolves(tunnelData);
|
|
133
|
-
forceUpdateCloudflareTunnelRoutesStub = sandbox.stub(servicesApi, 'forceUpdateCloudflareTunnelRoutes');
|
|
134
|
-
writeFileSyncStub = sandbox.stub(fse, 'writeFileSync');
|
|
135
|
-
spawnStub = sandbox.stub(childProcess, 'spawn');
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('should prepare the tunnel', async () => {
|
|
139
|
-
await testimCloudflare.connectTunnel({ company: {} });
|
|
140
|
-
sinon.assert.calledOnce(prepareTunnelStub);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('should get and the tunnel routes', async () => {
|
|
144
|
-
await testimCloudflare.connectTunnel({ company: {} });
|
|
145
|
-
sinon.assert.calledOnce(getCloudflareTunnelStub);
|
|
146
|
-
sinon.assert.calledWith(forceUpdateCloudflareTunnelRoutesStub);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it('should spawn the cloudflard process', async () => {
|
|
150
|
-
await testimCloudflare.connectTunnel({ company: {} });
|
|
151
|
-
sinon.assert.calledOnce(spawnStub);
|
|
152
|
-
expect(spawnStub.args[0][1]).to.eql(['tunnel', '--no-autoupdate', 'run', '--force', '--token', tunnelData.token]);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it('should write the tunnel data to a file', async () => {
|
|
156
|
-
tunnelData.routesMapping = utils.guid();
|
|
157
|
-
await testimCloudflare.connectTunnel({ company: {}, tunnelRoutesOutput: 'test.json' });
|
|
158
|
-
sinon.assert.calledOnce(writeFileSyncStub);
|
|
159
|
-
expect(writeFileSyncStub.args[0][0]).to.eql('test.json');
|
|
160
|
-
expect(writeFileSyncStub.args[0][1]).to.eql(JSON.stringify(tunnelData.routesMapping));
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('should set the baseUrl to the tunneled url', async () => {
|
|
164
|
-
tunnelData.routesMapping = { 'http://localhost:80': utils.guid() };
|
|
165
|
-
const opts = { company: {} };
|
|
166
|
-
await testimCloudflare.connectTunnel(opts);
|
|
167
|
-
expect(opts.baseUrl).to.eql(`https://${tunnelData.routesMapping['http://localhost:80']}`);
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it('should set the baseUrl to the tunneled url, overriding an existing baseURL', async () => {
|
|
171
|
-
const baseUrl = utils.guid();
|
|
172
|
-
tunnelData.routesMapping = { [baseUrl]: utils.guid() };
|
|
173
|
-
const opts = { company: {}, baseUrl };
|
|
174
|
-
await testimCloudflare.connectTunnel(opts);
|
|
175
|
-
expect(opts.baseUrl).to.eql(`https://${tunnelData.routesMapping[baseUrl]}`);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it('should set the baseUrl considering tunnelUseHttpAddress', async () => {
|
|
179
|
-
tunnelData.routesMapping = { 'http://localhost:80': utils.guid() };
|
|
180
|
-
const opts = { company: {}, tunnelUseHttpAddress: true };
|
|
181
|
-
await testimCloudflare.connectTunnel(opts);
|
|
182
|
-
expect(opts.baseUrl).to.eql(`http://${tunnelData.routesMapping['http://localhost:80']}`);
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
});
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const httpRequest = require('./httpRequest');
|
|
4
|
-
const config = require('./config');
|
|
5
|
-
const ArgError = require('../errors').ArgError;
|
|
6
|
-
const logger = require('./logger').getLogger('testim-custom-token');
|
|
7
|
-
const localRunnerCache = require('./runnerFileCache');
|
|
8
|
-
|
|
9
|
-
let _serverToken;
|
|
10
|
-
let _serverTokenExp;
|
|
11
|
-
let _refreshToken;
|
|
12
|
-
let _ngrokToken;
|
|
13
|
-
let _isNgrokWhitelisted;
|
|
14
|
-
|
|
15
|
-
let _projectId = null;
|
|
16
|
-
let _token = null;
|
|
17
|
-
|
|
18
|
-
const FIVE_MIN_IN_MS = 5 * 60 * 1000;
|
|
19
|
-
|
|
20
|
-
async function init(projectId, token) {
|
|
21
|
-
_projectId = projectId;
|
|
22
|
-
_token = token;
|
|
23
|
-
const tokenValue = await generateToken();
|
|
24
|
-
return tokenValue;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function initFromData(authData, projectId, token) {
|
|
28
|
-
_serverToken = authData.token;
|
|
29
|
-
_projectId = projectId;
|
|
30
|
-
_token = token;
|
|
31
|
-
_serverTokenExp = getTokenExp(_serverToken);
|
|
32
|
-
_refreshToken = authData.refreshToken;
|
|
33
|
-
_ngrokToken = authData.ngrokToken;
|
|
34
|
-
_isNgrokWhitelisted = authData.isNgrokWhitelisted;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function getTokenV3(projectId = _projectId, token = _token) {
|
|
38
|
-
return localRunnerCache.memoize(() => {
|
|
39
|
-
logger.info('request to get cli token from server');
|
|
40
|
-
return httpRequest.post({
|
|
41
|
-
url: `${config.SERVICES_HOST}/auth/token`,
|
|
42
|
-
body: { projectId, token },
|
|
43
|
-
});
|
|
44
|
-
}, 'getTokenV3', FIVE_MIN_IN_MS * 10, { projectId, token })();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async function refreshToken() {
|
|
48
|
-
logger.info('request to refresh JWT cli token from server');
|
|
49
|
-
const customToken = await httpRequest.post({
|
|
50
|
-
url: `${config.SERVICES_HOST}/auth/refreshToken`,
|
|
51
|
-
body: { token: _serverToken, refreshToken: _refreshToken },
|
|
52
|
-
});
|
|
53
|
-
_serverToken = customToken.token;
|
|
54
|
-
_serverTokenExp = getTokenExp(_serverToken);
|
|
55
|
-
return _serverToken;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function generateToken() {
|
|
59
|
-
return getTokenV3()
|
|
60
|
-
.then(customToken => {
|
|
61
|
-
logger.info('successfully get cli token from server');
|
|
62
|
-
_serverToken = customToken.token;
|
|
63
|
-
_serverTokenExp = getTokenExp(_serverToken);
|
|
64
|
-
_refreshToken = customToken.refreshToken;
|
|
65
|
-
_ngrokToken = customToken.ngrokToken;
|
|
66
|
-
_isNgrokWhitelisted = customToken.isNgrokWhitelisted;
|
|
67
|
-
return _serverToken;
|
|
68
|
-
})
|
|
69
|
-
.catch(error => {
|
|
70
|
-
if (error.message.includes('Unauthorized')) {
|
|
71
|
-
throw new ArgError(
|
|
72
|
-
'Error trying to retrieve CLI token. ' +
|
|
73
|
-
'Your CLI token and project might not match. ' +
|
|
74
|
-
'Please make sure to pass `--project` and `--token` that' +
|
|
75
|
-
' match to each other or make sure they match in your ~/.testim file.');
|
|
76
|
-
}
|
|
77
|
-
logger.error(`While trying to retrieve CLI token. caught error: ${error}`, { projectId: _projectId });
|
|
78
|
-
throw new ArgError(`While trying to retrieve CLI token, caught error: ${error}`);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function getTokenExp(token) {
|
|
83
|
-
const jwtLib = require('jsonwebtoken');
|
|
84
|
-
const jwt = jwtLib.decode(token);
|
|
85
|
-
return jwt.exp * 1000;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function getCustomTokenV3() {
|
|
89
|
-
if (!_serverTokenExp) {
|
|
90
|
-
return generateToken();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Refresh the token earlier than needed, to give
|
|
94
|
-
// clickim a chance to have more time to run, as
|
|
95
|
-
// it can't refresh it itself.
|
|
96
|
-
if (_serverTokenExp < (Date.now() + (4 * FIVE_MIN_IN_MS))) {
|
|
97
|
-
return refreshToken().catch(err => {
|
|
98
|
-
logger.error('failed to refresh token, executing fallback', err);
|
|
99
|
-
return generateToken();
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
return Promise.resolve(_serverToken);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function getRefreshToken() {
|
|
106
|
-
return _refreshToken;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function getTokenV3UserData() {
|
|
110
|
-
if (_serverToken) {
|
|
111
|
-
const jwtLib = require('jsonwebtoken');
|
|
112
|
-
const data = jwtLib.decode(_serverToken);
|
|
113
|
-
return { uid: data.id, ngrokToken: _ngrokToken, isNgrokWhitelisted: _isNgrokWhitelisted };
|
|
114
|
-
}
|
|
115
|
-
return {};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
module.exports = {
|
|
119
|
-
init,
|
|
120
|
-
initFromData,
|
|
121
|
-
getCustomTokenV3,
|
|
122
|
-
getTokenV3UserData,
|
|
123
|
-
getRefreshToken,
|
|
124
|
-
};
|