Always output explicit "false" to prevent hijacking

This commit is contained in:
Danny Gleckler 2024-02-08 20:20:05 -05:00
parent f908277314
commit 727a4d2137
4 changed files with 17 additions and 14 deletions

View File

@ -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(

View File

@ -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(

View File

@ -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);

View File

@ -12,7 +12,10 @@ import * as utils from "./utils/actionUtils";
export async function restoreImpl(
stateProvider: IStateProvider
): Promise<string | undefined> {
core.setOutput(Outputs.SaveAlways, core.getInput(Inputs.SaveAlways));
core.setOutput(
Outputs.SaveAlways,
core.getInput(Inputs.SaveAlways) || "false"
);
try {
if (!utils.isCacheFeatureAvailable()) {