Skip to content

Commit

Permalink
Fix Linting Errors (oauth2-proxy#1835)
Browse files Browse the repository at this point in the history
* initial commit: add groups to azure

Signed-off-by: andrewphamade@gmail.com <andrewphamade@gmail.com>

* fix deprecations and linting errors

Signed-off-by: Andrew Hamade <andrewphamade@gmail.com>

* remove groups testing from azure provider

Signed-off-by: Andrew Hamade <andrewphamade@gmail.com>

* fix test error

Signed-off-by: Andrew Hamade <andrewphamade@gmail.com>

* verify-generate

Signed-off-by: Andrew Hamade <andrewphamade@gmail.com>

Signed-off-by: andrewphamade@gmail.com <andrewphamade@gmail.com>
Signed-off-by: Andrew Hamade <andrewphamade@gmail.com>
  • Loading branch information
devopstagon authored Oct 21, 2022
1 parent a6c8f6f commit 7fe6384
Show file tree
Hide file tree
Showing 43 changed files with 134 additions and 146 deletions.
5 changes: 3 additions & 2 deletions docs/docs/configuration/alpha_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ the caller provides it, and no value will be sent otherwise.

Examples:

A parameter whose value is fixed
# A parameter whose value is fixed

```
name: organization
Expand Down Expand Up @@ -354,8 +354,9 @@ as backslash is not considered to be an escape character. Alternatively
use the "chomped block" format `|-`:
```
- pattern: |-
- pattern: |-
^[^@]*@example\.com$

```
The hyphen is important, a `|` block would have a trailing newline
Expand Down
5 changes: 2 additions & 3 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"errors"
"fmt"
"io/ioutil"
"os"
"strings"
"time"
Expand Down Expand Up @@ -191,7 +190,7 @@ redirect_url="http://localhost:4180/oauth2/callback"

if in.configContent != "" {
By("Writing the config to a temporary file", func() {
file, err := ioutil.TempFile("", "oauth2-proxy-test-config-XXXX.cfg")
file, err := os.CreateTemp("", "oauth2-proxy-test-config-XXXX.cfg")
Expect(err).ToNot(HaveOccurred())
defer file.Close()

Expand All @@ -204,7 +203,7 @@ redirect_url="http://localhost:4180/oauth2/callback"

if in.alphaConfigContent != "" {
By("Writing the config to a temporary file", func() {
file, err := ioutil.TempFile("", "oauth2-proxy-test-alpha-config-XXXX.yaml")
file, err := os.CreateTemp("", "oauth2-proxy-test-alpha-config-XXXX.yaml")
Expect(err).ToNot(HaveOccurred())
defer file.Close()

Expand Down
17 changes: 8 additions & 9 deletions oauthproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/base64"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -837,9 +836,9 @@ func NewProcessCookieTest(opts ProcessCookieTestOpts, modifiers ...OptionsModifi
}

groups := pcTest.opts.Providers[0].AllowedGroups
testProvider.AllowedGroups = make(map[string]struct{}, len(groups))
testProvider.ProviderData.AllowedGroups = make(map[string]struct{}, len(groups))
for _, group := range groups {
testProvider.AllowedGroups[group] = struct{}{}
testProvider.ProviderData.AllowedGroups[group] = struct{}{}
}
pcTest.proxy.provider = testProvider

Expand Down Expand Up @@ -1043,7 +1042,7 @@ func TestUserInfoEndpointAccepted(t *testing.T) {

test.proxy.ServeHTTP(test.rw, test.req)
assert.Equal(t, http.StatusOK, test.rw.Code)
bodyBytes, _ := ioutil.ReadAll(test.rw.Body)
bodyBytes, _ := io.ReadAll(test.rw.Body)
assert.Equal(t, tc.expectedResponse, string(bodyBytes))
})
}
Expand Down Expand Up @@ -1094,7 +1093,7 @@ func TestAuthOnlyEndpointAccepted(t *testing.T) {

test.proxy.ServeHTTP(test.rw, test.req)
assert.Equal(t, http.StatusAccepted, test.rw.Code)
bodyBytes, _ := ioutil.ReadAll(test.rw.Body)
bodyBytes, _ := io.ReadAll(test.rw.Body)
assert.Equal(t, "", string(bodyBytes))
}

Expand All @@ -1106,7 +1105,7 @@ func TestAuthOnlyEndpointUnauthorizedOnNoCookieSetError(t *testing.T) {

test.proxy.ServeHTTP(test.rw, test.req)
assert.Equal(t, http.StatusUnauthorized, test.rw.Code)
bodyBytes, _ := ioutil.ReadAll(test.rw.Body)
bodyBytes, _ := io.ReadAll(test.rw.Body)
assert.Equal(t, "Unauthorized\n", string(bodyBytes))
}

Expand All @@ -1126,7 +1125,7 @@ func TestAuthOnlyEndpointUnauthorizedOnExpiration(t *testing.T) {

test.proxy.ServeHTTP(test.rw, test.req)
assert.Equal(t, http.StatusUnauthorized, test.rw.Code)
bodyBytes, _ := ioutil.ReadAll(test.rw.Body)
bodyBytes, _ := io.ReadAll(test.rw.Body)
assert.Equal(t, "Unauthorized\n", string(bodyBytes))
}

Expand All @@ -1145,7 +1144,7 @@ func TestAuthOnlyEndpointUnauthorizedOnEmailValidationFailure(t *testing.T) {

test.proxy.ServeHTTP(test.rw, test.req)
assert.Equal(t, http.StatusUnauthorized, test.rw.Code)
bodyBytes, _ := ioutil.ReadAll(test.rw.Body)
bodyBytes, _ := io.ReadAll(test.rw.Body)
assert.Equal(t, "Unauthorized\n", string(bodyBytes))
}

Expand Down Expand Up @@ -1561,7 +1560,7 @@ func (st *SignatureTest) MakeRequestWithExpectedKey(method, body, key string) er

var bodyBuf io.ReadCloser
if body != "" {
bodyBuf = ioutil.NopCloser(&fakeNetConn{reqBody: body})
bodyBuf = io.NopCloser(&fakeNetConn{reqBody: body})
}
req := httptest.NewRequest(method, "/foo/bar", bodyBuf)
req.Header = st.header
Expand Down
8 changes: 5 additions & 3 deletions pkg/apis/options/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package options
import (
"errors"
"fmt"
"io/ioutil"
"os"
"reflect"
"strings"

Expand All @@ -17,7 +17,9 @@ import (
// variables (prefixed with `OAUTH2_PROXY`) and finally merges in flags from the flagSet.
// If a config value is unset and the flag has a non-zero value default, this default will be used.
// Eg. A field defined:
// FooBar `cfg:"foo_bar" flag:"foo-bar"`
//
// FooBar `cfg:"foo_bar" flag:"foo-bar"`
//
// Can be set in the config file as `foo_bar="baz"`, in the environment as `OAUTH2_PROXY_FOO_BAR=baz`,
// or via the command line flag `--foo-bar=baz`.
func Load(configFileName string, flagSet *pflag.FlagSet, into interface{}) error {
Expand Down Expand Up @@ -147,7 +149,7 @@ func LoadYAML(configFileName string, into interface{}) error {
return errors.New("no configuration file provided")
}

data, err := ioutil.ReadFile(configFileName)
data, err := os.ReadFile(configFileName)
if err != nil {
return fmt.Errorf("unable to load config file: %w", err)
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/apis/options/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package options
import (
"errors"
"fmt"
"io/ioutil"
"os"
"time"

Expand Down Expand Up @@ -118,7 +117,7 @@ var _ = Describe("Load", func() {

if o.configFile != nil {
By("Creating a config file")
configFile, err := ioutil.TempFile("", "oauth2-proxy-test-legacy-config-file")
configFile, err := os.CreateTemp("", "oauth2-proxy-test-legacy-config-file")
Expect(err).ToNot(HaveOccurred())
defer configFile.Close()

Expand Down Expand Up @@ -390,7 +389,7 @@ sub:

if in.configFile != nil {
By("Creating a config file")
configFile, err := ioutil.TempFile("", "oauth2-proxy-test-config-file")
configFile, err := os.CreateTemp("", "oauth2-proxy-test-config-file")
Expect(err).ToNot(HaveOccurred())
defer configFile.Close()

Expand Down Expand Up @@ -488,7 +487,7 @@ injectResponseHeaders:
`)

