@salesforce/core 3.21.5 → 3.22.1
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/CHANGELOG.md +15 -0
- package/README.md +75 -9
- package/lib/config/configStore.js +1 -0
- package/lib/config/tokensConfig.js +1 -1
- package/lib/exported.d.ts +2 -2
- package/lib/exported.js +2 -4
- package/lib/org/authInfo.d.ts +2 -0
- package/lib/org/authInfo.js +15 -14
- package/lib/org/connection.js +1 -1
- package/lib/org/org.js +1 -1
- package/lib/org/permissionSetAssignment.js +2 -1
- package/lib/org/scratchOrgCreate.js +1 -1
- package/lib/org/scratchOrgInfoApi.js +2 -3
- package/lib/org/user.js +9 -9
- package/lib/sfProject.js +6 -2
- package/lib/stateAggregator/accessors/orgAccessor.d.ts +69 -0
- package/lib/stateAggregator/accessors/orgAccessor.js +69 -0
- package/lib/stateAggregator/accessors/tokenAccessor.d.ts +41 -0
- package/lib/stateAggregator/accessors/tokenAccessor.js +41 -0
- package/lib/stateAggregator/globalInfoConfig.js +1 -1
- package/lib/testSetup.d.ts +101 -7
- package/lib/testSetup.js +113 -18
- package/package.json +4 -2
- package/lib/config/keychainConfig.d.ts +0 -19
- package/lib/config/keychainConfig.js +0 -44
|
@@ -17,12 +17,53 @@ export declare class GlobaInfoTokenAccessor {
|
|
|
17
17
|
}
|
|
18
18
|
export declare class TokenAccessor extends AsyncOptionalCreatable {
|
|
19
19
|
private config;
|
|
20
|
+
/**
|
|
21
|
+
* Return all tokens.
|
|
22
|
+
*
|
|
23
|
+
* @param decrypt
|
|
24
|
+
* @returns {SfTokens}
|
|
25
|
+
*/
|
|
20
26
|
getAll(decrypt?: boolean): SfTokens;
|
|
27
|
+
/**
|
|
28
|
+
* Return a token for the provided name.
|
|
29
|
+
*
|
|
30
|
+
* @param name
|
|
31
|
+
* @param decrypt
|
|
32
|
+
* @returns {Optional<SfToken & Timestamp>}
|
|
33
|
+
*/
|
|
21
34
|
get(name: string, decrypt?: boolean): Optional<SfToken & Timestamp>;
|
|
35
|
+
/**
|
|
36
|
+
* Return true if a given name has a token associated with it.
|
|
37
|
+
*
|
|
38
|
+
* @param name
|
|
39
|
+
* @returns {boolean}
|
|
40
|
+
*/
|
|
22
41
|
has(name: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Set the token for the provided name.
|
|
44
|
+
*
|
|
45
|
+
* @param name
|
|
46
|
+
* @param token
|
|
47
|
+
*/
|
|
23
48
|
set(name: string, token: SfToken): void;
|
|
49
|
+
/**
|
|
50
|
+
* Update the token for the provided name.
|
|
51
|
+
*
|
|
52
|
+
* @param name
|
|
53
|
+
* @param token
|
|
54
|
+
*/
|
|
24
55
|
update(name: string, token: Partial<SfToken>): void;
|
|
56
|
+
/**
|
|
57
|
+
* Unet the token for the provided name.
|
|
58
|
+
*
|
|
59
|
+
* @param name
|
|
60
|
+
*/
|
|
25
61
|
unset(name: string): void;
|
|
62
|
+
/**
|
|
63
|
+
* Write the contents to the token file.
|
|
64
|
+
*
|
|
65
|
+
* @returns {Promise<SfTokens>}
|
|
66
|
+
*/
|
|
26
67
|
write(): Promise<SfTokens>;
|
|
27
68
|
protected init(): Promise<void>;
|
|
28
69
|
}
|
|
@@ -38,24 +38,65 @@ class GlobaInfoTokenAccessor {
|
|
|
38
38
|
}
|
|
39
39
|
exports.GlobaInfoTokenAccessor = GlobaInfoTokenAccessor;
|
|
40
40
|
class TokenAccessor extends kit_1.AsyncOptionalCreatable {
|
|
41
|
+
/**
|
|
42
|
+
* Return all tokens.
|
|
43
|
+
*
|
|
44
|
+
* @param decrypt
|
|
45
|
+
* @returns {SfTokens}
|
|
46
|
+
*/
|
|
41
47
|
getAll(decrypt = false) {
|
|
42
48
|
return this.config.getContents(decrypt) || {};
|
|
43
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Return a token for the provided name.
|
|
52
|
+
*
|
|
53
|
+
* @param name
|
|
54
|
+
* @param decrypt
|
|
55
|
+
* @returns {Optional<SfToken & Timestamp>}
|
|
56
|
+
*/
|
|
44
57
|
get(name, decrypt = false) {
|
|
45
58
|
return this.config.get(name, decrypt);
|
|
46
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Return true if a given name has a token associated with it.
|
|
62
|
+
*
|
|
63
|
+
* @param name
|
|
64
|
+
* @returns {boolean}
|
|
65
|
+
*/
|
|
47
66
|
has(name) {
|
|
48
67
|
return !!this.getAll()[name];
|
|
49
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Set the token for the provided name.
|
|
71
|
+
*
|
|
72
|
+
* @param name
|
|
73
|
+
* @param token
|
|
74
|
+
*/
|
|
50
75
|
set(name, token) {
|
|
51
76
|
this.config.set(name, token);
|
|
52
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Update the token for the provided name.
|
|
80
|
+
*
|
|
81
|
+
* @param name
|
|
82
|
+
* @param token
|
|
83
|
+
*/
|
|
53
84
|
update(name, token) {
|
|
54
85
|
this.config.update(name, token);
|
|
55
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Unet the token for the provided name.
|
|
89
|
+
*
|
|
90
|
+
* @param name
|
|
91
|
+
*/
|
|
56
92
|
unset(name) {
|
|
57
93
|
this.config.unset(name);
|
|
58
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Write the contents to the token file.
|
|
97
|
+
*
|
|
98
|
+
* @returns {Promise<SfTokens>}
|
|
99
|
+
*/
|
|
59
100
|
async write() {
|
|
60
101
|
return this.config.write();
|
|
61
102
|
}
|
|
@@ -103,7 +103,7 @@ class GlobalInfo extends configFile_1.ConfigFile {
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
exports.GlobalInfo = GlobalInfo;
|
|
106
|
-
GlobalInfo.encryptedKeys = [/token/
|
|
106
|
+
GlobalInfo.encryptedKeys = [/token/i, /password/i, /secret/i];
|
|
107
107
|
GlobalInfo.EMPTY_DATA_MODEL = {
|
|
108
108
|
[types_1.SfInfoKeys.ORGS]: {},
|
|
109
109
|
[types_1.SfInfoKeys.TOKENS]: {},
|
package/lib/testSetup.d.ts
CHANGED
|
@@ -88,14 +88,21 @@ export interface TestContext {
|
|
|
88
88
|
[configName: string]: Optional<ConfigStub>;
|
|
89
89
|
AliasesConfig?: ConfigStub;
|
|
90
90
|
AuthInfoConfig?: ConfigStub;
|
|
91
|
-
|
|
91
|
+
Config?: ConfigStub;
|
|
92
92
|
SfProjectJson?: ConfigStub;
|
|
93
93
|
TokensConfig?: ConfigStub;
|
|
94
94
|
};
|
|
95
95
|
/**
|
|
96
96
|
* An record of stubs created during instantaion.
|
|
97
97
|
*/
|
|
98
|
-
stubs
|
|
98
|
+
stubs: {
|
|
99
|
+
configRead?: sinonType.SinonStub;
|
|
100
|
+
configReadSync?: sinonType.SinonStub;
|
|
101
|
+
configWriteSync?: sinonType.SinonStub;
|
|
102
|
+
configWrite?: sinonType.SinonStub;
|
|
103
|
+
configExists?: sinonType.SinonStub;
|
|
104
|
+
configRemove?: sinonType.SinonStub;
|
|
105
|
+
};
|
|
99
106
|
/**
|
|
100
107
|
* A function used when resolving the local path. Calls localPathResolverSync by default.
|
|
101
108
|
*
|
|
@@ -157,12 +164,45 @@ export interface TestContext {
|
|
|
157
164
|
* @param value The actual stub contents. The Mock data.
|
|
158
165
|
*/
|
|
159
166
|
setConfigStubContents(name: string, value: ConfigContents): void;
|
|
167
|
+
/**
|
|
168
|
+
* Set stubs for working in the context of a SfProject
|
|
169
|
+
*/
|
|
160
170
|
inProject(inProject: boolean): void;
|
|
171
|
+
/**
|
|
172
|
+
* Stub salesforce org authorizations.
|
|
173
|
+
*/
|
|
161
174
|
stubAuths(...orgs: MockTestOrgData[]): Promise<void>;
|
|
175
|
+
/**
|
|
176
|
+
* Stub salesforce sandbox authorizations.
|
|
177
|
+
*/
|
|
162
178
|
stubSandboxes(...orgs: MockTestSandboxData[]): Promise<void>;
|
|
179
|
+
/**
|
|
180
|
+
* Stub the aliases in the global aliases config file.
|
|
181
|
+
*/
|
|
163
182
|
stubAliases(aliases: Record<string, string>, group?: AliasGroup): void;
|
|
183
|
+
/**
|
|
184
|
+
* Stub contents in the config file.
|
|
185
|
+
*/
|
|
186
|
+
stubConfig(config: Record<string, string>): void;
|
|
187
|
+
/**
|
|
188
|
+
* Stub the tokens in the global token config file.
|
|
189
|
+
*/
|
|
190
|
+
stubTokens(tokens: Record<string, string>): void;
|
|
164
191
|
}
|
|
165
|
-
|
|
192
|
+
/**
|
|
193
|
+
* A function to generate a unique id and return it in the context of a template, if supplied.
|
|
194
|
+
*
|
|
195
|
+
* A template is a string that can contain `${%s}` to be replaced with a unique id.
|
|
196
|
+
* If the template contains the "%s" placeholder, it will be replaced with the unique id otherwise the id will be appended to the template.
|
|
197
|
+
*
|
|
198
|
+
* @param options an object with the following properties:
|
|
199
|
+
* - template: a template string.
|
|
200
|
+
* - length: the length of the unique id as presented in hexadecimal.
|
|
201
|
+
*/
|
|
202
|
+
export declare function uniqid(options?: {
|
|
203
|
+
template?: string;
|
|
204
|
+
length?: number;
|
|
205
|
+
}): string;
|
|
166
206
|
/**
|
|
167
207
|
* Instantiate a @salesforce/core test context. This is automatically created by `const $$ = testSetup()`
|
|
168
208
|
* but is useful if you don't want to have a global stub of @salesforce/core and you want to isolate it to
|
|
@@ -249,10 +289,10 @@ export declare const restoreContext: (testContext: TestContext) => void;
|
|
|
249
289
|
* $$.SANDBOX.stub(MyClass.prototype, 'myMethod').returnsFake(() => {});
|
|
250
290
|
*
|
|
251
291
|
* // Set the contents that is used when aliases are read. Same for all config files.
|
|
252
|
-
* $$.
|
|
292
|
+
* $$.stubAliases({ 'myTestAlias': 'user@company.com' });
|
|
253
293
|
*
|
|
254
294
|
* // Will use the contents set above.
|
|
255
|
-
* const username =
|
|
295
|
+
* const username = (await StateAggregator.getInstance()).aliases.resolveUseranme('myTestAlias');
|
|
256
296
|
* expect(username).to.equal('user@company.com');
|
|
257
297
|
* });
|
|
258
298
|
* });
|
|
@@ -286,7 +326,29 @@ export declare const unexpectedResult: SfError;
|
|
|
286
326
|
*
|
|
287
327
|
* @param f The async function that is expected to throw.
|
|
288
328
|
*/
|
|
289
|
-
export declare function shouldThrow(f: Promise<unknown
|
|
329
|
+
export declare function shouldThrow(f: Promise<unknown>, message?: string): Promise<never>;
|
|
330
|
+
/**
|
|
331
|
+
* Use for this testing pattern:
|
|
332
|
+
* ```
|
|
333
|
+
* try {
|
|
334
|
+
* call()
|
|
335
|
+
* assert.fail('this should never happen');
|
|
336
|
+
* } catch (e) {
|
|
337
|
+
* ...
|
|
338
|
+
* }
|
|
339
|
+
*
|
|
340
|
+
* Just do this
|
|
341
|
+
*
|
|
342
|
+
* try {
|
|
343
|
+
* shouldThrowSync(call); // If this succeeds unexpectedResultError is thrown.
|
|
344
|
+
* } catch(e) {
|
|
345
|
+
* ...
|
|
346
|
+
* }
|
|
347
|
+
* ```
|
|
348
|
+
*
|
|
349
|
+
* @param f The function that is expected to throw.
|
|
350
|
+
*/
|
|
351
|
+
export declare function shouldThrowSync(f: () => unknown, message?: string): never;
|
|
290
352
|
/**
|
|
291
353
|
* A helper to determine if a subscription will use callback or errorback.
|
|
292
354
|
* Enable errback to simulate a subscription failure.
|
|
@@ -385,7 +447,11 @@ export declare class StreamingMockCometClient extends CometClient {
|
|
|
385
447
|
disconnect(): Promise<void>;
|
|
386
448
|
}
|
|
387
449
|
/**
|
|
388
|
-
* Mock class for
|
|
450
|
+
* Mock class for Salesforce Orgs.
|
|
451
|
+
*
|
|
452
|
+
* @example
|
|
453
|
+
* const testOrg = new MockTestOrgData();
|
|
454
|
+
* await $$.stubAuths(testOrg)
|
|
389
455
|
*/
|
|
390
456
|
export declare class MockTestOrgData {
|
|
391
457
|
testId: string;
|
|
@@ -410,13 +476,38 @@ export declare class MockTestOrgData {
|
|
|
410
476
|
constructor(id?: string, options?: {
|
|
411
477
|
username: string;
|
|
412
478
|
});
|
|
479
|
+
/**
|
|
480
|
+
* Add devhub username to properties.
|
|
481
|
+
*/
|
|
413
482
|
createDevHubUsername(username: string): void;
|
|
483
|
+
/**
|
|
484
|
+
* Mark this org as a devhub.
|
|
485
|
+
*/
|
|
414
486
|
makeDevHub(): void;
|
|
487
|
+
/**
|
|
488
|
+
* Returns a MockTestOrgData that represents a user created in the org.
|
|
489
|
+
*/
|
|
415
490
|
createUser(user: string): MockTestOrgData;
|
|
491
|
+
/**
|
|
492
|
+
* Return mock user information based on this org.
|
|
493
|
+
*/
|
|
416
494
|
getMockUserInfo(): JsonMap;
|
|
495
|
+
/**
|
|
496
|
+
* Return the auth config file contents.
|
|
497
|
+
*/
|
|
417
498
|
getConfig(): Promise<AuthFields>;
|
|
499
|
+
/**
|
|
500
|
+
* Return the Connection for the org.
|
|
501
|
+
*/
|
|
418
502
|
getConnection(): Promise<Connection>;
|
|
419
503
|
}
|
|
504
|
+
/**
|
|
505
|
+
* Mock class for Salesforce Sandboxes.
|
|
506
|
+
*
|
|
507
|
+
* @example
|
|
508
|
+
* const testOrg = new MockTestSandboxData();
|
|
509
|
+
* await $$.stubSandboxes(testOrg)
|
|
510
|
+
*/
|
|
420
511
|
export declare class MockTestSandboxData {
|
|
421
512
|
id: string;
|
|
422
513
|
sandboxOrgId: string;
|
|
@@ -428,5 +519,8 @@ export declare class MockTestSandboxData {
|
|
|
428
519
|
name: string;
|
|
429
520
|
username: string;
|
|
430
521
|
}>);
|
|
522
|
+
/**
|
|
523
|
+
* Return the auth config file contents.
|
|
524
|
+
*/
|
|
431
525
|
getConfig(): Promise<SandboxFields>;
|
|
432
526
|
}
|
package/lib/testSetup.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MockTestSandboxData = exports.MockTestOrgData = exports.StreamingMockCometClient = exports.StreamingMockCometSubscription = exports.StreamingMockSubscriptionCall = exports.shouldThrow = exports.unexpectedResult = exports.testSetup = exports.restoreContext = exports.stubContext = exports.instantiateContext = exports.uniqid = void 0;
|
|
3
|
+
exports.MockTestSandboxData = exports.MockTestOrgData = exports.StreamingMockCometClient = exports.StreamingMockCometSubscription = exports.StreamingMockSubscriptionCall = exports.shouldThrowSync = exports.shouldThrow = exports.unexpectedResult = exports.testSetup = exports.restoreContext = exports.stubContext = exports.instantiateContext = exports.uniqid = void 0;
|
|
4
4
|
/*
|
|
5
5
|
* Copyright (c) 2020, salesforce.com, inc.
|
|
6
6
|
* All rights reserved.
|
|
@@ -12,6 +12,7 @@ const crypto_1 = require("crypto");
|
|
|
12
12
|
const events_1 = require("events");
|
|
13
13
|
const os_1 = require("os");
|
|
14
14
|
const path_1 = require("path");
|
|
15
|
+
const util = require("util");
|
|
15
16
|
const kit_1 = require("@salesforce/kit");
|
|
16
17
|
const ts_sinon_1 = require("@salesforce/ts-sinon");
|
|
17
18
|
const ts_types_1 = require("@salesforce/ts-types");
|
|
@@ -29,9 +30,28 @@ const org_1 = require("./org");
|
|
|
29
30
|
const sandboxAccessor_1 = require("./stateAggregator/accessors/sandboxAccessor");
|
|
30
31
|
const aliasesConfig_1 = require("./config/aliasesConfig");
|
|
31
32
|
const global_1 = require("./global");
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
/**
|
|
34
|
+
* A function to generate a unique id and return it in the context of a template, if supplied.
|
|
35
|
+
*
|
|
36
|
+
* A template is a string that can contain `${%s}` to be replaced with a unique id.
|
|
37
|
+
* If the template contains the "%s" placeholder, it will be replaced with the unique id otherwise the id will be appended to the template.
|
|
38
|
+
*
|
|
39
|
+
* @param options an object with the following properties:
|
|
40
|
+
* - template: a template string.
|
|
41
|
+
* - length: the length of the unique id as presented in hexadecimal.
|
|
42
|
+
*/
|
|
43
|
+
function uniqid(options) {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
const uniqueString = (0, crypto_1.randomBytes)(Math.ceil(((_a = options === null || options === void 0 ? void 0 : options.length) !== null && _a !== void 0 ? _a : 32) / 2.0))
|
|
46
|
+
.toString('hex')
|
|
47
|
+
.slice(0, (_b = options === null || options === void 0 ? void 0 : options.length) !== null && _b !== void 0 ? _b : 32);
|
|
48
|
+
if (!(options === null || options === void 0 ? void 0 : options.template)) {
|
|
49
|
+
return uniqueString;
|
|
50
|
+
}
|
|
51
|
+
return options.template.includes('%s')
|
|
52
|
+
? util.format(options.template, uniqueString)
|
|
53
|
+
: `${options.template}${uniqueString}`;
|
|
54
|
+
}
|
|
35
55
|
exports.uniqid = uniqid;
|
|
36
56
|
function getTestLocalPath(uid) {
|
|
37
57
|
return (0, path_1.join)((0, os_1.tmpdir)(), uid, 'sfdx_core', 'local');
|
|
@@ -39,11 +59,11 @@ function getTestLocalPath(uid) {
|
|
|
39
59
|
function getTestGlobalPath(uid) {
|
|
40
60
|
return (0, path_1.join)((0, os_1.tmpdir)(), uid, 'sfdx_core', 'global');
|
|
41
61
|
}
|
|
42
|
-
function retrieveRootPathSync(isGlobal, uid =
|
|
62
|
+
function retrieveRootPathSync(isGlobal, uid = uniqid()) {
|
|
43
63
|
return isGlobal ? getTestGlobalPath(uid) : getTestLocalPath(uid);
|
|
44
64
|
}
|
|
45
65
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
46
|
-
async function retrieveRootPath(isGlobal, uid =
|
|
66
|
+
async function retrieveRootPath(isGlobal, uid = uniqid()) {
|
|
47
67
|
return retrieveRootPathSync(isGlobal, uid);
|
|
48
68
|
}
|
|
49
69
|
function defaultFakeConnectionRequest() {
|
|
@@ -99,9 +119,10 @@ const instantiateContext = (sinon) => {
|
|
|
99
119
|
TEST_LOGGER: new logger_1.Logger({
|
|
100
120
|
name: 'SFDX_Core_Test_Logger',
|
|
101
121
|
}).useMemoryLogging(),
|
|
102
|
-
id:
|
|
103
|
-
uniqid
|
|
122
|
+
id: uniqid(),
|
|
123
|
+
uniqid,
|
|
104
124
|
configStubs: {},
|
|
125
|
+
stubs: {},
|
|
105
126
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
106
127
|
localPathRetriever: async (uid) => getTestLocalPath(uid),
|
|
107
128
|
localPathRetrieverSync: getTestLocalPath,
|
|
@@ -167,6 +188,12 @@ const instantiateContext = (sinon) => {
|
|
|
167
188
|
stubAliases(aliases, group = aliasesConfig_1.AliasGroup.ORGS) {
|
|
168
189
|
this.configStubs.AliasesConfig = { contents: { [group]: aliases } };
|
|
169
190
|
},
|
|
191
|
+
stubConfig(config) {
|
|
192
|
+
this.configStubs.Config = { contents: config };
|
|
193
|
+
},
|
|
194
|
+
stubTokens(tokens) {
|
|
195
|
+
this.configStubs.TokensConfig = { contents: tokens };
|
|
196
|
+
},
|
|
170
197
|
};
|
|
171
198
|
return testContext;
|
|
172
199
|
};
|
|
@@ -235,8 +262,8 @@ const stubContext = (testContext) => {
|
|
|
235
262
|
};
|
|
236
263
|
// Mock out all config file IO for all tests. They can restore individually if they need original functionality.
|
|
237
264
|
// @ts-ignore
|
|
238
|
-
testContext.SANDBOXES.CONFIG.stub(configFile_1.ConfigFile.prototype, 'readSync').callsFake(readSync);
|
|
239
|
-
testContext.SANDBOXES.CONFIG.stub(configFile_1.ConfigFile.prototype, 'read').callsFake(read);
|
|
265
|
+
stubs.configRead = testContext.SANDBOXES.CONFIG.stub(configFile_1.ConfigFile.prototype, 'readSync').callsFake(readSync);
|
|
266
|
+
stubs.configReadSync = testContext.SANDBOXES.CONFIG.stub(configFile_1.ConfigFile.prototype, 'read').callsFake(read);
|
|
240
267
|
const writeSync = function (newContents) {
|
|
241
268
|
if (!testContext.configStubs[this.constructor.name]) {
|
|
242
269
|
testContext.configStubs[this.constructor.name] = {};
|
|
@@ -358,10 +385,10 @@ const _testSetup = (sinon) => {
|
|
|
358
385
|
* $$.SANDBOX.stub(MyClass.prototype, 'myMethod').returnsFake(() => {});
|
|
359
386
|
*
|
|
360
387
|
* // Set the contents that is used when aliases are read. Same for all config files.
|
|
361
|
-
* $$.
|
|
388
|
+
* $$.stubAliases({ 'myTestAlias': 'user@company.com' });
|
|
362
389
|
*
|
|
363
390
|
* // Will use the contents set above.
|
|
364
|
-
* const username =
|
|
391
|
+
* const username = (await StateAggregator.getInstance()).aliases.resolveUseranme('myTestAlias');
|
|
365
392
|
* expect(username).to.equal('user@company.com');
|
|
366
393
|
* });
|
|
367
394
|
* });
|
|
@@ -395,11 +422,47 @@ exports.unexpectedResult = new sfError_1.SfError('This code was expected to fail
|
|
|
395
422
|
*
|
|
396
423
|
* @param f The async function that is expected to throw.
|
|
397
424
|
*/
|
|
398
|
-
async function shouldThrow(f) {
|
|
425
|
+
async function shouldThrow(f, message) {
|
|
399
426
|
await f;
|
|
400
|
-
|
|
427
|
+
if (message) {
|
|
428
|
+
throw new sfError_1.SfError(message, 'UnexpectedResult');
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
throw exports.unexpectedResult;
|
|
432
|
+
}
|
|
401
433
|
}
|
|
402
434
|
exports.shouldThrow = shouldThrow;
|
|
435
|
+
/**
|
|
436
|
+
* Use for this testing pattern:
|
|
437
|
+
* ```
|
|
438
|
+
* try {
|
|
439
|
+
* call()
|
|
440
|
+
* assert.fail('this should never happen');
|
|
441
|
+
* } catch (e) {
|
|
442
|
+
* ...
|
|
443
|
+
* }
|
|
444
|
+
*
|
|
445
|
+
* Just do this
|
|
446
|
+
*
|
|
447
|
+
* try {
|
|
448
|
+
* shouldThrowSync(call); // If this succeeds unexpectedResultError is thrown.
|
|
449
|
+
* } catch(e) {
|
|
450
|
+
* ...
|
|
451
|
+
* }
|
|
452
|
+
* ```
|
|
453
|
+
*
|
|
454
|
+
* @param f The function that is expected to throw.
|
|
455
|
+
*/
|
|
456
|
+
function shouldThrowSync(f, message) {
|
|
457
|
+
f();
|
|
458
|
+
if (message) {
|
|
459
|
+
throw new sfError_1.SfError(message, 'UnexpectedResult');
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
throw exports.unexpectedResult;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
exports.shouldThrowSync = shouldThrowSync;
|
|
403
466
|
/**
|
|
404
467
|
* A helper to determine if a subscription will use callback or errorback.
|
|
405
468
|
* Enable errback to simulate a subscription failure.
|
|
@@ -521,10 +584,14 @@ class StreamingMockCometClient extends streamingClient_1.CometClient {
|
|
|
521
584
|
}
|
|
522
585
|
exports.StreamingMockCometClient = StreamingMockCometClient;
|
|
523
586
|
/**
|
|
524
|
-
* Mock class for
|
|
587
|
+
* Mock class for Salesforce Orgs.
|
|
588
|
+
*
|
|
589
|
+
* @example
|
|
590
|
+
* const testOrg = new MockTestOrgData();
|
|
591
|
+
* await $$.stubAuths(testOrg)
|
|
525
592
|
*/
|
|
526
593
|
class MockTestOrgData {
|
|
527
|
-
constructor(id =
|
|
594
|
+
constructor(id = uniqid(), options) {
|
|
528
595
|
this.testId = id;
|
|
529
596
|
this.userId = `user_id_${this.testId}`;
|
|
530
597
|
this.orgId = `${this.testId}`;
|
|
@@ -536,14 +603,23 @@ class MockTestOrgData {
|
|
|
536
603
|
this.authcode = `${this.testId}/authcode`;
|
|
537
604
|
this.accessToken = `${this.testId}/accessToken`;
|
|
538
605
|
this.refreshToken = `${this.testId}/refreshToken`;
|
|
539
|
-
this.redirectUri =
|
|
606
|
+
this.redirectUri = 'http://localhost:1717/OauthRedirect';
|
|
540
607
|
}
|
|
608
|
+
/**
|
|
609
|
+
* Add devhub username to properties.
|
|
610
|
+
*/
|
|
541
611
|
createDevHubUsername(username) {
|
|
542
612
|
this.devHubUsername = username;
|
|
543
613
|
}
|
|
614
|
+
/**
|
|
615
|
+
* Mark this org as a devhub.
|
|
616
|
+
*/
|
|
544
617
|
makeDevHub() {
|
|
545
618
|
this.isDevHub = true;
|
|
546
619
|
}
|
|
620
|
+
/**
|
|
621
|
+
* Returns a MockTestOrgData that represents a user created in the org.
|
|
622
|
+
*/
|
|
547
623
|
createUser(user) {
|
|
548
624
|
const userMock = new MockTestOrgData();
|
|
549
625
|
userMock.username = user;
|
|
@@ -561,6 +637,9 @@ class MockTestOrgData {
|
|
|
561
637
|
userMock.isExpired = this.isExpired;
|
|
562
638
|
return userMock;
|
|
563
639
|
}
|
|
640
|
+
/**
|
|
641
|
+
* Return mock user information based on this org.
|
|
642
|
+
*/
|
|
564
643
|
getMockUserInfo() {
|
|
565
644
|
return {
|
|
566
645
|
Id: this.userId,
|
|
@@ -576,6 +655,9 @@ class MockTestOrgData {
|
|
|
576
655
|
Email: `user_email@${this.testId}.com`,
|
|
577
656
|
};
|
|
578
657
|
}
|
|
658
|
+
/**
|
|
659
|
+
* Return the auth config file contents.
|
|
660
|
+
*/
|
|
579
661
|
async getConfig() {
|
|
580
662
|
const crypto = await crypto_2.Crypto.create();
|
|
581
663
|
const config = {};
|
|
@@ -601,19 +683,32 @@ class MockTestOrgData {
|
|
|
601
683
|
config.isDevHub = this.isDevHub;
|
|
602
684
|
return config;
|
|
603
685
|
}
|
|
686
|
+
/**
|
|
687
|
+
* Return the Connection for the org.
|
|
688
|
+
*/
|
|
604
689
|
async getConnection() {
|
|
605
690
|
return (await org_1.Org.create({ aliasOrUsername: this.username })).getConnection();
|
|
606
691
|
}
|
|
607
692
|
}
|
|
608
693
|
exports.MockTestOrgData = MockTestOrgData;
|
|
694
|
+
/**
|
|
695
|
+
* Mock class for Salesforce Sandboxes.
|
|
696
|
+
*
|
|
697
|
+
* @example
|
|
698
|
+
* const testOrg = new MockTestSandboxData();
|
|
699
|
+
* await $$.stubSandboxes(testOrg)
|
|
700
|
+
*/
|
|
609
701
|
class MockTestSandboxData {
|
|
610
|
-
constructor(id =
|
|
702
|
+
constructor(id = uniqid(), options) {
|
|
611
703
|
this.id = id;
|
|
612
704
|
this.sandboxOrgId = id;
|
|
613
705
|
this.prodOrgUsername = (options === null || options === void 0 ? void 0 : options.prodOrgUsername) || `admin_${id}@gb.org`;
|
|
614
706
|
this.sandboxName = (options === null || options === void 0 ? void 0 : options.name) || `sandbox_${id}`;
|
|
615
707
|
this.username = (options === null || options === void 0 ? void 0 : options.username) || `${this.prodOrgUsername}.sandbox`;
|
|
616
708
|
}
|
|
709
|
+
/**
|
|
710
|
+
* Return the auth config file contents.
|
|
711
|
+
*/
|
|
617
712
|
async getConfig() {
|
|
618
713
|
return {
|
|
619
714
|
sandboxOrgId: this.sandboxOrgId,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.22.1",
|
|
4
4
|
"description": "Core libraries to interact with SFDX projects, orgs, and APIs.",
|
|
5
5
|
"main": "lib/exported",
|
|
6
6
|
"types": "lib/exported.d.ts",
|
|
@@ -56,13 +56,14 @@
|
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@salesforce/dev-config": "^3.0.1",
|
|
59
|
-
"@salesforce/dev-scripts": "^2.0.
|
|
59
|
+
"@salesforce/dev-scripts": "^2.0.3",
|
|
60
60
|
"@salesforce/prettier-config": "^0.0.2",
|
|
61
61
|
"@salesforce/ts-sinon": "^1.3.21",
|
|
62
62
|
"@types/archiver": "^5.3.1",
|
|
63
63
|
"@types/debug": "0.0.31",
|
|
64
64
|
"@types/jsen": "0.0.21",
|
|
65
65
|
"@types/jsonwebtoken": "8.5.7",
|
|
66
|
+
"@types/lodash": "^4.14.182",
|
|
66
67
|
"@types/shelljs": "0.8.11",
|
|
67
68
|
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
68
69
|
"@typescript-eslint/parser": "4.33.0",
|
|
@@ -78,6 +79,7 @@
|
|
|
78
79
|
"eslint-plugin-jsdoc": "^35.1.2",
|
|
79
80
|
"eslint-plugin-prettier": "^3.1.3",
|
|
80
81
|
"husky": "^7.0.4",
|
|
82
|
+
"lodash": "^4.17.21",
|
|
81
83
|
"mocha": "^9.1.3",
|
|
82
84
|
"nyc": "^15.1.0",
|
|
83
85
|
"prettier": "^2.5.1",
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ConfigFile } from './configFile';
|
|
2
|
-
import { ConfigContents } from './configStore';
|
|
3
|
-
/**
|
|
4
|
-
* Represent a key chain config backed by a json file.
|
|
5
|
-
*/
|
|
6
|
-
export declare class KeychainConfig extends ConfigFile<ConfigFile.Options> {
|
|
7
|
-
static getFileName(): string;
|
|
8
|
-
/**
|
|
9
|
-
* Gets default options for the KeychainConfig
|
|
10
|
-
*/
|
|
11
|
-
static getDefaultOptions(): ConfigFile.Options;
|
|
12
|
-
/**
|
|
13
|
-
* Write the config file with new contents. If no new contents are passed in
|
|
14
|
-
* it will write this.contents that was set from read(). Returns the written contents.
|
|
15
|
-
*
|
|
16
|
-
* @param newContents the new contents of the file
|
|
17
|
-
*/
|
|
18
|
-
write(newContents?: ConfigContents): Promise<ConfigContents>;
|
|
19
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2020, salesforce.com, inc.
|
|
4
|
-
* All rights reserved.
|
|
5
|
-
* Licensed under the BSD 3-Clause license.
|
|
6
|
-
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.KeychainConfig = void 0;
|
|
10
|
-
const path_1 = require("path");
|
|
11
|
-
const fs = require("fs");
|
|
12
|
-
const mkdirp = require("mkdirp");
|
|
13
|
-
const configFile_1 = require("./configFile");
|
|
14
|
-
/**
|
|
15
|
-
* Represent a key chain config backed by a json file.
|
|
16
|
-
*/
|
|
17
|
-
// istanbul ignore next - getPassword/setPassword is always mocked out
|
|
18
|
-
class KeychainConfig extends configFile_1.ConfigFile {
|
|
19
|
-
static getFileName() {
|
|
20
|
-
return 'key.json';
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Gets default options for the KeychainConfig
|
|
24
|
-
*/
|
|
25
|
-
static getDefaultOptions() {
|
|
26
|
-
return configFile_1.ConfigFile.getDefaultOptions(true, KeychainConfig.getFileName());
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Write the config file with new contents. If no new contents are passed in
|
|
30
|
-
* it will write this.contents that was set from read(). Returns the written contents.
|
|
31
|
-
*
|
|
32
|
-
* @param newContents the new contents of the file
|
|
33
|
-
*/
|
|
34
|
-
async write(newContents) {
|
|
35
|
-
if (newContents != null) {
|
|
36
|
-
this.setContents(newContents);
|
|
37
|
-
}
|
|
38
|
-
await mkdirp((0, path_1.dirname)(this.getPath()));
|
|
39
|
-
await fs.promises.writeFile(this.getPath(), JSON.stringify(this.getContents(), null, 4), { mode: '600' });
|
|
40
|
-
return this.getContents();
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.KeychainConfig = KeychainConfig;
|
|
44
|
-
//# sourceMappingURL=keychainConfig.js.map
|