Skip to content

Commit

Permalink
Handle rate_limit_before_auth setting in its deprecated location (#1573)
Browse files Browse the repository at this point in the history
* Handle `rate_limit_before_auth` setting in its deprecated location
* Update projects/gloo/pkg/plugins/ratelimit/plugin_test.go
* Restructure unit test
* Remove new getter function
  • Loading branch information
marcogschmidt authored and soloio-bulldozer[bot] committed Nov 1, 2019
1 parent dc0c0e3 commit bc3835e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
changelog:
- type: FIX
description: >
Handle the `rate_limit_before_auth` setting in its deprecated location. We currently correctly handle the flag in its
new location (`spec.extensions.configs.rate-limit.rate_limit_before_auth`) but ignore it in the
deprecated one (`spec.ratelimit_server.rate_limit_before_auth`).
issueLink: https://github.com/solo-io/gloo/issues/1572
1 change: 1 addition & 0 deletions projects/gloo/pkg/plugins/ratelimit/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (p *Plugin) handleDeprecatedPluginConfig(params plugins.InitParams) error {
p.upstreamRef = settings.RatelimitServerRef
p.timeout = settings.RequestTimeout
p.denyOnFail = settings.DenyOnFail
p.rateLimitBeforeAuth = settings.RateLimitBeforeAuth
return nil
}

Expand Down
38 changes: 18 additions & 20 deletions projects/gloo/pkg/plugins/ratelimit/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package ratelimit_test
import (
"time"

"github.com/solo-io/gloo/projects/gloo/pkg/plugins/ratelimit"

extauthapi "github.com/solo-io/gloo/projects/gloo/pkg/api/v1/enterprise/plugins/extauth/v1"
"github.com/solo-io/gloo/projects/gloo/pkg/plugins/extauth"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

. "github.com/solo-io/gloo/projects/gloo/pkg/plugins/ratelimit"

envoycore "github.com/envoyproxy/go-control-plane/envoy/api/v2/core"
envoyratelimit "github.com/envoyproxy/go-control-plane/envoy/config/filter/http/rate_limit/v2"
envoyhttp "github.com/envoyproxy/go-control-plane/envoy/config/filter/network/http_connection_manager/v2"
Expand All @@ -30,13 +30,13 @@ var _ = Describe("Plugin", func() {
rlSettings *ratelimitpb.Settings
initParams plugins.InitParams
params plugins.Params
rlPlugin *Plugin
rlPlugin *ratelimit.Plugin
extensions *gloov1.Extensions
ref core.ResourceRef
)

beforeEach := func() {
rlPlugin = NewPlugin()
rlPlugin = ratelimit.NewPlugin()
ref = core.ResourceRef{
Name: "test",
Namespace: "test",
Expand All @@ -63,7 +63,7 @@ var _ = Describe("Plugin", func() {
Expect(cfg.FailureModeDeny).To(BeFalse())
}

hundredms := DefaultTimeout
hundredms := ratelimit.DefaultTimeout
expectedConfig := &envoyratelimit.RateLimit{
Domain: "custom",
FailureModeDeny: false,
Expand All @@ -86,7 +86,7 @@ var _ = Describe("Plugin", func() {
It("default timeout is 100ms", func() {
filters, err := rlPlugin.HttpFilters(params, nil)
Expect(err).NotTo(HaveOccurred())
timeout := DefaultTimeout
timeout := ratelimit.DefaultTimeout
Expect(filters).To(HaveLen(1))
for _, f := range filters {
cfg := getConfig(f.HttpFilter)
Expand All @@ -113,7 +113,7 @@ var _ = Describe("Plugin", func() {
})

Context("rate limit ordering", func() {
JustBeforeEach(func() {
BeforeEach(func() {
timeout := time.Second
params.Snapshot.Upstreams = []*gloov1.Upstream{
{
Expand All @@ -124,17 +124,13 @@ var _ = Describe("Plugin", func() {
},
}
rlSettings.RateLimitBeforeAuth = true
initParams.Settings = &gloov1.Settings{
RatelimitServer: rlSettings,
Extauth: &extauthapi.Settings{
ExtauthzServerRef: &core.ResourceRef{
Name: "extauth-upstream",
Namespace: "ns",
},
RequestTimeout: &timeout,
initParams.Settings.Extauth = &extauthapi.Settings{
ExtauthzServerRef: &core.ResourceRef{
Name: "extauth-upstream",
Namespace: "ns",
},
RequestTimeout: &timeout,
}
rlPlugin.Init(initParams)
})

It("should be ordered before ext auth", func() {
Expand Down Expand Up @@ -185,13 +181,14 @@ var _ = Describe("Plugin", func() {
Expect(err).NotTo(HaveOccurred())

glooExtensions := map[string]*types.Struct{
ExtensionName: settingsStruct,
ratelimit.ExtensionName: settingsStruct,
}
extensions = &gloov1.Extensions{
Configs: glooExtensions,
}
initParams.ExtensionsSettings = extensions
rlPlugin.Init(initParams)
err = rlPlugin.Init(initParams)
Expect(err).NotTo(HaveOccurred())
})
allTests()
})
Expand All @@ -201,8 +198,9 @@ var _ = Describe("Plugin", func() {
BeforeEach(beforeEach)

JustBeforeEach(func() {
initParams.Settings = &gloov1.Settings{RatelimitServer: rlSettings}
rlPlugin.Init(initParams)
initParams.Settings.RatelimitServer = rlSettings
err := rlPlugin.Init(initParams)
Expect(err).NotTo(HaveOccurred())
})
allTests()
})
Expand Down

0 comments on commit bc3835e

Please sign in to comment.