mirror of
https://github.com/portainer/portainer.git
synced 2025-08-05 05:45:22 +02:00
fix(linters): add the bodyclose linter BE-12112 (#959)
This commit is contained in:
parent
da30780ac2
commit
3eab294908
4 changed files with 50 additions and 1 deletions
|
@ -13,6 +13,7 @@ linters:
|
|||
- intrange
|
||||
- perfsprint
|
||||
- ineffassign
|
||||
- bodyclose
|
||||
|
||||
linters-settings:
|
||||
depguard:
|
||||
|
|
|
@ -33,8 +33,13 @@ func TestLimitAccess(t *testing.T) {
|
|||
|
||||
ts := httptest.NewServer(handler)
|
||||
defer ts.Close()
|
||||
http.Get(ts.URL)
|
||||
|
||||
resp, err := http.Get(ts.URL)
|
||||
if err == nil {
|
||||
resp.Body.Close()
|
||||
}
|
||||
|
||||
resp, err = http.Get(ts.URL)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -42,6 +42,8 @@ func ValidateHelmRepositoryURL(repoUrl string, client *http.Client) error {
|
|||
return fmt.Errorf("%s is not a valid chart repository or cannot be reached: %w", repoUrl, err)
|
||||
}
|
||||
|
||||
response.Body.Close()
|
||||
|
||||
// Success is indicated with 2xx status codes. 3xx status codes indicate a redirect.
|
||||
statusOK := response.StatusCode >= 200 && response.StatusCode < 300
|
||||
if !statusOK {
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package libhelm
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/portainer/portainer/pkg/libhelm/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_ValidateHelmRepositoryURL(t *testing.T) {
|
||||
|
@ -49,3 +52,41 @@ func Test_ValidateHelmRepositoryURL(t *testing.T) {
|
|||
}(test)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateHelmRepositoryURL(t *testing.T) {
|
||||
var fail bool
|
||||
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if fail {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
// Success
|
||||
err := ValidateHelmRepositoryURL(srv.URL, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Failure
|
||||
fail = true
|
||||
|
||||
var failureURLs = []string{
|
||||
"",
|
||||
"!",
|
||||
"oci://example.com",
|
||||
"ftp://example.com",
|
||||
srv.URL,
|
||||
}
|
||||
|
||||
for _, url := range failureURLs {
|
||||
err = ValidateHelmRepositoryURL(url, nil)
|
||||
require.Error(t, err)
|
||||
|
||||
err = ValidateHelmRepositoryURL(srv.URL, nil)
|
||||
require.Error(t, err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue