@salesforce/cli-plugins-testkit
Advanced tools
Comparing version 0.0.11 to 0.0.12
@@ -5,2 +5,9 @@ # Changelog | ||
### [0.0.12](https://github.com/salesforcecli/cli-plugins-testkit/compare/v0.0.11...v0.0.12) (2021-02-25) | ||
### Features | ||
* specify auth strategy ([7f07f22](https://github.com/salesforcecli/cli-plugins-testkit/commit/7f07f228ba3c4f957a5cbf81e22ffc43189a6413)) | ||
### [0.0.11](https://github.com/salesforcecli/cli-plugins-testkit/compare/v0.0.10...v0.0.11) (2021-02-25) | ||
@@ -7,0 +14,0 @@ |
@@ -0,1 +1,9 @@ | ||
export declare enum AuthStrategy { | ||
JWT = "JWT", | ||
AUTH_URL = "AUTH_URL", | ||
REUSE = "REUSE", | ||
NONE = "NONE" | ||
} | ||
export declare const prepareForJwt: (homeDir: string) => string; | ||
export declare const prepareForAuthUrl: (homeDir: string) => string; | ||
/** | ||
@@ -6,2 +14,3 @@ * Inspects the environment (via AuthStrategy) and authenticates to a devhub via JWT or AuthUrl | ||
* @param homeDir the testSession directory where credential files will be written | ||
* @param authStrategy the authorization method to use | ||
* | ||
@@ -11,5 +20,5 @@ * reads environment variables that are set by the user OR via transferExistingAuthToEnv | ||
* optional but recommended: TESTKIT_HUB_INSTANCE | ||
* required for AuthUrl: | ||
* required for AuthUrl: TESTKIT_AUTH_URL | ||
*/ | ||
export declare const testkitHubAuth: (homeDir: string) => void; | ||
export declare const testkitHubAuth: (homeDir: string, authStrategy?: AuthStrategy) => void; | ||
/** | ||
@@ -27,2 +36,2 @@ * For scenarios where a hub has already been authenticated in the environment and the username is provided, | ||
*/ | ||
export declare const transferExistingAuthToEnv: () => void; | ||
export declare const transferExistingAuthToEnv: (authStrategy?: AuthStrategy) => void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.transferExistingAuthToEnv = exports.testkitHubAuth = void 0; | ||
exports.transferExistingAuthToEnv = exports.testkitHubAuth = exports.prepareForAuthUrl = exports.prepareForJwt = exports.AuthStrategy = void 0; | ||
/* | ||
@@ -24,3 +24,3 @@ * Copyright (c) 2020, salesforce.com, inc. | ||
AuthStrategy["NONE"] = "NONE"; | ||
})(AuthStrategy || (AuthStrategy = {})); | ||
})(AuthStrategy = exports.AuthStrategy || (exports.AuthStrategy = {})); | ||
const DEFAULT_INSTANCE_URL = 'https://login.salesforce.com'; | ||
@@ -55,2 +55,14 @@ /** | ||
}; | ||
const prepareForJwt = (homeDir) => { | ||
const jwtKey = path.join(homeDir, 'jwtKey'); | ||
core_1.fs.writeFileSync(jwtKey, formatJwtKey()); | ||
return jwtKey; | ||
}; | ||
exports.prepareForJwt = prepareForJwt; | ||
const prepareForAuthUrl = (homeDir) => { | ||
const tmpUrl = path.join(homeDir, 'tmpUrl'); | ||
core_1.fs.writeFileSync(tmpUrl, kit_1.env.getString('TESTKIT_AUTH_URL', '')); | ||
return tmpUrl; | ||
}; | ||
exports.prepareForAuthUrl = prepareForAuthUrl; | ||
/** | ||
@@ -61,2 +73,3 @@ * Inspects the environment (via AuthStrategy) and authenticates to a devhub via JWT or AuthUrl | ||
* @param homeDir the testSession directory where credential files will be written | ||
* @param authStrategy the authorization method to use | ||
* | ||
@@ -66,10 +79,9 @@ * reads environment variables that are set by the user OR via transferExistingAuthToEnv | ||
* optional but recommended: TESTKIT_HUB_INSTANCE | ||
* required for AuthUrl: | ||
* required for AuthUrl: TESTKIT_AUTH_URL | ||
*/ | ||
const testkitHubAuth = (homeDir) => { | ||
const testkitHubAuth = (homeDir, authStrategy = getAuthStrategy()) => { | ||
const logger = debug_1.debug('testkit:authFromStubbedHome'); | ||
if (getAuthStrategy() === AuthStrategy.JWT) { | ||
if (authStrategy === AuthStrategy.JWT) { | ||
logger('trying jwt auth'); | ||
const jwtKey = path.join(homeDir, 'jwtKey'); | ||
core_1.fs.writeFileSync(jwtKey, formatJwtKey()); | ||
const jwtKey = exports.prepareForJwt(homeDir); | ||
const results = shell.exec(`sfdx auth:jwt:grant -d -u ${kit_1.env.getString('TESTKIT_HUB_USERNAME', '')} -i ${kit_1.env.getString('TESTKIT_JWT_CLIENT_ID', '')} -f ${jwtKey} -r ${kit_1.env.getString('TESTKIT_HUB_INSTANCE', DEFAULT_INSTANCE_URL)}`, { silent: true }); | ||
@@ -81,6 +93,5 @@ if (results.code !== 0) { | ||
} | ||
if (getAuthStrategy() === AuthStrategy.AUTH_URL) { | ||
if (authStrategy === AuthStrategy.AUTH_URL) { | ||
logger('trying to authenticate with AuthUrl'); | ||
const tmpUrl = path.join(homeDir, 'tmpUrl'); | ||
core_1.fs.writeFileSync(tmpUrl, kit_1.env.getString('TESTKIT_AUTH_URL', '')); | ||
const tmpUrl = exports.prepareForAuthUrl(homeDir); | ||
const shellOutput = shell.exec(`sfdx auth:sfdxurl:store -d -f ${tmpUrl}`, { silent: true }); | ||
@@ -123,5 +134,5 @@ logger(shellOutput); | ||
*/ | ||
const transferExistingAuthToEnv = () => { | ||
const transferExistingAuthToEnv = (authStrategy = getAuthStrategy()) => { | ||
// nothing to do if the variables are already provided | ||
if (getAuthStrategy() !== AuthStrategy.REUSE) | ||
if (authStrategy !== AuthStrategy.REUSE) | ||
return; | ||
@@ -128,0 +139,0 @@ const logger = debug_1.debug('testkit:AuthReuse'); |
export * from './genUniqueString'; | ||
export * from './execCmd'; | ||
export { prepareForAuthUrl, prepareForJwt } from './hubAuth'; | ||
export * from './testProject'; | ||
export * from './testSession'; | ||
export { Duration } from '@salesforce/kit'; |
@@ -19,5 +19,8 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Duration = void 0; | ||
exports.Duration = exports.prepareForJwt = exports.prepareForAuthUrl = void 0; | ||
__exportStar(require("./genUniqueString"), exports); | ||
__exportStar(require("./execCmd"), exports); | ||
var hubAuth_1 = require("./hubAuth"); | ||
Object.defineProperty(exports, "prepareForAuthUrl", { enumerable: true, get: function () { return hubAuth_1.prepareForAuthUrl; } }); | ||
Object.defineProperty(exports, "prepareForJwt", { enumerable: true, get: function () { return hubAuth_1.prepareForJwt; } }); | ||
__exportStar(require("./testProject"), exports); | ||
@@ -24,0 +27,0 @@ __exportStar(require("./testSession"), exports); |
import { AnyJson, Optional } from '@salesforce/ts-types'; | ||
import * as shell from 'shelljs'; | ||
import { TestProject, TestProjectOptions } from './testProject'; | ||
import { AuthStrategy } from './hubAuth'; | ||
export interface TestSessionOptions { | ||
@@ -19,2 +20,6 @@ /** | ||
setupCommands?: string[]; | ||
/** | ||
* The preferred auth method to use | ||
*/ | ||
authStrategy?: keyof typeof AuthStrategy; | ||
} | ||
@@ -43,3 +48,2 @@ /** | ||
* TESTKIT_AUTH_URL = auth url to be used with auth:sfdxurl:store | ||
*/ | ||
@@ -46,0 +50,0 @@ export declare class TestSession { |
@@ -43,3 +43,2 @@ "use strict"; | ||
* TESTKIT_AUTH_URL = auth url to be used with auth:sfdxurl:store | ||
*/ | ||
@@ -78,8 +77,9 @@ class TestSession { | ||
core_1.fs.writeJsonSync(path.join(this.dir, 'testSessionOptions.json'), JSON.parse(JSON.stringify(options))); | ||
const authStrategy = options.authStrategy ? hubAuth_1.AuthStrategy[options.authStrategy] : undefined; | ||
// have to grab this before we change the home | ||
hubAuth_1.transferExistingAuthToEnv(); | ||
hubAuth_1.transferExistingAuthToEnv(authStrategy); | ||
// Set the homedir used by this test, on the TestSession and the process | ||
process.env.USERPROFILE = process.env.HOME = this.homeDir = kit_1.env.getString('TESTKIT_HOMEDIR', this.dir); | ||
process.env.SFDX_USE_GENERIC_UNIX_KEYCHAIN = 'true'; | ||
hubAuth_1.testkitHubAuth(this.homeDir); | ||
hubAuth_1.testkitHubAuth(this.homeDir, authStrategy); | ||
// Run all setup commands | ||
@@ -86,0 +86,0 @@ this.setupCommands(options.setupCommands); |
{ | ||
"name": "@salesforce/cli-plugins-testkit", | ||
"description": "Provides test utilities to assist Salesforce CLI plug-in authors with writing non-unit tests (NUT).", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"author": "Salesforce", | ||
@@ -6,0 +6,0 @@ "license": "BSD-3-Clause", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54055
991