Skip to content

Commit

Permalink
OTWO-7262 Fixed null timespan in vulnerabilities (#1792)
Browse files Browse the repository at this point in the history
  • Loading branch information
Priya5 authored Jul 25, 2024
1 parent 9cda888 commit 36ac735
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
13 changes: 10 additions & 3 deletions app/helpers/vulnerabilities_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,28 @@ def filter_severity_param
end

def filter_version_param
params.fetch(:filter, {})[:version]
decoded_params.fetch(:filter, {})[:version]
end

def filter_major_version_param
params.fetch(:filter, {})[:major_version]
decoded_params.fetch(:filter, {})[:major_version]
end

def filter_period_param
params.fetch(:filter, {})[:period]
decoded_params.fetch(:filter, {})[:period]
end

def sort_col_param
params.fetch(:sort, {})[:col]
end

def decoded_params
return params unless params.fetch(:filter, {})[:period].to_s.match(/filter/)

decoded_params = URI.decode_www_form(CGI.unescape(request.query_string))
decoded_params.to_h
end

def no_versions_available
[Release.new(id: '', version: t('.vulnerabilities.filter.no_versions_available'))]
end
Expand Down
8 changes: 8 additions & 0 deletions test/controllers/vulnerabilities_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ class VulnerabilitiesControllerTest < ActionController::TestCase
_(assigns(:vulnerabilities).to_a).must_equal r1_3.vulnerabilities.order_by
end

it 'should parse the filters correctly and return the vulnerabilities' do
get :index,
params: { id: security_set.project.to_param, filter: { major_version: '1', period: '&filter[version]=1' } }
_(assigns(:release)).must_equal r1_3
_(assigns(:minor_versions).to_a).must_equal [r1_3]
_(assigns(:vulnerabilities).to_a).must_equal r1_3.vulnerabilities.order_by
end

it 'Release timespan should be disable if there are no releases availble within the timespan' do
security_set = create(:project_security_set)
create(:release, version: '1.0', released_on: 5.years.ago, project_security_set: security_set)
Expand Down

0 comments on commit 36ac735

Please sign in to comment.