From 5d7ba4f9ce600af9d2a9cfa40f79af6f4594e0ef Mon Sep 17 00:00:00 2001 From: AI-Mozi Date: Mon, 19 Aug 2024 21:36:30 +0200 Subject: [PATCH] Add a `Values::URL#===` method --- lib/ronin/recon/values/url.rb | 18 ++++++++++++++++++ spec/values/url_spec.rb | 31 +++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/lib/ronin/recon/values/url.rb b/lib/ronin/recon/values/url.rb index 9eb8f05..c2b82f7 100644 --- a/lib/ronin/recon/values/url.rb +++ b/lib/ronin/recon/values/url.rb @@ -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 diff --git a/spec/values/url_spec.rb b/spec/values/url_spec.rb index 0930fea..3eb39e5 100644 --- a/spec/values/url_spec.rb +++ b/spec/values/url_spec.rb @@ -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' } @@ -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