@unito/integration-cli 1.3.5 → 1.5.0
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/boilerplate/package-lock.json +6 -6
- package/dist/schemas/configuration.json +3 -15
- package/dist/src/commands/activity.js +5 -6
- package/dist/src/commands/dev.d.ts +0 -1
- package/dist/src/commands/dev.js +15 -24
- package/dist/src/commands/encrypt.js +3 -4
- package/dist/src/commands/graph.d.ts +0 -1
- package/dist/src/commands/graph.js +14 -23
- package/dist/src/commands/invite.js +5 -6
- package/dist/src/commands/login.js +4 -5
- package/dist/src/commands/oauth2.d.ts +0 -1
- package/dist/src/commands/oauth2.js +17 -39
- package/dist/src/commands/publish.js +7 -8
- package/dist/src/commands/schema-snapshot.js +9 -15
- package/dist/src/commands/test.js +15 -24
- package/dist/src/configurationTypes.d.ts +3 -14
- package/dist/src/resources/configuration.d.ts +1 -5
- package/dist/src/resources/configuration.js +11 -28
- package/dist/test/commands/dev.test.js +4 -6
- package/dist/test/commands/encrypt.test.js +2 -2
- package/dist/test/commands/graph.test.js +1 -3
- package/dist/test/commands/oauth2.test.js +36 -64
- package/dist/test/commands/publish.test.js +23 -23
- package/dist/test/commands/test.test.js +5 -18
- package/dist/test/resources/configuration.test.js +28 -80
- package/dist/test/resources/decryption.test.js +3 -8
- package/oclif.manifest.json +14 -70
- package/package.json +1 -1
|
@@ -19,7 +19,7 @@ class Test extends baseCommand_1.BaseCommand {
|
|
|
19
19
|
environment: core_1.Flags.custom({
|
|
20
20
|
description: 'the environment of the platform',
|
|
21
21
|
options: Object.values(GlobalConfiguration.Environment),
|
|
22
|
-
default: GlobalConfiguration.Environment.
|
|
22
|
+
default: GlobalConfiguration.Environment.Local,
|
|
23
23
|
})(),
|
|
24
24
|
verbose: core_1.Flags.boolean({
|
|
25
25
|
description: 'output more (debug) information',
|
|
@@ -45,11 +45,6 @@ class Test extends baseCommand_1.BaseCommand {
|
|
|
45
45
|
description: '(advanced) credential to use.',
|
|
46
46
|
exclusive: ['credential-payload'],
|
|
47
47
|
}),
|
|
48
|
-
'test-account': core_1.Flags.string({
|
|
49
|
-
description: 'test account to use.',
|
|
50
|
-
options: Object.values(configuration_1.CredentialScope),
|
|
51
|
-
default: configuration_1.CredentialScope.DEVELOPMENT,
|
|
52
|
-
}),
|
|
53
48
|
'read-only': core_1.Flags.boolean({
|
|
54
49
|
description: 'whether or not to only perform read operations',
|
|
55
50
|
allowNo: true,
|
|
@@ -113,12 +108,11 @@ class Test extends baseCommand_1.BaseCommand {
|
|
|
113
108
|
core_1.ux.action.stop();
|
|
114
109
|
}
|
|
115
110
|
// Resolve the configuration.
|
|
116
|
-
const
|
|
117
|
-
const configuration = await (0, configuration_1.getConfiguration)(environment, flags['config-path']);
|
|
111
|
+
const configuration = await (0, configuration_1.getConfiguration)(flags.environment, flags['config-path']);
|
|
118
112
|
let credentialPayload = '{}';
|
|
119
113
|
let readOnly = flags['read-only'] ?? false;
|
|
120
114
|
if (flags['credential-id']) {
|
|
121
|
-
const credential = await (0, credentials_1.fetchCredential)(environment, this.config.configDir, flags['credential-id']);
|
|
115
|
+
const credential = await (0, credentials_1.fetchCredential)(flags.environment, this.config.configDir, flags['credential-id']);
|
|
122
116
|
credentialPayload = JSON.stringify({
|
|
123
117
|
...credential.payload,
|
|
124
118
|
unitoCredentialId: credential.id,
|
|
@@ -130,27 +124,24 @@ class Test extends baseCommand_1.BaseCommand {
|
|
|
130
124
|
else if (flags['credential-payload']) {
|
|
131
125
|
credentialPayload = flags['credential-payload'];
|
|
132
126
|
}
|
|
133
|
-
else {
|
|
134
|
-
const
|
|
135
|
-
if (
|
|
136
|
-
|
|
137
|
-
if (decryptedEntries.failed.length) {
|
|
138
|
-
throw new errors_1.EntryDecryptionError(decryptedEntries.failed.at(0), environment);
|
|
139
|
-
}
|
|
140
|
-
credentialPayload = JSON.stringify({
|
|
141
|
-
...decryptedEntries.successful,
|
|
142
|
-
unitoCredentialId: flags['test-account'],
|
|
143
|
-
unitoUserId: flags['test-account'],
|
|
144
|
-
});
|
|
127
|
+
else if (configuration.testAccount && Object.keys(configuration.testAccount).length) {
|
|
128
|
+
const decryptedEntries = await (0, decryption_1.decryptEntries)(configuration.name, flags.environment, this.config.configDir, configuration.testAccount);
|
|
129
|
+
if (decryptedEntries.failed.length) {
|
|
130
|
+
throw new errors_1.EntryDecryptionError(decryptedEntries.failed.at(0), flags.environment);
|
|
145
131
|
}
|
|
132
|
+
credentialPayload = JSON.stringify({
|
|
133
|
+
...decryptedEntries.successful,
|
|
134
|
+
unitoCredentialId: 'testAccount',
|
|
135
|
+
unitoUserId: 'testAccount',
|
|
136
|
+
});
|
|
146
137
|
}
|
|
147
138
|
// Load secrets.
|
|
148
|
-
const { successful: secrets, failed: failedSecrets } = await (0, decryption_1.decryptEntries)(configuration.name, environment, this.config.configDir, configuration.secrets ?? {});
|
|
139
|
+
const { successful: secrets, failed: failedSecrets } = await (0, decryption_1.decryptEntries)(configuration.name, flags.environment, this.config.configDir, configuration.secrets ?? {});
|
|
149
140
|
if (failedSecrets.length) {
|
|
150
|
-
throw new errors_1.EntryDecryptionError(failedSecrets.at(0), environment);
|
|
141
|
+
throw new errors_1.EntryDecryptionError(failedSecrets.at(0), flags.environment);
|
|
151
142
|
}
|
|
152
143
|
// Load environment variables.
|
|
153
|
-
const { successful: environmentVariables, failed: failedEnvironmentVariables } = await (0, decryption_1.decryptEntries)(configuration.name, environment, this.config.configDir, configuration.environmentVariables ?? {});
|
|
144
|
+
const { successful: environmentVariables, failed: failedEnvironmentVariables } = await (0, decryption_1.decryptEntries)(configuration.name, flags.environment, this.config.configDir, configuration.environmentVariables ?? {});
|
|
154
145
|
for (const environmentVariable of failedEnvironmentVariables) {
|
|
155
146
|
if (!process.env[environmentVariable]) {
|
|
156
147
|
core_1.ux.log();
|
|
@@ -53,21 +53,10 @@ export interface Configuration {
|
|
|
53
53
|
*/
|
|
54
54
|
authorizations?: Authorization[];
|
|
55
55
|
/**
|
|
56
|
-
* The test
|
|
56
|
+
* The test account of the integration
|
|
57
57
|
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
* Test account for local development
|
|
61
|
-
*/
|
|
62
|
-
development?: {
|
|
63
|
-
[k: string]: unknown;
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* Test account for compliance tests
|
|
67
|
-
*/
|
|
68
|
-
compliance?: {
|
|
69
|
-
[k: string]: unknown;
|
|
70
|
-
};
|
|
58
|
+
testAccount?: {
|
|
59
|
+
[k: string]: unknown;
|
|
71
60
|
};
|
|
72
61
|
/**
|
|
73
62
|
* The secrets of the integration
|
|
@@ -5,10 +5,6 @@ export declare enum CrawlMode {
|
|
|
5
5
|
SAMPLE = "sample",
|
|
6
6
|
SINGLE = "single"
|
|
7
7
|
}
|
|
8
|
-
export declare enum CredentialScope {
|
|
9
|
-
DEVELOPMENT = "development",
|
|
10
|
-
COMPLIANCE = "compliance"
|
|
11
|
-
}
|
|
12
8
|
export declare const DEFAULT_CONFIGURATION_NAME: string;
|
|
13
9
|
export declare const ENCRYPTION_PREFIX = "unito-secret-v1://";
|
|
14
10
|
/**
|
|
@@ -27,4 +23,4 @@ export declare function writeConfiguration(configuration: Configuration, environ
|
|
|
27
23
|
export declare function writeTestAccount(configuration: Configuration, environment: Environment | undefined, customConfigPath: string | undefined, account: {
|
|
28
24
|
accessToken: string;
|
|
29
25
|
refreshToken?: string;
|
|
30
|
-
}
|
|
26
|
+
}): Promise<void>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ENCRYPTION_PREFIX = exports.DEFAULT_CONFIGURATION_NAME = exports.
|
|
3
|
+
exports.ENCRYPTION_PREFIX = exports.DEFAULT_CONFIGURATION_NAME = exports.CrawlMode = void 0;
|
|
4
4
|
exports.getConfigurationPath = getConfigurationPath;
|
|
5
5
|
exports.getConfiguration = getConfiguration;
|
|
6
6
|
exports.writeConfiguration = writeConfiguration;
|
|
@@ -20,11 +20,6 @@ var CrawlMode;
|
|
|
20
20
|
CrawlMode["SAMPLE"] = "sample";
|
|
21
21
|
CrawlMode["SINGLE"] = "single";
|
|
22
22
|
})(CrawlMode || (exports.CrawlMode = CrawlMode = {}));
|
|
23
|
-
var CredentialScope;
|
|
24
|
-
(function (CredentialScope) {
|
|
25
|
-
CredentialScope["DEVELOPMENT"] = "development";
|
|
26
|
-
CredentialScope["COMPLIANCE"] = "compliance";
|
|
27
|
-
})(CredentialScope || (exports.CredentialScope = CredentialScope = {}));
|
|
28
23
|
exports.DEFAULT_CONFIGURATION_NAME = '.unito.json';
|
|
29
24
|
exports.ENCRYPTION_PREFIX = 'unito-secret-v1://';
|
|
30
25
|
/**
|
|
@@ -63,12 +58,7 @@ async function getConfiguration(environment, customConfigPath) {
|
|
|
63
58
|
throw new errors_1.ConfigurationMalformed();
|
|
64
59
|
}
|
|
65
60
|
// Initialize the required structure in the configuration.
|
|
66
|
-
|
|
67
|
-
configuration.testAccounts = { development: {} };
|
|
68
|
-
}
|
|
69
|
-
if (!configuration.testAccounts.development) {
|
|
70
|
-
configuration.testAccounts.development = {};
|
|
71
|
-
}
|
|
61
|
+
configuration.testAccount ??= {};
|
|
72
62
|
for (const authorization of configuration.authorizations ?? []) {
|
|
73
63
|
if (authorization.oauth2) {
|
|
74
64
|
if (!authorization.oauth2.grantType) {
|
|
@@ -96,13 +86,8 @@ async function writeConfiguration(configuration, environment = globalConfigurati
|
|
|
96
86
|
: getConfigurationPath(environment);
|
|
97
87
|
await fs.promises.writeFile(configurationPath, JSON.stringify(configuration, null, 2));
|
|
98
88
|
}
|
|
99
|
-
async function writeTestAccount(configuration, environment = globalConfiguration_1.Environment.Production, customConfigPath, account
|
|
100
|
-
|
|
101
|
-
if (accountName !== 'development' && accountName !== 'compliance') {
|
|
102
|
-
throw new Error('Invalid account name');
|
|
103
|
-
}
|
|
104
|
-
configuration.testAccounts ??= {};
|
|
105
|
-
configuration.testAccounts[accountName] = { ...configuration.testAccounts[accountName], ...account };
|
|
89
|
+
async function writeTestAccount(configuration, environment = globalConfiguration_1.Environment.Production, customConfigPath, account) {
|
|
90
|
+
configuration.testAccount = { ...configuration.testAccount, ...account };
|
|
106
91
|
await writeConfiguration(configuration, environment, customConfigPath);
|
|
107
92
|
}
|
|
108
93
|
async function validateConfiguration(configuration) {
|
|
@@ -124,22 +109,20 @@ async function validateConfiguration(configuration) {
|
|
|
124
109
|
if (validate.errors) {
|
|
125
110
|
throw new errors_1.ConfigurationInvalid('Your configuration file is invalid!', validate.errors, (0, better_ajv_errors_1.default)(schema, configuration, validate.errors, { indent: 2 }));
|
|
126
111
|
}
|
|
127
|
-
// Validate test
|
|
128
|
-
if (configuration.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
}
|
|
112
|
+
// Validate the test account.
|
|
113
|
+
if (configuration.testAccount &&
|
|
114
|
+
Object.keys(configuration.testAccount).length &&
|
|
115
|
+
configuration.authorizations?.length) {
|
|
116
|
+
validateTestAccount(configuration.testAccount, configuration.authorizations, spec);
|
|
134
117
|
}
|
|
135
118
|
}
|
|
136
|
-
function validateTestAccount(
|
|
119
|
+
function validateTestAccount(credential, authorizationDefinitions, spec) {
|
|
137
120
|
const authorizationSchemas = authorizationDefinitions.map(constructAuthorizationSchema);
|
|
138
121
|
const schema = { anyOf: authorizationSchemas };
|
|
139
122
|
const validate = spec.compile(schema);
|
|
140
123
|
validate(credential);
|
|
141
124
|
if (validate.errors) {
|
|
142
|
-
throw new errors_1.ConfigurationInvalid(`Your testAccount
|
|
125
|
+
throw new errors_1.ConfigurationInvalid(`Your testAccount is invalid!`, validate.errors, (0, better_ajv_errors_1.default)(schema, credential, validate.errors, { indent: 2 }));
|
|
143
126
|
}
|
|
144
127
|
}
|
|
145
128
|
function constructAuthorizationSchema(authorizationDefinition) {
|
|
@@ -26,11 +26,9 @@ describe('Dev', () => {
|
|
|
26
26
|
secrets: {
|
|
27
27
|
secret: 'encryptedSecret',
|
|
28
28
|
},
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
encryptedToken: `${ConfigurationResource.ENCRYPTION_PREFIX}decrypt-me`,
|
|
33
|
-
},
|
|
29
|
+
testAccount: {
|
|
30
|
+
key: 'value',
|
|
31
|
+
encryptedToken: `${ConfigurationResource.ENCRYPTION_PREFIX}decrypt-me`,
|
|
34
32
|
},
|
|
35
33
|
};
|
|
36
34
|
let execSyncStub;
|
|
@@ -62,7 +60,7 @@ describe('Dev', () => {
|
|
|
62
60
|
.stub(ConfigurationResource, 'getConfiguration', stub => stub.returns(cliConfiguration))
|
|
63
61
|
.command(['dev'])
|
|
64
62
|
.it('decrypts credentials', () => {
|
|
65
|
-
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--credential-payload={"key":"value","encryptedToken":"decrypted-me","unitoCredentialId":"
|
|
63
|
+
(0, test_1.expect)(spawnStub.getCall(0).args.at(1)).to.include('--credential-payload={"key":"value","encryptedToken":"decrypted-me","unitoCredentialId":"testAccount","unitoUserId":"testAccount"}');
|
|
66
64
|
});
|
|
67
65
|
test_1.test
|
|
68
66
|
.stdout()
|
|
@@ -34,14 +34,14 @@ describe('encrypt', () => {
|
|
|
34
34
|
test_1.test
|
|
35
35
|
.stdout()
|
|
36
36
|
.stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' }))
|
|
37
|
-
.command(['encrypt'])
|
|
37
|
+
.command(['encrypt', '--environment=production'])
|
|
38
38
|
.it('encrypts data - default', ctx => {
|
|
39
39
|
(0, test_1.expect)(ctx.stdout).to.contains('Encrypted Data:');
|
|
40
40
|
});
|
|
41
41
|
test_1.test
|
|
42
42
|
.stdout()
|
|
43
43
|
.stub(GlobalConfiguration, 'read', stub => stub.returns({ apiKey: 'foo' }))
|
|
44
|
-
.command(['encrypt', '--sensitive'])
|
|
44
|
+
.command(['encrypt', '--sensitive', '--environment=production'])
|
|
45
45
|
.it('encrypts data - sensitive', ctx => {
|
|
46
46
|
(0, test_1.expect)(ctx.stdout).to.contains('Encrypted Data:');
|
|
47
47
|
});
|
|
@@ -11,9 +11,7 @@ const Integrations = tslib_1.__importStar(require("../../src/resources/integrati
|
|
|
11
11
|
const originalReadFile = fs_1.default.promises.readFile.bind(fs_1.default.promises);
|
|
12
12
|
const MOCK_CONFIG = {
|
|
13
13
|
name: 'salesforce-v2',
|
|
14
|
-
|
|
15
|
-
development: { token: 'test-token' },
|
|
16
|
-
},
|
|
14
|
+
testAccount: { token: 'test-token' },
|
|
17
15
|
secrets: {},
|
|
18
16
|
};
|
|
19
17
|
const MOCK_RESPONSE = {
|
|
@@ -35,7 +35,6 @@ describe('oauth2', () => {
|
|
|
35
35
|
oauth2: oauth2Information,
|
|
36
36
|
},
|
|
37
37
|
],
|
|
38
|
-
testAccounts: {},
|
|
39
38
|
};
|
|
40
39
|
const credentials = {
|
|
41
40
|
accessToken: 'accessToken',
|
|
@@ -62,7 +61,7 @@ describe('oauth2', () => {
|
|
|
62
61
|
...baseConfiguration,
|
|
63
62
|
authorizations: [],
|
|
64
63
|
}))
|
|
65
|
-
.command(['oauth2'
|
|
64
|
+
.command(['oauth2'])
|
|
66
65
|
.exit(-1)
|
|
67
66
|
.it("Errors out if no oauth2 authorization scheme is found in the integration's configuration");
|
|
68
67
|
test_1.test
|
|
@@ -88,12 +87,12 @@ describe('oauth2', () => {
|
|
|
88
87
|
.resolves({ encryptedData: `${Configuration.ENCRYPTION_PREFIX}encryptedRefreshToken` });
|
|
89
88
|
})
|
|
90
89
|
.stub(DecryptionResource, 'decryptEntries', stub => stub.resolves({ successful: { ...oauth2Information, clientId: 'devClientID' }, failed: [] }))
|
|
91
|
-
.command(['oauth2'
|
|
90
|
+
.command(['oauth2'])
|
|
92
91
|
.it('prioritize development authorization', () => {
|
|
93
92
|
(0, test_1.expect)(performOAuth2FlowStub.getCalls().length).to.equal(1);
|
|
94
93
|
(0, test_1.expect)(performOAuth2FlowStub.getCall(0).args).to.deep.equal([
|
|
95
94
|
{ ...oauth2Information, clientId: 'devClientID' },
|
|
96
|
-
'
|
|
95
|
+
'local',
|
|
97
96
|
undefined,
|
|
98
97
|
]);
|
|
99
98
|
(0, test_1.expect)(updateTokenStub.getCalls().length).to.equal(0);
|
|
@@ -110,10 +109,9 @@ describe('oauth2', () => {
|
|
|
110
109
|
},
|
|
111
110
|
],
|
|
112
111
|
},
|
|
113
|
-
'
|
|
112
|
+
'local',
|
|
114
113
|
undefined,
|
|
115
114
|
credentials,
|
|
116
|
-
'development',
|
|
117
115
|
]);
|
|
118
116
|
});
|
|
119
117
|
test_1.test
|
|
@@ -121,9 +119,7 @@ describe('oauth2', () => {
|
|
|
121
119
|
.do(() => {
|
|
122
120
|
getConfigurationsStub.returns({
|
|
123
121
|
...baseConfiguration,
|
|
124
|
-
|
|
125
|
-
development: credentials,
|
|
126
|
-
},
|
|
122
|
+
testAccount: credentials,
|
|
127
123
|
});
|
|
128
124
|
sinon
|
|
129
125
|
.stub(IntegrationsPlatform, 'encryptData')
|
|
@@ -133,21 +129,18 @@ describe('oauth2', () => {
|
|
|
133
129
|
.resolves({ encryptedData: `${Configuration.ENCRYPTION_PREFIX}encryptedRefreshToken` });
|
|
134
130
|
})
|
|
135
131
|
.stub(DecryptionResource, 'decryptEntries', stub => stub.resolves({ successful: { ...oauth2Information }, failed: [] }))
|
|
136
|
-
.command(['oauth2', '--
|
|
137
|
-
.it('performs the oauth flow when there is a test
|
|
132
|
+
.command(['oauth2', '--reauth'])
|
|
133
|
+
.it('performs the oauth flow when there is a test account, the auth information are setup and --reauth flag is present', () => {
|
|
138
134
|
(0, test_1.expect)(performOAuth2FlowStub.getCalls().length).to.equal(1);
|
|
139
135
|
(0, test_1.expect)(updateTokenStub.getCalls().length).to.equal(0);
|
|
140
136
|
(0, test_1.expect)(writeTestAccountStub.getCall(0).args).to.deep.equal([
|
|
141
137
|
{
|
|
142
138
|
...baseConfiguration,
|
|
143
|
-
|
|
144
|
-
development: credentials,
|
|
145
|
-
},
|
|
139
|
+
testAccount: credentials,
|
|
146
140
|
},
|
|
147
|
-
'
|
|
141
|
+
'local',
|
|
148
142
|
undefined,
|
|
149
143
|
credentials,
|
|
150
|
-
'development',
|
|
151
144
|
]);
|
|
152
145
|
});
|
|
153
146
|
test_1.test
|
|
@@ -155,9 +148,7 @@ describe('oauth2', () => {
|
|
|
155
148
|
.do(() => {
|
|
156
149
|
getConfigurationsStub.returns({
|
|
157
150
|
...baseConfiguration,
|
|
158
|
-
|
|
159
|
-
development: { something: 'something' },
|
|
160
|
-
},
|
|
151
|
+
testAccount: {},
|
|
161
152
|
});
|
|
162
153
|
sinon
|
|
163
154
|
.stub(IntegrationsPlatform, 'encryptData')
|
|
@@ -167,21 +158,18 @@ describe('oauth2', () => {
|
|
|
167
158
|
.resolves({ encryptedData: `${Configuration.ENCRYPTION_PREFIX}encryptedRefreshToken` });
|
|
168
159
|
})
|
|
169
160
|
.stub(DecryptionResource, 'decryptEntries', stub => stub.resolves({ successful: { ...oauth2Information }, failed: [] }))
|
|
170
|
-
.command(['oauth2'
|
|
171
|
-
.it('performs the oauth flow when the
|
|
161
|
+
.command(['oauth2'])
|
|
162
|
+
.it('performs the oauth flow when the test account is not setup', () => {
|
|
172
163
|
(0, test_1.expect)(performOAuth2FlowStub.getCalls().length).to.equal(1);
|
|
173
164
|
(0, test_1.expect)(updateTokenStub.getCalls().length).to.equal(0);
|
|
174
165
|
(0, test_1.expect)(writeTestAccountStub.getCall(0).args).to.deep.equal([
|
|
175
166
|
{
|
|
176
167
|
...baseConfiguration,
|
|
177
|
-
|
|
178
|
-
development: { something: 'something' },
|
|
179
|
-
},
|
|
168
|
+
testAccount: {},
|
|
180
169
|
},
|
|
181
|
-
'
|
|
170
|
+
'local',
|
|
182
171
|
undefined,
|
|
183
172
|
credentials,
|
|
184
|
-
'compliance',
|
|
185
173
|
]);
|
|
186
174
|
});
|
|
187
175
|
test_1.test
|
|
@@ -189,9 +177,7 @@ describe('oauth2', () => {
|
|
|
189
177
|
.do(() => {
|
|
190
178
|
getConfigurationsStub.returns({
|
|
191
179
|
...baseConfiguration,
|
|
192
|
-
|
|
193
|
-
development: credentials,
|
|
194
|
-
},
|
|
180
|
+
testAccount: credentials,
|
|
195
181
|
});
|
|
196
182
|
sinon
|
|
197
183
|
.stub(IntegrationsPlatform, 'encryptData')
|
|
@@ -201,21 +187,18 @@ describe('oauth2', () => {
|
|
|
201
187
|
.resolves({ encryptedData: `${Configuration.ENCRYPTION_PREFIX}encryptedRefreshToken` });
|
|
202
188
|
})
|
|
203
189
|
.stub(DecryptionResource, 'decryptEntries', stub => stub.resolves({ successful: { ...oauth2Information }, failed: [] }))
|
|
204
|
-
.command(['oauth2'
|
|
205
|
-
.it('refresh the token when there is an existing test
|
|
190
|
+
.command(['oauth2'])
|
|
191
|
+
.it('refresh the token when there is an existing test account and the auth information are setup', () => {
|
|
206
192
|
(0, test_1.expect)(performOAuth2FlowStub.getCalls().length).to.equal(0);
|
|
207
193
|
(0, test_1.expect)(updateTokenStub.getCalls().length).to.equal(1);
|
|
208
194
|
(0, test_1.expect)(writeTestAccountStub.getCall(0).args).to.deep.equal([
|
|
209
195
|
{
|
|
210
196
|
...baseConfiguration,
|
|
211
|
-
|
|
212
|
-
development: credentials,
|
|
213
|
-
},
|
|
197
|
+
testAccount: credentials,
|
|
214
198
|
},
|
|
215
|
-
'
|
|
199
|
+
'local',
|
|
216
200
|
undefined,
|
|
217
201
|
credentials,
|
|
218
|
-
'development',
|
|
219
202
|
]);
|
|
220
203
|
});
|
|
221
204
|
test_1.test
|
|
@@ -230,11 +213,9 @@ describe('oauth2', () => {
|
|
|
230
213
|
oauth2: { ...oauth2Information, clientSecret: `${Configuration.ENCRYPTION_PREFIX}devClientID` },
|
|
231
214
|
},
|
|
232
215
|
],
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
refreshToken: `${Configuration.ENCRYPTION_PREFIX}devRefreshToken`,
|
|
237
|
-
},
|
|
216
|
+
testAccount: {
|
|
217
|
+
accessToken: `${Configuration.ENCRYPTION_PREFIX}devAccessToken`,
|
|
218
|
+
refreshToken: `${Configuration.ENCRYPTION_PREFIX}devRefreshToken`,
|
|
238
219
|
},
|
|
239
220
|
});
|
|
240
221
|
sinon
|
|
@@ -256,8 +237,8 @@ describe('oauth2', () => {
|
|
|
256
237
|
.onSecondCall()
|
|
257
238
|
.resolves({ encryptedData: `${Configuration.ENCRYPTION_PREFIX}encryptedRefreshToken` });
|
|
258
239
|
})
|
|
259
|
-
.command(['oauth2'
|
|
260
|
-
.it('decrypt oauth2 authorization entries and test
|
|
240
|
+
.command(['oauth2'])
|
|
241
|
+
.it('decrypt oauth2 authorization entries and test account', () => {
|
|
261
242
|
(0, test_1.expect)(performOAuth2FlowStub.getCalls().length).to.equal(0);
|
|
262
243
|
(0, test_1.expect)(updateTokenStub.getCalls().length).to.equal(1);
|
|
263
244
|
(0, test_1.expect)(writeTestAccountStub.getCall(0).args).to.deep.equal([
|
|
@@ -270,20 +251,17 @@ describe('oauth2', () => {
|
|
|
270
251
|
oauth2: { ...oauth2Information, clientSecret: `${Configuration.ENCRYPTION_PREFIX}devClientID` },
|
|
271
252
|
},
|
|
272
253
|
],
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
refreshToken: `${Configuration.ENCRYPTION_PREFIX}devRefreshToken`,
|
|
277
|
-
},
|
|
254
|
+
testAccount: {
|
|
255
|
+
accessToken: `${Configuration.ENCRYPTION_PREFIX}devAccessToken`,
|
|
256
|
+
refreshToken: `${Configuration.ENCRYPTION_PREFIX}devRefreshToken`,
|
|
278
257
|
},
|
|
279
258
|
},
|
|
280
|
-
'
|
|
259
|
+
'local',
|
|
281
260
|
undefined,
|
|
282
261
|
{
|
|
283
262
|
accessToken: `${Configuration.ENCRYPTION_PREFIX}encryptedAccessToken`,
|
|
284
263
|
refreshToken: `${Configuration.ENCRYPTION_PREFIX}encryptedRefreshToken`,
|
|
285
264
|
},
|
|
286
|
-
'development',
|
|
287
265
|
]);
|
|
288
266
|
});
|
|
289
267
|
test_1.test
|
|
@@ -291,9 +269,7 @@ describe('oauth2', () => {
|
|
|
291
269
|
.stderr()
|
|
292
270
|
.do(() => getConfigurationsStub.returns({
|
|
293
271
|
...baseConfiguration,
|
|
294
|
-
|
|
295
|
-
development: { something: 'something' },
|
|
296
|
-
},
|
|
272
|
+
testAccount: { something: 'something' },
|
|
297
273
|
}))
|
|
298
274
|
.stub(DecryptionResource, 'decryptEntries', stub => stub.resolves({ successful: {}, failed: ['boom!'] }))
|
|
299
275
|
.command(['oauth2'])
|
|
@@ -308,9 +284,7 @@ describe('oauth2', () => {
|
|
|
308
284
|
.do(() => {
|
|
309
285
|
getConfigurationsStub.returns({
|
|
310
286
|
...baseConfiguration,
|
|
311
|
-
|
|
312
|
-
development: credentials,
|
|
313
|
-
},
|
|
287
|
+
testAccount: credentials,
|
|
314
288
|
});
|
|
315
289
|
sinon
|
|
316
290
|
.stub(IntegrationsPlatform, 'encryptData')
|
|
@@ -324,7 +298,7 @@ describe('oauth2', () => {
|
|
|
324
298
|
.resolves({ successful: { ...oauth2Information }, failed: [] })
|
|
325
299
|
.onSecondCall()
|
|
326
300
|
.resolves({ successful: { refreshToken: 'test-refresh-token' }, failed: [] }))
|
|
327
|
-
.command(['oauth2', '--
|
|
301
|
+
.command(['oauth2', '--environment', 'staging'])
|
|
328
302
|
.it('passes the staging environment to updateToken when specified', () => {
|
|
329
303
|
(0, test_1.expect)(performOAuth2FlowStub.getCalls().length).to.equal(0);
|
|
330
304
|
(0, test_1.expect)(updateTokenStub.getCalls().length).to.equal(1);
|
|
@@ -341,9 +315,7 @@ describe('oauth2', () => {
|
|
|
341
315
|
.do(() => {
|
|
342
316
|
getConfigurationsStub.returns({
|
|
343
317
|
...baseConfiguration,
|
|
344
|
-
|
|
345
|
-
development: credentials,
|
|
346
|
-
},
|
|
318
|
+
testAccount: credentials,
|
|
347
319
|
});
|
|
348
320
|
sinon
|
|
349
321
|
.stub(IntegrationsPlatform, 'encryptData')
|
|
@@ -357,16 +329,16 @@ describe('oauth2', () => {
|
|
|
357
329
|
.resolves({ successful: { ...oauth2Information }, failed: [] })
|
|
358
330
|
.onSecondCall()
|
|
359
331
|
.resolves({ successful: { refreshToken: 'test-refresh-token' }, failed: [] }))
|
|
360
|
-
.command(['oauth2'
|
|
361
|
-
.it('defaults to
|
|
332
|
+
.command(['oauth2'])
|
|
333
|
+
.it('defaults to local environment when no environment flag is specified', () => {
|
|
362
334
|
(0, test_1.expect)(performOAuth2FlowStub.getCalls().length).to.equal(0);
|
|
363
335
|
(0, test_1.expect)(updateTokenStub.getCalls().length).to.equal(1);
|
|
364
|
-
// Verify that updateToken was called with the default
|
|
336
|
+
// Verify that updateToken was called with the default local environment
|
|
365
337
|
const updateTokenCall = updateTokenStub.getCall(0);
|
|
366
338
|
(0, test_1.expect)(updateTokenCall.args).to.have.lengthOf(4);
|
|
367
339
|
(0, test_1.expect)(updateTokenCall.args[0]).to.deep.equal(oauth2Information); // oauth2 config
|
|
368
340
|
(0, test_1.expect)(updateTokenCall.args[1]).to.equal('test-refresh-token'); // refresh token
|
|
369
341
|
(0, test_1.expect)(updateTokenCall.args[2]).to.deep.equal({ refreshToken: 'test-refresh-token' }); // credential payload
|
|
370
|
-
(0, test_1.expect)(updateTokenCall.args[3]).to.equal('
|
|
342
|
+
(0, test_1.expect)(updateTokenCall.args[3]).to.equal('local'); // environment (default)
|
|
371
343
|
});
|
|
372
344
|
});
|