Skip to content

Commit b647ae6

Browse files
committed
fix failing tests
1 parent 7a190fc commit b647ae6

File tree

5 files changed

+96
-11
lines changed

5 files changed

+96
-11
lines changed

lib/helpers/vulnerability_helpers.rb

+14-6
Original file line numberDiff line numberDiff line change
@@ -447,14 +447,22 @@ def find_duplicate_vulnerability(vulnerability, options={})
447447
end
448448
else
449449
begin
450+
450451
vuln_url = URI.parse(vulnerability.url)
451-
existing_vulnerabilities.select{|v|
452-
v["type"] == vulnerability.type &&
453-
vuln_url.host == URI.parse(v["url"]).host &&
454-
vuln_url.path == URI.parse(v["url"]).path &&
455-
URI.parse(v["url"]).query.split('&').each_slice(1).map(&:join).map { |param| param.split('=').first }.sort == vuln_url.query.split('&').each_slice(1).map(&:join).map { |param| param.split('=').first }.sort}
452+
if vuln_url.query.to_s.present?
453+
existing_vulnerabilities.select{|v|
454+
v["type"] == vulnerability.type &&
455+
vuln_url.host == URI.parse(v["url"]).host &&
456+
vuln_url.path == URI.parse(v["url"]).path &&
457+
URI.parse(v["url"]).query.split('&').each_slice(1).map(&:join).map { |param| param.split('=').first }.sort == vuln_url.query.split('&').each_slice(1).map(&:join).map { |param| param.split('=').first }.sort}
458+
else
459+
existing_vulnerabilities.select{|v|
460+
v["type"] == vulnerability.type && v["url"] == vulnerability.url}
461+
end
456462
rescue => e
457-
puts e
463+
require 'byebug'
464+
byebug
465+
puts 1
458466
end
459467

460468
end

test/fixtures/results.yml

+78-1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,83 @@ result_2:
153153
key_suffix: {}
154154
metadata_hash:
155155

156+
result_4:
157+
id: 4
158+
title: https://github.com/Netflix/grouper3
159+
url: https://github.com/Netflix/grouper3
160+
status_id:
161+
created_at: 2016-11-16 01:45:41.206070000 Z
162+
updated_at: 2017-01-12 21:36:06.803003000 Z
163+
domain: github.com
164+
user_id:
165+
content:
166+
metadata_archive: {}
167+
metadata:
168+
github_analyzer:
169+
owner: Netflix
170+
private: true
171+
language:
172+
account_type: Organization
173+
git_clone_url: ssh://github.com/Netflix/grouper3.git
174+
vulnerabilities:
175+
- id: 2600a431554c04bbbcd2b74a57f18d54
176+
url: https://github.com/Netflix/grouper3/blob/e4ff5ffe59451067881faeb08a46119c759e38b2/grouper/static/app/angular/search/services.js
177+
term: ssss
178+
type: '"sss" - content match'
179+
score: 1.131043
180+
source:
181+
- github
182+
status: Open
183+
task_id: '3'
184+
severity: High
185+
file_name: services.js
186+
identified: '2016-11-15T17:45:41.211-08:00'
187+
code_fragment: |-
188+
'use strict';
189+
190+
angular.module('grouper')
191+
.service('SearchApi', function (GrouperRestangular
192+
external_link: {}
193+
attack_vectors: []
194+
match_location: content
195+
- id: 22222431554c04bbbcd2b74a57f18d22
196+
url: https://www.netflix.com/bar/whatever?stuff=salkafdskjfs&things=salsjklfasj&bar=<script>alert()</script>
197+
type: 'Reflected XSS'
198+
task_id: '3'
199+
source:
200+
- detectify
201+
severity: Observation
202+
status: Open
203+
- id: da05be901b9be3c6fadec856d5f29158
204+
url: https://github.com/Netflix/grouper/blob/e4ff5ffe59451067881faeb08a46119c759e38b2/grouper/static/app/angular/search/services.js
205+
term: sss
206+
type: '"ssss" - content match'
207+
score: 1.131043
208+
source:
209+
- github
210+
status: Open
211+
task_id: '3'
212+
severity: Observation
213+
file_name: services.js
214+
identified: '2016-11-15T17:45:41.211-08:00'
215+
code_fragment: |-
216+
) {
217+
return GrouperRestangular.all('search');
218+
})
219+
.service('SearchService', function (SearchApi
220+
external_link: {}
221+
attack_vectors: []
222+
match_location: content
223+
vulnerability_count:
224+
open: 3
225+
closed: 0
226+
source:
227+
github: 3
228+
task_id:
229+
'2': 3
230+
key_suffix: {}
231+
metadata_hash:
232+
156233
result_3:
157234
id: 3
158235
title: https://github.com/Netflix/grouper2
@@ -192,7 +269,7 @@ result_3:
192269
external_link: {}
193270
attack_vectors: []
194271
match_location: content
195-
- id: 2600a431554c04bbbcd2b74a57f18d54
272+
- id: 22222431554c04bbbcd2b74a57f18d22
196273
url: https://www.netflix.com/bar/whatever?stuff=salkafdskjfs&things=salsjklfasj&bar=<script>alert()</script>
197274
type: 'Reflected XSS'
198275
task_id: '3'

test/models/results_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ResultTest < ActiveSupport::TestCase
3838
test "should perform a default result search" do
3939

4040
ransack, results = Result.perform_search(q={"status_id_includes_closed"=>"0", "g"=>{"0"=>{"m"=>"or", "status_id_null"=>1, "status_closed_not_eq"=>true}}})
41-
assert_equal(5, results.length)
41+
assert_equal(6, results.length)
4242
end
4343

4444
test "should perform a tag result search" do
@@ -68,7 +68,7 @@ class ResultTest < ActiveSupport::TestCase
6868

6969
test "should perform a negative metadata element result search" do
7070
ransack, results = Result.perform_search({metadata_search: "github_analyzer:private!=false"}, 1, 25, {include_metadata_column:true})
71-
assert_equal(2, results.length)
71+
assert_equal(3, results.length)
7272
end
7373

7474
# Instance Method Tests

test/models/status_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class StatusTest < ActiveSupport::TestCase
2727
# require 'active_record/fixtures'
2828
# ActiveRecord::FixtureSet.create_fixtures(Rails.root.join('test', 'fixtures'), 'results')
2929
# byebug
30-
assert_equal(5, fixture_status.reset_default.count)
30+
assert_equal(6, fixture_status.reset_default.count)
3131
end
3232

3333
test "should to_string a name" do

test/tasks/vulnerability_helper_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class VulnerabilityHelperTest < ActiveSupport::TestCase
33
test "Check for duplicate vulnerabilities which have complex query, should pass" do
44
require_relative "#{Rails.root.join('lib', 'helpers', 'vulnerability_helpers')}"
55
# The params and values are in a differnet order, but this should still result in a duplicate
6-
result = Result.find(3)
6+
result = Result.find(4)
77

88
vuln = Vulnerability.new
99
vuln.url = "https://www.netflix.com/bar/whatever?things=salsjklfasj&bar=<scrssfipt>alert()</script>&stuff=salkfsaafsafdskjfs"

0 commit comments

Comments
 (0)