Skip to content

Commit

Permalink
Add a Values::URL#=== method
Browse files Browse the repository at this point in the history
  • Loading branch information
moozzi committed Aug 28, 2024
1 parent 2338010 commit 5d7ba4f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/ronin/recon/values/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,24 @@ def self.value_type
:url
end

#
# Case equality method used for fuzzy matching.
#
# @param [URL, Value] other
# The other value to compare.
#
# @return [Boolean]
# Indicates whether the other value is an URL with
# the same uri.
#
def ===(other)
case other
when URL
@uri == other.uri
else
false
end
end
end
end
end
Expand Down
31 changes: 31 additions & 0 deletions spec/values/url_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'spec_helper'
require 'ronin/recon/values/url'
require 'ronin/recon/values/domain'

describe Ronin::Recon::Values::URL do
let(:url) { 'https://www.example.com/index.html' }
Expand Down Expand Up @@ -234,4 +235,34 @@
expect(subject.value_type).to be(:url)
end
end

describe "#===" do
let(:url) { 'https://www.foo.example.com/index.html' }

context "when given an URL object" do
context "and it has the same uri as the other URL value" do
let(:other) { described_class.new(url) }

it "must return true" do
expect(subject === other).to be(true)
end
end

context "but it has diffferent uri than the other URL value" do
let(:other) { described_class.new('https://www.example.net/index.html') }

it "must return false" do
expect(subject === other).to be(false)
end
end
end

context "when given non-URL object" do
let(:other) { Ronin::Recon::Values::Domain.new('example.com') }

it "must return false" do
expect(subject === other).to be(false)
end
end
end
end

0 comments on commit 5d7ba4f

Please sign in to comment.