Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.

Commit 7fe6384

Browse files
authored
Fix Linting Errors (oauth2-proxy#1835)
* initial commit: add groups to azure Signed-off-by: [email protected] <[email protected]> * fix deprecations and linting errors Signed-off-by: Andrew Hamade <[email protected]> * remove groups testing from azure provider Signed-off-by: Andrew Hamade <[email protected]> * fix test error Signed-off-by: Andrew Hamade <[email protected]> * verify-generate Signed-off-by: Andrew Hamade <[email protected]> Signed-off-by: [email protected] <[email protected]> Signed-off-by: Andrew Hamade <[email protected]>
1 parent a6c8f6f commit 7fe6384

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+134
-146
lines changed

docs/docs/configuration/alpha_config.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ the caller provides it, and no value will be sent otherwise.
306306

307307
Examples:
308308

309-
A parameter whose value is fixed
309+
# A parameter whose value is fixed
310310

311311
```
312312
name: organization
@@ -354,8 +354,9 @@ as backslash is not considered to be an escape character. Alternatively
354354
use the "chomped block" format `|-`:
355355
356356
```
357-
- pattern: |-
357+
- pattern: |-
358358
^[^@]*@example\.com$
359+
359360
```
360361
361362
The hyphen is important, a `|` block would have a trailing newline

main_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"errors"
55
"fmt"
6-
"io/ioutil"
76
"os"
87
"strings"
98
"time"
@@ -191,7 +190,7 @@ redirect_url="http://localhost:4180/oauth2/callback"
191190

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

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

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

oauthproxy_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"encoding/base64"
77
"fmt"
88
"io"
9-
"io/ioutil"
109
"net/http"
1110
"net/http/httptest"
1211
"net/url"
@@ -837,9 +836,9 @@ func NewProcessCookieTest(opts ProcessCookieTestOpts, modifiers ...OptionsModifi
837836
}
838837

839838
groups := pcTest.opts.Providers[0].AllowedGroups
840-
testProvider.AllowedGroups = make(map[string]struct{}, len(groups))
839+
testProvider.ProviderData.AllowedGroups = make(map[string]struct{}, len(groups))
841840
for _, group := range groups {
842-
testProvider.AllowedGroups[group] = struct{}{}
841+
testProvider.ProviderData.AllowedGroups[group] = struct{}{}
843842
}
844843
pcTest.proxy.provider = testProvider
845844

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

10441043
test.proxy.ServeHTTP(test.rw, test.req)
10451044
assert.Equal(t, http.StatusOK, test.rw.Code)
1046-
bodyBytes, _ := ioutil.ReadAll(test.rw.Body)
1045+
bodyBytes, _ := io.ReadAll(test.rw.Body)
10471046
assert.Equal(t, tc.expectedResponse, string(bodyBytes))
10481047
})
10491048
}
@@ -1094,7 +1093,7 @@ func TestAuthOnlyEndpointAccepted(t *testing.T) {
10941093

10951094
test.proxy.ServeHTTP(test.rw, test.req)
10961095
assert.Equal(t, http.StatusAccepted, test.rw.Code)
1097-
bodyBytes, _ := ioutil.ReadAll(test.rw.Body)
1096+
bodyBytes, _ := io.ReadAll(test.rw.Body)
10981097
assert.Equal(t, "", string(bodyBytes))
10991098
}
11001099

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

11071106
test.proxy.ServeHTTP(test.rw, test.req)
11081107
assert.Equal(t, http.StatusUnauthorized, test.rw.Code)
1109-
bodyBytes, _ := ioutil.ReadAll(test.rw.Body)
1108+
bodyBytes, _ := io.ReadAll(test.rw.Body)
11101109
assert.Equal(t, "Unauthorized\n", string(bodyBytes))
11111110
}
11121111

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

11271126
test.proxy.ServeHTTP(test.rw, test.req)
11281127
assert.Equal(t, http.StatusUnauthorized, test.rw.Code)
1129-
bodyBytes, _ := ioutil.ReadAll(test.rw.Body)
1128+
bodyBytes, _ := io.ReadAll(test.rw.Body)
11301129
assert.Equal(t, "Unauthorized\n", string(bodyBytes))
11311130
}
11321131

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

11461145
test.proxy.ServeHTTP(test.rw, test.req)
11471146
assert.Equal(t, http.StatusUnauthorized, test.rw.Code)
1148-
bodyBytes, _ := ioutil.ReadAll(test.rw.Body)
1147+
bodyBytes, _ := io.ReadAll(test.rw.Body)
11491148
assert.Equal(t, "Unauthorized\n", string(bodyBytes))
11501149
}
11511150

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

15621561
var bodyBuf io.ReadCloser
15631562
if body != "" {
1564-
bodyBuf = ioutil.NopCloser(&fakeNetConn{reqBody: body})
1563+
bodyBuf = io.NopCloser(&fakeNetConn{reqBody: body})
15651564
}
15661565
req := httptest.NewRequest(method, "/foo/bar", bodyBuf)
15671566
req.Header = st.header

pkg/apis/options/load.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package options
33
import (
44
"errors"
55
"fmt"
6-
"io/ioutil"
6+
"os"
77
"reflect"
88
"strings"
99

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

150-
data, err := ioutil.ReadFile(configFileName)
152+
data, err := os.ReadFile(configFileName)
151153
if err != nil {
152154
return fmt.Errorf("unable to load config file: %w", err)
153155
}

pkg/apis/options/load_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package options
33
import (
44
"errors"
55
"fmt"
6-
"io/ioutil"
76
"os"
87
"time"
98

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

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

@@ -390,7 +389,7 @@ sub:
390389

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

@@ -488,7 +487,7 @@ injectResponseHeaders:
488487
`)
489488

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

