From 727a4d213743f2cb4da3d5cd287dc2ba4bfbc985 Mon Sep 17 00:00:00 2001 From: Danny Gleckler Date: Thu, 8 Feb 2024 20:20:05 -0500 Subject: [PATCH] Always output explicit "false" to prevent hijacking --- __tests__/restore.test.ts | 8 ++++---- __tests__/restoreImpl.test.ts | 12 ++++++------ __tests__/restoreOnly.test.ts | 6 +++--- src/restoreImpl.ts | 5 ++++- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index ff09552..1cfb246 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -177,7 +177,7 @@ test("restore with cache found for key", async () => { expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true"); expect(setCacheHitOutputMock).toHaveBeenCalledWith( "save-always-d18d746b9", - "" + "false" ); expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`); @@ -226,7 +226,7 @@ test("restore with cache found for restore key", async () => { expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false"); expect(setCacheHitOutputMock).toHaveBeenCalledWith( "save-always-d18d746b9", - "" + "false" ); expect(infoMock).toHaveBeenCalledWith( `Cache restored from key: ${restoreKey}` @@ -271,7 +271,7 @@ test("Fail restore when fail on cache miss is enabled and primary + restore keys expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); expect(setCacheHitOutputMock).toHaveBeenCalledWith( "save-always-d18d746b9", - "" + "false" ); expect(failedMock).toHaveBeenCalledWith( @@ -322,7 +322,7 @@ test("restore when fail on cache miss is enabled and primary key doesn't match r expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false"); expect(setCacheHitOutputMock).toHaveBeenCalledWith( "save-always-d18d746b9", - "" + "false" ); expect(infoMock).toHaveBeenCalledWith( diff --git a/__tests__/restoreImpl.test.ts b/__tests__/restoreImpl.test.ts index 5992473..88662a3 100644 --- a/__tests__/restoreImpl.test.ts +++ b/__tests__/restoreImpl.test.ts @@ -83,7 +83,7 @@ test("restore without AC available should no-op", async () => { expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false"); expect(setCacheHitOutputMock).toHaveBeenCalledWith( "save-always-d18d746b9", - "" + "false" ); }); @@ -103,7 +103,7 @@ test("restore on GHES without AC available should no-op", async () => { expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false"); expect(setCacheHitOutputMock).toHaveBeenCalledWith( "save-always-d18d746b9", - "" + "false" ); }); @@ -145,7 +145,7 @@ test("restore on GHES with AC available ", async () => { expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true"); expect(setCacheHitOutputMock).toHaveBeenCalledWith( "save-always-d18d746b9", - "" + "false" ); expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`); @@ -371,7 +371,7 @@ test("restore with cache found for key", async () => { expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true"); expect(setCacheHitOutputMock).toHaveBeenCalledWith( "save-always-d18d746b9", - "" + "false" ); expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`); @@ -417,7 +417,7 @@ test("restore with cache found for restore key", async () => { expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false"); expect(setCacheHitOutputMock).toHaveBeenCalledWith( "save-always-d18d746b9", - "" + "false" ); expect(infoMock).toHaveBeenCalledWith( `Cache restored from key: ${restoreKey}` @@ -465,7 +465,7 @@ test("restore with lookup-only set", async () => { expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true"); expect(setCacheHitOutputMock).toHaveBeenCalledWith( "save-always-d18d746b9", - "" + "false" ); expect(infoMock).toHaveBeenCalledWith( diff --git a/__tests__/restoreOnly.test.ts b/__tests__/restoreOnly.test.ts index 40875ec..8a0eb41 100644 --- a/__tests__/restoreOnly.test.ts +++ b/__tests__/restoreOnly.test.ts @@ -86,7 +86,7 @@ test("restore with no cache found", async () => { ); expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key); - expect(outputMock).toHaveBeenCalledWith("save-always-d18d746b9", ""); + expect(outputMock).toHaveBeenCalledWith("save-always-d18d746b9", "false"); expect(outputMock).toHaveBeenCalledTimes(2); expect(failedMock).toHaveBeenCalledTimes(0); @@ -170,7 +170,7 @@ test("restore with cache found for key", async () => { expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key); expect(outputMock).toHaveBeenCalledWith("cache-hit", "true"); expect(outputMock).toHaveBeenCalledWith("cache-matched-key", key); - expect(outputMock).toHaveBeenCalledWith("save-always-d18d746b9", ""); + expect(outputMock).toHaveBeenCalledWith("save-always-d18d746b9", "false"); expect(outputMock).toHaveBeenCalledTimes(4); @@ -214,7 +214,7 @@ test("restore with cache found for restore key", async () => { expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key); expect(outputMock).toHaveBeenCalledWith("cache-hit", "false"); expect(outputMock).toHaveBeenCalledWith("cache-matched-key", restoreKey); - expect(outputMock).toHaveBeenCalledWith("save-always-d18d746b9", ""); + expect(outputMock).toHaveBeenCalledWith("save-always-d18d746b9", "false"); expect(outputMock).toHaveBeenCalledTimes(4); diff --git a/src/restoreImpl.ts b/src/restoreImpl.ts index 98fbbde..2582f38 100644 --- a/src/restoreImpl.ts +++ b/src/restoreImpl.ts @@ -12,7 +12,10 @@ import * as utils from "./utils/actionUtils"; export async function restoreImpl( stateProvider: IStateProvider ): Promise { - core.setOutput(Outputs.SaveAlways, core.getInput(Inputs.SaveAlways)); + core.setOutput( + Outputs.SaveAlways, + core.getInput(Inputs.SaveAlways) || "false" + ); try { if (!utils.isCacheFeatureAvailable()) {