File tree 4 files changed +17
-2
lines changed
4 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -161,6 +161,8 @@ def lengths
161
161
162
162
class History
163
163
def initialize ( days_previous , start_date = nil )
164
+ # we only store five years of data in Redis
165
+ raise ArgumentError if days_previous < 1 || days_previous > ( 5 * 365 )
164
166
@days_previous = days_previous
165
167
@start_date = start_date || Time . now . utc . to_date
166
168
end
Original file line number Diff line number Diff line change @@ -50,7 +50,10 @@ def self.set(key, val)
50
50
51
51
get "/" do
52
52
@redis_info = redis_info . select { |k , v | REDIS_KEYS . include? k }
53
- stats_history = Sidekiq ::Stats ::History . new ( ( params [ "days" ] || 30 ) . to_i )
53
+ days = ( params [ "days" ] || 30 ) . to_i
54
+ return halt ( 401 ) if days < 1 || days > 180
55
+
56
+ stats_history = Sidekiq ::Stats ::History . new ( days )
54
57
@processed_history = stats_history . processed
55
58
@failed_history = stats_history . failed
56
59
Original file line number Diff line number Diff line change 156
156
Time ::DATE_FORMATS [ :default ] = @before
157
157
end
158
158
159
+ describe "history" do
160
+ it "does not allow invalid input" do
161
+ assert_raises ( ArgumentError ) { Sidekiq ::Stats ::History . new ( -1 ) }
162
+ assert_raises ( ArgumentError ) { Sidekiq ::Stats ::History . new ( 0 ) }
163
+ assert_raises ( ArgumentError ) { Sidekiq ::Stats ::History . new ( 2000 ) }
164
+ assert Sidekiq ::Stats ::History . new ( 200 )
165
+ end
166
+ end
167
+
159
168
describe "processed" do
160
169
it 'retrieves hash of dates' do
161
170
Sidekiq . redis do |c |
Original file line number Diff line number Diff line change @@ -748,8 +748,9 @@ def app
748
748
basic_authorize 'a' , 'b'
749
749
750
750
get '/'
751
-
752
751
assert_equal 200 , last_response . status
752
+ get '/?days=1000000'
753
+ assert_equal 401 , last_response . status
753
754
end
754
755
end
755
756
You can’t perform that action at this time.
0 commit comments