pkg/apis/options/login_url_parameters.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ package options
1414
//
1515
// Examples:
1616
//
17-
// A parameter whose value is fixed
17+
// # A parameter whose value is fixed
1818
//
1919
// ```
2020
// name: organization
@@ -62,8 +62,9 @@ package options
6262
// use the "chomped block" format `|-`:
6363
//
6464
// ```
65-
// - pattern: |-
65+
// - pattern: |-
6666
// ^[^@]*@example\.com$
67+
//
6768
// ```
6869
//
6970
// The hyphen is important, a `|` block would have a trailing newline

pkg/apis/options/util/util.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package util
22

33
import (
44
"errors"
5-
"io/ioutil"
65
"os"
76

87
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
@@ -16,7 +15,7 @@ func GetSecretValue(source *options.SecretSource) ([]byte, error) {
1615
case len(source.Value) == 0 && source.FromEnv != "" && source.FromFile == "":
1716
return []byte(os.Getenv(source.FromEnv)), nil
1817
case len(source.Value) == 0 && source.FromEnv == "" && source.FromFile != "":
19-
return ioutil.ReadFile(source.FromFile)
18+
return os.ReadFile(source.FromFile)
2019
default:
2120
return nil, errors.New("secret source is invalid: exactly one entry required, specify either value, fromEnv or fromFile")
2221
}

pkg/apis/options/util/util_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package util
22

33
import (
4-
"io/ioutil"
54
"os"
65
"path"
76

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

2221
var err error
23-
fileDir, err = ioutil.TempDir("", "oauth2-proxy-util-get-secret-value")
22+
fileDir, err = os.MkdirTemp("", "oauth2-proxy-util-get-secret-value")
2423
Expect(err).ToNot(HaveOccurred())
25-
Expect(ioutil.WriteFile(path.Join(fileDir, "secret-file"), secretFileValue, 0600)).To(Succeed())
24+
Expect(os.WriteFile(path.Join(fileDir, "secret-file"), secretFileValue, 0600)).To(Succeed())
2625
})
2726

2827
AfterEach(func() {

pkg/apis/sessions/session_state.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"context"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"time"
109

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

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

247-
payload, err := ioutil.ReadAll(buf)
246+
payload, err := io.ReadAll(buf)
248247
if err != nil {
249248
return nil, fmt.Errorf("error reading lz4 buffer: %w", err)
250249
}

pkg/app/pagewriter/error_page_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package pagewriter
33
import (
44
"errors"
55
"html/template"
6-
"io/ioutil"
6+
"io"
77
"net/http/httptest"
88

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

39-
body, err := ioutil.ReadAll(recorder.Result().Body)
39+
body, err := io.ReadAll(recorder.Result().Body)
4040
Expect(err).ToNot(HaveOccurred())
4141
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"))
4242
})
@@ -50,7 +50,7 @@ var _ = Describe("Error Page Writer", func() {
5050
AppError: "Access Denied",
5151
})
5252

53-
body, err := ioutil.ReadAll(recorder.Result().Body)
53+
body, err := io.ReadAll(recorder.Result().Body)
5454
Expect(err).ToNot(HaveOccurred())
5555
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"))
5656
})
@@ -68,7 +68,7 @@ var _ = Describe("Error Page Writer", func() {
6868
},
6969
})
7070

71-
body, err := ioutil.ReadAll(recorder.Result().Body)
71+
body, err := io.ReadAll(recorder.Result().Body)
7272
Expect(err).ToNot(HaveOccurred())
7373
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"))
7474
})
@@ -82,7 +82,7 @@ var _ = Describe("Error Page Writer", func() {
8282
AppError: "Access Denied",
8383
})
8484

85-
body, err := ioutil.ReadAll(recorder.Result().Body)
85+
body, err := io.ReadAll(recorder.Result().Body)
8686
Expect(err).ToNot(HaveOccurred())
8787
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"))
8888
})
@@ -97,7 +97,7 @@ var _ = Describe("Error Page Writer", func() {
9797
recorder := httptest.NewRecorder()
9898
errorPage.ProxyErrorHandler(recorder, req, errors.New("some upstream error"))
9999

100-
body, err := ioutil.ReadAll(recorder.Result().Body)
100+
body, err := io.ReadAll(recorder.Result().Body)
101101
Expect(err).ToNot(HaveOccurred())
102102
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"))
103103
})
@@ -121,7 +121,7 @@ var _ = Describe("Error Page Writer", func() {
121121
AppError: "Debug error",
122122
})
123123

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

139-
body, err := ioutil.ReadAll(recorder.Result().Body)
139+
body, err := io.ReadAll(recorder.Result().Body)
140140
Expect(err).ToNot(HaveOccurred())
141141
Expect(string(body)).To(Equal("some upstream error"))
142142
})

0 commit comments

Comments
 (0)