mirror of
https://github.com/github/codeql-action.git
synced 2026-04-29 02:18:47 +00:00
Only validate property value type if we care about the property
This commit is contained in:
@@ -64,6 +64,29 @@ test.serial(
|
||||
},
|
||||
);
|
||||
|
||||
test.serial(
|
||||
"loadPropertiesFromApi does not throw for unexpected value types of unknown properties",
|
||||
async (t) => {
|
||||
sinon.stub(api, "getRepositoryProperties").resolves({
|
||||
headers: {},
|
||||
status: 200,
|
||||
url: "",
|
||||
data: [{ property_name: "not-used-by-us", value: { foo: "bar" } }],
|
||||
});
|
||||
const logger = getRunnerLogger(true);
|
||||
const mockRepositoryNwo = parseRepositoryNwo("owner/repo");
|
||||
await t.notThrowsAsync(
|
||||
properties.loadPropertiesFromApi(
|
||||
{
|
||||
type: util.GitHubVariant.DOTCOM,
|
||||
},
|
||||
logger,
|
||||
mockRepositoryNwo,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test.serial(
|
||||
"loadPropertiesFromApi returns empty object if on GHES",
|
||||
async (t) => {
|
||||
|
||||
@@ -85,13 +85,15 @@ export async function loadPropertiesFromApi(
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof property.value !== "string") {
|
||||
throw new Error(
|
||||
`Expected repository property '${property.property_name}' to have a string value, but got: ${JSON.stringify(property)}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (isKnownPropertyName(property.property_name)) {
|
||||
// Only validate the type of `value` if this is a property we care about, to avoid throwing
|
||||
// on unrelated properties that may use representations we do not support.
|
||||
if (typeof property.value !== "string") {
|
||||
throw new Error(
|
||||
`Expected repository property '${property.property_name}' to have a string value, but got: ${JSON.stringify(property)}`,
|
||||
);
|
||||
}
|
||||
|
||||
setProperty(properties, property.property_name, property.value, logger);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user