Fix Linting Errors (#1835)
* 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>
This commit is contained in:
		
							parent
							
								
									a6c8f6f04a
								
							
						
					
					
						commit
						7fe6384f38
					
				|  | @ -306,7 +306,7 @@ the caller provides it, and no value will be sent otherwise. | ||||||
| 
 | 
 | ||||||
| Examples: | Examples: | ||||||
| 
 | 
 | ||||||
| A parameter whose value is fixed | # A parameter whose value is fixed | ||||||
| 
 | 
 | ||||||
| ``` | ``` | ||||||
| name: organization | name: organization | ||||||
|  | @ -354,8 +354,9 @@ as backslash is not considered to be an escape character.  Alternatively | ||||||
| use the "chomped block" format `|-`: | use the "chomped block" format `|-`: | ||||||
| 
 | 
 | ||||||
| ``` | ``` | ||||||
| - pattern: |- |   - pattern: |- | ||||||
|     ^[^@]*@example\.com$ |     ^[^@]*@example\.com$ | ||||||
|  | 
 | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| The hyphen is important, a `|` block would have a trailing newline | The hyphen is important, a `|` block would have a trailing newline | ||||||
|  |  | ||||||
|  | @ -3,7 +3,6 @@ package main | ||||||
| import ( | import ( | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io/ioutil" |  | ||||||
| 	"os" | 	"os" | ||||||
| 	"strings" | 	"strings" | ||||||
| 	"time" | 	"time" | ||||||
|  | @ -191,7 +190,7 @@ redirect_url="http://localhost:4180/oauth2/callback" | ||||||
| 
 | 
 | ||||||
| 			if in.configContent != "" { | 			if in.configContent != "" { | ||||||
| 				By("Writing the config to a temporary file", func() { | 				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()) | 					Expect(err).ToNot(HaveOccurred()) | ||||||
| 					defer file.Close() | 					defer file.Close() | ||||||
| 
 | 
 | ||||||
|  | @ -204,7 +203,7 @@ redirect_url="http://localhost:4180/oauth2/callback" | ||||||
| 
 | 
 | ||||||
| 			if in.alphaConfigContent != "" { | 			if in.alphaConfigContent != "" { | ||||||
| 				By("Writing the config to a temporary file", func() { | 				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()) | 					Expect(err).ToNot(HaveOccurred()) | ||||||
| 					defer file.Close() | 					defer file.Close() | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -6,7 +6,6 @@ import ( | ||||||
| 	"encoding/base64" | 	"encoding/base64" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io" | 	"io" | ||||||
| 	"io/ioutil" |  | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"net/http/httptest" | 	"net/http/httptest" | ||||||
| 	"net/url" | 	"net/url" | ||||||
|  | @ -837,9 +836,9 @@ func NewProcessCookieTest(opts ProcessCookieTestOpts, modifiers ...OptionsModifi | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	groups := pcTest.opts.Providers[0].AllowedGroups | 	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 { | 	for _, group := range groups { | ||||||
| 		testProvider.AllowedGroups[group] = struct{}{} | 		testProvider.ProviderData.AllowedGroups[group] = struct{}{} | ||||||
| 	} | 	} | ||||||
| 	pcTest.proxy.provider = testProvider | 	pcTest.proxy.provider = testProvider | ||||||
| 
 | 
 | ||||||
|  | @ -1043,7 +1042,7 @@ func TestUserInfoEndpointAccepted(t *testing.T) { | ||||||
| 
 | 
 | ||||||
| 			test.proxy.ServeHTTP(test.rw, test.req) | 			test.proxy.ServeHTTP(test.rw, test.req) | ||||||
| 			assert.Equal(t, http.StatusOK, test.rw.Code) | 			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)) | 			assert.Equal(t, tc.expectedResponse, string(bodyBytes)) | ||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
|  | @ -1094,7 +1093,7 @@ func TestAuthOnlyEndpointAccepted(t *testing.T) { | ||||||
| 
 | 
 | ||||||
| 	test.proxy.ServeHTTP(test.rw, test.req) | 	test.proxy.ServeHTTP(test.rw, test.req) | ||||||
| 	assert.Equal(t, http.StatusAccepted, test.rw.Code) | 	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)) | 	assert.Equal(t, "", string(bodyBytes)) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -1106,7 +1105,7 @@ func TestAuthOnlyEndpointUnauthorizedOnNoCookieSetError(t *testing.T) { | ||||||
| 
 | 
 | ||||||
| 	test.proxy.ServeHTTP(test.rw, test.req) | 	test.proxy.ServeHTTP(test.rw, test.req) | ||||||
| 	assert.Equal(t, http.StatusUnauthorized, test.rw.Code) | 	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)) | 	assert.Equal(t, "Unauthorized\n", string(bodyBytes)) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -1126,7 +1125,7 @@ func TestAuthOnlyEndpointUnauthorizedOnExpiration(t *testing.T) { | ||||||
| 
 | 
 | ||||||
| 	test.proxy.ServeHTTP(test.rw, test.req) | 	test.proxy.ServeHTTP(test.rw, test.req) | ||||||
| 	assert.Equal(t, http.StatusUnauthorized, test.rw.Code) | 	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)) | 	assert.Equal(t, "Unauthorized\n", string(bodyBytes)) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -1145,7 +1144,7 @@ func TestAuthOnlyEndpointUnauthorizedOnEmailValidationFailure(t *testing.T) { | ||||||
| 
 | 
 | ||||||
| 	test.proxy.ServeHTTP(test.rw, test.req) | 	test.proxy.ServeHTTP(test.rw, test.req) | ||||||
| 	assert.Equal(t, http.StatusUnauthorized, test.rw.Code) | 	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)) | 	assert.Equal(t, "Unauthorized\n", string(bodyBytes)) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -1561,7 +1560,7 @@ func (st *SignatureTest) MakeRequestWithExpectedKey(method, body, key string) er | ||||||
| 
 | 
 | ||||||
| 	var bodyBuf io.ReadCloser | 	var bodyBuf io.ReadCloser | ||||||
| 	if body != "" { | 	if body != "" { | ||||||
| 		bodyBuf = ioutil.NopCloser(&fakeNetConn{reqBody: body}) | 		bodyBuf = io.NopCloser(&fakeNetConn{reqBody: body}) | ||||||
| 	} | 	} | ||||||
| 	req := httptest.NewRequest(method, "/foo/bar", bodyBuf) | 	req := httptest.NewRequest(method, "/foo/bar", bodyBuf) | ||||||
| 	req.Header = st.header | 	req.Header = st.header | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ package options | ||||||
| import ( | import ( | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io/ioutil" | 	"os" | ||||||
| 	"reflect" | 	"reflect" | ||||||
| 	"strings" | 	"strings" | ||||||
| 
 | 
 | ||||||
|  | @ -17,7 +17,9 @@ import ( | ||||||
| // variables (prefixed with `OAUTH2_PROXY`) and finally merges in flags from the flagSet.
 | // 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.
 | // If a config value is unset and the flag has a non-zero value default, this default will be used.
 | ||||||
| // Eg. A field defined:
 | // 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`,
 | // 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`.
 | // or via the command line flag `--foo-bar=baz`.
 | ||||||
| func Load(configFileName string, flagSet *pflag.FlagSet, into interface{}) error { | func Load(configFileName string, flagSet *pflag.FlagSet, into interface{}) error { | ||||||
|  | @ -147,7 +149,7 @@ func LoadYAML(configFileName string, into interface{}) error { | ||||||
| 		return errors.New("no configuration file provided") | 		return errors.New("no configuration file provided") | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	data, err := ioutil.ReadFile(configFileName) | 	data, err := os.ReadFile(configFileName) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return fmt.Errorf("unable to load config file: %w", err) | 		return fmt.Errorf("unable to load config file: %w", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -3,7 +3,6 @@ package options | ||||||
| import ( | import ( | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io/ioutil" |  | ||||||
| 	"os" | 	"os" | ||||||
| 	"time" | 	"time" | ||||||
| 
 | 
 | ||||||
|  | @ -118,7 +117,7 @@ var _ = Describe("Load", func() { | ||||||
| 
 | 
 | ||||||
| 				if o.configFile != nil { | 				if o.configFile != nil { | ||||||
| 					By("Creating a config file") | 					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()) | 					Expect(err).ToNot(HaveOccurred()) | ||||||
| 					defer configFile.Close() | 					defer configFile.Close() | ||||||
| 
 | 
 | ||||||
|  | @ -390,7 +389,7 @@ sub: | ||||||
| 
 | 
 | ||||||
| 				if in.configFile != nil { | 				if in.configFile != nil { | ||||||
| 					By("Creating a config file") | 					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()) | 					Expect(err).ToNot(HaveOccurred()) | ||||||
| 					defer configFile.Close() | 					defer configFile.Close() | ||||||
| 
 | 
 | ||||||
|  | @ -488,7 +487,7 @@ injectResponseHeaders: | ||||||
| `) | `) | ||||||
| 
 | 
 | ||||||
| 		By("Creating a config file") | 		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()) | 		Expect(err).ToNot(HaveOccurred()) | ||||||
| 		defer configFile.Close() | 		defer configFile.Close() | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -14,7 +14,7 @@ package options | ||||||
| //
 | //
 | ||||||
| // Examples:
 | // Examples:
 | ||||||
| //
 | //
 | ||||||
| // A parameter whose value is fixed
 | // # A parameter whose value is fixed
 | ||||||
| //
 | //
 | ||||||
| // ```
 | // ```
 | ||||||
| // name: organization
 | // name: organization
 | ||||||
|  | @ -64,6 +64,7 @@ package options | ||||||
| // ```
 | // ```
 | ||||||
| //   - pattern: |-
 | //   - pattern: |-
 | ||||||
| //     ^[^@]*@example\.com$
 | //     ^[^@]*@example\.com$
 | ||||||
|  | //
 | ||||||
| // ```
 | // ```
 | ||||||
| //
 | //
 | ||||||
| // The hyphen is important, a `|` block would have a trailing newline
 | // The hyphen is important, a `|` block would have a trailing newline
 | ||||||
|  |  | ||||||
|  | @ -2,7 +2,6 @@ package util | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"io/ioutil" |  | ||||||
| 	"os" | 	"os" | ||||||
| 
 | 
 | ||||||
| 	"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options" | 	"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options" | ||||||
|  | @ -16,7 +15,7 @@ func GetSecretValue(source *options.SecretSource) ([]byte, error) { | ||||||
| 	case len(source.Value) == 0 && source.FromEnv != "" && source.FromFile == "": | 	case len(source.Value) == 0 && source.FromEnv != "" && source.FromFile == "": | ||||||
| 		return []byte(os.Getenv(source.FromEnv)), nil | 		return []byte(os.Getenv(source.FromEnv)), nil | ||||||
| 	case len(source.Value) == 0 && source.FromEnv == "" && source.FromFile != "": | 	case len(source.Value) == 0 && source.FromEnv == "" && source.FromFile != "": | ||||||
| 		return ioutil.ReadFile(source.FromFile) | 		return os.ReadFile(source.FromFile) | ||||||
| 	default: | 	default: | ||||||
| 		return nil, errors.New("secret source is invalid: exactly one entry required, specify either value, fromEnv or fromFile") | 		return nil, errors.New("secret source is invalid: exactly one entry required, specify either value, fromEnv or fromFile") | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -1,7 +1,6 @@ | ||||||
| package util | package util | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"io/ioutil" |  | ||||||
| 	"os" | 	"os" | ||||||
| 	"path" | 	"path" | ||||||
| 
 | 
 | ||||||
|  | @ -20,9 +19,9 @@ var _ = Describe("GetSecretValue", func() { | ||||||
| 		os.Setenv(secretEnvKey, secretEnvValue) | 		os.Setenv(secretEnvKey, secretEnvValue) | ||||||
| 
 | 
 | ||||||
| 		var err error | 		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(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() { | 	AfterEach(func() { | ||||||
|  |  | ||||||
|  | @ -5,7 +5,6 @@ import ( | ||||||
| 	"context" | 	"context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io" | 	"io" | ||||||
| 	"io/ioutil" |  | ||||||
| 	"time" | 	"time" | ||||||
| 
 | 
 | ||||||
| 	"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/clock" | 	"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/clock" | ||||||
|  | @ -225,7 +224,7 @@ func lz4Compress(payload []byte) ([]byte, error) { | ||||||
| 		return nil, fmt.Errorf("error closing lz4 writer: %w", err) | 		return nil, fmt.Errorf("error closing lz4 writer: %w", err) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	compressed, err := ioutil.ReadAll(buf) | 	compressed, err := io.ReadAll(buf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, fmt.Errorf("error reading lz4 buffer: %w", err) | 		return nil, fmt.Errorf("error reading lz4 buffer: %w", err) | ||||||
| 	} | 	} | ||||||
|  | @ -244,7 +243,7 @@ func lz4Decompress(compressed []byte) ([]byte, error) { | ||||||
| 		return nil, fmt.Errorf("error copying lz4 stream to buffer: %w", err) | 		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 { | 	if err != nil { | ||||||
| 		return nil, fmt.Errorf("error reading lz4 buffer: %w", err) | 		return nil, fmt.Errorf("error reading lz4 buffer: %w", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ package pagewriter | ||||||
| import ( | import ( | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"html/template" | 	"html/template" | ||||||
| 	"io/ioutil" | 	"io" | ||||||
| 	"net/http/httptest" | 	"net/http/httptest" | ||||||
| 
 | 
 | ||||||
| 	middlewareapi "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/middleware" | 	middlewareapi "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/middleware" | ||||||
|  | @ -36,7 +36,7 @@ var _ = Describe("Error Page Writer", func() { | ||||||
| 				AppError:    "Access Denied", | 				AppError:    "Access Denied", | ||||||
| 			}) | 			}) | ||||||
| 
 | 
 | ||||||
| 			body, err := ioutil.ReadAll(recorder.Result().Body) | 			body, err := io.ReadAll(recorder.Result().Body) | ||||||
| 			Expect(err).ToNot(HaveOccurred()) | 			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")) | 			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")) | ||||||
| 		}) | 		}) | ||||||
|  | @ -50,7 +50,7 @@ var _ = Describe("Error Page Writer", func() { | ||||||
| 				AppError:    "Access Denied", | 				AppError:    "Access Denied", | ||||||
| 			}) | 			}) | ||||||
| 
 | 
 | ||||||
| 			body, err := ioutil.ReadAll(recorder.Result().Body) | 			body, err := io.ReadAll(recorder.Result().Body) | ||||||
| 			Expect(err).ToNot(HaveOccurred()) | 			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")) | 			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")) | ||||||
| 		}) | 		}) | ||||||
|  | @ -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(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")) | 			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")) | ||||||
| 		}) | 		}) | ||||||
|  | @ -82,7 +82,7 @@ var _ = Describe("Error Page Writer", func() { | ||||||
| 				AppError:    "Access Denied", | 				AppError:    "Access Denied", | ||||||
| 			}) | 			}) | ||||||
| 
 | 
 | ||||||
| 			body, err := ioutil.ReadAll(recorder.Result().Body) | 			body, err := io.ReadAll(recorder.Result().Body) | ||||||
| 			Expect(err).ToNot(HaveOccurred()) | 			Expect(err).ToNot(HaveOccurred()) | ||||||
| 			Expect(string(body)).To(Equal("Forbidden You do not have permission to access this resource. /prefix/ 403 /redirect <script>alert(1)</script> Custom Footer Text v0.0.0-test")) | 			Expect(string(body)).To(Equal("Forbidden You do not have permission to access this resource. /prefix/ 403 /redirect <script>alert(1)</script> Custom Footer Text v0.0.0-test")) | ||||||
| 		}) | 		}) | ||||||
|  | @ -97,7 +97,7 @@ var _ = Describe("Error Page Writer", func() { | ||||||
| 			recorder := httptest.NewRecorder() | 			recorder := httptest.NewRecorder() | ||||||
| 			errorPage.ProxyErrorHandler(recorder, req, errors.New("some upstream error")) | 			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(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")) | 			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")) | ||||||
| 		}) | 		}) | ||||||
|  | @ -121,7 +121,7 @@ var _ = Describe("Error Page Writer", func() { | ||||||
| 					AppError:    "Debug error", | 					AppError:    "Debug error", | ||||||
| 				}) | 				}) | ||||||
| 
 | 
 | ||||||
