@unito/integration-cli 0.56.0 → 0.56.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.
Files changed (35) hide show
  1. package/dist/integrationGenerator/integrationBoilerplate/.nvmrc +1 -1
  2. package/dist/integrationGenerator/integrationBoilerplate/Dockerfile +2 -2
  3. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/.nvmrc +1 -1
  4. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/Dockerfile +2 -2
  5. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/package.json +2 -2
  6. package/dist/integrationGenerator/integrationBoilerplate/integrationBoilerplate/src/middlewares/additionalLoggingContext.ts +1 -1
  7. package/dist/integrationGenerator/integrationBoilerplate/package.json +2 -2
  8. package/dist/integrationGenerator/integrationBoilerplate/src/middlewares/additionalLoggingContext.ts +1 -1
  9. package/dist/src/commands/activity.js +13 -4
  10. package/dist/src/commands/dev.js +9 -3
  11. package/dist/src/commands/invite.js +13 -4
  12. package/dist/src/commands/oauth2.d.ts +6 -1
  13. package/dist/src/commands/oauth2.js +58 -55
  14. package/dist/src/commands/publish.js +13 -2
  15. package/dist/src/commands/test.js +9 -3
  16. package/dist/src/commands/upgrade.js +0 -12
  17. package/dist/src/errors.d.ts +2 -2
  18. package/dist/src/errors.js +11 -9
  19. package/dist/src/resources/configuration.d.ts +1 -1
  20. package/dist/src/resources/configuration.js +5 -2
  21. package/dist/src/resources/decryption.d.ts +10 -4
  22. package/dist/src/resources/decryption.js +13 -40
  23. package/dist/src/services/integrationsPlatform.d.ts +1 -1
  24. package/dist/src/services/integrationsPlatform.js +1 -8
  25. package/dist/test/commands/activity.test.js +3 -1
  26. package/dist/test/commands/invite.test.js +3 -1
  27. package/dist/test/commands/login.test.js +1 -1
  28. package/dist/test/commands/oauth2.test.js +155 -11
  29. package/dist/test/commands/publish.test.js +23 -23
  30. package/dist/test/commands/upgrade.test.js +1 -1
  31. package/dist/test/errors.test.js +1 -9
  32. package/dist/test/resources/decryption.test.js +28 -19
  33. package/dist/test/services/integrationsPlatform.test.js +0 -4
  34. package/oclif.manifest.json +36 -5
  35. package/package.json +3 -3
@@ -62,14 +62,7 @@ async function getIntegration(integrationId) {
62
62
  }
63
63
  exports.getIntegration = getIntegration;
64
64
  async function getIntegrationByName(integrationName) {
65
- let integration;
66
- try {
67
- integration = await integrations_platform_client_1.default.getIntegrationByName(integrationName);
68
- }
69
- catch {
70
- return null;
71
- }
72
- return integration;
65
+ return integrations_platform_client_1.default.getIntegrationByName(integrationName);
73
66
  }
74
67
  exports.getIntegrationByName = getIntegrationByName;
