fix(ci): reject failed responses when linting a remote URL
What does this MR do and why?
When glab ci lint is given a URL it fetches it and copies the response body
straight into the payload, without looking at the status code:
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
_, err = io.Copy(&stdout, resp.Body)
...
content = stdout.Bytes()A 404 page is therefore submitted to the lint API as if it were a CI configuration. Whatever the API makes of that body is reported back, so a typo in the URL, an expired link or a login redirect can be reported as a valid pipeline rather than as a fetch failure. The user is told their configuration is fine when it was never read.
This rejects any non-2xx response before the body is used:
fetching https://example.com/missing.yml: 404 Not Foundglab release download already refuses to write a file for an error status,
so failing on a bad response is the existing behaviour in this codebase rather
than a new policy.
Test coverage
Test_lintRun_remoteURL is new and uses httptest:
- a 404 response must produce an error, and the mock lint API is given no expectation, so a regression that forwards the error body would fail;
- a 200 response must still lint normally.
Checked out against main, the first case fails and the second passes, so the
test pins the behaviour being fixed rather than the fix itself.
Related issues
Closes #8411 (closed)