Skip to content

Commit

Permalink
Add a Values::URL#=== method (#164)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Postmodern <postmodern.mod3@gmail.com>
  • Loading branch information
AI-Mozi and postmodern authored Aug 28, 2024
1 parent 2338010 commit fc4ba5b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/ronin/recon/values/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,27 @@ def as_json
return hash
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.
#
# @since 0.3.0
#
def ===(other)
case other
when URL
@uri == other.uri
else
false
end
end

#
# Returns the type or kind of recon value.
#
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 fc4ba5b

Please sign in to comment.