By("Creating a config file")
configFile, err := ioutil.TempFile("", "oauth2-proxy-test-alpha-config-file")
configFile, err := os.CreateTemp("", "oauth2-proxy-test-alpha-config-file")
Expect(err).ToNot(HaveOccurred())
defer configFile.Close()

Expand Down
5 changes: 3 additions & 2 deletions pkg/apis/options/login_url_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ package options
//
// Examples:
//
// A parameter whose value is fixed
// # A parameter whose value is fixed
//
// ```
// name: organization
Expand Down Expand Up @@ -62,8 +62,9 @@ package options
// use the "chomped block" format `|-`:
//
// ```
// - pattern: |-
// - pattern: |-
// ^[^@]*@example\.com$
//
// ```
//
// The hyphen is important, a `|` block would have a trailing newline
Expand Down
3 changes: 1 addition & 2 deletions pkg/apis/options/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package util

import (
"errors"
"io/ioutil"
"os"

"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
Expand All @@ -16,7 +15,7 @@ func GetSecretValue(source *options.SecretSource) ([]byte, error) {
case len(source.Value) == 0 && source.FromEnv != "" && source.FromFile == "":
return []byte(os.Getenv(source.FromEnv)), nil
case len(source.Value) == 0 && source.FromEnv == "" && source.FromFile != "":
return ioutil.ReadFile(source.FromFile)
return os.ReadFile(source.FromFile)
default:
return nil, errors.New("secret source is invalid: exactly one entry required, specify either value, fromEnv or fromFile")
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/apis/options/util/util_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package util

import (
"io/ioutil"
"os"
"path"

Expand All @@ -20,9 +19,9 @@ var _ = Describe("GetSecretValue", func() {
os.Setenv(secretEnvKey, secretEnvValue)

var err error
fileDir, err = ioutil.TempDir("", "oauth2-proxy-util-get-secret-value")
fileDir, err = os.MkdirTemp("", "oauth2-proxy-util-get-secret-value")
Expect(err).ToNot(HaveOccurred())
Expect(ioutil.WriteFile(path.Join(fileDir, "secret-file"), secretFileValue, 0600)).To(Succeed())
Expect(os.WriteFile(path.Join(fileDir, "secret-file"), secretFileValue, 0600)).To(Succeed())
})

AfterEach(func() {
Expand Down
5 changes: 2 additions & 3 deletions pkg/apis/sessions/session_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"time"

"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/clock"
Expand Down Expand Up @@ -225,7 +224,7 @@ func lz4Compress(payload []byte) ([]byte, error) {
return nil, fmt.Errorf("error closing lz4 writer: %w", err)
}

compressed, err := ioutil.ReadAll(buf)
compressed, err := io.ReadAll(buf)
if err != nil {
return nil, fmt.Errorf("error reading lz4 buffer: %w", err)
}
Expand All @@ -244,7 +243,7 @@ func lz4Decompress(compressed []byte) ([]byte, error) {
return nil, fmt.Errorf("error copying lz4 stream to buffer: %w", err)
}

payload, err := ioutil.ReadAll(buf)
payload, err := io.ReadAll(buf)
if err != nil {
return nil, fmt.Errorf("error reading lz4 buffer: %w", err)
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/app/pagewriter/error_page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package pagewriter
import (
"errors"
"html/template"
"io/ioutil"
"io"
"net/http/httptest"

middlewareapi "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/middleware"
Expand Down Expand Up @@ -36,7 +36,7 @@ var _ = Describe("Error Page Writer", func() {
AppError: "Access Denied",
})

body, err := ioutil.ReadAll(recorder.Result().Body)
body, err := io.ReadAll(recorder.Result().Body)
Expect(err).ToNot(HaveOccurred())
Expect(string(body)).To(Equal("Forbidden You do not have permission to access this resource. /prefix/ 403 /redirect 11111111-2222-4333-8444-555555555555 Custom Footer Text v0.0.0-test"))
})
Expand All @@ -50,7 +50,7 @@ var _ = Describe("Error Page Writer", func() {
AppError: "Access Denied",
})

body, err := ioutil.ReadAll(recorder.Result().Body)
body, err := io.ReadAll(recorder.Result().Body)
Expect(err).ToNot(HaveOccurred())
Expect(string(body)).To(Equal("Internal Server Error Oops! Something went wrong. For more information contact your server administrator. /prefix/ 500 /redirect 11111111-2222-4333-8444-555555555555 Custom Footer Text v0.0.0-test"))
})
Expand All @@ -68,7 +68,7 @@ var _ = Describe("Error Page Writer", func() {
},
})

body, err := ioutil.ReadAll(recorder.Result().Body)
body, err := io.ReadAll(recorder.Result().Body)
Expect(err).ToNot(HaveOccurred())
Expect(string(body)).To(Equal("Forbidden An extra message: with more context. /prefix/ 403 /redirect 11111111-2222-4333-8444-555555555555 Custom Footer Text v0.0.0-test"))
})
Expand All @@ -82,7 +82,7 @@ var _ = Describe("Error Page Writer", func() {
AppError: "Access Denied",
})

