Fix merge confict
This commit is contained in:
@@ -26,6 +26,7 @@ jest.mock("@actions/exec", () => ({
|
||||
jest.mock("@1password/op-js");
|
||||
jest.mock("@1password/sdk", () => ({
|
||||
createClient: jest.fn(),
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
Secrets: {
|
||||
validateSecretReference: jest.fn(),
|
||||
},
|
||||
@@ -153,6 +154,12 @@ describe("extractSecret", () => {
|
||||
});
|
||||
|
||||
describe("loadSecrets when using Connect", () => {
|
||||
beforeEach(() => {
|
||||
process.env[envConnectHost] = "https://localhost:8000";
|
||||
process.env[envConnectToken] = "token";
|
||||
process.env[envServiceAccountToken] = "";
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
process.env[envConnectHost] = "https://connect.example";
|
||||
process.env[envConnectToken] = "test-token";
|
||||
@@ -310,6 +317,15 @@ describe("loadSecrets when using Service Account", () => {
|
||||
expect(core.exportVariable).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("wraps createClient errors with a descriptive message", async () => {
|
||||
(createClient as jest.Mock).mockRejectedValue(
|
||||
new Error("invalid token format"),
|
||||
);
|
||||
await expect(loadSecrets(false)).rejects.toThrow(
|
||||
"Service account authentication failed: invalid token format",
|
||||
);
|
||||
});
|
||||
|
||||
describe("multiple refs", () => {
|
||||
const ref1 = "op://vault/item/field";
|
||||
const ref2 = "op://vault/other/item";
|
||||
|
||||
15
src/utils.ts
15
src/utils.ts
@@ -266,7 +266,7 @@ export const validateAuth = (): void => {
|
||||
core.info(`Authenticated with ${authType}.`);
|
||||
};
|
||||
|
||||
export const getEnvVarNamesWithSecretRefs = (): string[] =>
|
||||
const getEnvVarNamesWithSecretRefs = (): string[] =>
|
||||
Object.keys(process.env).filter(
|
||||
(key) =>
|
||||
typeof process.env[key] === "string" &&
|
||||
@@ -317,8 +317,6 @@ export const extractSecret = (
|
||||
envName: string,
|
||||
shouldExportEnv: boolean,
|
||||
): void => {
|
||||
core.info(`Populating variable: ${envName}`);
|
||||
|
||||
const ref = process.env[envName];
|
||||
if (!ref) {
|
||||
return;
|
||||
@@ -329,16 +327,7 @@ export const extractSecret = (
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldExportEnv) {
|
||||
core.exportVariable(envName, secretValue);
|
||||
} else {
|
||||
core.setOutput(envName, secretValue);
|
||||
}
|
||||
// Skip setSecret for empty strings to avoid the warning:
|
||||
// "Can't add secret mask for empty string in ##[add-mask] command."
|
||||
if (secretValue) {
|
||||
core.setSecret(secretValue);
|
||||
}
|
||||
setResolvedSecret(envName, secretValue, shouldExportEnv);
|
||||
};
|
||||
|
||||
// Connect loads secrets via the Connect JS SDK
|
||||
|
||||
Reference in New Issue
Block a user