Skip to content

Commit

Permalink
Add evss claims async to rack attack throttling (#3454)
Browse files Browse the repository at this point in the history
* Add evss claims async to rack attack throttling

* Update rack_attack.rb

* Change throttle to match polling rate
  • Loading branch information
edmkitty authored Oct 21, 2019
1 parent cc24b80 commit 1dfd82b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config/initializers/rack_attack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class Rack::Attack
req.ip if req.path == '/v0/vic/vic_submissions' && req.post?
end

throttle('evss_claims_async', limit: 12, period: 60) do |req|
req.ip if req.path == '/v0/evss_claims_async'
end

# Source: https://github.com/kickstarter/rack-attack#x-ratelimit-headers-for-well-behaved-clients
Rack::Attack.throttled_response = lambda do |env|
rate_limit = env['rack.attack.match_data']
Expand Down
9 changes: 9 additions & 0 deletions spec/middleware/rack/attack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,14 @@ def app
expect(last_response.status).to eq(429)
end
end

context 'evss claims' do
let(:limit) { 12 }
let(:endpoint) { '/v0/evss_claims_async' }

it 'limits requests' do
expect(last_response.status).to eq(429)
end
end
end
end

0 comments on commit 1dfd82b

Please sign in to comment.