1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2025-08-06 22:42:56 +02:00

fix: return error for empty Redis URL list (#3101)

* fix: return error for empty Redis URL list

* add changelog entry

Signed-off-by: Jan Larwig <jan@larwig.com>

---------

Signed-off-by: Jan Larwig <jan@larwig.com>
Co-authored-by: Jan Larwig <jan@larwig.com>
This commit is contained in:
Daniel Givens
2025-07-17 02:23:28 -05:00
committed by GitHub
parent 6c30a3c70b
commit 0e1dc9bb84
3 changed files with 174 additions and 140 deletions

View File

@ -11,6 +11,7 @@
- [#3072](https://github.com/oauth2-proxy/oauth2-proxy/pull/3072) feat: support for multiple github orgs #3072 (@daniel-mersch)
- [#3116](https://github.com/oauth2-proxy/oauth2-proxy/pull/3116) feat: bump to go1.24.5 and full dependency update (@wardviaene / @dolmen)
- [#3097](https://github.com/oauth2-proxy/oauth2-proxy/pull/3097) chore(deps): update alpine base image to v3.22.0
- [#3101](https://github.com/oauth2-proxy/oauth2-proxy/pull/3101) fix: return error for empty Redis URL list (@dgivens)
# V7.9.0

View File

@ -218,6 +218,10 @@ func setupTLSConfig(opts options.RedisStoreOptions, opt *redis.Options) error {
// parseRedisURLs parses a list of redis urls and returns a list
// of addresses in the form of host:port and redis.Options that can be used to connect to Redis
func parseRedisURLs(urls []string) ([]string, *redis.Options, error) {
if len(urls) == 0 {
return nil, nil, fmt.Errorf("unable to parse redis urls: no redis urls provided")
}
addrs := []string{}
var redisOptions *redis.Options
for _, u := range urls {

View File

@ -19,6 +19,7 @@ const (
)
var _ = Describe("Redis SessionStore Tests", func() {
Describe("Redis SessionStore Creation", func() {
// helper interface to allow us to close client connections
// All non-nil redis clients should implement this
type closer interface {
@ -243,3 +244,31 @@ var _ = Describe("Redis SessionStore Tests", func() {
})
})
})
Describe("Redis URL Parsing", func() {
It("should parse valid redis URL", func() {
addrs, opts, err := parseRedisURLs([]string{"redis://localhost:6379"})
Expect(err).ToNot(HaveOccurred())
Expect(addrs).To(Equal([]string{"localhost:6379"}))
Expect(opts).ToNot(BeNil())
Expect(opts.Addr).To(Equal("localhost:6379"))
})
It("should return error for invalid redis URL", func() {
addrs, opts, err := parseRedisURLs([]string{"invalid://url"})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("unable to parse redis url"))
Expect(err.Error()).To(Not(ContainSubstring("no redis urls provided")))
Expect(addrs).To(BeNil())
Expect(opts).To(BeNil())
})
It("should return error when no URLs provided", func() {
addrs, opts, err := parseRedisURLs([]string{})
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("unable to parse redis urls: no redis urls provided"))
Expect(addrs).To(BeNil())
Expect(opts).To(BeNil())
})
})
})