Update formatting
This commit is contained in:
@@ -203,7 +203,10 @@ describe("loadSecrets when using Connect", () => {
|
|||||||
it("sets step output when shouldExportEnv is false", async () => {
|
it("sets step output when shouldExportEnv is false", async () => {
|
||||||
await loadSecrets(false);
|
await loadSecrets(false);
|
||||||
|
|
||||||
expect(core.setOutput).toHaveBeenCalledWith("MY_SECRET", "resolved-via-connect");
|
expect(core.setOutput).toHaveBeenCalledWith(
|
||||||
|
"MY_SECRET",
|
||||||
|
"resolved-via-connect",
|
||||||
|
);
|
||||||
expect(core.exportVariable).not.toHaveBeenCalled();
|
expect(core.exportVariable).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -217,9 +220,7 @@ describe("loadSecrets when using Connect", () => {
|
|||||||
process.env.MY_SECRET = "op://my-vault-name/my-item/field";
|
process.env.MY_SECRET = "op://my-vault-name/my-item/field";
|
||||||
const mockGetVault = jest.fn().mockResolvedValue({ id: "vault-uuid" });
|
const mockGetVault = jest.fn().mockResolvedValue({ id: "vault-uuid" });
|
||||||
const mockGetItem = jest.fn().mockResolvedValue({
|
const mockGetItem = jest.fn().mockResolvedValue({
|
||||||
fields: [
|
fields: [{ label: "field", value: "secret-value", section: undefined }],
|
||||||
{ label: "field", value: "secret-value", section: undefined },
|
|
||||||
],
|
|
||||||
sections: [],
|
sections: [],
|
||||||
});
|
});
|
||||||
(OnePasswordConnect as jest.Mock).mockReturnValue({
|
(OnePasswordConnect as jest.Mock).mockReturnValue({
|
||||||
@@ -247,10 +248,16 @@ describe("loadSecrets when using Connect", () => {
|
|||||||
|
|
||||||
it("resolves vault by name and uses returned id for getItem", async () => {
|
it("resolves vault by name and uses returned id for getItem", async () => {
|
||||||
process.env.MY_SECRET = "op://My Vault/My Item/field";
|
process.env.MY_SECRET = "op://My Vault/My Item/field";
|
||||||
const mockGetVault = jest.fn().mockResolvedValue({ id: "uuid-for-my-vault" });
|
const mockGetVault = jest
|
||||||
|
.fn()
|
||||||
|
.mockResolvedValue({ id: "uuid-for-my-vault" });
|
||||||
const mockGetItem = jest.fn().mockResolvedValue({
|
const mockGetItem = jest.fn().mockResolvedValue({
|
||||||
fields: [
|
fields: [
|
||||||
{ label: "field", value: "secret-from-named-vault", section: undefined },
|
{
|
||||||
|
label: "field",
|
||||||
|
value: "secret-from-named-vault",
|
||||||
|
section: undefined,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
sections: [],
|
sections: [],
|
||||||
});
|
});
|
||||||
@@ -270,7 +277,9 @@ describe("loadSecrets when using Connect", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("calls getItem with vault id from getVault, not ref vault segment", async () => {
|
it("calls getItem with vault id from getVault, not ref vault segment", async () => {
|
||||||
const mockGetVault = jest.fn().mockResolvedValue({ id: "resolved-vault-id" });
|
const mockGetVault = jest
|
||||||
|
.fn()
|
||||||
|
.mockResolvedValue({ id: "resolved-vault-id" });
|
||||||
const mockGetItem = jest.fn().mockResolvedValue({
|
const mockGetItem = jest.fn().mockResolvedValue({
|
||||||
fields: [
|
fields: [
|
||||||
{ label: "field", value: "resolved-via-connect", section: undefined },
|
{ label: "field", value: "resolved-via-connect", section: undefined },
|
||||||
@@ -290,7 +299,9 @@ describe("loadSecrets when using Connect", () => {
|
|||||||
|
|
||||||
it("rejects when getItem fails", async () => {
|
it("rejects when getItem fails", async () => {
|
||||||
const mockGetVault = jest.fn().mockResolvedValue({ id: "vault-id-123" });
|
const mockGetVault = jest.fn().mockResolvedValue({ id: "vault-id-123" });
|
||||||
const mockGetItem = jest.fn().mockRejectedValue(new Error("Item not found"));
|
const mockGetItem = jest
|
||||||
|
.fn()
|
||||||
|
.mockRejectedValue(new Error("Item not found"));
|
||||||
(OnePasswordConnect as jest.Mock).mockReturnValue({
|
(OnePasswordConnect as jest.Mock).mockReturnValue({
|
||||||
getVault: mockGetVault,
|
getVault: mockGetVault,
|
||||||
getItem: mockGetItem,
|
getItem: mockGetItem,
|
||||||
@@ -303,7 +314,9 @@ describe("loadSecrets when using Connect", () => {
|
|||||||
delete process.env.MY_SECRET;
|
delete process.env.MY_SECRET;
|
||||||
process.env.SECRET_A = "op://vault-a/item1/field1";
|
process.env.SECRET_A = "op://vault-a/item1/field1";
|
||||||
process.env.SECRET_B = "op://vault-b/item2/field2";
|
process.env.SECRET_B = "op://vault-b/item2/field2";
|
||||||
const mockGetVault = jest.fn().mockImplementation(async (vaultName: string) =>
|
const mockGetVault = jest
|
||||||
|
.fn()
|
||||||
|
.mockImplementation(async (vaultName: string) =>
|
||||||
Promise.resolve({
|
Promise.resolve({
|
||||||
id: vaultName === "vault-a" ? "id-a" : "id-b",
|
id: vaultName === "vault-a" ? "id-a" : "id-b",
|
||||||
}),
|
}),
|
||||||
@@ -311,15 +324,11 @@ describe("loadSecrets when using Connect", () => {
|
|||||||
const mockGetItem = jest
|
const mockGetItem = jest
|
||||||
.fn()
|
.fn()
|
||||||
.mockResolvedValueOnce({
|
.mockResolvedValueOnce({
|
||||||
fields: [
|
fields: [{ label: "field1", value: "value-a", section: undefined }],
|
||||||
{ label: "field1", value: "value-a", section: undefined },
|
|
||||||
],
|
|
||||||
sections: [],
|
sections: [],
|
||||||
})
|
})
|
||||||
.mockResolvedValueOnce({
|
.mockResolvedValueOnce({
|
||||||
fields: [
|
fields: [{ label: "field2", value: "value-b", section: undefined }],
|
||||||
{ label: "field2", value: "value-b", section: undefined },
|
|
||||||
],
|
|
||||||
sections: [],
|
sections: [],
|
||||||
});
|
});
|
||||||
(OnePasswordConnect as jest.Mock).mockReturnValue({
|
(OnePasswordConnect as jest.Mock).mockReturnValue({
|
||||||
|
|||||||
Reference in New Issue
Block a user