75
68
  async function getIntegrations() {
@@ -53,7 +53,9 @@ describe('activity', () => {
53
53
  });
54
54
  test_1.test
55
55
  .stdout()
56
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
56
+ .stub(IntegrationsPlatform, 'getIntegrationByName', () => {
57
+ throw new Error();
58
+ })
57
59
  .command(['activity'])
58
60
  .catch(error => {
59
61
  (0, test_1.expect)(error.message).to.equal('EEXIT: -1');
@@ -47,7 +47,9 @@ describe('invite', () => {
47
47
  test_1.test
48
48
  .stdout()
49
49
  .stub(GlobalConfiguration, 'read', () => ({ email: 'foo@bar.com' }))
50
- .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
50
+ .stub(IntegrationsPlatform, 'getIntegrationByName', () => {
51
+ throw new Error();
52
+ })
51
53
  .command(['invite'])
52
54
  .catch(error => {
53
55
  (0, test_1.expect)(error.message).to.equal('EEXIT: -1');
@@ -82,7 +82,7 @@ describe('Login', () => {
82
82
  test_1.test
83
83
  .stdout()
84
84
  .stub(GlobalConfiguration, 'read', () => {
85
- throw new errors_1.MissingEnvironmentVariableError();
85
+ throw new errors_1.ConfigurationMalformed();
86
86
  })
87
87
  .command(['login'])
88
88
  .exit(-1)
@@ -7,12 +7,13 @@ const sinon = tslib_1.__importStar(require("sinon"));
7
7
  const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
8
8
  const Configuration = tslib_1.__importStar(require("../../src/resources/configuration"));
9
9
  const oauth2Service = tslib_1.__importStar(require("../../src/services/oauth2Helper"));
10
+ const IntegrationsPlatform = tslib_1.__importStar(require("../../src/services/integrationsPlatform"));
11
+ const decryptionResource = tslib_1.__importStar(require("../../src/resources/decryption"));
10
12
  const configurationTypes_1 = require("../../src/configurationTypes");
11
13
  describe('oauth2', () => {
12
14
  const INTEGRATION_NAME = 'myintegration';
13
15
  const sandbox = sinon.createSandbox();
14
16
  let getConfigurationsStub;
15
- let writeConfigurationStub;
16
17
  let writeTestAccountStub;
17
18
  let performOAuth2FlowStub;
18
19
  let updateTokenStub;
@@ -30,7 +31,7 @@ describe('oauth2', () => {
30
31
  name: INTEGRATION_NAME,
31
32
  authorizations: [
32
33
  {
33
- name: 'development',
34
+ name: 'MyAuthorization',
34
35
  method: configurationTypes_1.Method.OAUTH2,
35
36
  oauth2: oauth2Information,
36
37
  },
@@ -48,7 +49,6 @@ describe('oauth2', () => {
48
49
  sandbox.stub(inquirer_1.default, 'prompt').resolves({
49
50
  oauth2Information: JSON.stringify(oauth2Information),
50
51
  });
51
- writeConfigurationStub = sandbox.stub(Configuration, 'writeConfiguration');
52
52
  writeTestAccountStub = sandbox.stub(Configuration, 'writeTestAccount');
53
53
  performOAuth2FlowStub = sandbox.stub(oauth2Service, 'performOAuth2Flow');
54
54
  performOAuth2FlowStub.resolves(credentials);
@@ -63,16 +63,48 @@ describe('oauth2', () => {
63
63
  ...baseConfiguration,
64
64
  authorizations: [],
65
65
  }))
66
- .command(['oauth2', '--accountName', 'development'])
67
- .it("asks for authentication information when it's not setup in the configuration file", () => {
68
- (0, test_1.expect)(writeConfigurationStub.getCall(0)?.firstArg).to.deep.equal({
69
- ...baseConfiguration,
70
- authorizations: [{ oauth2: oauth2Information, name: 'development', method: 'oauth2', development: true }],
71
- });
66
+ .command(['oauth2', '--test-account', 'development'])
67
+ .exit(-1)
68
+ .it("Errors out if no oauth2 authorization scheme is found in the integration's configuration");
69
+ test_1.test
70
+ .stdout()
71
+ .do(() => getConfigurationsStub.returns({
72
+ ...baseConfiguration,
73
+ authorizations: [
74
+ ...(baseConfiguration.authorizations ?? []),
75
+ {
76
+ name: 'Development Authorization',
77
+ method: configurationTypes_1.Method.OAUTH2,
78
+ oauth2: { ...oauth2Information, clientId: 'devClientID' },
79
+ development: true,
80
+ },
81
+ ],
82
+ }))
83
+ .command(['oauth2', '--test-account', 'development'])
84
+ .it('prioritize development authorization', () => {
85
+ (0, test_1.expect)(performOAuth2FlowStub.getCalls().length).to.equal(1);
86
+ (0, test_1.expect)(performOAuth2FlowStub.getCall(0).args).to.deep.equal([{ ...oauth2Information, clientId: 'devClientID' }]);
87
+ (0, test_1.expect)(updateTokenStub.getCalls().length).to.equal(0);
88
+ (0, test_1.expect)(writeTestAccountStub.getCall(0).args).to.deep.equal([
89
+ {
90
+ ...baseConfiguration,
91
+ authorizations: [
92
+ ...(baseConfiguration.authorizations ?? []),
93
+ {
94
+ name: 'Development Authorization',
95
+ method: configurationTypes_1.Method.OAUTH2,
96
+ oauth2: { ...oauth2Information, clientId: 'devClientID' },
97
+ development: true,
98
+ },
99
+ ],
100
+ },
101
+ credentials,
102
+ 'development',
103
+ ]);
72
104
  });
73
105
  test_1.test
74
106
  .stdout()
75
- .command(['oauth2', '--accountName', 'development'])
107
+ .command(['oauth2', '--test-account', 'development'])
76
108
  .it('performs the oauth flow when there is no test accounts and the auth information are setup', () => {
77
109
  (0, test_1.expect)(performOAuth2FlowStub.getCalls().length).to.equal(1);
78
110
  (0, test_1.expect)(updateTokenStub.getCalls().length).to.equal(0);
@@ -86,7 +118,53 @@ describe('oauth2', () => {
86
118
  development: credentials,
87
119
  },
88
120
  }))
89
- .command(['oauth2', '--accountName', 'development'])
121
+ .command(['oauth2', '--test-account', 'development', '--reauth'])
122
+ .it('performs the oauth flow when there is a test accounts, the auth information are setup and --reauth flag is present', () => {
123
+ (0, test_1.expect)(performOAuth2FlowStub.getCalls().length).to.equal(1);
124
+ (0, test_1.expect)(updateTokenStub.getCalls().length).to.equal(0);
125
+ (0, test_1.expect)(writeTestAccountStub.getCall(0).args).to.deep.equal([
126
+ {
127
+ ...baseConfiguration,
128
+ testAccounts: {
129
+ development: credentials,
130
+ },
131
+ },
132
+ credentials,
133
+ 'development',
134
+ ]);
135
+ });
136
+ test_1.test
137
+ .stdout()
138
+ .do(() => getConfigurationsStub.returns({
139
+ ...baseConfiguration,
140
+ testAccounts: {
141
+ development: { something: 'something' },
142
+ },
143
+ }))
144
+ .command(['oauth2', '--test-account', 'compliance'])
145
+ .it('performs the oauth flow when the requested test account is not setup', () => {
146
+ (0, test_1.expect)(performOAuth2FlowStub.getCalls().length).to.equal(1);
147
+ (0, test_1.expect)(updateTokenStub.getCalls().length).to.equal(0);
148
+ (0, test_1.expect)(writeTestAccountStub.getCall(0).args).to.deep.equal([
149
+ {
150
+ ...baseConfiguration,
151
+ testAccounts: {
152
+ development: { something: 'something' },
153
+ },
154
+ },
155
+ credentials,
156
+ 'compliance',
157
+ ]);
158
+ });
159
+ test_1.test
160
+ .stdout()
161
+ .do(() => getConfigurationsStub.returns({
162
+ ...baseConfiguration,
163
+ testAccounts: {
164
+ development: credentials,
165
+ },
166
+ }))
167
+ .command(['oauth2', '--test-account', 'development'])
90
168
  .it('refresh the token when there is an existing test accounts and the auth information are setup', () => {
91
169
  (0, test_1.expect)(performOAuth2FlowStub.getCalls().length).to.equal(0);
92
170
  (0, test_1.expect)(updateTokenStub.getCalls().length).to.equal(1);
@@ -101,4 +179,70 @@ describe('oauth2', () => {
101
179
  'development',
102
180
  ]);
103
181
  });
182
+ test_1.test
183
+ .stdout()
184
+ .do(() => {
185
+ getConfigurationsStub.returns({
186
+ ...baseConfiguration,
187
+ authorizations: [
188
+ {
189
+ name: 'Authorization',
190
+ method: configurationTypes_1.Method.OAUTH2,
191
+ oauth2: { ...oauth2Information, clientSecret: `${Configuration.ENCRYPTION_PREFIX}devClientID` },
192
+ },
193
+ ],
194
+ testAccounts: {
195
+ development: {
196
+ accessToken: `${Configuration.ENCRYPTION_PREFIX}devAccessToken`,
197
+ refreshToken: `${Configuration.ENCRYPTION_PREFIX}devRefreshToken`,
198
+ },
199
+ },
200
+ });
201
+ sandbox
202
+ .stub(decryptionResource, 'decryptEntries')
203
+ .onFirstCall()
204
+ .resolves({ decryptedKeys: ['clientSecret'], entries: { ...oauth2Information, clientSecret: 'devClientID' } })
205
+ .onSecondCall()
206
+ .resolves({
207
+ decryptedKeys: ['accessToken', 'refreshToken'],
208
+ entries: {
209
+ accessToken: 'devAccessToken',
210
+ refreshToken: 'devRefreshToken',
211
+ },
212
+ });
213
+ sandbox
214
+ .stub(IntegrationsPlatform, 'encryptData')
215
+ .onFirstCall()
216
+ .resolves({ encryptedData: `${Configuration.ENCRYPTION_PREFIX}encryptedAccessToken` })
217
+ .onSecondCall()
218
+ .resolves({ encryptedData: `${Configuration.ENCRYPTION_PREFIX}encryptedRefreshToken` });
219
+ })
220
+ .command(['oauth2', '--test-account', 'development'])
221
+ .it('decrypt oauth2 authorization entries and test-account', () => {
222
+ (0, test_1.expect)(performOAuth2FlowStub.getCalls().length).to.equal(0);
223
+ (0, test_1.expect)(updateTokenStub.getCalls().length).to.equal(1);
224
+ (0, test_1.expect)(writeTestAccountStub.getCall(0).args).to.deep.equal([
225
+ {
226
+ ...baseConfiguration,
227
+ authorizations: [
228
+ {
229
+ name: 'Authorization',
230
+ method: configurationTypes_1.Method.OAUTH2,
231
+ oauth2: { ...oauth2Information, clientSecret: `${Configuration.ENCRYPTION_PREFIX}devClientID` },
232
+ },
233
+ ],
234
+ testAccounts: {
235
+ development: {
236
+ accessToken: `${Configuration.ENCRYPTION_PREFIX}devAccessToken`,
237
+ refreshToken: `${Configuration.ENCRYPTION_PREFIX}devRefreshToken`,
238
+ },
239
+ },
240
+ },
241
+ {
242
+ accessToken: `${Configuration.ENCRYPTION_PREFIX}encryptedAccessToken`,
243
+ refreshToken: `${Configuration.ENCRYPTION_PREFIX}encryptedRefreshToken`,
244
+ },
245
+ 'development',
246
+ ]);
247
+ });
104
248
  });
@@ -55,7 +55,7 @@ describe('Publish', () => {
55
55
  (0, test_1.expect)(customPath).to.be.undefined;
56
56
  return { name: 'a' };
57
57
  })
58
- .stub(IntegrationsPlatform, 'getIntegrations', () => [])
58
+ .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
59
59
  .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
60
60
  .command(['publish'])
61
61
  .it('publish the integration - default', ctx => {
@@ -72,7 +72,7 @@ describe('Publish', () => {
72
72
  (0, test_1.expect)(customPath).to.equal('/custom-config.json');
73
73
  return { name: 'a' };
74
74
  })
75
- .stub(IntegrationsPlatform, 'getIntegrations', () => [])
75
+ .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
76
76
  .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
77
77
  .command(['publish', '--config-path', '/custom-config.json'])
78
78
  .it('publish the integration with custom config - default', ctx => {
@@ -89,7 +89,7 @@ describe('Publish', () => {
89
89
  (0, test_1.expect)(customPath).to.be.undefined;
90
90
  return { name: 'a' };
91
91
  })
92
- .stub(IntegrationsPlatform, 'getIntegrations', () => [])
92
+ .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
93
93
  .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
94
94
  .command(['publish', '--environment', 'local'])
95
95
  .it('publish the integration - local', ctx => {
@@ -108,7 +108,7 @@ describe('Publish', () => {
108
108
  return { name: 'a' };
109
109
  })
110
110
  .stub(IntegrationConfiguration, 'writeConfiguration', () => Promise)
111
- .stub(IntegrationsPlatform, 'getIntegrations', () => [])
111
+ .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
112
112
  .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
113
113
  .command(['publish', '--environment', 'local'])
114
114
  .it('publish the integration using .unito.local.json - local', ctx => {
@@ -126,7 +126,7 @@ describe('Publish', () => {
126
126
  (0, test_1.expect)(customPath).to.be.undefined;
127
127
  return { name: 'a' };
128
128
  })
129
- .stub(IntegrationsPlatform, 'getIntegrations', () => [])
129
+ .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
130
130
  .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
131
131
  .command(['publish', '--environment', 'staging'])
132
132
  .it('publish the integration - staging', ctx => {
@@ -145,7 +145,7 @@ describe('Publish', () => {
145
145
  return {};
146
146
  })
147
147
  .stub(IntegrationConfiguration, 'writeConfiguration', () => Promise)
148
- .stub(IntegrationsPlatform, 'getIntegrations', () => [])
148
+ .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
149
149
  .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
150
150
  .command(['publish', '--environment', 'staging'])
151
151
  .it('publish the integration using .unito.staging.json - staging', ctx => {
@@ -163,7 +163,7 @@ describe('Publish', () => {
163
163
  (0, test_1.expect)(customPath).to.equal('/my-awesome-config.json');
164
164
  return { name: 'a' };
165
165
  })
166
- .stub(IntegrationsPlatform, 'getIntegrations', () => [])
166
+ .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
167
167
  .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
168
168
  .command(['publish', '--config-path', '/my-awesome-config.json'])
169
169
  .it('publish the integration using custom configuration', ctx => {
@@ -173,7 +173,7 @@ describe('Publish', () => {
173
173
  .stdout()
174
174
  .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
175
175
  .stub(IntegrationConfiguration, 'getConfiguration', () => ({}))
176
- .stub(IntegrationsPlatform, 'getIntegrations', () => [])
176
+ .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
177
177
  .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
178
178
  .stub(inquirer_1.default, 'prompt', () => Promise.resolve({ proceed: false }))
179
179
  .command(['publish', '--registry-only'])
@@ -186,7 +186,7 @@ describe('Publish', () => {
186
186
  .stdout()
187
187
  .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
188
188
  .stub(IntegrationConfiguration, 'getConfiguration', () => ({}))
189
- .stub(IntegrationsPlatform, 'getIntegrations', () => [])
189
+ .stub(IntegrationsPlatform, 'getIntegration', () => undefined)
190
190
  .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
191
191
  .stub(inquirer_1.default, 'prompt', () => Promise.resolve({ proceed: false }))
192
192
  .command(['publish', '--registry-only', '--force'])
@@ -198,7 +198,7 @@ describe('Publish', () => {
198
198
  .stdout()
199
199
  .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
200
200
  .stub(IntegrationConfiguration, 'getConfiguration', () => ({}))
201
- .stub(IntegrationsPlatform, 'getIntegrations', () => [])
201
+ .stub(IntegrationsPlatform, 'getIntegration', () => undefined)
202
202
  .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
203
203
  .stub(inquirer_1.default, 'prompt', () => Promise.resolve({ proceed: true }))
204
204
  .command(['publish', '--registry-only'])
@@ -210,7 +210,7 @@ describe('Publish', () => {
210
210
  .stdout()
211
211
  .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
212
212
  .stub(IntegrationConfiguration, 'getConfiguration', () => ({ name: 'a' }))
213
- .stub(IntegrationsPlatform, 'getIntegrations', () => [{ name: 'a' }])
213
+ .stub(IntegrationsPlatform, 'getIntegrationByName', () => ({ name: 'a' }))
214
214
  .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
215
215
  .stub(inquirer_1.default, 'prompt', () => Promise.resolve({ proceed: true }))
216
216
  .command(['publish', '--registry-only'])
@@ -225,7 +225,7 @@ describe('Publish', () => {
225
225
  .stub(IntegrationConfiguration, 'getConfiguration', () => ({
226
226
  authorizations: [{ type: 'custom', development: true }, { type: 'oauth2' }],
227
227
  }))
228
- .stub(IntegrationsPlatform, 'getIntegrations', () => [])
228
+ .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
229
229
  // eslint-disable-next-line
230
230
  // @ts-ignore typing doesn't work here, for some reason.
231
231
  .stub(IntegrationsPlatform, 'createIntegration', (config) => config)
@@ -240,7 +240,7 @@ describe('Publish', () => {
240
240
  .stdout()
241
241
  .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
242
242
  .stub(IntegrationConfiguration, 'getConfiguration', () => ({ name: 'foo' }))
243
- .stub(IntegrationsPlatform, 'getIntegrations', () => [])
243
+ .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
244
244
  .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
245
245
  .command(['publish', '--preview'])
246
246
  .it('preview the integration', ctx => {
@@ -250,7 +250,7 @@ describe('Publish', () => {
250
250
  .stdout()
251
251
  .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
252
252
  .stub(IntegrationConfiguration, 'getConfiguration', () => ({ name: 'foo', ui: { displayName: 'Foo' } }))
253
- .stub(IntegrationsPlatform, 'getIntegrations', () => [])
253
+ .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
254
254
  // eslint-disable-next-line
255
255
  // @ts-ignore typing doesn't work here, for some reason.
256
256
  .stub(IntegrationConfiguration, 'writeConfiguration', configuration => {
@@ -281,7 +281,7 @@ describe('Publish', () => {
281
281
  .stdout()
282
282
  .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
283
283
  .stub(IntegrationConfiguration, 'getConfiguration', () => ({}))
284
- .stub(IntegrationsPlatform, 'getIntegrations', () => [])
284
+ .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
285
285
  .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
286
286
  .command(['publish', '--live-preview'])
287
287
  .it('live-preview the integration', ctx => {
@@ -291,7 +291,7 @@ describe('Publish', () => {
291
291
  .stdout()
292
292
  .stub(GlobalConfiguration, 'read', () => ({ apiKey: 'foo' }))
293
293
  .stub(IntegrationConfiguration, 'getConfiguration', () => ({ ui: { displayName: 'Foo' } }))
294
- .stub(IntegrationsPlatform, 'getIntegrations', () => [])
294
+ .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
295
295
  // eslint-disable-next-line
296
296
  // @ts-ignore typing doesn't work here, for some reason.
297
297
  .stub(IntegrationsPlatform, 'createIntegration', (config) => config)
@@ -304,7 +304,7 @@ describe('Publish', () => {
304
304
  .stderr()
305
305
  .stub(GlobalConfiguration, 'read', () => ({}))
306
306
  .stub(IntegrationConfiguration, 'getConfiguration', () => ({}))
307
- .stub(IntegrationsPlatform, 'getIntegrations', () => [])
307
+ .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
308
308
  .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
309
309
  .command(['publish'])
310
310
  .exit(-1)
@@ -333,7 +333,7 @@ describe('Publish', () => {
333
333
  authorizations: [{ name: 'oauth2', oauth2: { clientSecret: 'unito-secret-' } }],
334
334
  secrets: { secret1: 'unito-secret-', invalidSecret: 'Should never happen anyway' },
335
335
  }))
336
- .stub(IntegrationsPlatform, 'getIntegrations', () => [])
336
+ .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
337
337
  .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
338
338
  .command(['publish', '--preview'])
339
339
  .it('reencrypts the clientSecret on preview', ctx => {
@@ -349,7 +349,7 @@ describe('Publish', () => {
349
349
  authorizations: [{ name: 'oauth2', oauth2: { clientSecret: 'unito-secret-' } }],
350
350
  secrets: { secret1: 'unito-secret-', invalidSecret: 'Should never happen anyway' },
351
351
  }))
352
- .stub(IntegrationsPlatform, 'getIntegrations', () => [])
352
+ .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
353
353
  .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
354
354
  .command(['publish', '--live-preview'])
355
355
  .it('reencrypts the clientSecret on live-preview', ctx => {
@@ -364,7 +364,7 @@ describe('Publish', () => {
364
364
  name: 'myIntegration',
365
365
  authorizations: [{ name: 'oauth2', oauth2: { clientSecret: 'toto' } }],
366
366
  }))
367
- .stub(IntegrationsPlatform, 'getIntegrations', () => [])
367
+ .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
368
368
  .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('')))
369
369
  .command(['publish', '--live-preview'])
370
370
  .it('skips reencryption', ctx => {
@@ -381,7 +381,7 @@ describe('Publish', () => {
381
381
  },
382
382
  ],
383
383
  }))
384
- .stub(IntegrationsPlatform, 'getIntegrations', () => [])
384
+ .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
385
385
  .stub(FileSystem, 'getFileBuffer', () => Promise.resolve(Buffer.from('foo')))
386
386
  .stub(inquirer_1.default, 'prompt', () => Promise.resolve({ proceed: true }))
387
387
  .command(['publish', '--registry-only'])
@@ -400,7 +400,7 @@ describe('Publish', () => {
400
400
  },
401
401
  ],
402
402
  }))
403
- .stub(IntegrationsPlatform, 'getIntegrations', () => [])
403
+ .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
404
404
  .stub(FileSystem, 'getFileBuffer', () => Promise.reject())
405
405
  .stub(inquirer_1.default, 'prompt', () => Promise.resolve({ proceed: true }))
406
406
  .command(['publish', '--registry-only'])
@@ -418,7 +418,7 @@ describe('Publish', () => {
418
418
  },
419
419
  ],
420
420
  }))
421
- .stub(IntegrationsPlatform, 'getIntegrations', () => [])
421
+ .stub(IntegrationsPlatform, 'getIntegrationByName', () => undefined)
422
422
  .stub(FileSystem, 'getFileBuffer', () => null)
423
423
  .stub(inquirer_1.default, 'prompt', () => Promise.resolve({ proceed: true }))
424
424
  .command(['publish', '--registry-only'])
@@ -39,7 +39,7 @@ describe('Upgrade', () => {
39
39
  test_1.test
40
40
  .stdout()
41
41
  .stub(child_process_1.default, 'execSync', () => {
42
- throw new errors_1.MissingEnvironmentVariableError();
42
+ throw new errors_1.ConfigurationMalformed();
43
43
  })
44
44
  .command(['upgrade'])
45
45
  .exit(-1)
@@ -37,21 +37,13 @@ describe('handleError', () => {
37
37
  (0, chai_1.expect)(stdErrStub.firstCall.args[0]).to.equal(chalk_1.default.redBright('This command requires a configuration file for your integration :('));
38
38
  (0, chai_1.expect)(stdErrStub.secondCall.args[0]).to.equal(`This file should be located at ${chalk_1.default.yellowBright(path_1.default.relative(process.cwd(), (0, configuration_1.getConfigurationPath)()))}.`);
39
39
  });
40
- it('should handle MissingEnvironmentVariableError', () => {
41
- const error = new errors_1.MissingEnvironmentVariableError('VAR_NAME');
42
- const handled = (0, errors_1.handleError)(command, error);
43
- (0, chai_1.expect)(handled).to.be.true;
44
- (0, chai_1.expect)(stdErrStub.calledTwice).to.be.true;
45
- (0, chai_1.expect)(stdErrStub.firstCall.args[0]).to.equal(chalk_1.default.redBright('This command requires a variable which is missing from your environment :('));
46
- (0, chai_1.expect)(stdErrStub.secondCall.args[0]).to.equal(`Make sure the environment variable ${chalk_1.default.yellowBright('VAR_NAME')} is defined.`);
47
- });
48
40
  it('should return false for unrecognized error', () => {
49
41
  const error = new Error('Unrecognized error');
50
42
  const handled = (0, errors_1.handleError)(command, error);
51
43
  (0, chai_1.expect)(handled).to.be.false;
52
44
  (0, chai_1.expect)(stdErrStub.called).to.be.false;
53
45
  });
54
- it('should handle MissingEnvironmentVariableError', () => {
46
+ it('should handle ConfigurationInvalid', () => {
55
47
  const error = new errors_1.ConfigurationInvalid('VAR_NAME', 'details', 'prettyDetails');
56
48
  const handled = (0, errors_1.handleError)(command, error);
57
49
  (0, chai_1.expect)(handled).to.be.true;
@@ -8,7 +8,7 @@ const IntegrationsPlatform = tslib_1.__importStar(require("../../src/services/in
8
8
  const GlobalConfiguration = tslib_1.__importStar(require("../../src/resources/globalConfiguration"));
9
9
  const configuration_1 = require("../../src/resources/configuration");
10
10
  const decryptionHelper = tslib_1.__importStar(require("../../src/resources/decryption"));
11
- describe('decryptionHelper', () => {
11
+ describe('decryption helper', () => {
12
12
  const configuration = {
13
13
  name: 'a',
14
14
  baseUrl: 'b',
@@ -34,35 +34,44 @@ describe('decryptionHelper', () => {
34
34
  afterEach(() => {
35
35
  sinon_1.default.restore();
36
36
  });
37
- describe('decryptCredentials', () => {
38
- it('support unencrypted credentials', async () => {
39
- const decryptedCredentials = await decryptionHelper.decryptTestAccountCredentials(configuration, GlobalConfiguration.Environment.Local, configuration_1.CredentialScope.DEVELOPMENT, '/path/to/config');
40
- (0, chai_1.expect)(decryptedCredentials).to.deep.equal({
37
+ describe('decryptEntries', () => {
38
+ it('support unencrypted entries', async () => {
39
+ const decryptionResult = await decryptionHelper.decryptEntries(configuration.name, GlobalConfiguration.Environment.Local, '/path/to/config', {
40
+ accessToken: 'developmentToken',
41
+ accessToken1: 'developmentToken1',
42
+ });
43
+ (0, chai_1.expect)(decryptionResult.decryptedKeys).to.deep.equal([]);
44
+ (0, chai_1.expect)(decryptionResult.entries).to.deep.equal({
45
+ accessToken1: 'developmentToken1',
41
46
  accessToken: 'developmentToken',
42
47
  });
43
48
  });
44
- it('support encrypted credentials', async () => {
45
- const decryptedCredentials = await decryptionHelper.decryptTestAccountCredentials(configuration, GlobalConfiguration.Environment.Local, configuration_1.CredentialScope.COMPLIANCE, '/path/to/config');
46
- (0, chai_1.expect)(decryptedCredentials).to.deep.equal({
49
+ it('support mixed encrypted and not encrypted entries', async () => {
50
+ const decryptionResult = await decryptionHelper.decryptEntries(configuration.name, GlobalConfiguration.Environment.Local, '/path/to/config', {
51
+ accessToken: 'token',
52
+ encryptedToken: `${configuration_1.ENCRYPTION_PREFIX}decrypt-me`,
53
+ });
54
+ (0, chai_1.expect)(decryptionResult.decryptedKeys).to.deep.equal(['encryptedToken']);
55
+ (0, chai_1.expect)(decryptionResult.entries).to.deep.equal({
47
56
  accessToken: 'token',
48
57
  encryptedToken: `decrypted-me`,
49
58
  });
50
59
  });
51
- });
52
- describe('decryptSecrets', () => {
53
- it('support encrypted secrets', async () => {
54
- const decryptedSecrets = await decryptionHelper.decryptSecrets(configuration, GlobalConfiguration.Environment.Local, '/path/to/config');
55
- (0, chai_1.expect)(decryptedSecrets).to.deep.equal({
60
+ it('support multiple encrypted entries', async () => {
61
+ const decryptionResult = await decryptionHelper.decryptEntries(configuration.name, GlobalConfiguration.Environment.Local, '/path/to/config', {
62
+ encryptedSecret1: `${configuration_1.ENCRYPTION_PREFIX}decrypt-me`,
63
+ encryptedSecret2: `${configuration_1.ENCRYPTION_PREFIX}decrypt-me`,
64
+ });
65
+ (0, chai_1.expect)(decryptionResult.decryptedKeys).to.deep.equal(['encryptedSecret1', 'encryptedSecret2']);
66
+ (0, chai_1.expect)(decryptionResult.entries).to.deep.equal({
56
67
  encryptedSecret1: 'decrypted-me',
57
68
  encryptedSecret2: 'decrypted-me',
58
69
  });
59
70
  });
60
- it('support empty secrets', async () => {
61
- const decryptedSecrets = await decryptionHelper.decryptSecrets({
62
- ...configuration,
63
- secrets: {},
64
- }, GlobalConfiguration.Environment.Local, '/path/to/config');
65
- (0, chai_1.expect)(decryptedSecrets).to.deep.equal({});
71
+ it('support empty object', async () => {
72
+ const decryptionResult = await decryptionHelper.decryptEntries(configuration.name, GlobalConfiguration.Environment.Local, '/path/to/config', {});
73
+ (0, chai_1.expect)(decryptionResult.decryptedKeys).to.deep.equal([]);
74
+ (0, chai_1.expect)(decryptionResult.entries).to.deep.equal({});
66
75
  });
67
76
  });
68
77
  });
@@ -70,10 +70,6 @@ describe('integrations platform', function () {
70
70
  sinon.stub(integrations_platform_client_1.default, 'getIntegrationByName').resolves(integration);
71
71
  (0, chai_1.expect)(await IntegrationsPlatform.getIntegrationByName('foo')).to.deep.equal(integration);
72
72
  });
73
- it('getIntegrationByName - error', async function () {
74
- sinon.stub(integrations_platform_client_1.default, 'getIntegrationByName').throws();
75
- (0, chai_1.expect)(await IntegrationsPlatform.getIntegrationByName('foo')).to.deep.equal(null);
76
- });
77
73
  it('getIntegrations', async function () {
78
74
  sinon.stub(integrations_platform_client_1.default, 'getIntegrations').resolves({ total: 1, data: [integrationSummary] });
79
75
  (0, chai_1.expect)(await IntegrationsPlatform.getIntegrations()).to.deep.equal([integrationSummary]);
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.56.0",
2
+ "version": "0.56.2",
3
3
  "commands": {
4
4
  "activity": {
5
5
  "id": "activity",
@@ -201,7 +201,8 @@
201
201
  },
202
202
  "oauth2": {
203
203
  "id": "oauth2",
204
- "description": "Perform an OAuth2 workflow locally",
204
+ "summary": "Perform an OAuth2 workflow locally",
205
+ "description": "The Oauth2 command allows you to perform an OAuth2 workflow locally, either to create a new test account or to refresh an existing one.",
205
206
  "strict": true,
206
207
  "pluginName": "@unito/integration-cli",
207
208
  "pluginAlias": "@unito/integration-cli",
@@ -211,10 +212,40 @@
211
212
  "<%= config.bin %> <%= command.id %>"
212
213
  ],
213
214
  "flags": {
214
- "accountName": {
215
- "name": "accountName",
215
+ "test-account": {
216
+ "name": "test-account",
217
+ "type": "option",
218
+ "description": "Test account to use.",
219
+ "multiple": false,
220
+ "options": [
221
+ "development",
222
+ "compliance"
223
+ ],
224
+ "default": "development"
225
+ },
226
+ "environment": {
227
+ "name": "environment",
228
+ "type": "option",
229
+ "description": "the environment of the platform",
230
+ "multiple": false,
231
+ "options": [
232
+ "local",
233
+ "staging",
234
+ "production"
235
+ ],
236
+ "default": "production"
237
+ },
238
+ "reauth": {
239
+ "name": "reauth",
240
+ "type": "boolean",
241
+ "description": "triggers a new oauth2 flow to collect credentials and overwrite the current one",
242
+ "allowNo": false
243
+ },
244
+ "config-path": {
245
+ "name": "config-path",
216
246
  "type": "option",
217
- "description": "Name of the account used to perfom oauth2 actions",
247
+ "summary": "relative path to a custom \".unito.json\" file",
248
+ "description": "Use a custom configuration file instead of the default '.unito.json' or other environment specific\n ones.\n\n If you want to force the CLI to use a specific configuration file, you can use this flag to specify the relative\n path from your integration's root folder (with a leading '/').\n\n Usage: <%= config.bin %> <%= command.id %> --config-path=/myCustomConfig.json",
218
249
  "multiple": false
219
250
  }
220
251
  },