| 				body, err := ioutil.ReadAll(recorder.Result().Body) | 				body, err := io.ReadAll(recorder.Result().Body) | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(string(body)).To(Equal("Debug error")) | 				Expect(string(body)).To(Equal("Debug error")) | ||||||
| 			}) | 			}) | ||||||
|  | @ -136,7 +136,7 @@ var _ = Describe("Error Page Writer", func() { | ||||||
| 				recorder := httptest.NewRecorder() | 				recorder := httptest.NewRecorder() | ||||||
| 				errorPage.ProxyErrorHandler(recorder, req, errors.New("some upstream error")) | 				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(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(string(body)).To(Equal("some upstream error")) | 				Expect(string(body)).To(Equal("some upstream error")) | ||||||
| 			}) | 			}) | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ package pagewriter | ||||||
| import ( | import ( | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io/ioutil" | 	"io" | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"net/http/httptest" | 	"net/http/httptest" | ||||||
| 	"os" | 	"os" | ||||||
|  | @ -50,7 +50,7 @@ var _ = Describe("Writer", func() { | ||||||
| 					AppError:    "Some debug error", | 					AppError:    "Some debug error", | ||||||
| 				}) | 				}) | ||||||
| 
 | 
 | ||||||
| 				body, err := ioutil.ReadAll(recorder.Result().Body) | 				body, err := io.ReadAll(recorder.Result().Body) | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(string(body)).To(HavePrefix("\n<!DOCTYPE html>")) | 				Expect(string(body)).To(HavePrefix("\n<!DOCTYPE html>")) | ||||||
| 			}) | 			}) | ||||||
|  | @ -59,7 +59,7 @@ var _ = Describe("Writer", func() { | ||||||
| 				recorder := httptest.NewRecorder() | 				recorder := httptest.NewRecorder() | ||||||
| 				writer.WriteSignInPage(recorder, request, "/redirect", http.StatusOK) | 				writer.WriteSignInPage(recorder, request, "/redirect", http.StatusOK) | ||||||
| 
 | 
 | ||||||
| 				body, err := ioutil.ReadAll(recorder.Result().Body) | 				body, err := io.ReadAll(recorder.Result().Body) | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(string(body)).To(HavePrefix("\n<!DOCTYPE html>")) | 				Expect(string(body)).To(HavePrefix("\n<!DOCTYPE html>")) | ||||||
| 			}) | 			}) | ||||||
|  | @ -70,14 +70,14 @@ var _ = Describe("Writer", func() { | ||||||
| 
 | 
 | ||||||
| 			BeforeEach(func() { | 			BeforeEach(func() { | ||||||
| 				var err error | 				var err error | ||||||
| 				customDir, err = ioutil.TempDir("", "oauth2-proxy-pagewriter-test") | 				customDir, err = os.MkdirTemp("", "oauth2-proxy-pagewriter-test") | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 
 | 
 | ||||||
| 				templateHTML := `Custom Template` | 				templateHTML := `Custom Template` | ||||||
| 				signInFile := filepath.Join(customDir, signInTemplateName) | 				signInFile := filepath.Join(customDir, signInTemplateName) | ||||||
| 				Expect(ioutil.WriteFile(signInFile, []byte(templateHTML), 0600)).To(Succeed()) | 				Expect(os.WriteFile(signInFile, []byte(templateHTML), 0600)).To(Succeed()) | ||||||
| 				errorFile := filepath.Join(customDir, errorTemplateName) | 				errorFile := filepath.Join(customDir, errorTemplateName) | ||||||
| 				Expect(ioutil.WriteFile(errorFile, []byte(templateHTML), 0600)).To(Succeed()) | 				Expect(os.WriteFile(errorFile, []byte(templateHTML), 0600)).To(Succeed()) | ||||||
| 
 | 
 | ||||||
| 				opts.TemplatesPath = customDir | 				opts.TemplatesPath = customDir | ||||||
| 
 | 
 | ||||||
|  | @ -97,7 +97,7 @@ var _ = Describe("Writer", func() { | ||||||
| 					AppError:    "Some debug error", | 					AppError:    "Some debug error", | ||||||
| 				}) | 				}) | ||||||
| 
 | 
 | ||||||
| 				body, err := ioutil.ReadAll(recorder.Result().Body) | 				body, err := io.ReadAll(recorder.Result().Body) | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(string(body)).To(Equal("Custom Template")) | 				Expect(string(body)).To(Equal("Custom Template")) | ||||||
| 			}) | 			}) | ||||||
|  | @ -106,7 +106,7 @@ var _ = Describe("Writer", func() { | ||||||
| 				recorder := httptest.NewRecorder() | 				recorder := httptest.NewRecorder() | ||||||
| 				writer.WriteSignInPage(recorder, request, "/redirect", http.StatusOK) | 				writer.WriteSignInPage(recorder, request, "/redirect", http.StatusOK) | ||||||
| 
 | 
 | ||||||
| 				body, err := ioutil.ReadAll(recorder.Result().Body) | 				body, err := io.ReadAll(recorder.Result().Body) | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(string(body)).To(Equal("Custom Template")) | 				Expect(string(body)).To(Equal("Custom Template")) | ||||||
| 			}) | 			}) | ||||||
|  | @ -117,12 +117,12 @@ var _ = Describe("Writer", func() { | ||||||
| 
 | 
 | ||||||
| 			BeforeEach(func() { | 			BeforeEach(func() { | ||||||
| 				var err error | 				var err error | ||||||
| 				customDir, err = ioutil.TempDir("", "oauth2-proxy-pagewriter-test") | 				customDir, err = os.MkdirTemp("", "oauth2-proxy-pagewriter-test") | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 
 | 
 | ||||||
| 				templateHTML := `{{ Custom Broken Template` | 				templateHTML := `{{ Custom Broken Template` | ||||||
| 				signInFile := filepath.Join(customDir, signInTemplateName) | 				signInFile := filepath.Join(customDir, signInTemplateName) | ||||||
| 				Expect(ioutil.WriteFile(signInFile, []byte(templateHTML), 0600)).To(Succeed()) | 				Expect(os.WriteFile(signInFile, []byte(templateHTML), 0600)).To(Succeed()) | ||||||
| 
 | 
 | ||||||
| 				opts.TemplatesPath = customDir | 				opts.TemplatesPath = customDir | ||||||
| 			}) | 			}) | ||||||
|  | @ -155,7 +155,7 @@ var _ = Describe("Writer", func() { | ||||||
| 
 | 
 | ||||||
| 				Expect(rw.Result().StatusCode).To(Equal(in.expectedStatus)) | 				Expect(rw.Result().StatusCode).To(Equal(in.expectedStatus)) | ||||||
| 
 | 
 | ||||||
| 				body, err := ioutil.ReadAll(rw.Result().Body) | 				body, err := io.ReadAll(rw.Result().Body) | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(string(body)).To(Equal(in.expectedBody)) | 				Expect(string(body)).To(Equal(in.expectedBody)) | ||||||
| 			}, | 			}, | ||||||
|  | @ -188,7 +188,7 @@ var _ = Describe("Writer", func() { | ||||||
| 
 | 
 | ||||||
| 				Expect(rw.Result().StatusCode).To(Equal(in.expectedStatus)) | 				Expect(rw.Result().StatusCode).To(Equal(in.expectedStatus)) | ||||||
| 
 | 
 | ||||||
| 				body, err := ioutil.ReadAll(rw.Result().Body) | 				body, err := io.ReadAll(rw.Result().Body) | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(string(body)).To(Equal(in.expectedBody)) | 				Expect(string(body)).To(Equal(in.expectedBody)) | ||||||
| 			}, | 			}, | ||||||
|  | @ -218,7 +218,7 @@ var _ = Describe("Writer", func() { | ||||||
| 
 | 
 | ||||||
| 				Expect(rw.Result().StatusCode).To(Equal(in.expectedStatus)) | 				Expect(rw.Result().StatusCode).To(Equal(in.expectedStatus)) | ||||||
| 
 | 
 | ||||||
| 				body, err := ioutil.ReadAll(rw.Result().Body) | 				body, err := io.ReadAll(rw.Result().Body) | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(string(body)).To(Equal(in.expectedBody)) | 				Expect(string(body)).To(Equal(in.expectedBody)) | ||||||
| 			}, | 			}, | ||||||
|  | @ -257,7 +257,7 @@ var _ = Describe("Writer", func() { | ||||||
| 
 | 
 | ||||||
| 				Expect(rw.Result().StatusCode).To(Equal(in.expectedStatus)) | 				Expect(rw.Result().StatusCode).To(Equal(in.expectedStatus)) | ||||||
| 
 | 
 | ||||||
| 				body, err := ioutil.ReadAll(rw.Result().Body) | 				body, err := io.ReadAll(rw.Result().Body) | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(string(body)).To(Equal(in.expectedBody)) | 				Expect(string(body)).To(Equal(in.expectedBody)) | ||||||
| 			}, | 			}, | ||||||
|  |  | ||||||
|  | @ -4,7 +4,7 @@ import ( | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"html/template" | 	"html/template" | ||||||
| 	"io/ioutil" | 	"io" | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"net/http/httptest" | 	"net/http/httptest" | ||||||
| 	"os" | 	"os" | ||||||
|  | @ -56,7 +56,7 @@ var _ = Describe("SignIn Page", func() { | ||||||
| 				recorder := httptest.NewRecorder() | 				recorder := httptest.NewRecorder() | ||||||
| 				signInPage.WriteSignInPage(recorder, request, "/redirect", http.StatusOK) | 				signInPage.WriteSignInPage(recorder, request, "/redirect", http.StatusOK) | ||||||
| 
 | 
 | ||||||
| 				body, err := ioutil.ReadAll(recorder.Result().Body) | 				body, err := io.ReadAll(recorder.Result().Body) | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(string(body)).To(Equal("/prefix/ My Provider Sign In Here Custom Footer Text v0.0.0-test /redirect true Logo Data")) | 				Expect(string(body)).To(Equal("/prefix/ My Provider Sign In Here Custom Footer Text v0.0.0-test /redirect true Logo Data")) | ||||||
| 			}) | 			}) | ||||||
|  | @ -70,7 +70,7 @@ var _ = Describe("SignIn Page", func() { | ||||||
| 				recorder := httptest.NewRecorder() | 				recorder := httptest.NewRecorder() | ||||||
| 				signInPage.WriteSignInPage(recorder, request, "/redirect", http.StatusOK) | 				signInPage.WriteSignInPage(recorder, request, "/redirect", http.StatusOK) | ||||||
| 
 | 
 | ||||||
| 				body, err := ioutil.ReadAll(recorder.Result().Body) | 				body, err := io.ReadAll(recorder.Result().Body) | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(string(body)).To(Equal(fmt.Sprintf("Internal Server Error | %s", testRequestID))) | 				Expect(string(body)).To(Equal(fmt.Sprintf("Internal Server Error | %s", testRequestID))) | ||||||
| 			}) | 			}) | ||||||
|  | @ -84,12 +84,12 @@ var _ = Describe("SignIn Page", func() { | ||||||
| 
 | 
 | ||||||
| 		BeforeEach(func() { | 		BeforeEach(func() { | ||||||
| 			var err error | 			var err error | ||||||
| 			customDir, err = ioutil.TempDir("", "oauth2-proxy-sign-in-page-test") | 			customDir, err = os.MkdirTemp("", "oauth2-proxy-sign-in-page-test") | ||||||
| 			Expect(err).ToNot(HaveOccurred()) | 			Expect(err).ToNot(HaveOccurred()) | ||||||
| 
 | 
 | ||||||
| 			for _, ext := range []string{".svg", ".png", ".jpg", ".jpeg", ".gif"} { | 			for _, ext := range []string{".svg", ".png", ".jpg", ".jpeg", ".gif"} { | ||||||
| 				fileName := filepath.Join(customDir, fmt.Sprintf("logo%s", ext)) | 				fileName := filepath.Join(customDir, fmt.Sprintf("logo%s", ext)) | ||||||
| 				Expect(ioutil.WriteFile(fileName, []byte(fakeImageData), 0600)).To(Succeed()) | 				Expect(os.WriteFile(fileName, []byte(fakeImageData), 0600)).To(Succeed()) | ||||||
| 			} | 			} | ||||||
| 		}) | 		}) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ package pagewriter | ||||||
| import ( | import ( | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"html/template" | 	"html/template" | ||||||
| 	"io/ioutil" | 	"io" | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"net/http/httptest" | 	"net/http/httptest" | ||||||
| 	"os" | 	"os" | ||||||
|  | @ -27,11 +27,11 @@ var _ = Describe("Static Pages", func() { | ||||||
| 			template: errorTmpl, | 			template: errorTmpl, | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		customDir, err = ioutil.TempDir("", "oauth2-proxy-static-pages-test") | 		customDir, err = os.MkdirTemp("", "oauth2-proxy-static-pages-test") | ||||||
| 		Expect(err).ToNot(HaveOccurred()) | 		Expect(err).ToNot(HaveOccurred()) | ||||||
| 
 | 
 | ||||||
| 		robotsTxtFile := filepath.Join(customDir, robotsTxtName) | 		robotsTxtFile := filepath.Join(customDir, robotsTxtName) | ||||||
| 		Expect(ioutil.WriteFile(robotsTxtFile, []byte(customRobots), 0400)).To(Succeed()) | 		Expect(os.WriteFile(robotsTxtFile, []byte(customRobots), 0400)).To(Succeed()) | ||||||
| 
 | 
 | ||||||
| 		request = httptest.NewRequest("", "http://127.0.0.1/", nil) | 		request = httptest.NewRequest("", "http://127.0.0.1/", nil) | ||||||
| 		request = middlewareapi.AddRequestScope(request, &middlewareapi.RequestScope{ | 		request = middlewareapi.AddRequestScope(request, &middlewareapi.RequestScope{ | ||||||
|  | @ -58,7 +58,7 @@ var _ = Describe("Static Pages", func() { | ||||||
| 					recorder := httptest.NewRecorder() | 					recorder := httptest.NewRecorder() | ||||||
| 					pageWriter.WriteRobotsTxt(recorder, request) | 					pageWriter.WriteRobotsTxt(recorder, request) | ||||||
| 
 | 
 | ||||||
| 					body, err := ioutil.ReadAll(recorder.Result().Body) | 					body, err := io.ReadAll(recorder.Result().Body) | ||||||
| 					Expect(err).ToNot(HaveOccurred()) | 					Expect(err).ToNot(HaveOccurred()) | ||||||
| 					Expect(string(body)).To(Equal(customRobots)) | 					Expect(string(body)).To(Equal(customRobots)) | ||||||
| 
 | 
 | ||||||
|  | @ -81,7 +81,7 @@ var _ = Describe("Static Pages", func() { | ||||||
| 					recorder := httptest.NewRecorder() | 					recorder := httptest.NewRecorder() | ||||||
| 					pageWriter.WriteRobotsTxt(recorder, request) | 					pageWriter.WriteRobotsTxt(recorder, request) | ||||||
| 
 | 
 | ||||||
| 					body, err := ioutil.ReadAll(recorder.Result().Body) | 					body, err := io.ReadAll(recorder.Result().Body) | ||||||
| 					Expect(err).ToNot(HaveOccurred()) | 					Expect(err).ToNot(HaveOccurred()) | ||||||
| 					Expect(string(body)).To(Equal(string(defaultRobotsTxt))) | 					Expect(string(body)).To(Equal(string(defaultRobotsTxt))) | ||||||
| 
 | 
 | ||||||
|  | @ -94,7 +94,7 @@ var _ = Describe("Static Pages", func() { | ||||||
| 					} | 					} | ||||||
| 					pageWriter.WriteRobotsTxt(recorder, request) | 					pageWriter.WriteRobotsTxt(recorder, request) | ||||||
| 
 | 
 | ||||||
| 					body, err := ioutil.ReadAll(recorder.Result().Body) | 					body, err := io.ReadAll(recorder.Result().Body) | ||||||
| 					Expect(err).ToNot(HaveOccurred()) | 					Expect(err).ToNot(HaveOccurred()) | ||||||
| 					Expect(string(body)).To(Equal(string("Internal Server Error"))) | 					Expect(string(body)).To(Equal(string("Internal Server Error"))) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -3,7 +3,6 @@ package pagewriter | ||||||
| import ( | import ( | ||||||
| 	"bytes" | 	"bytes" | ||||||
| 	"html/template" | 	"html/template" | ||||||
| 	"io/ioutil" |  | ||||||
| 	"os" | 	"os" | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
| 
 | 
 | ||||||
|  | @ -16,14 +15,14 @@ var _ = Describe("Templates", func() { | ||||||
| 
 | 
 | ||||||
| 	BeforeEach(func() { | 	BeforeEach(func() { | ||||||
| 		var err error | 		var err error | ||||||
| 		customDir, err = ioutil.TempDir("", "oauth2-proxy-templates-test") | 		customDir, err = os.MkdirTemp("", "oauth2-proxy-templates-test") | ||||||
| 		Expect(err).ToNot(HaveOccurred()) | 		Expect(err).ToNot(HaveOccurred()) | ||||||
| 
 | 
 | ||||||
| 		templateHTML := `{{.TestString}} {{.TestString | ToLower}} {{.TestString | ToUpper}}` | 		templateHTML := `{{.TestString}} {{.TestString | ToLower}} {{.TestString | ToUpper}}` | ||||||
| 		signInFile := filepath.Join(customDir, signInTemplateName) | 		signInFile := filepath.Join(customDir, signInTemplateName) | ||||||
| 		Expect(ioutil.WriteFile(signInFile, []byte(templateHTML), 0600)).To(Succeed()) | 		Expect(os.WriteFile(signInFile, []byte(templateHTML), 0600)).To(Succeed()) | ||||||
| 		errorFile := filepath.Join(customDir, errorTemplateName) | 		errorFile := filepath.Join(customDir, errorTemplateName) | ||||||
| 		Expect(ioutil.WriteFile(errorFile, []byte(templateHTML), 0600)).To(Succeed()) | 		Expect(os.WriteFile(errorFile, []byte(templateHTML), 0600)).To(Succeed()) | ||||||
| 	}) | 	}) | ||||||
| 
 | 
 | ||||||
| 	AfterEach(func() { | 	AfterEach(func() { | ||||||
|  | @ -162,7 +161,7 @@ var _ = Describe("Templates", func() { | ||||||
| 			Context("With an invalid sign_in template", func() { | 			Context("With an invalid sign_in template", func() { | ||||||
| 				BeforeEach(func() { | 				BeforeEach(func() { | ||||||
| 					signInFile := filepath.Join(customDir, signInTemplateName) | 					signInFile := filepath.Join(customDir, signInTemplateName) | ||||||
| 					Expect(ioutil.WriteFile(signInFile, []byte("{{"), 0600)) | 					Expect(os.WriteFile(signInFile, []byte("{{"), 0600)) | ||||||
| 				}) | 				}) | ||||||
| 
 | 
 | ||||||
| 				It("Should return an error when loading templates", func() { | 				It("Should return an error when loading templates", func() { | ||||||
|  | @ -175,7 +174,7 @@ var _ = Describe("Templates", func() { | ||||||
| 			Context("With an invalid error template", func() { | 			Context("With an invalid error template", func() { | ||||||
| 				BeforeEach(func() { | 				BeforeEach(func() { | ||||||
| 					errorFile := filepath.Join(customDir, errorTemplateName) | 					errorFile := filepath.Join(customDir, errorTemplateName) | ||||||
| 					Expect(ioutil.WriteFile(errorFile, []byte("{{"), 0600)) | 					Expect(os.WriteFile(errorFile, []byte("{{"), 0600)) | ||||||
| 				}) | 				}) | ||||||
| 
 | 
 | ||||||
| 				It("Should return an error when loading templates", func() { | 				It("Should return an error when loading templates", func() { | ||||||
|  |  | ||||||
|  | @ -1,7 +1,6 @@ | ||||||
| package header | package header | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"io/ioutil" |  | ||||||
| 	"os" | 	"os" | ||||||
| 	"path" | 	"path" | ||||||
| 	"testing" | 	"testing" | ||||||
|  | @ -26,9 +25,9 @@ func TestHeaderSuite(t *testing.T) { | ||||||
| var _ = BeforeSuite(func() { | var _ = BeforeSuite(func() { | ||||||
| 	os.Setenv("SECRET_ENV", "super-secret-env") | 	os.Setenv("SECRET_ENV", "super-secret-env") | ||||||
| 
 | 
 | ||||||
| 	dir, err := ioutil.TempDir("", "oauth2-proxy-header-suite") | 	dir, err := os.MkdirTemp("", "oauth2-proxy-header-suite") | ||||||
| 	Expect(err).ToNot(HaveOccurred()) | 	Expect(err).ToNot(HaveOccurred()) | ||||||
| 	Expect(ioutil.WriteFile(path.Join(dir, "secret-file"), []byte("super-secret-file"), 0644)).To(Succeed()) | 	Expect(os.WriteFile(path.Join(dir, "secret-file"), []byte("super-secret-file"), 0644)).To(Succeed()) | ||||||
| 	filesDir = dir | 	filesDir = dir | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -186,7 +186,7 @@ func (s *server) Start(ctx context.Context) error { | ||||||
| // When the given context is cancelled the server will be shutdown.
 | // When the given context is cancelled the server will be shutdown.
 | ||||||
| // If any errors occur, only the first error will be returned.
 | // If any errors occur, only the first error will be returned.
 | ||||||
| func (s *server) startServer(ctx context.Context, listener net.Listener) error { | func (s *server) startServer(ctx context.Context, listener net.Listener) error { | ||||||
| 	srv := &http.Server{Handler: s.handler} | 	srv := &http.Server{Handler: s.handler, ReadHeaderTimeout: time.Minute} | ||||||
| 	g, groupCtx := errgroup.WithContext(ctx) | 	g, groupCtx := errgroup.WithContext(ctx) | ||||||
| 
 | 
 | ||||||
| 	g.Go(func() error { | 	g.Go(func() error { | ||||||
|  |  | ||||||
|  | @ -4,7 +4,7 @@ import ( | ||||||
| 	"context" | 	"context" | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io/ioutil" | 	"io" | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 
 | 
 | ||||||
| 	"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options" | 	"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options" | ||||||
|  | @ -565,7 +565,7 @@ var _ = Describe("Server", func() { | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(resp.StatusCode).To(Equal(http.StatusOK)) | 				Expect(resp.StatusCode).To(Equal(http.StatusOK)) | ||||||
| 
 | 
 | ||||||
| 				body, err := ioutil.ReadAll(resp.Body) | 				body, err := io.ReadAll(resp.Body) | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(string(body)).To(Equal(hello)) | 				Expect(string(body)).To(Equal(hello)) | ||||||
| 			}) | 			}) | ||||||
|  | @ -619,7 +619,7 @@ var _ = Describe("Server", func() { | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(resp.StatusCode).To(Equal(http.StatusOK)) | 				Expect(resp.StatusCode).To(Equal(http.StatusOK)) | ||||||
| 
 | 
 | ||||||
| 				body, err := ioutil.ReadAll(resp.Body) | 				body, err := io.ReadAll(resp.Body) | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(string(body)).To(Equal(hello)) | 				Expect(string(body)).To(Equal(hello)) | ||||||
| 			}) | 			}) | ||||||
|  | @ -690,7 +690,7 @@ var _ = Describe("Server", func() { | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(resp.StatusCode).To(Equal(http.StatusOK)) | 				Expect(resp.StatusCode).To(Equal(http.StatusOK)) | ||||||
| 
 | 
 | ||||||
| 				body, err := ioutil.ReadAll(resp.Body) | 				body, err := io.ReadAll(resp.Body) | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(string(body)).To(Equal(hello)) | 				Expect(string(body)).To(Equal(hello)) | ||||||
| 			}) | 			}) | ||||||
|  | @ -705,7 +705,7 @@ var _ = Describe("Server", func() { | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(resp.StatusCode).To(Equal(http.StatusOK)) | 				Expect(resp.StatusCode).To(Equal(http.StatusOK)) | ||||||
| 
 | 
 | ||||||
| 				body, err := ioutil.ReadAll(resp.Body) | 				body, err := io.ReadAll(resp.Body) | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(string(body)).To(Equal(hello)) | 				Expect(string(body)).To(Equal(hello)) | ||||||
| 			}) | 			}) | ||||||
|  | @ -761,7 +761,7 @@ var _ = Describe("Server", func() { | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(resp.StatusCode).To(Equal(http.StatusOK)) | 				Expect(resp.StatusCode).To(Equal(http.StatusOK)) | ||||||
| 
 | 
 | ||||||
| 				body, err := ioutil.ReadAll(resp.Body) | 				body, err := io.ReadAll(resp.Body) | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(string(body)).To(Equal(hello)) | 				Expect(string(body)).To(Equal(hello)) | ||||||
| 			}) | 			}) | ||||||
|  | @ -815,7 +815,7 @@ var _ = Describe("Server", func() { | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(resp.StatusCode).To(Equal(http.StatusOK)) | 				Expect(resp.StatusCode).To(Equal(http.StatusOK)) | ||||||
| 
 | 
 | ||||||
| 				body, err := ioutil.ReadAll(resp.Body) | 				body, err := io.ReadAll(resp.Body) | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(string(body)).To(Equal(hello)) | 				Expect(string(body)).To(Equal(hello)) | ||||||
| 			}) | 			}) | ||||||
|  | @ -886,7 +886,7 @@ var _ = Describe("Server", func() { | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(resp.StatusCode).To(Equal(http.StatusOK)) | 				Expect(resp.StatusCode).To(Equal(http.StatusOK)) | ||||||
| 
 | 
 | ||||||
| 				body, err := ioutil.ReadAll(resp.Body) | 				body, err := io.ReadAll(resp.Body) | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(string(body)).To(Equal(hello)) | 				Expect(string(body)).To(Equal(hello)) | ||||||
| 			}) | 			}) | ||||||
|  | @ -901,7 +901,7 @@ var _ = Describe("Server", func() { | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(resp.StatusCode).To(Equal(http.StatusOK)) | 				Expect(resp.StatusCode).To(Equal(http.StatusOK)) | ||||||
| 
 | 
 | ||||||
| 				body, err := ioutil.ReadAll(resp.Body) | 				body, err := io.ReadAll(resp.Body) | ||||||
| 				Expect(err).ToNot(HaveOccurred()) | 				Expect(err).ToNot(HaveOccurred()) | ||||||
| 				Expect(string(body)).To(Equal(hello)) | 				Expect(string(body)).To(Equal(hello)) | ||||||
| 			}) | 			}) | ||||||
|  |  | ||||||
|  | @ -98,7 +98,7 @@ func (c *claimExtractor) loadProfileClaims() (*simplejson.Json, error) { | ||||||
| 		WithContext(c.ctx). | 		WithContext(c.ctx). | ||||||
| 		WithHeaders(c.requestHeaders). | 		WithHeaders(c.requestHeaders). | ||||||
| 		Do(). | 		Do(). | ||||||
| 		UnmarshalJSON() | 		UnmarshalSimpleJSON() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, fmt.Errorf("error making request to profile URL: %v", err) | 		return nil, fmt.Errorf("error making request to profile URL: %v", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -4,7 +4,6 @@ import ( | ||||||
| 	"context" | 	"context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io" | 	"io" | ||||||
| 	"io/ioutil" |  | ||||||
| 	"net/http" | 	"net/http" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | @ -107,7 +106,7 @@ func (r *builder) do() Result { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	defer resp.Body.Close() | 	defer resp.Body.Close() | ||||||
| 	body, err := ioutil.ReadAll(resp.Body) | 	body, err := io.ReadAll(resp.Body) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		r.result = &result{err: fmt.Errorf("error reading response body: %v", err)} | 		r.result = &result{err: fmt.Errorf("error reading response body: %v", err)} | ||||||
| 		return r.result | 		return r.result | ||||||
|  |  | ||||||
|  | @ -285,7 +285,7 @@ func assertSuccessfulRequest(builder func() Builder, expectedRequest testHTTPReq | ||||||
| 
 | 
 | ||||||
| 		BeforeEach(func() { | 		BeforeEach(func() { | ||||||
| 			var err error | 			var err error | ||||||
| 			response, err = builder().Do().UnmarshalJSON() | 			response, err = builder().Do().UnmarshalSimpleJSON() | ||||||
| 			Expect(err).ToNot(HaveOccurred()) | 			Expect(err).ToNot(HaveOccurred()) | ||||||
| 		}) | 		}) | ||||||
| 
 | 
 | ||||||
|  | @ -340,7 +340,7 @@ func assertRequestError(builder func() Builder, errorMessage string) { | ||||||
| 
 | 
 | ||||||
| 	Context("UnmarshalJSON", func() { | 	Context("UnmarshalJSON", func() { | ||||||
| 		It("returns an error", func() { | 		It("returns an error", func() { | ||||||
| 			resp, err := builder().Do().UnmarshalJSON() | 			resp, err := builder().Do().UnmarshalSimpleJSON() | ||||||
| 			Expect(err).To(MatchError(ContainSubstring(errorMessage))) | 			Expect(err).To(MatchError(ContainSubstring(errorMessage))) | ||||||
| 			Expect(resp).To(BeNil()) | 			Expect(resp).To(BeNil()) | ||||||
| 		}) | 		}) | ||||||
|  | @ -368,7 +368,7 @@ func assertJSONError(builder func() Builder, errorMessage string) { | ||||||
| 
 | 
 | ||||||
| 	Context("UnmarshalJSON", func() { | 	Context("UnmarshalJSON", func() { | ||||||
| 		It("returns an error", func() { | 		It("returns an error", func() { | ||||||
| 			resp, err := builder().Do().UnmarshalJSON() | 			resp, err := builder().Do().UnmarshalSimpleJSON() | ||||||
| 			Expect(err).To(MatchError(ContainSubstring(errorMessage))) | 			Expect(err).To(MatchError(ContainSubstring(errorMessage))) | ||||||
| 			Expect(resp).To(BeNil()) | 			Expect(resp).To(BeNil()) | ||||||
| 		}) | 		}) | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ package requests | ||||||
| import ( | import ( | ||||||
| 	"encoding/json" | 	"encoding/json" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io/ioutil" | 	"io" | ||||||
| 	"log" | 	"log" | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"net/http/httptest" | 	"net/http/httptest" | ||||||
|  | @ -82,7 +82,7 @@ func toTestHTTPRequest(req *http.Request) (testHTTPRequest, error) { | ||||||
| 	requestBody := []byte{} | 	requestBody := []byte{} | ||||||
| 	if req.Body != http.NoBody { | 	if req.Body != http.NoBody { | ||||||
| 		var err error | 		var err error | ||||||
| 		requestBody, err = ioutil.ReadAll(req.Body) | 		requestBody, err = io.ReadAll(req.Body) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return testHTTPRequest{}, err | 			return testHTTPRequest{}, err | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | @ -15,7 +15,7 @@ type Result interface { | ||||||
| 	Headers() http.Header | 	Headers() http.Header | ||||||
| 	Body() []byte | 	Body() []byte | ||||||
| 	UnmarshalInto(interface{}) error | 	UnmarshalInto(interface{}) error | ||||||
| 	UnmarshalJSON() (*simplejson.Json, error) | 	UnmarshalSimpleJSON() (*simplejson.Json, error) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type result struct { | type result struct { | ||||||
|  | @ -66,10 +66,10 @@ func (r *result) UnmarshalInto(into interface{}) error { | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // UnmarshalJSON performs the request and attempts to unmarshal the response into a
 | // UnmarshalSimpleJSON performs the request and attempts to unmarshal the response into a
 | ||||||
| // simplejson.Json. The response body is assume to be JSON.
 | // simplejson.Json. The response body is assume to be JSON.
 | ||||||
| // The response must have a 200 status otherwise an error will be returned.
 | // The response must have a 200 status otherwise an error will be returned.
 | ||||||
| func (r *result) UnmarshalJSON() (*simplejson.Json, error) { | func (r *result) UnmarshalSimpleJSON() (*simplejson.Json, error) { | ||||||
| 	body, err := r.getBodyForUnmarshal() | 	body, err := r.getBodyForUnmarshal() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
|  |  | ||||||
|  | @ -198,7 +198,7 @@ var _ = Describe("Result suite", func() { | ||||||
| 
 | 
 | ||||||
| 		DescribeTable("with a result", | 		DescribeTable("with a result", | ||||||
| 			func(in unmarshalJSONTableInput) { | 			func(in unmarshalJSONTableInput) { | ||||||
| 				j, err := in.result.UnmarshalJSON() | 				j, err := in.result.UnmarshalSimpleJSON() | ||||||
| 				if in.expectedErr != nil { | 				if in.expectedErr != nil { | ||||||
| 					Expect(err).To(MatchError(in.expectedErr)) | 					Expect(err).To(MatchError(in.expectedErr)) | ||||||
| 					Expect(j).To(BeNil()) | 					Expect(j).To(BeNil()) | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ import ( | ||||||
| 	"crypto/tls" | 	"crypto/tls" | ||||||
| 	"crypto/x509" | 	"crypto/x509" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io/ioutil" | 	"os" | ||||||
| 	"time" | 	"time" | ||||||
| 
 | 
 | ||||||
| 	"github.com/go-redis/redis/v8" | 	"github.com/go-redis/redis/v8" | ||||||
|  | @ -170,7 +170,7 @@ func setupTLSConfig(opts options.RedisStoreOptions, opt *redis.Options) error { | ||||||
| 		if rootCAs == nil { | 		if rootCAs == nil { | ||||||
| 			rootCAs = x509.NewCertPool() | 			rootCAs = x509.NewCertPool() | ||||||
| 		} | 		} | ||||||
| 		certs, err := ioutil.ReadFile(opts.CAPath) | 		certs, err := os.ReadFile(opts.CAPath) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return fmt.Errorf("failed to load %q, %v", opts.CAPath, err) | 			return fmt.Errorf("failed to load %q, %v", opts.CAPath, err) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ package upstream | ||||||
| import ( | import ( | ||||||
| 	"encoding/json" | 	"encoding/json" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io/ioutil" | 	"io" | ||||||
| 	"log" | 	"log" | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"net/http/httptest" | 	"net/http/httptest" | ||||||
|  | @ -35,12 +35,12 @@ func TestUpstreamSuite(t *testing.T) { | ||||||
| 
 | 
 | ||||||
| var _ = BeforeSuite(func() { | var _ = BeforeSuite(func() { | ||||||
| 	// Set up files for serving via file servers
 | 	// Set up files for serving via file servers
 | ||||||
| 	dir, err := ioutil.TempDir("", "oauth2-proxy-upstream-suite") | 	dir, err := os.MkdirTemp("", "oauth2-proxy-upstream-suite") | ||||||
| 	Expect(err).ToNot(HaveOccurred()) | 	Expect(err).ToNot(HaveOccurred()) | ||||||
| 	Expect(ioutil.WriteFile(path.Join(dir, "foo"), []byte("foo"), 0644)).To(Succeed()) | 	Expect(os.WriteFile(path.Join(dir, "foo"), []byte("foo"), 0644)).To(Succeed()) | ||||||
| 	Expect(ioutil.WriteFile(path.Join(dir, "bar"), []byte("bar"), 0644)).To(Succeed()) | 	Expect(os.WriteFile(path.Join(dir, "bar"), []byte("bar"), 0644)).To(Succeed()) | ||||||
| 	Expect(os.Mkdir(path.Join(dir, "subdir"), os.ModePerm)).To(Succeed()) | 	Expect(os.Mkdir(path.Join(dir, "subdir"), os.ModePerm)).To(Succeed()) | ||||||
| 	Expect(ioutil.WriteFile(path.Join(dir, "subdir", "baz"), []byte("baz"), 0644)).To(Succeed()) | 	Expect(os.WriteFile(path.Join(dir, "subdir", "baz"), []byte("baz"), 0644)).To(Succeed()) | ||||||
| 	filesDir = dir | 	filesDir = dir | ||||||
| 
 | 
 | ||||||
| 	// Set up a webserver that reflects requests
 | 	// Set up a webserver that reflects requests
 | ||||||
|  | @ -148,7 +148,7 @@ func toTestHTTPRequest(req *http.Request) (testHTTPRequest, error) { | ||||||
| 	requestBody := []byte{} | 	requestBody := []byte{} | ||||||
| 	if req.Body != http.NoBody { | 	if req.Body != http.NoBody { | ||||||
| 		var err error | 		var err error | ||||||
| 		requestBody, err = ioutil.ReadAll(req.Body) | 		requestBody, err = io.ReadAll(req.Body) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return testHTTPRequest{}, err | 			return testHTTPRequest{}, err | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | @ -6,10 +6,10 @@ import ( | ||||||
| 	"crypto/x509" | 	"crypto/x509" | ||||||
| 	"crypto/x509/pkix" | 	"crypto/x509/pkix" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io/ioutil" |  | ||||||
| 	"math/big" | 	"math/big" | ||||||
| 	"net" | 	"net" | ||||||
| 	"net/url" | 	"net/url" | ||||||
|  | 	"os" | ||||||
| 	"strings" | 	"strings" | ||||||
| 	"time" | 	"time" | ||||||
| ) | ) | ||||||
|  | @ -21,7 +21,7 @@ func GetCertPool(paths []string) (*x509.CertPool, error) { | ||||||
| 	pool := x509.NewCertPool() | 	pool := x509.NewCertPool() | ||||||
| 	for _, path := range paths { | 	for _, path := range paths { | ||||||
| 		// Cert paths are a configurable option
 | 		// Cert paths are a configurable option
 | ||||||
| 		data, err := ioutil.ReadFile(path) // #nosec G304
 | 		data, err := os.ReadFile(path) // #nosec G304
 | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, fmt.Errorf("certificate authority file (%s) could not be read - %s", path, err) | 			return nil, fmt.Errorf("certificate authority file (%s) could not be read - %s", path, err) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | @ -3,7 +3,6 @@ package util | ||||||
| import ( | import ( | ||||||
| 	"crypto/x509" | 	"crypto/x509" | ||||||
| 	"encoding/pem" | 	"encoding/pem" | ||||||
| 	"io/ioutil" |  | ||||||
| 	"os" | 	"os" | ||||||
| 	"testing" | 	"testing" | ||||||
| 
 | 
 | ||||||
|  | @ -183,7 +182,7 @@ WrW4JMzLaGDtoHxRNNfo8E7fGkQ= | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func makeTestCertFile(t *testing.T, pem, dir string) *os.File { | func makeTestCertFile(t *testing.T, pem, dir string) *os.File { | ||||||
| 	file, err := ioutil.TempFile(dir, "test-certfile") | 	file, err := os.CreateTemp(dir, "test-certfile") | ||||||
| 	assert.NoError(t, err) | 	assert.NoError(t, err) | ||||||
| 	_, err = file.Write([]byte(pem)) | 	_, err = file.Write([]byte(pem)) | ||||||
| 	assert.NoError(t, err) | 	assert.NoError(t, err) | ||||||
|  | @ -196,7 +195,7 @@ func TestGetCertPool_NoRoots(t *testing.T) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestGetCertPool(t *testing.T) { | func TestGetCertPool(t *testing.T) { | ||||||
| 	tempDir, err := ioutil.TempDir("", "certtest") | 	tempDir, err := os.MkdirTemp("", "certtest") | ||||||
| 	assert.NoError(t, err) | 	assert.NoError(t, err) | ||||||
| 	defer func(path string) { | 	defer func(path string) { | ||||||
| 		rerr := os.RemoveAll(path) | 		rerr := os.RemoveAll(path) | ||||||
|  |  | ||||||
|  | @ -1,7 +1,6 @@ | ||||||
| package validation | package validation | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"io/ioutil" |  | ||||||
| 	"os" | 	"os" | ||||||
| 
 | 
 | ||||||
| 	"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options" | 	"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options" | ||||||
|  | @ -18,7 +17,7 @@ var _ = Describe("Common", func() { | ||||||
| 	BeforeEach(func() { | 	BeforeEach(func() { | ||||||
| 		validSecretSourceValue = []byte("This is a secret source value") | 		validSecretSourceValue = []byte("This is a secret source value") | ||||||
| 		Expect(os.Setenv(validSecretSourceEnv, "This is a secret source env")).To(Succeed()) | 		Expect(os.Setenv(validSecretSourceEnv, "This is a secret source env")).To(Succeed()) | ||||||
| 		tmp, err := ioutil.TempFile("", "oauth2-proxy-secret-source-test") | 		tmp, err := os.CreateTemp("", "oauth2-proxy-secret-source-test") | ||||||
| 		Expect(err).ToNot(HaveOccurred()) | 		Expect(err).ToNot(HaveOccurred()) | ||||||
| 		defer tmp.Close() | 		defer tmp.Close() | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2,7 +2,6 @@ package validation | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"crypto" | 	"crypto" | ||||||
| 	"io/ioutil" |  | ||||||
| 	"net/url" | 	"net/url" | ||||||
| 	"os" | 	"os" | ||||||
| 	"strings" | 	"strings" | ||||||
|  | @ -205,7 +204,7 @@ func TestRealClientIPHeader(t *testing.T) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestProviderCAFilesError(t *testing.T) { | func TestProviderCAFilesError(t *testing.T) { | ||||||
| 	file, err := ioutil.TempFile("", "absent.*.crt") | 	file, err := os.CreateTemp("", "absent.*.crt") | ||||||
| 	assert.NoError(t, err) | 	assert.NoError(t, err) | ||||||
| 	assert.NoError(t, file.Close()) | 	assert.NoError(t, file.Close()) | ||||||
| 	assert.NoError(t, os.Remove(file.Name())) | 	assert.NoError(t, os.Remove(file.Name())) | ||||||
|  |  | ||||||
|  | @ -2,7 +2,6 @@ package validation | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io/ioutil" |  | ||||||
| 	"os" | 	"os" | ||||||
| 
 | 
 | ||||||
| 	"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options" | 	"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options" | ||||||
|  | @ -53,7 +52,7 @@ func validateProvider(provider options.Provider, providerIDs map[string]struct{} | ||||||
| 			msgs = append(msgs, "missing setting: client-secret or client-secret-file") | 			msgs = append(msgs, "missing setting: client-secret or client-secret-file") | ||||||
| 		} | 		} | ||||||
| 		if provider.ClientSecret == "" && provider.ClientSecretFile != "" { | 		if provider.ClientSecret == "" && provider.ClientSecretFile != "" { | ||||||
| 			_, err := ioutil.ReadFile(provider.ClientSecretFile) | 			_, err := os.ReadFile(provider.ClientSecretFile) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				msgs = append(msgs, "could not read client secret file: "+provider.ClientSecretFile) | 				msgs = append(msgs, "could not read client secret file: "+provider.ClientSecretFile) | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|  | @ -347,7 +347,7 @@ func (p *AzureProvider) getEmailFromProfileAPI(ctx context.Context, accessToken | ||||||
| 		WithContext(ctx). | 		WithContext(ctx). | ||||||
| 		WithHeaders(makeAzureHeader(accessToken)). | 		WithHeaders(makeAzureHeader(accessToken)). | ||||||
| 		Do(). | 		Do(). | ||||||
| 		UnmarshalJSON() | 		UnmarshalSimpleJSON() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return "", err | 		return "", err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -72,7 +72,7 @@ func (p *DigitalOceanProvider) GetEmailAddress(ctx context.Context, s *sessions. | ||||||
| 		WithContext(ctx). | 		WithContext(ctx). | ||||||
| 		WithHeaders(makeOIDCHeader(s.AccessToken)). | 		WithHeaders(makeOIDCHeader(s.AccessToken)). | ||||||
| 		Do(). | 		Do(). | ||||||
| 		UnmarshalJSON() | 		UnmarshalSimpleJSON() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return "", err | 		return "", err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -8,7 +8,6 @@ import ( | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io" | 	"io" | ||||||
| 	"io/ioutil" |  | ||||||
| 	"net/url" | 	"net/url" | ||||||
| 	"os" | 	"os" | ||||||
| 	"strings" | 	"strings" | ||||||
|  | @ -231,7 +230,7 @@ func (p *GoogleProvider) setGroupRestriction(groups []string, adminEmail string, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func getAdminService(adminEmail string, credentialsReader io.Reader) *admin.Service { | func getAdminService(adminEmail string, credentialsReader io.Reader) *admin.Service { | ||||||
| 	data, err := ioutil.ReadAll(credentialsReader) | 	data, err := io.ReadAll(credentialsReader) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		logger.Fatal("can't read Google credentials file:", err) | 		logger.Fatal("can't read Google credentials file:", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -166,7 +166,6 @@ func TestGoogleProviderGroupValidator(t *testing.T) { | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //
 |  | ||||||
| func TestGoogleProviderGetEmailAddressInvalidEncoding(t *testing.T) { | func TestGoogleProviderGetEmailAddressInvalidEncoding(t *testing.T) { | ||||||
| 	p := newGoogleProvider(t) | 	p := newGoogleProvider(t) | ||||||
| 	body, err := json.Marshal(redeemResponse{ | 	body, err := json.Marshal(redeemResponse{ | ||||||
|  |  | ||||||
|  | @ -77,7 +77,7 @@ func (p *KeycloakProvider) EnrichSession(ctx context.Context, s *sessions.Sessio | ||||||
| 		WithContext(ctx). | 		WithContext(ctx). | ||||||
| 		SetHeader("Authorization", "Bearer "+s.AccessToken). | 		SetHeader("Authorization", "Bearer "+s.AccessToken). | ||||||
| 		Do(). | 		Do(). | ||||||
| 		UnmarshalJSON() | 		UnmarshalSimpleJSON() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		logger.Errorf("failed making request %v", err) | 		logger.Errorf("failed making request %v", err) | ||||||
| 		return err | 		return err | ||||||
|  |  | ||||||
|  | @ -124,6 +124,7 @@ func (p *KeycloakOIDCProvider) getAccessClaims(ctx context.Context, s *sessions. | ||||||
| // the format `client:role`.
 | // the format `client:role`.
 | ||||||
| //
 | //
 | ||||||
| // ResourceAccess format:
 | // ResourceAccess format:
 | ||||||
|  | //
 | ||||||
| //	"resource_access": {
 | //	"resource_access": {
 | ||||||
| //	  "clientA": {
 | //	  "clientA": {
 | ||||||
| //	    "roles": [
 | //	    "roles": [
 | ||||||
|  |  | ||||||
|  | @ -90,7 +90,7 @@ func (p *LinkedInProvider) GetEmailAddress(ctx context.Context, s *sessions.Sess | ||||||
| 		WithContext(ctx). | 		WithContext(ctx). | ||||||
| 		WithHeaders(makeLinkedInHeader(s.AccessToken)). | 		WithHeaders(makeLinkedInHeader(s.AccessToken)). | ||||||
| 		Do(). | 		Do(). | ||||||
| 		UnmarshalJSON() | 		UnmarshalSimpleJSON() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return "", err | 		return "", err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -7,9 +7,9 @@ import ( | ||||||
| 	"crypto/rsa" | 	"crypto/rsa" | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io/ioutil" |  | ||||||
| 	"math/big" | 	"math/big" | ||||||
| 	"net/url" | 	"net/url" | ||||||
|  | 	"os" | ||||||
| 	"time" | 	"time" | ||||||
| 
 | 
 | ||||||
| 	"github.com/golang-jwt/jwt" | 	"github.com/golang-jwt/jwt" | ||||||
|  | @ -123,7 +123,7 @@ func (p *LoginGovProvider) configure(opts options.LoginGovOptions) error { | ||||||
| 		p.JWTKey = signKey | 		p.JWTKey = signKey | ||||||
| 	case opts.JWTKeyFile != "": | 	case opts.JWTKeyFile != "": | ||||||
| 		// The JWT key is in the filesystem
 | 		// The JWT key is in the filesystem
 | ||||||
| 		keyData, err := ioutil.ReadFile(opts.JWTKeyFile) | 		keyData, err := os.ReadFile(opts.JWTKeyFile) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return fmt.Errorf("could not read key file: %v", opts.JWTKeyFile) | 			return fmt.Errorf("could not read key file: %v", opts.JWTKeyFile) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | @ -44,7 +44,7 @@ func (p *NextcloudProvider) EnrichSession(ctx context.Context, s *sessions.Sessi | ||||||
| 		WithContext(ctx). | 		WithContext(ctx). | ||||||
| 		SetHeader("Authorization", "Bearer "+s.AccessToken). | 		SetHeader("Authorization", "Bearer "+s.AccessToken). | ||||||
| 		Do(). | 		Do(). | ||||||
| 		UnmarshalJSON() | 		UnmarshalSimpleJSON() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		logger.Errorf("failed making request %v", err) | 		logger.Errorf("failed making request %v", err) | ||||||
| 		return err | 		return err | ||||||
|  |  | ||||||
|  | @ -4,9 +4,9 @@ import ( | ||||||
| 	"context" | 	"context" | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io/ioutil" |  | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"net/url" | 	"net/url" | ||||||
|  | 	"os" | ||||||
| 	"regexp" | 	"regexp" | ||||||
| 	"strings" | 	"strings" | ||||||
| 
 | 
 | ||||||
|  | @ -67,7 +67,7 @@ func (p *ProviderData) GetClientSecret() (clientSecret string, err error) { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// Getting ClientSecret can fail in runtime so we need to report it without returning the file name to the user
 | 	// Getting ClientSecret can fail in runtime so we need to report it without returning the file name to the user
 | ||||||
| 	fileClientSecret, err := ioutil.ReadFile(p.ClientSecretFile) | 	fileClientSecret, err := os.ReadFile(p.ClientSecretFile) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		logger.Errorf("error reading client secret file %s: %s", p.ClientSecretFile, err) | 		logger.Errorf("error reading client secret file %s: %s", p.ClientSecretFile, err) | ||||||
| 		return "", errors.New("could not read client secret file") | 		return "", errors.New("could not read client secret file") | ||||||
|  |  | ||||||
|  | @ -1,7 +1,6 @@ | ||||||
| package providers | package providers | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"io/ioutil" |  | ||||||
| 	"os" | 	"os" | ||||||
| 	"testing" | 	"testing" | ||||||
| 
 | 
 | ||||||
|  | @ -43,7 +42,7 @@ func TestClientSecretFileOptionFails(t *testing.T) { | ||||||
| func TestClientSecretFileOption(t *testing.T) { | func TestClientSecretFileOption(t *testing.T) { | ||||||
| 	g := NewWithT(t) | 	g := NewWithT(t) | ||||||
| 
 | 
 | ||||||
| 	f, err := ioutil.TempFile("", "client_secret_temp_file_") | 	f, err := os.CreateTemp("", "client_secret_temp_file_") | ||||||
| 	g.Expect(err).ToNot(HaveOccurred()) | 	g.Expect(err).ToNot(HaveOccurred()) | ||||||
| 
 | 
 | ||||||
| 	clientSecretFileName := f.Name() | 	clientSecretFileName := f.Name() | ||||||
|  |  | ||||||
|  | @ -1,7 +1,6 @@ | ||||||
| package main | package main | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"io/ioutil" |  | ||||||
| 	"os" | 	"os" | ||||||
| 	"strings" | 	"strings" | ||||||
| 	"testing" | 	"testing" | ||||||
|  | @ -18,7 +17,7 @@ type ValidatorTest struct { | ||||||
| func NewValidatorTest(t *testing.T) *ValidatorTest { | func NewValidatorTest(t *testing.T) *ValidatorTest { | ||||||
| 	vt := &ValidatorTest{} | 	vt := &ValidatorTest{} | ||||||
| 	var err error | 	var err error | ||||||
| 	f, err := ioutil.TempFile("", "test_auth_emails_") | 	f, err := os.CreateTemp("", "test_auth_emails_") | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		t.Fatalf("failed to create temp file: %v", err) | 		t.Fatalf("failed to create temp file: %v", err) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue