Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/devfile/sample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"path"
"strings"
"testing"
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestGetRegistrySamples(t *testing.T) {
registryServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// fmt.Printf("Mock registry server handles %s\n", r.URL.Path)
if r.URL.Path == "/index/sample" {
samples, loadErr := ioutil.ReadFile(path.Join(test.registryFolder, "sample.json"))
samples, loadErr := os.ReadFile(path.Join(test.registryFolder, "sample.json"))
if loadErr != nil {
t.Errorf("Could not read samples: %v", loadErr)
w.WriteHeader(http.StatusInternalServerError)
Expand Down
8 changes: 4 additions & 4 deletions pkg/graphql/resolver/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"

Expand All @@ -29,7 +29,7 @@ func (r *K8sResolver) FetchURL(ctx context.Context, args struct{ URL string }) (
r.K8sProxy.ServeHTTP(rr, request)
result := rr.Result()
defer result.Body.Close()
body, err := ioutil.ReadAll(result.Body)
body, err := io.ReadAll(result.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -98,7 +98,7 @@ func (r *K8sResolver) SelfSubjectReview(ctx context.Context) (*SelfSubjectReview
result := rr.Result()
defer result.Body.Close()
if result.StatusCode < 200 || result.StatusCode > 299 {
body, err := ioutil.ReadAll(result.Body)
body, err := io.ReadAll(result.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -143,7 +143,7 @@ func (r *K8sResolver) SelfSubjectAccessReview(ctx context.Context, args SSARArgs
result := rr.Result()
defer result.Body.Close()
if result.StatusCode < 200 || result.StatusCode > 299 {
body, err := ioutil.ReadAll(result.Body)
body, err := io.ReadAll(result.Body)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/helm/actions/auth_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package actions

import (
"io/ioutil"
"os"
"testing"

Comment on lines 3 to 6
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Don’t ignore os.ReadFile errors in tests.

If ./server.crt / ./server.key can’t be read, the test will proceed with empty/nil data and fail later in less obvious ways.

Proposed fix
 			if tt.hasTLS {
-				cert, _ := os.ReadFile("./server.crt")
-				key, _ := os.ReadFile("./server.key")
+				cert, err := os.ReadFile("./server.crt")
+				require.NoError(t, err)
+				key, err := os.ReadFile("./server.key")
+				require.NoError(t, err)
 				tlsSecret := &v1.Secret{
 					Data: map[string][]byte{
 						tlsSecretCertKey: cert,
 						tlsSecretKey:     key,
 					},
 					ObjectMeta: metav1.ObjectMeta{Name: "test-tls", Namespace: configNamespace},
 				}
 				objs = append(objs, tlsSecret)
 			}

Also applies to: 71-82

🤖 Prompt for AI Agents
In @pkg/helm/actions/auth_test.go around lines 3 - 6, The test currently calls
os.ReadFile for "./server.crt" and "./server.key" but ignores the returned
errors; change these calls to check the error and fail the test immediately (use
t.Fatalf or t.Fatal) when os.ReadFile returns a non-nil error so the test stops
with a clear message about failing to read the certificate/key (refer to the
variables holding the cert/key bytes and the test function in
pkg/helm/actions/auth_test.go where the reads occur, lines around the existing
os.ReadFile calls).

configv1 "github.com/openshift/api/config/v1"
Expand Down Expand Up @@ -69,8 +69,8 @@ func TestAuthenticationDoesNotSetRepoURL(t *testing.T) {
}

if tt.hasTLS {
cert, _ := ioutil.ReadFile("./server.crt")
key, _ := ioutil.ReadFile("./server.key")
cert, _ := os.ReadFile("./server.crt")
key, _ := os.ReadFile("./server.key")
tlsSecret := &v1.Secret{
Data: map[string][]byte{
tlsSecretCertKey: cert,
Expand Down
15 changes: 8 additions & 7 deletions pkg/helm/actions/get_chart_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package actions

import (
"io/ioutil"
"io"
"os"
"testing"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -89,7 +90,7 @@ func TestGetChartWithoutTls(t *testing.T) {
actionConfig := &action.Configuration{
RESTClientGetter: FakeConfig{},
Releases: store,
KubeClient: &kubefake.PrintingKubeClient{Out: ioutil.Discard},
KubeClient: &kubefake.PrintingKubeClient{Out: io.Discard},
Capabilities: chartutil.DefaultCapabilities,
Log: func(format string, v ...interface{}) {},
}
Expand Down Expand Up @@ -202,7 +203,7 @@ func TestGetChartWithTlsData(t *testing.T) {
actionConfig := &action.Configuration{
RESTClientGetter: FakeConfig{},
Releases: store,
KubeClient: &kubefake.PrintingKubeClient{Out: ioutil.Discard},
KubeClient: &kubefake.PrintingKubeClient{Out: io.Discard},
Capabilities: chartutil.DefaultCapabilities,
Log: func(format string, v ...interface{}) {},
}
Expand All @@ -216,9 +217,9 @@ func TestGetChartWithTlsData(t *testing.T) {
}
// create a secret in required namespace
if test.createSecret {
certificate, errCert := ioutil.ReadFile("./server.crt")
certificate, errCert := os.ReadFile("./server.crt")
require.NoError(t, errCert)
key, errKey := ioutil.ReadFile("./server.key")
key, errKey := os.ReadFile("./server.key")
require.NoError(t, errKey)
data := map[string][]byte{
tlsSecretKey: key,
Expand All @@ -229,7 +230,7 @@ func TestGetChartWithTlsData(t *testing.T) {
}
//create a configMap in openshift-config namespace
if test.createConfigMap {
caCert, err := ioutil.ReadFile("./cacert.pem")
caCert, err := os.ReadFile("./cacert.pem")
require.NoError(t, err)
data := map[string]string{
caBundleKey: string(caCert),
Expand Down Expand Up @@ -336,7 +337,7 @@ func TestGetChartBasicAuth(t *testing.T) {
actionConfig := &action.Configuration{
RESTClientGetter: FakeConfig{},
Releases: store,
KubeClient: &kubefake.PrintingKubeClient{Out: ioutil.Discard},
KubeClient: &kubefake.PrintingKubeClient{Out: io.Discard},
Capabilities: chartutil.DefaultCapabilities,
Log: func(format string, v ...interface{}) {},
}
Expand Down
13 changes: 7 additions & 6 deletions pkg/helm/actions/get_release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package actions

import (
"fmt"
"io/ioutil"
"io"
"os"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -70,7 +71,7 @@ func TestGetRelease(t *testing.T) {
actionConfig := &action.Configuration{
RESTClientGetter: FakeConfig{},
Releases: store,
KubeClient: &kubefake.PrintingKubeClient{Out: ioutil.Discard},
KubeClient: &kubefake.PrintingKubeClient{Out: io.Discard},
Capabilities: chartutil.DefaultCapabilities,
Log: func(format string, v ...interface{}) {},
}
Expand Down Expand Up @@ -155,7 +156,7 @@ func TestGetReleaseWithTlsData(t *testing.T) {
actionConfig := &action.Configuration{
RESTClientGetter: FakeConfig{},
Releases: store,
KubeClient: &kubefake.PrintingKubeClient{Out: ioutil.Discard},
KubeClient: &kubefake.PrintingKubeClient{Out: io.Discard},
Capabilities: chartutil.DefaultCapabilities,
Log: func(format string, v ...interface{}) {},
}
Expand All @@ -166,9 +167,9 @@ func TestGetReleaseWithTlsData(t *testing.T) {
}
// create a secret in required namespace
if tt.createSecret {
certificate, errCert := ioutil.ReadFile("./server.crt")
certificate, errCert := os.ReadFile("./server.crt")
require.NoError(t, errCert)
key, errKey := ioutil.ReadFile("./server.key")
key, errKey := os.ReadFile("./server.key")
require.NoError(t, errKey)
data := map[string][]byte{
tlsSecretKey: key,
Expand All @@ -179,7 +180,7 @@ func TestGetReleaseWithTlsData(t *testing.T) {
}
//create a configMap in openshift-config namespace
if tt.createConfigMap {
caCert, err := ioutil.ReadFile("./cacert.pem")
caCert, err := os.ReadFile("./cacert.pem")
require.NoError(t, err)
data := map[string]string{
caBundleKey: string(caCert),
Expand Down
19 changes: 10 additions & 9 deletions pkg/helm/actions/install_chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package actions

import (
"fmt"
"io/ioutil"
"io"
"os"
"testing"
"time"

Expand Down Expand Up @@ -94,7 +95,7 @@ func TestInstallChart(t *testing.T) {
actionConfig := &action.Configuration{
RESTClientGetter: FakeConfig{},
Releases: store,
KubeClient: &kubefake.PrintingKubeClient{Out: ioutil.Discard},
KubeClient: &kubefake.PrintingKubeClient{Out: io.Discard},
Capabilities: chartutil.DefaultCapabilities,
Log: func(format string, v ...interface{}) {},
}
Expand Down Expand Up @@ -173,7 +174,7 @@ func TestInstallChartWithTlsData(t *testing.T) {
actionConfig := &action.Configuration{
RESTClientGetter: FakeConfig{},
Releases: store,
KubeClient: &kubefake.PrintingKubeClient{Out: ioutil.Discard},
KubeClient: &kubefake.PrintingKubeClient{Out: io.Discard},
Capabilities: chartutil.DefaultCapabilities,
Log: func(format string, v ...interface{}) {},
}
Expand All @@ -184,9 +185,9 @@ func TestInstallChartWithTlsData(t *testing.T) {
}
// create a secret in required namespace
if tt.createSecret {
certificate, errCert := ioutil.ReadFile("./server.crt")
certificate, errCert := os.ReadFile("./server.crt")
require.NoError(t, errCert)
key, errKey := ioutil.ReadFile("./server.key")
key, errKey := os.ReadFile("./server.key")
require.NoError(t, errKey)
data := map[string][]byte{
tlsSecretKey: key,
Expand All @@ -197,7 +198,7 @@ func TestInstallChartWithTlsData(t *testing.T) {
}
//create a configMap in openshift-config namespace
if tt.createConfigMap {
caCert, err := ioutil.ReadFile("./cacert.pem")
caCert, err := os.ReadFile("./cacert.pem")
require.NoError(t, err)
data := map[string]string{
caBundleKey: string(caCert),
Expand Down Expand Up @@ -270,7 +271,7 @@ func TestInstallChartBasicAuth(t *testing.T) {
actionConfig := &action.Configuration{
RESTClientGetter: FakeConfig{},
Releases: store,
KubeClient: &kubefake.PrintingKubeClient{Out: ioutil.Discard},
KubeClient: &kubefake.PrintingKubeClient{Out: io.Discard},
Capabilities: chartutil.DefaultCapabilities,
Log: func(format string, v ...interface{}) {},
}
Expand All @@ -293,7 +294,7 @@ func TestInstallChartBasicAuth(t *testing.T) {
}
//create a configMap in openshift-config namespace
if tt.createConfigMap {
caCert, err := ioutil.ReadFile("./cacert.pem")
caCert, err := os.ReadFile("./cacert.pem")
require.NoError(t, err)
data := map[string]string{
caBundleKey: string(caCert),
Expand Down Expand Up @@ -357,7 +358,7 @@ func TestInstallChartAsync(t *testing.T) {
actionConfig := &action.Configuration{
RESTClientGetter: FakeConfig{},
Releases: store,
KubeClient: &kubefake.PrintingKubeClient{Out: ioutil.Discard},
KubeClient: &kubefake.PrintingKubeClient{Out: io.Discard},
Capabilities: chartutil.DefaultCapabilities,
Log: func(format string, v ...interface{}) {},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/helm/actions/list_releases_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package actions

import (
"io/ioutil"
"io"
"testing"

"helm.sh/helm/v3/pkg/action"
Expand Down Expand Up @@ -44,7 +44,7 @@ func TestListReleases(t *testing.T) {
err := store.Create(&tt.release)
actionConfig := &action.Configuration{
Releases: store,
KubeClient: &kubefake.PrintingKubeClient{Out: ioutil.Discard},
KubeClient: &kubefake.PrintingKubeClient{Out: io.Discard},
Capabilities: chartutil.DefaultCapabilities,
Log: func(format string, v ...interface{}) {},
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/helm/actions/release_history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package actions

import (
"fmt"
"io/ioutil"
"io"
"testing"

"helm.sh/helm/v3/pkg/action"
Expand Down Expand Up @@ -40,7 +40,7 @@ func TestGetReleaseHistory(t *testing.T) {
store := storage.Init(driver.NewMemory())
actionConfig := &action.Configuration{
Releases: store,
KubeClient: &kubefake.PrintingKubeClient{Out: ioutil.Discard},
KubeClient: &kubefake.PrintingKubeClient{Out: io.Discard},
Capabilities: chartutil.DefaultCapabilities,
Log: func(format string, v ...interface{}) {},
}
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestNonExistGetReleaseHistory(t *testing.T) {
store := storage.Init(driver.NewMemory())
actionConfig := &action.Configuration{
Releases: store,
KubeClient: &kubefake.PrintingKubeClient{Out: ioutil.Discard},
KubeClient: &kubefake.PrintingKubeClient{Out: io.Discard},
Capabilities: chartutil.DefaultCapabilities,
Log: func(format string, v ...interface{}) {},
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/helm/actions/rollback_release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package actions
import (
"errors"
"fmt"
"io/ioutil"
"io"
"testing"

"helm.sh/helm/v3/pkg/action"
Expand Down Expand Up @@ -52,7 +52,7 @@ func TestRollbackRelease(t *testing.T) {
// create fake release
actionConfig := &action.Configuration{
Releases: store,
KubeClient: &kubefake.PrintingKubeClient{Out: ioutil.Discard},
KubeClient: &kubefake.PrintingKubeClient{Out: io.Discard},
Capabilities: chartutil.DefaultCapabilities,
Log: func(format string, v ...interface{}) {},
}
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestRollbackNonExistRelease(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
actionConfig := &action.Configuration{
Releases: store,
KubeClient: &kubefake.PrintingKubeClient{Out: ioutil.Discard},
KubeClient: &kubefake.PrintingKubeClient{Out: io.Discard},
Capabilities: chartutil.DefaultCapabilities,
Log: func(format string, v ...interface{}) {},
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/helm/actions/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package actions

import (
"fmt"
"io/ioutil"
"io"
"os"
"os/exec"
"testing"
Expand Down Expand Up @@ -91,13 +91,13 @@ func ExecuteScript(filepath string, waitForCompletion bool) error {
tlsCmd.Stderr = os.Stderr
err := tlsCmd.Start()
if err != nil {
bytes, _ := ioutil.ReadAll(os.Stderr)
bytes, _ := io.ReadAll(os.Stderr)
return fmt.Errorf("Error starting program :%s:%s:%w", filepath, string(bytes), err)
}
if waitForCompletion {
err = tlsCmd.Wait()
if err != nil {
bytes, _ := ioutil.ReadAll(os.Stderr)
bytes, _ := io.ReadAll(os.Stderr)
return fmt.Errorf("Error waiting program :%s:%s:%w", filepath, string(bytes), err)
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/helm/actions/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package actions

import (
"encoding/json"
"io/ioutil"
"io"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestRenderManifests(t *testing.T) {
actionConfig := &action.Configuration{
RESTClientGetter: FakeConfig{},
Releases: store,
KubeClient: &kubefake.PrintingKubeClient{Out: ioutil.Discard},
KubeClient: &kubefake.PrintingKubeClient{Out: io.Discard},
Capabilities: chartutil.DefaultCapabilities,
Log: func(format string, v ...interface{}) {},
}
Expand Down Expand Up @@ -182,7 +182,7 @@ func TestRenderManifestsBasicAuth(t *testing.T) {
actionConfig := &action.Configuration{
RESTClientGetter: FakeConfig{},
Releases: store,
KubeClient: &kubefake.PrintingKubeClient{Out: ioutil.Discard},
KubeClient: &kubefake.PrintingKubeClient{Out: io.Discard},
Capabilities: chartutil.DefaultCapabilities,
Log: func(format string, v ...interface{}) {},
}
Expand Down
Loading