require "test_helper"
class VulnerabilityHelperTest < ActiveSupport::TestCase
  test "Check for duplicate vulnerabilities which have complex query, should pass" do
    require_relative "#{Rails.root.join('lib', 'helpers', 'vulnerability_helpers')}"
    # The params and values are in a differnet order, but this should still result in a duplicate
    result = Result.find(4)

    vuln = Vulnerability.new
    vuln.url = "https://www.netflix.com/bar/whatever?things=salsjklfasj&bar=<scrssfipt>alert()</script>&stuff=salkfsaafsafdskjfs"
    vuln.type = "Reflected XSS"
    result.update_vulnerabilities([vuln])

    # With a differenet param, it should create a new result
    assert_equal(3, result.metadata["vulnerabilities"].count)
    vuln2 = Vulnerability.new
    vuln2.url = "https://www.netflix.com/bar/whatever?new_param=salkafdskjfs&things=salsjklfasj&bar=<script>alert()</script>"
    vuln2.type = "Reflected XSS"
    result.update_vulnerabilities([vuln2])
    assert_equal(4, result.metadata["vulnerabilities"].count)
  end
end


# detectify

# we shoudl expec ton-call to be a bit busy