body, err := ioutil.ReadAll(recorder.Result().Body)
body, err := io.ReadAll(recorder.Result().Body)
Expect(err).ToNot(HaveOccurred())
Expect(string(body)).To(Equal("Forbidden You do not have permission to access this resource. /prefix/ 403 /redirect &lt;script&gt;alert(1)&lt;/script&gt; Custom Footer Text v0.0.0-test"))
})
Expand All @@ -97,7 +97,7 @@ var _ = Describe("Error Page Writer", func() {
recorder := httptest.NewRecorder()
errorPage.ProxyErrorHandler(recorder, req, errors.New("some upstream error"))

body, err := ioutil.ReadAll(recorder.Result().Body)
body, err := io.ReadAll(recorder.Result().Body)
Expect(err).ToNot(HaveOccurred())
Expect(string(body)).To(Equal("Bad Gateway There was a problem connecting to the upstream server. /prefix/ 502 11111111-2222-4333-8444-555555555555 Custom Footer Text v0.0.0-test"))
})
Expand All @@ -121,7 +121,7 @@ var _ = Describe("Error Page Writer", func() {
AppError: "Debug error",
})

body, err := ioutil.ReadAll(recorder.Result().Body)
body, err := io.ReadAll(recorder.Result().Body)
Expect(err).ToNot(HaveOccurred())
Expect(string(body)).To(Equal("Debug error"))
})
Expand All @@ -136,7 +136,7 @@ var _ = Describe("Error Page Writer", func() {
recorder := httptest.NewRecorder()
errorPage.ProxyErrorHandler(recorder, req, errors.New("some upstream error"))

body, err := ioutil.ReadAll(recorder.Result().Body)
body, err := io.ReadAll(recorder.Result().Body)
Expect(err).ToNot(HaveOccurred())
Expect(string(body)).To(Equal("some upstream error"))
})
Expand Down
Loading

0 comments on commit 7fe6384

Please sign in to comment.