summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorfeistel <6742251-feistel@users.noreply.gitlab.com>2021-08-19 15:54:20 +0000
committerfeistel <6742251-feistel@users.noreply.gitlab.com>2021-08-19 15:54:20 +0000
commit087c010c476ed6c009b6c94a76a7e9db3b9d3fdd (patch)
treec68aac4473adea2eae5ead5d49c173f80dac3e8c /internal
parenta83f8b31982222ad64b23a47ee6d092042cf9f1a (diff)
downloadgitlab-shell-087c010c476ed6c009b6c94a76a7e9db3b9d3fdd.tar.gz
refactor: move away from ioutil (deprecated)
Diffstat (limited to 'internal')
-rw-r--r--internal/command/lfsauthenticate/lfsauthenticate_test.go6
-rw-r--r--internal/command/personalaccesstoken/personalaccesstoken_test.go4
-rw-r--r--internal/command/shared/accessverifier/accessverifier_test.go4
-rw-r--r--internal/command/shared/customaction/customaction_test.go10
-rw-r--r--internal/command/twofactorrecover/twofactorrecover_test.go4
-rw-r--r--internal/command/twofactorverify/twofactorverify_test.go4
-rw-r--r--internal/config/config.go5
-rw-r--r--internal/gitlabnet/accessverifier/client_test.go9
-rw-r--r--internal/gitlabnet/lfsauthenticate/client_test.go4
-rw-r--r--internal/gitlabnet/personalaccesstoken/client_test.go4
-rw-r--r--internal/gitlabnet/twofactorrecover/client_test.go4
-rw-r--r--internal/gitlabnet/twofactorverify/client_test.go7
-rw-r--r--internal/logger/logger.go3
-rw-r--r--internal/logger/logger_test.go11
-rw-r--r--internal/sshd/sshd.go4
-rw-r--r--internal/sshd/sshd_test.go6
-rw-r--r--internal/testhelper/testhelper.go3
17 files changed, 45 insertions, 47 deletions
diff --git a/internal/command/lfsauthenticate/lfsauthenticate_test.go b/internal/command/lfsauthenticate/lfsauthenticate_test.go
index 63aecb0..63124f5 100644
--- a/internal/command/lfsauthenticate/lfsauthenticate_test.go
+++ b/internal/command/lfsauthenticate/lfsauthenticate_test.go
@@ -4,7 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
- "io/ioutil"
+ "io"
"net/http"
"testing"
@@ -70,7 +70,7 @@ func TestLfsAuthenticateRequests(t *testing.T) {
{
Path: "/api/v4/internal/lfs_authenticate",
Handler: func(w http.ResponseWriter, r *http.Request) {
- b, err := ioutil.ReadAll(r.Body)
+ b, err := io.ReadAll(r.Body)
defer r.Body.Close()
require.NoError(t, err)
@@ -94,7 +94,7 @@ func TestLfsAuthenticateRequests(t *testing.T) {
{
Path: "/api/v4/internal/allowed",
Handler: func(w http.ResponseWriter, r *http.Request) {
- b, err := ioutil.ReadAll(r.Body)
+ b, err := io.ReadAll(r.Body)
defer r.Body.Close()
require.NoError(t, err)
diff --git a/internal/command/personalaccesstoken/personalaccesstoken_test.go b/internal/command/personalaccesstoken/personalaccesstoken_test.go
index 37d5ae7..a82e07f 100644
--- a/internal/command/personalaccesstoken/personalaccesstoken_test.go
+++ b/internal/command/personalaccesstoken/personalaccesstoken_test.go
@@ -4,7 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
- "io/ioutil"
+ "io"
"net/http"
"testing"
@@ -26,7 +26,7 @@ func setup(t *testing.T) {
{
Path: "/api/v4/internal/personal_access_token",
Handler: func(w http.ResponseWriter, r *http.Request) {
- b, err := ioutil.ReadAll(r.Body)
+ b, err := io.ReadAll(r.Body)
defer r.Body.Close()
require.NoError(t, err)
diff --git a/internal/command/shared/accessverifier/accessverifier_test.go b/internal/command/shared/accessverifier/accessverifier_test.go
index 8e0b5f9..54904e0 100644
--- a/internal/command/shared/accessverifier/accessverifier_test.go
+++ b/internal/command/shared/accessverifier/accessverifier_test.go
@@ -4,7 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
- "io/ioutil"
+ "io"
"net/http"
"testing"
@@ -27,7 +27,7 @@ func setup(t *testing.T) (*Command, *bytes.Buffer, *bytes.Buffer) {
{
Path: "/api/v4/internal/allowed",
Handler: func(w http.ResponseWriter, r *http.Request) {
- b, err := ioutil.ReadAll(r.Body)
+ b, err := io.ReadAll(r.Body)
require.NoError(t, err)
var requestBody *accessverifier.Request
diff --git a/internal/command/shared/customaction/customaction_test.go b/internal/command/shared/customaction/customaction_test.go
index d3e794c..b26ce81 100644
--- a/internal/command/shared/customaction/customaction_test.go
+++ b/internal/command/shared/customaction/customaction_test.go
@@ -4,7 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
- "io/ioutil"
+ "io"
"net/http"
"testing"
@@ -23,7 +23,7 @@ func TestExecuteEOFSent(t *testing.T) {
{
Path: "/geo/proxy/info_refs_receive_pack",
Handler: func(w http.ResponseWriter, r *http.Request) {
- b, err := ioutil.ReadAll(r.Body)
+ b, err := io.ReadAll(r.Body)
require.NoError(t, err)
var request *Request
@@ -39,7 +39,7 @@ func TestExecuteEOFSent(t *testing.T) {
{
Path: "/geo/proxy/receive_pack",
Handler: func(w http.ResponseWriter, r *http.Request) {
- b, err := ioutil.ReadAll(r.Body)
+ b, err := io.ReadAll(r.Body)
require.NoError(t, err)
var request *Request
@@ -92,7 +92,7 @@ func TestExecuteNoEOFSent(t *testing.T) {
{
Path: "/geo/proxy/info_refs_upload_pack",
Handler: func(w http.ResponseWriter, r *http.Request) {
- b, err := ioutil.ReadAll(r.Body)
+ b, err := io.ReadAll(r.Body)
require.NoError(t, err)
var request *Request
@@ -108,7 +108,7 @@ func TestExecuteNoEOFSent(t *testing.T) {
{
Path: "/geo/proxy/upload_pack",
Handler: func(w http.ResponseWriter, r *http.Request) {
- b, err := ioutil.ReadAll(r.Body)
+ b, err := io.ReadAll(r.Body)
require.NoError(t, err)
var request *Request
diff --git a/internal/command/twofactorrecover/twofactorrecover_test.go b/internal/command/twofactorrecover/twofactorrecover_test.go
index 01852f6..948b138 100644
--- a/internal/command/twofactorrecover/twofactorrecover_test.go
+++ b/internal/command/twofactorrecover/twofactorrecover_test.go
@@ -4,7 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
- "io/ioutil"
+ "io"
"net/http"
"strings"
"testing"
@@ -27,7 +27,7 @@ func setup(t *testing.T) {
{
Path: "/api/v4/internal/two_factor_recovery_codes",
Handler: func(w http.ResponseWriter, r *http.Request) {
- b, err := ioutil.ReadAll(r.Body)
+ b, err := io.ReadAll(r.Body)
defer r.Body.Close()
require.NoError(t, err)
diff --git a/internal/command/twofactorverify/twofactorverify_test.go b/internal/command/twofactorverify/twofactorverify_test.go
index 2e9e0ea..899813a 100644
--- a/internal/command/twofactorverify/twofactorverify_test.go
+++ b/internal/command/twofactorverify/twofactorverify_test.go
@@ -4,7 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
- "io/ioutil"
+ "io"
"net/http"
"testing"
@@ -22,7 +22,7 @@ func setup(t *testing.T) []testserver.TestRequestHandler {
{
Path: "/api/v4/internal/two_factor_otp_check",
Handler: func(w http.ResponseWriter, r *http.Request) {
- b, err := ioutil.ReadAll(r.Body)
+ b, err := io.ReadAll(r.Body)
defer r.Body.Close()
require.NoError(t, err)
diff --git a/internal/config/config.go b/internal/config/config.go
index f69a6c8..c67f60a 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -2,7 +2,6 @@ package config
import (
"errors"
- "io/ioutil"
"net/url"
"os"
"path"
@@ -147,7 +146,7 @@ func newFromFile(path string) (*Config, error) {
*cfg = DefaultConfig
cfg.RootDir = filepath.Dir(path)
- configBytes, err := ioutil.ReadFile(path)
+ configBytes, err := os.ReadFile(path)
if err != nil {
return nil, err
}
@@ -191,7 +190,7 @@ func parseSecret(cfg *Config) error {
cfg.SecretFilePath = path.Join(cfg.RootDir, cfg.SecretFilePath)
}
- secretFileContent, err := ioutil.ReadFile(cfg.SecretFilePath)
+ secretFileContent, err := os.ReadFile(cfg.SecretFilePath)
if err != nil {
return err
}
diff --git a/internal/gitlabnet/accessverifier/client_test.go b/internal/gitlabnet/accessverifier/client_test.go
index d3f34f6..f617c38 100644
--- a/internal/gitlabnet/accessverifier/client_test.go
+++ b/internal/gitlabnet/accessverifier/client_test.go
@@ -3,8 +3,9 @@ package accessverifier
import (
"context"
"encoding/json"
- "io/ioutil"
+ "io"
"net/http"
+ "os"
"path"
"testing"
@@ -165,14 +166,14 @@ func TestErrorResponses(t *testing.T) {
func setup(t *testing.T, allowedPayload string) *Client {
testhelper.PrepareTestRootDir(t)
- body, err := ioutil.ReadFile(path.Join(testhelper.TestRoot, "responses/allowed.json"))
+ body, err := os.ReadFile(path.Join(testhelper.TestRoot, "responses/allowed.json"))
require.NoError(t, err)
var bodyWithPayload []byte
if allowedPayload != "" {
allowedWithPayloadPath := path.Join(testhelper.TestRoot, allowedPayload)
- bodyWithPayload, err = ioutil.ReadFile(allowedWithPayloadPath)
+ bodyWithPayload, err = os.ReadFile(allowedWithPayloadPath)
require.NoError(t, err)
}
@@ -180,7 +181,7 @@ func setup(t *testing.T, allowedPayload string) *Client {
{
Path: "/api/v4/internal/allowed",
Handler: func(w http.ResponseWriter, r *http.Request) {
- b, err := ioutil.ReadAll(r.Body)
+ b, err := io.ReadAll(r.Body)
require.NoError(t, err)
var requestBody *Request
diff --git a/internal/gitlabnet/lfsauthenticate/client_test.go b/internal/gitlabnet/lfsauthenticate/client_test.go
index d554cac..c745306 100644
--- a/internal/gitlabnet/lfsauthenticate/client_test.go
+++ b/internal/gitlabnet/lfsauthenticate/client_test.go
@@ -3,7 +3,7 @@ package lfsauthenticate
import (
"context"
"encoding/json"
- "io/ioutil"
+ "io"
"net/http"
"testing"
@@ -24,7 +24,7 @@ func setup(t *testing.T) []testserver.TestRequestHandler {
{
Path: "/api/v4/internal/lfs_authenticate",
Handler: func(w http.ResponseWriter, r *http.Request) {
- b, err := ioutil.ReadAll(r.Body)
+ b, err := io.ReadAll(r.Body)
defer r.Body.Close()
require.NoError(t, err)
diff --git a/internal/gitlabnet/personalaccesstoken/client_test.go b/internal/gitlabnet/personalaccesstoken/client_test.go
index d67b085..d36cd44 100644
--- a/internal/gitlabnet/personalaccesstoken/client_test.go
+++ b/internal/gitlabnet/personalaccesstoken/client_test.go
@@ -3,7 +3,7 @@ package personalaccesstoken
import (
"context"
"encoding/json"
- "io/ioutil"
+ "io"
"net/http"
"testing"
@@ -24,7 +24,7 @@ func initialize(t *testing.T) {
{
Path: "/api/v4/internal/personal_access_token",
Handler: func(w http.ResponseWriter, r *http.Request) {
- b, err := ioutil.ReadAll(r.Body)
+ b, err := io.ReadAll(r.Body)
defer r.Body.Close()
require.NoError(t, err)
diff --git a/internal/gitlabnet/twofactorrecover/client_test.go b/internal/gitlabnet/twofactorrecover/client_test.go
index 62f88dc..921c114 100644
--- a/internal/gitlabnet/twofactorrecover/client_test.go
+++ b/internal/gitlabnet/twofactorrecover/client_test.go
@@ -3,7 +3,7 @@ package twofactorrecover
import (
"context"
"encoding/json"
- "io/ioutil"
+ "io"
"net/http"
"testing"
@@ -24,7 +24,7 @@ func initialize(t *testing.T) {
{
Path: "/api/v4/internal/two_factor_recovery_codes",
Handler: func(w http.ResponseWriter, r *http.Request) {
- b, err := ioutil.ReadAll(r.Body)
+ b, err := io.ReadAll(r.Body)
defer r.Body.Close()
require.NoError(t, err)
diff --git a/internal/gitlabnet/twofactorverify/client_test.go b/internal/gitlabnet/twofactorverify/client_test.go
index 9893b12..e4f837b 100644
--- a/internal/gitlabnet/twofactorverify/client_test.go
+++ b/internal/gitlabnet/twofactorverify/client_test.go
@@ -3,11 +3,12 @@ package twofactorverify
import (
"context"
"encoding/json"
- "gitlab.com/gitlab-org/gitlab-shell/internal/gitlabnet/discover"
- "io/ioutil"
+ "io"
"net/http"
"testing"
+ "gitlab.com/gitlab-org/gitlab-shell/internal/gitlabnet/discover"
+
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitlab-shell/client"
"gitlab.com/gitlab-org/gitlab-shell/client/testserver"
@@ -20,7 +21,7 @@ func initialize(t *testing.T) []testserver.TestRequestHandler {
{
Path: "/api/v4/internal/two_factor_otp_check",
Handler: func(w http.ResponseWriter, r *http.Request) {
- b, err := ioutil.ReadAll(r.Body)
+ b, err := io.ReadAll(r.Body)
defer r.Body.Close()
require.NoError(t, err)
diff --git a/internal/logger/logger.go b/internal/logger/logger.go
index 3ffd501..1165680 100644
--- a/internal/logger/logger.go
+++ b/internal/logger/logger.go
@@ -3,7 +3,6 @@ package logger
import (
"fmt"
"io"
- "io/ioutil"
"log/syslog"
"os"
"time"
@@ -43,7 +42,7 @@ func buildOpts(cfg *config.Config) []log.LoggerOption {
// mode an empty LogFile is not accepted and syslog is used as a fallback when LogFile could not be
// opened for writing.
func Configure(cfg *config.Config) io.Closer {
- var closer io.Closer = ioutil.NopCloser(nil)
+ var closer io.Closer = io.NopCloser(nil)
err := fmt.Errorf("No logfile specified")
if cfg.LogFile != "" {
diff --git a/internal/logger/logger_test.go b/internal/logger/logger_test.go
index 43bd2ab..bda36d9 100644
--- a/internal/logger/logger_test.go
+++ b/internal/logger/logger_test.go
@@ -1,7 +1,6 @@
package logger
import (
- "io/ioutil"
"os"
"regexp"
"strings"
@@ -14,7 +13,7 @@ import (
)
func TestConfigure(t *testing.T) {
- tmpFile, err := ioutil.TempFile(os.TempDir(), "logtest-")
+ tmpFile, err := os.CreateTemp(os.TempDir(), "logtest-")
require.NoError(t, err)
defer tmpFile.Close()
@@ -30,13 +29,13 @@ func TestConfigure(t *testing.T) {
tmpFile.Close()
- data, err := ioutil.ReadFile(tmpFile.Name())
+ data, err := os.ReadFile(tmpFile.Name())
require.NoError(t, err)
require.True(t, strings.Contains(string(data), `msg":"this is a test"`))
}
func TestConfigureWithPermissionError(t *testing.T) {
- tmpPath, err := ioutil.TempDir(os.TempDir(), "logtest-")
+ tmpPath, err := os.MkdirTemp(os.TempDir(), "logtest-")
require.NoError(t, err)
defer os.RemoveAll(tmpPath)
@@ -52,7 +51,7 @@ func TestConfigureWithPermissionError(t *testing.T) {
}
func TestLogInUTC(t *testing.T) {
- tmpFile, err := ioutil.TempFile(os.TempDir(), "logtest-")
+ tmpFile, err := os.CreateTemp(os.TempDir(), "logtest-")
require.NoError(t, err)
defer tmpFile.Close()
defer os.Remove(tmpFile.Name())
@@ -67,7 +66,7 @@ func TestLogInUTC(t *testing.T) {
log.Info("this is a test")
- data, err := ioutil.ReadFile(tmpFile.Name())
+ data, err := os.ReadFile(tmpFile.Name())
require.NoError(t, err)
utc := `[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z`
diff --git a/internal/sshd/sshd.go b/internal/sshd/sshd.go
index b918109..de5fbd4 100644
--- a/internal/sshd/sshd.go
+++ b/internal/sshd/sshd.go
@@ -5,9 +5,9 @@ import (
"encoding/base64"
"errors"
"fmt"
- "io/ioutil"
"net"
"net/http"
+ "os"
"strconv"
"sync"
"time"
@@ -51,7 +51,7 @@ func NewServer(cfg *config.Config) (*Server, error) {
var hostKeys []ssh.Signer
for _, filename := range cfg.Server.HostKeyFiles {
- keyRaw, err := ioutil.ReadFile(filename)
+ keyRaw, err := os.ReadFile(filename)
if err != nil {
log.WithError(err).Warnf("Failed to read host key %v", filename)
continue
diff --git a/internal/sshd/sshd_test.go b/internal/sshd/sshd_test.go
index 2923737..32946af 100644
--- a/internal/sshd/sshd_test.go
+++ b/internal/sshd/sshd_test.go
@@ -3,9 +3,9 @@ package sshd
import (
"context"
"fmt"
- "io/ioutil"
"net/http"
"net/http/httptest"
+ "os"
"path"
"testing"
"time"
@@ -148,11 +148,11 @@ func setupServer(t *testing.T) *Server {
}
func clientConfig(t *testing.T) *ssh.ClientConfig {
- keyRaw, err := ioutil.ReadFile(path.Join(testhelper.TestRoot, "certs/valid/server_authorized_key"))
+ keyRaw, err := os.ReadFile(path.Join(testhelper.TestRoot, "certs/valid/server_authorized_key"))
pKey, _, _, _, err := ssh.ParseAuthorizedKey(keyRaw)
require.NoError(t, err)
- key, err := ioutil.ReadFile(path.Join(testhelper.TestRoot, "certs/client/key.pem"))
+ key, err := os.ReadFile(path.Join(testhelper.TestRoot, "certs/client/key.pem"))
require.NoError(t, err)
signer, err := ssh.ParsePrivateKey(key)
require.NoError(t, err)
diff --git a/internal/testhelper/testhelper.go b/internal/testhelper/testhelper.go
index 65fb975..43e36c3 100644
--- a/internal/testhelper/testhelper.go
+++ b/internal/testhelper/testhelper.go
@@ -2,7 +2,6 @@ package testhelper
import (
"fmt"
- "io/ioutil"
"os"
"path"
"runtime"
@@ -13,7 +12,7 @@ import (
)
var (
- TestRoot, _ = ioutil.TempDir("", "test-gitlab-shell")
+ TestRoot, _ = os.MkdirTemp("", "test-gitlab-shell")
)
func TempEnv(env map[string]string) func() {