Skip to content

Commit a12f426

Browse files
Add authLogout to run cx auth logout
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b78977a commit a12f426

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

‎src/main/wrapper/CxConstants.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export enum CxConstants {
2929
SCA_REMEDIATION_PACKAGE_VERSION = "--package-version",
3030
CMD_AUTH = "auth",
3131
SUB_CMD_VALIDATE = "validate",
32+
SUB_CMD_LOGOUT = "logout",
3233
CMD_CONFIGURE = "configure",
3334
SUB_CMD_SET = "set",
3435
PROP_NAME = "--prop-name",

‎src/main/wrapper/CxWrapper.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ export class CxWrapper {
110110
return await exec.executeCommands(this.config.pathToExecutable, commands);
111111
}
112112

113+
/** Signs the cx CLI out (`cx auth logout`). No credentials are sent. */
114+
async authLogout(): Promise<CxCommandOutput> {
115+
const commands: string[] = [CxConstants.CMD_AUTH, CxConstants.SUB_CMD_LOGOUT];
116+
const exec = new ExecutionService();
117+
return await exec.executeCommands(this.config.pathToExecutable, commands);
118+
}
119+
113120
/**
114121
* Saves an API key or OAuth refresh token as the CLI's own login (`cx configure set cx_apikey`), so
115122
* every cx process of this user, such as the cx-devassist plugin, uses the same login. cx decides

‎src/tests/ConfigureApiKeyTest.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ describe("Configure API key", () => {
4545
["configure", "set", "--prop-name", "cx_apikey", "--prop-value", ""]);
4646
});
4747

48+
it('authLogout runs auth logout without credentials', async () => {
49+
const done = new CxCommandOutput();
50+
done.exitCode = 0;
51+
const spy = jest.spyOn(ExecutionService.prototype, "executeCommands").mockResolvedValue(done);
52+
53+
const output = await wrapper().authLogout();
54+
55+
expect(output.exitCode).toBe(0);
56+
expect(spy).toHaveBeenCalledWith(process.execPath, ["auth", "logout"]);
57+
});
58+
4859
it('executeSensitiveCommands returns the exit code and never logs or returns the output', async () => {
4960
const info = jest.spyOn(logger, "info");
5061
const error = jest.spyOn(logger, "error");

0 commit comments

Comments
 (0)