mirror of
https://github.com/github/codeql-action.git
synced 2026-10-03 17:41:28 +00:00
Break up wrapApiConfigurationError tests
This commit is contained in:
@@ -111,71 +111,69 @@ test.serial("getGitHubVersion for GHEC-DR", async (t) => {
|
|||||||
t.deepEqual({ type: util.GitHubVariant.GHEC_DR }, gheDotcom);
|
t.deepEqual({ type: util.GitHubVariant.GHEC_DR }, gheDotcom);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("wrapApiConfigurationError correctly wraps specific configuration errors", (t) => {
|
test("wrapApiConfigurationError doesn't wrap errors it isn't supposed to", (t) => {
|
||||||
|
const unwrappedErrors = [
|
||||||
// We don't reclassify arbitrary errors
|
// We don't reclassify arbitrary errors
|
||||||
const arbitraryError = new Error("arbitrary error");
|
new Error("arbitrary error"),
|
||||||
let res = api.wrapApiConfigurationError(arbitraryError);
|
// Same goes for arbitrary strings
|
||||||
t.is(res, arbitraryError);
|
"arbitrary error",
|
||||||
|
// If an HTTP error doesn't contain a specific error message, we don't wrap it.
|
||||||
|
new util.HTTPError("arbitrary HTTP error", 456),
|
||||||
|
];
|
||||||
|
|
||||||
// Same goes for arbitrary errors
|
for (const unwrappedError of unwrappedErrors) {
|
||||||
const configError = new util.ConfigurationError("arbitrary error");
|
const res = api.wrapApiConfigurationError(unwrappedError);
|
||||||
res = api.wrapApiConfigurationError(configError);
|
t.is(
|
||||||
t.is(res, configError);
|
res,
|
||||||
|
unwrappedError,
|
||||||
// If an HTTP error doesn't contain a specific error message, we don't
|
`${util.getErrorMessage(unwrappedError)} should not be wrapped by wrapApiConfigurationError`,
|
||||||
// wrap is an an API error.
|
);
|
||||||
const httpError = new util.HTTPError("arbitrary HTTP error", 456);
|
}
|
||||||
res = api.wrapApiConfigurationError(httpError);
|
});
|
||||||
t.is(res, httpError);
|
|
||||||
|
|
||||||
|
test("wrapApiConfigurationError correctly wraps specific configuration errors", (t) => {
|
||||||
// For other HTTP errors, we wrap them as Configuration errors if they contain
|
// For other HTTP errors, we wrap them as Configuration errors if they contain
|
||||||
// specific error messages.
|
// specific error messages.
|
||||||
const httpNotFoundError = new util.HTTPError("commit not found", 404);
|
const httpNotFoundError = new util.HTTPError("commit not found", 404);
|
||||||
res = api.wrapApiConfigurationError(httpNotFoundError);
|
|
||||||
t.deepEqual(res, new util.ConfigurationError("commit not found"));
|
|
||||||
|
|
||||||
const refNotFoundError = new util.HTTPError(
|
const refNotFoundError = new util.HTTPError(
|
||||||
"ref 'refs/heads/jitsi' not found in this repository - https://docs.github.com/rest",
|
"ref 'refs/heads/jitsi' not found in this repository - https://docs.github.com/rest",
|
||||||
404,
|
404,
|
||||||
);
|
);
|
||||||
res = api.wrapApiConfigurationError(refNotFoundError);
|
|
||||||
t.deepEqual(
|
|
||||||
res,
|
|
||||||
new util.ConfigurationError(
|
|
||||||
"ref 'refs/heads/jitsi' not found in this repository - https://docs.github.com/rest",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
const apiRateLimitError = new util.HTTPError(
|
const apiRateLimitError = new util.HTTPError(
|
||||||
"API rate limit exceeded for installation",
|
"API rate limit exceeded for installation",
|
||||||
403,
|
403,
|
||||||
);
|
);
|
||||||
res = api.wrapApiConfigurationError(apiRateLimitError);
|
|
||||||
t.deepEqual(
|
|
||||||
res,
|
|
||||||
new util.ConfigurationError("API rate limit exceeded for installation"),
|
|
||||||
);
|
|
||||||
|
|
||||||
const tokenSuggestionMessage =
|
|
||||||
"Please check that your token is valid and has the required permissions: contents: read, security-events: write";
|
|
||||||
const badCredentialsError = new util.HTTPError("Bad credentials", 401);
|
|
||||||
res = api.wrapApiConfigurationError(badCredentialsError);
|
|
||||||
t.deepEqual(res, new util.ConfigurationError(tokenSuggestionMessage));
|
|
||||||
|
|
||||||
const notFoundError = new util.HTTPError("Not Found", 404);
|
|
||||||
res = api.wrapApiConfigurationError(notFoundError);
|
|
||||||
t.deepEqual(res, new util.ConfigurationError(tokenSuggestionMessage));
|
|
||||||
|
|
||||||
const resourceNotAccessibleError = new util.HTTPError(
|
const resourceNotAccessibleError = new util.HTTPError(
|
||||||
"Resource not accessible by integration",
|
"Resource not accessible by integration",
|
||||||
403,
|
403,
|
||||||
);
|
);
|
||||||
res = api.wrapApiConfigurationError(resourceNotAccessibleError);
|
const errorsToWrap = [
|
||||||
t.deepEqual(
|
httpNotFoundError,
|
||||||
res,
|
refNotFoundError,
|
||||||
new util.ConfigurationError("Resource not accessible by integration"),
|
apiRateLimitError,
|
||||||
);
|
resourceNotAccessibleError,
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const errorToWrap of errorsToWrap) {
|
||||||
|
const res = api.wrapApiConfigurationError(errorToWrap);
|
||||||
|
t.deepEqual(res, new util.ConfigurationError(errorToWrap.message));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test("wrapApiConfigurationError wraps token errors", async (t) => {
|
||||||
|
const tokenSuggestionMessage =
|
||||||
|
"Please check that your token is valid and has the required permissions: contents: read, security-events: write";
|
||||||
|
const badCredentialsError = new util.HTTPError("Bad credentials", 401);
|
||||||
|
const notFoundError = new util.HTTPError("Not Found", 404);
|
||||||
|
const errorsToWrap = [badCredentialsError, notFoundError];
|
||||||
|
|
||||||
|
for (const errorToWrap of errorsToWrap) {
|
||||||
|
const res = api.wrapApiConfigurationError(errorToWrap);
|
||||||
|
t.deepEqual(res, new util.ConfigurationError(tokenSuggestionMessage));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test("wrapApiConfigurationError wraps enablement errors", async (t) => {
|
||||||
// Enablement errors.
|
// Enablement errors.
|
||||||
const enablementErrorMessages = [
|
const enablementErrorMessages = [
|
||||||
"Code Security must be enabled for this repository to use code scanning",
|
"Code Security must be enabled for this repository to use code scanning",
|
||||||
@@ -195,7 +193,7 @@ test("wrapApiConfigurationError correctly wraps specific configuration errors",
|
|||||||
transform(enablementErrorMessage),
|
transform(enablementErrorMessage),
|
||||||
403,
|
403,
|
||||||
);
|
);
|
||||||
res = api.wrapApiConfigurationError(enablementError);
|
const res = api.wrapApiConfigurationError(enablementError);
|
||||||
t.deepEqual(
|
t.deepEqual(
|
||||||
res,
|
res,
|
||||||
new util.ConfigurationError(
|
new util.ConfigurationError(
|
||||||
|
|||||||
Reference in New Issue
Block a user