Only validate property value type if we care about the property

This commit is contained in:
Michael B. Gale
2026-03-09 12:10:30 +00:00
parent 8e70ae21a1
commit 9c75a5f60c
3 changed files with 36 additions and 11 deletions
+23
View File
@@ -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) => {
+8 -6
View File
@@ -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);
}
}