@unito/integration-cli 0.57.1 → 0.57.2
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/dist/integrationGenerator/test/resources/integration.test.js +7 -8
- package/dist/src/commands/activity.d.ts +2 -2
- package/dist/src/commands/activity.js +2 -2
- package/dist/src/commands/dev.d.ts +4 -4
- package/dist/src/commands/dev.js +3 -2
- package/dist/src/commands/encrypt.d.ts +1 -1
- package/dist/src/commands/encrypt.js +1 -1
- package/dist/src/commands/init.d.ts +1 -1
- package/dist/src/commands/init.js +1 -1
- package/dist/src/commands/invite.d.ts +1 -1
- package/dist/src/commands/invite.js +2 -2
- package/dist/src/commands/login.d.ts +1 -1
- package/dist/src/commands/login.js +1 -1
- package/dist/src/commands/oauth2.d.ts +3 -3
- package/dist/src/commands/oauth2.js +4 -4
- package/dist/src/commands/publish.d.ts +2 -2
- package/dist/src/commands/publish.js +12 -12
- package/dist/src/commands/test.js +4 -2
- package/dist/src/commands/upgrade.js +3 -3
- package/dist/src/oauth2Helper/oauth2Helper.d.ts +4 -2
- package/dist/src/oauth2Helper/oauth2Helper.js +31 -11
- package/dist/src/services/oauth2Helper.d.ts +2 -1
- package/dist/src/services/oauth2Helper.js +4 -3
- package/dist/test/commands/activity.test.js +12 -9
- package/dist/test/commands/dev.test.js +38 -10
- package/dist/test/commands/encrypt.test.js +6 -7
- package/dist/test/commands/init.test.js +6 -8
- package/dist/test/commands/invite.test.js +11 -11
- package/dist/test/commands/login.test.js +19 -23
- package/dist/test/commands/oauth2.test.js +4 -1
- package/dist/test/commands/publish.test.js +151 -218
- package/dist/test/commands/test.test.js +43 -13
- package/dist/test/commands/upgrade.test.js +3 -6
- package/dist/test/errors.test.js +36 -36
- package/dist/test/helpers/integrations.d.ts +26 -0
- package/dist/test/helpers/integrations.js +25 -0
- package/dist/test/helpers/styles.d.ts +1 -0
- package/dist/test/helpers/styles.js +8 -0
- package/dist/test/oauth2Helper/oauth2Helper.test.js +20 -20
- package/dist/test/resources/configuration.test.js +24 -24
- package/dist/test/resources/decryption.test.js +9 -9
- package/dist/test/resources/globalConfiguration.test.js +4 -4
- package/dist/test/services/integrationsPlatform.test.js +20 -20
- package/dist/test/services/oauth2Helper.test.js +7 -7
- package/oclif.manifest.json +1 -1
- package/package.json +3 -7
- package/dist/test/mocha.hooks.d.ts +0 -2
- package/dist/test/mocha.hooks.js +0 -37
|
@@ -13,6 +13,9 @@ describe('Test', () => {
|
|
|
13
13
|
const cliConfiguration = {
|
|
14
14
|
name: 'a',
|
|
15
15
|
baseUrl: 'b',
|
|
16
|
+
secrets: {
|
|
17
|
+
secret: 'encryptedSecret',
|
|
18
|
+
},
|
|
16
19
|
testAccounts: {
|
|
17
20
|
compliance: {
|
|
18
21
|
accessToken: 'token',
|
|
@@ -28,9 +31,7 @@ describe('Test', () => {
|
|
|
28
31
|
beforeEach(() => {
|
|
29
32
|
process.env.NODE_MODULES_FOLDER = '/path/to/node_modules';
|
|
30
33
|
sinon_1.default.stub(IntegrationsPlatform, 'decryptData').resolves({ decryptedData: 'decrypted-me' });
|
|
31
|
-
sinon_1.default.stub(IntegrationResource, 'validateIsIntegrationDirectory');
|
|
32
34
|
sinon_1.default.stub(IntegrationsPlatformResource, 'validateAuthenticated');
|
|
33
|
-
sinon_1.default.stub(ConfigurationResource, 'getConfiguration').resolves(cliConfiguration);
|
|
34
35
|
execSyncStub = sinon_1.default.stub(child_process_1.default, 'execSync');
|
|
35
36
|
spawnStub = sinon_1.default.stub(child_process_1.default, 'spawn').returns({ on: (..._args) => { } });
|
|
36
37
|
});
|
|
@@ -40,6 +41,8 @@ describe('Test', () => {
|
|
|
40
41
|
});
|
|
41
42
|
test_1.test
|
|
42
43
|
.stdout()
|
|
44
|
+
.stub(ConfigurationResource, 'getConfiguration', stub => stub.returns(cliConfiguration))
|
|
45
|
+
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
|
|
43
46
|
.command(['test'])
|
|
44
47
|
.it('launches the debugger', () => {
|
|
45
48
|
(0, test_1.expect)(execSyncStub.getCall(0).args.at(0).split(' ').slice(0, 2)).to.deep.equal(['npm', 'install']);
|
|
@@ -47,9 +50,8 @@ describe('Test', () => {
|
|
|
47
50
|
});
|
|
48
51
|
test_1.test
|
|
49
52
|
.stdout()
|
|
50
|
-
.stub(
|
|
51
|
-
|
|
52
|
-
})
|
|
53
|
+
.stub(ConfigurationResource, 'getConfiguration', stub => stub.resolves(cliConfiguration))
|
|
54
|
+
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.throws(new Error('boom!')))
|
|
53
55
|
.command(['test'])
|
|
54
56
|
.catch(ctx => {
|
|
55
57
|
(0, test_1.expect)(ctx.message).to.equal('boom!');
|
|
@@ -57,44 +59,63 @@ describe('Test', () => {
|
|
|
57
59
|
.it('unhandled exception');
|
|
58
60
|
test_1.test
|
|
59
61
|
.stdout()
|
|
60
|
-
.stub(
|
|
61
|
-
|
|
62
|
-
})
|
|
62
|
+
.stub(ConfigurationResource, 'getConfiguration', stub => stub.resolves(cliConfiguration))
|
|
63
|
+
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.throws(new errors_1.NoIntegrationFoundError()))
|
|
63
64
|
.command(['test'])
|
|
64
65
|
.exit(-1)
|
|
65
66
|
.it('handled exception');
|
|
66
67
|
test_1.test
|
|
67
68
|
.stdout()
|
|
69
|
+
.stub(ConfigurationResource, 'getConfiguration', stub => stub.resolves(cliConfiguration))
|
|
70
|
+
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
|
|
68
71
|
.command(['test', '--verbose'])
|
|
69
72
|
.it('verbose mode', () => {
|
|
70
73
|
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--verbose');
|
|
71
74
|
});
|
|
72
75
|
test_1.test
|
|
73
76
|
.stdout()
|
|
77
|
+
.stub(ConfigurationResource, 'getConfiguration', stub => stub.resolves(cliConfiguration))
|
|
78
|
+
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
|
|
74
79
|
.command(['test', '--credential-payload', '{"foo": "bar"}'])
|
|
75
80
|
.it('uses provided credentials', () => {
|
|
76
81
|
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--credential-payload={"foo": "bar"}');
|
|
77
82
|
});
|
|
78
83
|
test_1.test
|
|
79
84
|
.stdout()
|
|
85
|
+
.stub(ConfigurationResource, 'getConfiguration', stub => stub.resolves(cliConfiguration))
|
|
86
|
+
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
|
|
80
87
|
.command(['test'])
|
|
81
88
|
.it('defaults to test account when no flag is provided', () => {
|
|
82
89
|
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--credential-payload={"accessToken":"developmentToken"}');
|
|
83
90
|
});
|
|
84
91
|
test_1.test
|
|
85
92
|
.stdout()
|
|
93
|
+
.stub(ConfigurationResource, 'getConfiguration', stub => stub.resolves(cliConfiguration))
|
|
94
|
+
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
|
|
86
95
|
.command(['test', '--test-account', 'compliance'])
|
|
87
96
|
.it('uses compliance credentials when a flag is provided', () => {
|
|
88
97
|
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--credential-payload={"accessToken":"token","encryptedToken":"decrypted-me"}');
|
|
89
98
|
});
|
|
90
99
|
test_1.test
|
|
91
100
|
.stdout()
|
|
101
|
+
.stub(ConfigurationResource, 'getConfiguration', stub => stub.resolves(cliConfiguration))
|
|
102
|
+
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
|
|
103
|
+
.command(['test'])
|
|
104
|
+
.it('decrypt secrets correctly', () => {
|
|
105
|
+
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--secrets-payload={"secret":"encryptedSecret"}');
|
|
106
|
+
});
|
|
107
|
+
test_1.test
|
|
108
|
+
.stdout()
|
|
109
|
+
.stub(ConfigurationResource, 'getConfiguration', stub => stub.resolves(cliConfiguration))
|
|
110
|
+
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
|
|
92
111
|
.command(['test', '--output-path', 'foo.json'])
|
|
93
112
|
.it('output path', () => {
|
|
94
113
|
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--output-path=foo.json');
|
|
95
114
|
});
|
|
96
115
|
test_1.test
|
|
97
116
|
.stdout()
|
|
117
|
+
.stub(ConfigurationResource, 'getConfiguration', stub => stub.resolves(cliConfiguration))
|
|
118
|
+
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
|
|
98
119
|
.command(['test', '--crawlMode=sample'])
|
|
99
120
|
.it('sampling crawlMode', () => {
|
|
100
121
|
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--operation-collection-items-per-page=10');
|
|
@@ -102,6 +123,8 @@ describe('Test', () => {
|
|
|
102
123
|
});
|
|
103
124
|
test_1.test
|
|
104
125
|
.stdout()
|
|
126
|
+
.stub(ConfigurationResource, 'getConfiguration', stub => stub.resolves(cliConfiguration))
|
|
127
|
+
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
|
|
105
128
|
.command(['test', '--crawlMode=single'])
|
|
106
129
|
.it('single crawlMode', () => {
|
|
107
130
|
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--operation-collection-items-per-page=1');
|
|
@@ -109,50 +132,57 @@ describe('Test', () => {
|
|
|
109
132
|
});
|
|
110
133
|
test_1.test
|
|
111
134
|
.stdout()
|
|
135
|
+
.stub(ConfigurationResource, 'getConfiguration', stub => stub.resolves(cliConfiguration))
|
|
136
|
+
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
|
|
112
137
|
.command(['test', '--checks', 'foo,bar'])
|
|
113
138
|
.it('checks', () => {
|
|
114
139
|
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--checks=foo,bar');
|
|
115
140
|
});
|
|
116
141
|
test_1.test
|
|
117
142
|
.stdout()
|
|
118
|
-
.stub(ConfigurationResource, 'getConfiguration',
|
|
143
|
+
.stub(ConfigurationResource, 'getConfiguration', stub => stub.returns({ ...cliConfiguration, graphRelativeUrl: 'foo' }))
|
|
144
|
+
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
|
|
119
145
|
.command(['test'])
|
|
120
146
|
.it('overrides --graph-relative-url', () => {
|
|
121
147
|
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--graph-relative-url=foo');
|
|
122
148
|
});
|
|
123
149
|
test_1.test
|
|
124
150
|
.stdout()
|
|
125
|
-
.stub(ConfigurationResource, 'getConfiguration',
|
|
151
|
+
.stub(ConfigurationResource, 'getConfiguration', stub => stub.returns({
|
|
126
152
|
...cliConfiguration,
|
|
127
153
|
credentialAccountRelativeUrl: 'foo',
|
|
128
154
|
}))
|
|
155
|
+
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
|
|
129
156
|
.command(['test'])
|
|
130
157
|
.it('overrides --credential-account-relative-url', () => {
|
|
131
158
|
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--credential-account-relative-url=foo');
|
|
132
159
|
});
|
|
133
160
|
test_1.test
|
|
134
161
|
.stdout()
|
|
135
|
-
.stub(ConfigurationResource, 'getConfiguration',
|
|
162
|
+
.stub(ConfigurationResource, 'getConfiguration', stub => stub.returns({ ...cliConfiguration, webhookParsingRelativeUrl: 'foo' }))
|
|
163
|
+
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
|
|
136
164
|
.command(['test'])
|
|
137
165
|
.it('overrides --webhook-parsing-relative-url', () => {
|
|
138
166
|
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--webhook-parsing-relative-url=foo');
|
|
139
167
|
});
|
|
140
168
|
test_1.test
|
|
141
169
|
.stdout()
|
|
142
|
-
.stub(ConfigurationResource, 'getConfiguration',
|
|
170
|
+
.stub(ConfigurationResource, 'getConfiguration', stub => stub.returns({
|
|
143
171
|
...cliConfiguration,
|
|
144
172
|
webhookSubscriptionsRelativeUrl: 'foo',
|
|
145
173
|
}))
|
|
174
|
+
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
|
|
146
175
|
.command(['test'])
|
|
147
176
|
.it('overrides --webhook-subscriptions-relative-url', () => {
|
|
148
177
|
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--webhook-subscriptions-relative-url=foo');
|
|
149
178
|
});
|
|
150
179
|
test_1.test
|
|
151
180
|
.stdout()
|
|
152
|
-
.stub(ConfigurationResource, 'getConfiguration',
|
|
181
|
+
.stub(ConfigurationResource, 'getConfiguration', stub => stub.returns({
|
|
153
182
|
...cliConfiguration,
|
|
154
183
|
webhookAcknowledgeRelativeUrl: 'bar',
|
|
155
184
|
}))
|
|
185
|
+
.stub(IntegrationResource, 'validateIsIntegrationDirectory', stub => stub.returns(true))
|
|
156
186
|
.command(['test'])
|
|
157
187
|
.it('overrides --webhook-acknowledge-relative-url', () => {
|
|
158
188
|
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--webhook-acknowledge-relative-url=bar');
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const test_1 = require("@oclif/test");
|
|
5
|
-
const sinon_1 = tslib_1.__importDefault(require("sinon"));
|
|
6
5
|
const child_process_1 = tslib_1.__importDefault(require("child_process"));
|
|
7
6
|
const errors_1 = require("../../src/errors");
|
|
8
7
|
describe('Upgrade', () => {
|
|
@@ -14,7 +13,7 @@ describe('Upgrade', () => {
|
|
|
14
13
|
});
|
|
15
14
|
test_1.test
|
|
16
15
|
.stdout()
|
|
17
|
-
.stub(child_process_1.default, 'execSync',
|
|
16
|
+
.stub(child_process_1.default, 'execSync', stub => stub.onCall(0).returns('1').onCall(1).returns('2').onCall(2).returns('ok'))
|
|
18
17
|
.command(['upgrade'])
|
|
19
18
|
.it('upgrades the CLI', ctx => {
|
|
20
19
|
const execSyncStub = child_process_1.default.execSync;
|
|
@@ -26,7 +25,7 @@ describe('Upgrade', () => {
|
|
|
26
25
|
});
|
|
27
26
|
test_1.test
|
|
28
27
|
.stdout()
|
|
29
|
-
.stub(child_process_1.default, 'execSync',
|
|
28
|
+
.stub(child_process_1.default, 'execSync', stub => stub.onCall(0).returns('1').onCall(1).returns('1'))
|
|
30
29
|
.command(['upgrade'])
|
|
31
30
|
.it('validates the CLI', ctx => {
|
|
32
31
|
const execSyncStub = child_process_1.default.execSync;
|
|
@@ -38,9 +37,7 @@ describe('Upgrade', () => {
|
|
|
38
37
|
});
|
|
39
38
|
test_1.test
|
|
40
39
|
.stdout()
|
|
41
|
-
.stub(child_process_1.default, 'execSync',
|
|
42
|
-
throw new errors_1.ConfigurationMalformed();
|
|
43
|
-
})
|
|
40
|
+
.stub(child_process_1.default, 'execSync', stub => stub.throws(new errors_1.ConfigurationMalformed()))
|
|
44
41
|
.command(['upgrade'])
|
|
45
42
|
.exit(-1)
|
|
46
43
|
.it('handle exception');
|
package/dist/test/errors.test.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const
|
|
4
|
+
const strict_1 = tslib_1.__importDefault(require("node:assert/strict"));
|
|
5
5
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
6
6
|
const sinon_1 = tslib_1.__importDefault(require("sinon"));
|
|
7
7
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
@@ -21,67 +21,67 @@ describe('handleError', () => {
|
|
|
21
21
|
afterEach(() => {
|
|
22
22
|
sinon_1.default.restore();
|
|
23
23
|
});
|
|
24
|
-
it('
|
|
24
|
+
it('handles NoIntegrationFoundError', () => {
|
|
25
25
|
const error = new errors_1.NoIntegrationFoundError();
|
|
26
26
|
const handled = (0, errors_1.handleError)(command, error);
|
|
27
|
-
(0,
|
|
28
|
-
(0,
|
|
29
|
-
|
|
30
|
-
(0,
|
|
27
|
+
(0, strict_1.default)(handled);
|
|
28
|
+
(0, strict_1.default)(stdErrStub.calledTwice);
|
|
29
|
+
strict_1.default.equal(stdErrStub.firstCall.args[0], chalk_1.default.redBright('Your directory does not seem to contain an integration :('));
|
|
30
|
+
(0, strict_1.default)(stdErrStub.secondCall.args[0].includes('Make sure you are in the right directory'));
|
|
31
31
|
});
|
|
32
|
-
it('
|
|
32
|
+
it('handles NoConfigurationFileError', () => {
|
|
33
33
|
const error = new errors_1.NoConfigurationFileError();
|
|
34
34
|
const handled = (0, errors_1.handleError)(command, error);
|
|
35
|
-
(0,
|
|
36
|
-
(0,
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
(0, strict_1.default)(handled);
|
|
36
|
+
(0, strict_1.default)(stdErrStub.calledTwice);
|
|
37
|
+
strict_1.default.equal(stdErrStub.firstCall.args[0], chalk_1.default.redBright('This command requires a configuration file for your integration :('));
|
|
38
|
+
strict_1.default.equal(stdErrStub.secondCall.args[0], `This file should be located at ${chalk_1.default.yellowBright(path_1.default.relative(process.cwd(), (0, configuration_1.getConfigurationPath)()))}.`);
|
|
39
39
|
});
|
|
40
40
|
it('should return false for unrecognized error', () => {
|
|
41
41
|
const error = new Error('Unrecognized error');
|
|
42
42
|
const handled = (0, errors_1.handleError)(command, error);
|
|
43
|
-
(
|
|
44
|
-
|
|
43
|
+
strict_1.default.equal(handled, false);
|
|
44
|
+
strict_1.default.equal(stdErrStub.called, false);
|
|
45
45
|
});
|
|
46
|
-
it('
|
|
46
|
+
it('handles ConfigurationInvalid', () => {
|
|
47
47
|
const error = new errors_1.ConfigurationInvalid('VAR_NAME', 'details', 'prettyDetails');
|
|
48
48
|
const handled = (0, errors_1.handleError)(command, error);
|
|
49
|
-
(0,
|
|
50
|
-
(0,
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
(0, strict_1.default)(handled);
|
|
50
|
+
(0, strict_1.default)(stdErrStub.calledThrice);
|
|
51
|
+
strict_1.default.equal(stdErrStub.firstCall.args[0], chalk_1.default.redBright(`Your ${chalk_1.default.yellowBright(path_1.default.basename((0, configuration_1.getConfigurationPath)()))} is invalid!`));
|
|
52
|
+
strict_1.default.equal(stdErrStub.thirdCall.args[0], 'prettyDetails');
|
|
53
53
|
});
|
|
54
|
-
it('
|
|
54
|
+
it('handles NoRefreshTokenError', () => {
|
|
55
55
|
const error = new errors_1.NoRefreshTokenError();
|
|
56
56
|
const handled = (0, errors_1.handleError)(command, error);
|
|
57
|
-
(0,
|
|
58
|
-
(0,
|
|
59
|
-
|
|
57
|
+
(0, strict_1.default)(handled);
|
|
58
|
+
(0, strict_1.default)(stdErrStub.calledOnce);
|
|
59
|
+
strict_1.default.equal(stdErrStub.firstCall.args[0], chalk_1.default.redBright('No refresh token found in your configuration file'));
|
|
60
60
|
});
|
|
61
|
-
it('
|
|
61
|
+
it('handles FailedToRetrieveAccessTokenError', () => {
|
|
62
62
|
const error = new errors_1.FailedToRetrieveAccessTokenError('Credentials invalid');
|
|
63
63
|
const handled = (0, errors_1.handleError)(command, error);
|
|
64
|
-
(0,
|
|
65
|
-
(0,
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
(0, strict_1.default)(handled);
|
|
65
|
+
(0, strict_1.default)(stdErrStub.calledThrice);
|
|
66
|
+
strict_1.default.equal(stdErrStub.firstCall.args[0], chalk_1.default.redBright('Failed to retrieve access token'));
|
|
67
|
+
strict_1.default.equal(stdErrStub.thirdCall.args[0], 'Credentials invalid');
|
|
68
68
|
});
|
|
69
|
-
it('
|
|
69
|
+
it('handles InvalidRequestContentTypeError', () => {
|
|
70
70
|
const error = new errors_1.InvalidRequestContentTypeError('Invalid content type');
|
|
71
71
|
const handled = (0, errors_1.handleError)(command, error);
|
|
72
|
-
(0,
|
|
73
|
-
(0,
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
(0, strict_1.default)(handled);
|
|
73
|
+
(0, strict_1.default)(stdErrStub.calledThrice);
|
|
74
|
+
strict_1.default.equal(stdErrStub.firstCall.args[0], chalk_1.default.redBright('Invalid request content type'));
|
|
75
|
+
strict_1.default.equal(stdErrStub.thirdCall.args[0], 'Invalid content type');
|
|
76
76
|
});
|
|
77
|
-
it('
|
|
77
|
+
it('handles DecryptionAuthenticationError', () => {
|
|
78
78
|
const error = new errors_1.DecryptionAuthenticationError('secrets');
|
|
79
79
|
const handled = (0, errors_1.handleError)(command, error);
|
|
80
|
-
(0,
|
|
80
|
+
(0, strict_1.default)(handled);
|
|
81
81
|
});
|
|
82
|
-
it('
|
|
82
|
+
it('handles EntryDecryptionError', () => {
|
|
83
83
|
const error = new errors_1.EntryDecryptionError('key', 'value', 'staging');
|
|
84
84
|
const handled = (0, errors_1.handleError)(command, error);
|
|
85
|
-
(0,
|
|
85
|
+
(0, strict_1.default)(handled);
|
|
86
86
|
});
|
|
87
87
|
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as IntegrationsPlatform from '../../src/services/integrationsPlatform';
|
|
2
|
+
export declare function generateIntegration(overrides?: Partial<IntegrationsPlatform.Integration>): {
|
|
3
|
+
createdAt: string;
|
|
4
|
+
updatedAt: string;
|
|
5
|
+
archivedAt: string | null;
|
|
6
|
+
id: number;
|
|
7
|
+
name: string;
|
|
8
|
+
baseUrl: string | null;
|
|
9
|
+
graphRelativeUrl: string;
|
|
10
|
+
credentialAccountRelativeUrl: string;
|
|
11
|
+
webhookParsingRelativeUrl?: string | null | undefined;
|
|
12
|
+
webhookSubscriptionsRelativeUrl?: string | null | undefined;
|
|
13
|
+
webhookAcknowledgeRelativeUrl?: string | null | undefined;
|
|
14
|
+
visibility: string;
|
|
15
|
+
unitoOrganizationIds: string[];
|
|
16
|
+
ui: {
|
|
17
|
+
displayName: string;
|
|
18
|
+
logo: string | null;
|
|
19
|
+
};
|
|
20
|
+
secrets?: {
|
|
21
|
+
[key: string]: string;
|
|
22
|
+
} | undefined;
|
|
23
|
+
disabledAt?: string | null | undefined;
|
|
24
|
+
authorizations: import("@unito/integrations-platform-client/dist/src/api").Authorization[];
|
|
25
|
+
userIds: number[];
|
|
26
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateIntegration = void 0;
|
|
4
|
+
function generateIntegration(overrides = {}) {
|
|
5
|
+
return {
|
|
6
|
+
id: 1,
|
|
7
|
+
name: 'foo',
|
|
8
|
+
baseUrl: '',
|
|
9
|
+
graphRelativeUrl: '',
|
|
10
|
+
credentialAccountRelativeUrl: '',
|
|
11
|
+
visibility: 'private',
|
|
12
|
+
unitoOrganizationIds: [],
|
|
13
|
+
createdAt: '',
|
|
14
|
+
updatedAt: '',
|
|
15
|
+
archivedAt: null,
|
|
16
|
+
authorizations: [],
|
|
17
|
+
userIds: [],
|
|
18
|
+
ui: {
|
|
19
|
+
displayName: '',
|
|
20
|
+
logo: '',
|
|
21
|
+
},
|
|
22
|
+
...overrides,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
exports.generateIntegration = generateIntegration;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function uncolorize(text: string): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uncolorize = void 0;
|
|
4
|
+
function uncolorize(text) {
|
|
5
|
+
// eslint-disable-next-line
|
|
6
|
+
return text.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
|
|
7
|
+
}
|
|
8
|
+
exports.uncolorize = uncolorize;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
|
-
const
|
|
5
|
+
const strict_1 = tslib_1.__importDefault(require("node:assert/strict"));
|
|
6
6
|
const sinon_1 = tslib_1.__importDefault(require("sinon"));
|
|
7
7
|
const oauth2Helper_1 = tslib_1.__importStar(require("../../src/oauth2Helper/oauth2Helper")), oauth2Namespace = oauth2Helper_1;
|
|
8
8
|
const configurationTypes_1 = require("../../src/configurationTypes");
|
|
@@ -29,7 +29,7 @@ describe('OAuth2Helper', () => {
|
|
|
29
29
|
};
|
|
30
30
|
oauth2Helper = new oauth2Helper_1.default(authorizationInfo);
|
|
31
31
|
fetchStub = sinon_1.default.stub().resolves({ json: sinon_1.default.stub().resolves({}), status: 200 });
|
|
32
|
-
sinon_1.default.stub(oauth2Helper, 'startServer').
|
|
32
|
+
sinon_1.default.stub(oauth2Helper, 'startServer').resolves('http://localhost:5050');
|
|
33
33
|
sinon_1.default.stub(oauth2Helper, 'stopServer');
|
|
34
34
|
sinon_1.default.replace(global, 'fetch', fetchStub);
|
|
35
35
|
sinon_1.default.replace(oauth2Namespace, 'open', { open: (_url) => undefined });
|
|
@@ -41,32 +41,32 @@ describe('OAuth2Helper', () => {
|
|
|
41
41
|
describe('handleAuthorize', () => {
|
|
42
42
|
it('should open the authorization URL', async () => {
|
|
43
43
|
const req = {};
|
|
44
|
-
const res = {
|
|
44
|
+
const res = { sendStatus: sinon_1.default.stub() };
|
|
45
45
|
await oauth2Helper['handleAuthorize'](req, res);
|
|
46
46
|
sinon_1.default.assert.calledOnce(openSpy);
|
|
47
|
-
sinon_1.default.assert.calledWith(openSpy, 'https://provider.com/oauth/authorize?client_id=your-client-id&redirect_uri
|
|
48
|
-
sinon_1.default.assert.calledOnce(res.
|
|
47
|
+
sinon_1.default.assert.calledWith(openSpy, 'https://provider.com/oauth/authorize?client_id=your-client-id&redirect_uri=https%3A%2F%2Fintegrations-platform.unito.io%2Fcredentials%2Fnew%2Foauth2%2Fcallback-cli&state=eyJjbGlDYWxsYmFja1VybCI6Ii9jcmVkZW50aWFscy9uZXcvb2F1dGgyL2NhbGxiYWNrIn0%3D&scope=scope1+scope2&response_type=code');
|
|
48
|
+
sinon_1.default.assert.calledOnce(res.sendStatus);
|
|
49
49
|
});
|
|
50
50
|
it('should maintain the pre-existing query parameters in authorization URL', async () => {
|
|
51
51
|
oauth2Helper['providerAuthorizationUrl'] = 'https://provider.com/oauth/authorize?query1=value1&query2=value2';
|
|
52
52
|
const req = {};
|
|
53
|
-
const res = {
|
|
53
|
+
const res = { sendStatus: sinon_1.default.stub() };
|
|
54
54
|
await oauth2Helper['handleAuthorize'](req, res);
|
|
55
55
|
sinon_1.default.assert.calledOnce(openSpy);
|
|
56
|
-
sinon_1.default.assert.calledWith(openSpy, 'https://provider.com/oauth/authorize?query1=value1&query2=value2&client_id=your-client-id&redirect_uri
|
|
57
|
-
(0,
|
|
58
|
-
(0,
|
|
59
|
-
sinon_1.default.assert.calledOnce(res.
|
|
56
|
+
sinon_1.default.assert.calledWith(openSpy, 'https://provider.com/oauth/authorize?query1=value1&query2=value2&client_id=your-client-id&redirect_uri=https%3A%2F%2Fintegrations-platform.unito.io%2Fcredentials%2Fnew%2Foauth2%2Fcallback-cli&state=eyJjbGlDYWxsYmFja1VybCI6Ii9jcmVkZW50aWFscy9uZXcvb2F1dGgyL2NhbGxiYWNrIn0%3D&scope=scope1+scope2&response_type=code');
|
|
57
|
+
(0, strict_1.default)(openSpy.firstCall.args[0].includes('query1=value1'));
|
|
58
|
+
(0, strict_1.default)(openSpy.firstCall.args[0].includes('query2=value2'));
|
|
59
|
+
sinon_1.default.assert.calledOnce(res.sendStatus);
|
|
60
60
|
});
|
|
61
61
|
});
|
|
62
62
|
describe('handleCallback', () => {
|
|
63
63
|
it('should store the authorization code', async () => {
|
|
64
64
|
const code = 'test-code';
|
|
65
|
-
const req = { query: { code } };
|
|
66
|
-
const res = {
|
|
65
|
+
const req = { body: { query: { code } } };
|
|
66
|
+
const res = { sendStatus: sinon_1.default.stub() };
|
|
67
67
|
await oauth2Helper['handleCallback'](req, res);
|
|
68
|
-
|
|
69
|
-
sinon_1.default.assert.calledOnce(res.
|
|
68
|
+
strict_1.default.equal(oauth2Helper['code'], code);
|
|
69
|
+
sinon_1.default.assert.calledOnce(res.sendStatus);
|
|
70
70
|
});
|
|
71
71
|
});
|
|
72
72
|
describe('handleToken', () => {
|
|
@@ -103,7 +103,7 @@ describe('OAuth2Helper', () => {
|
|
|
103
103
|
describe('updateToken', () => {
|
|
104
104
|
it('should throw an error when no refresh token is available', async () => {
|
|
105
105
|
const response = oauth2Helper.updateToken();
|
|
106
|
-
await (
|
|
106
|
+
await strict_1.default.rejects(response, errors_1.NoRefreshTokenError);
|
|
107
107
|
});
|
|
108
108
|
it('should retrieve the access token when a refresh token is available', async () => {
|
|
109
109
|
const refreshToken = 'test-refresh-token';
|
|
@@ -112,7 +112,7 @@ describe('OAuth2Helper', () => {
|
|
|
112
112
|
const fetchResponse = { access_token: accessToken, refresh_token: refreshToken };
|
|
113
113
|
fetchStub.resolves({ status: 200, json: sinon_1.default.stub().resolves(fetchResponse) });
|
|
114
114
|
const result = await oauth2Helper.updateToken();
|
|
115
|
-
(
|
|
115
|
+
strict_1.default.deepEqual(result, { accessToken, refreshToken });
|
|
116
116
|
sinon_1.default.assert.calledOnce(fetchStub);
|
|
117
117
|
});
|
|
118
118
|
it('should throw an error when failing to refresh the access token', async () => {
|
|
@@ -120,7 +120,7 @@ describe('OAuth2Helper', () => {
|
|
|
120
120
|
oauth2Helper['refreshToken'] = refreshToken;
|
|
121
121
|
fetchStub.rejects(new Error('Failed to retrieve access token'));
|
|
122
122
|
const response = oauth2Helper.updateToken();
|
|
123
|
-
await (
|
|
123
|
+
await strict_1.default.rejects(response, errors_1.FailedToRetrieveAccessTokenError);
|
|
124
124
|
sinon_1.default.assert.calledOnce(fetchStub);
|
|
125
125
|
});
|
|
126
126
|
it("should throw an error if we don't support the request content type", async () => {
|
|
@@ -128,7 +128,7 @@ describe('OAuth2Helper', () => {
|
|
|
128
128
|
oauth2Helper['refreshToken'] = refreshToken;
|
|
129
129
|
oauth2Helper['requestContentType'] = 'random';
|
|
130
130
|
const response = oauth2Helper.updateToken();
|
|
131
|
-
await (
|
|
131
|
+
await strict_1.default.rejects(response, errors_1.InvalidRequestContentTypeError);
|
|
132
132
|
});
|
|
133
133
|
});
|
|
134
134
|
describe('encodeBody', () => {
|
|
@@ -137,14 +137,14 @@ describe('OAuth2Helper', () => {
|
|
|
137
137
|
const contentType = configurationTypes_1.RequestContentType.URL_ENCODED;
|
|
138
138
|
const expectedEncodedBody = 'key1=value1&key2=value2';
|
|
139
139
|
const encodedBody = oauth2Helper['encodeBody'](bodyData, contentType);
|
|
140
|
-
|
|
140
|
+
strict_1.default.equal(encodedBody, expectedEncodedBody);
|
|
141
141
|
});
|
|
142
142
|
it('should encode body data as JSON when content type is JSON', () => {
|
|
143
143
|
const bodyData = { key1: 'value1', key2: 'value2' };
|
|
144
144
|
const contentType = configurationTypes_1.RequestContentType.JSON;
|
|
145
145
|
const expectedEncodedBody = JSON.stringify(bodyData);
|
|
146
146
|
const encodedBody = oauth2Helper['encodeBody'](bodyData, contentType);
|
|
147
|
-
|
|
147
|
+
strict_1.default.equal(encodedBody, expectedEncodedBody);
|
|
148
148
|
});
|
|
149
149
|
});
|
|
150
150
|
});
|