<commit_before>require 'spec_helper'

describe Whois::Server::Adapters::Verisign do

  let(:definition) { [:tld, ".test", "whois.test", {}] }
  let(:server) { described_class.new(*definition) }


  describe "#lookup" do
    context "without referral" do
      it "returns the WHOIS record" do
        response = "No match for example.test."
        expected = response
        server.query_handler.expects(:call).with("=example.test", "whois.test", 43).returns(response)

        record = server.lookup("example.test")
        record.to_s.should  == expected
        record.parts.should have(1).part
        record.parts.should == [Whois::Record::Part.new(:body => response, :host => "whois.test")]
      end
    end

    context "with referral" do
      it "follows all referrals" do
        referral = File.read(fixture("referrals/crsnic.com.txt"))
        response = "Match for example.test."
        expected = referral + "\n" + response
        server.query_handler.expects(:call).with("=example.test", "whois.test", 43).returns(referral)
        server.query_handler.expects(:call).with("example.test", "whois.markmonitor.com", 43).returns(response)

        record = server.lookup("example.test")
        record.to_s.should  == expected
        record.parts.should have(2).parts
        record.parts.should == [Whois::Record::Part.new(:body => referral, :host => "whois.test"), Whois::Record::Part.new(:body => response, :host => "whois.markmonitor.com")]
      end

      it "extracts the closest referral if multiple referrals" do
        referral = File.read(fixture("referrals/crsnic.com_referral_multiple.txt"))
        server.query_handler.expects(:call).with("=example.test", "whois.test", 43).returns(referral)
        server.query_handler.expects(:call).with("example.test", "whois.markmonitor.com", 43).returns("")

        record = server.lookup("example.test")
        record.parts.should have(2).parts
      end

      it "ignores referral if is not defined" do
        referral = File.read(fixture("referrals/crsnic.com_referral_not_defined.txt"))
        server.query_handler.expects(:call).with("=example.test", "whois.test", 43).returns(referral)
        server.query_handler.expects(:call).never

        record = server.lookup("example.test")
        record.parts.should have(1).part
      end

      it "ignores referral if options[:referral] is false" do
        referral = File.read(fixture("referrals/crsnic.com_referral_not_defined.txt"))
        # server.options[:referral] = false
        server.query_handler.expects(:call).with("=example.test", "whois.test", 43).returns(referral)
        server.query_handler.expects(:call).never

        record = server.lookup("example.test")
        record.parts.should have(1).part
      end

      # (see #103)
      # This is the case of vrsn-20100925-dnssecmonitor86.net
      it "ignores referral (gracefully) if missing" do
        referral = File.read(fixture("referrals/crsnic.com_referral_missing.txt"))
        server.query_handler.expects(:call).with("=example.test", "whois.test", 43).returns(referral)
        server.query_handler.expects(:call).never
<commit_msg>Fix test to correctly ignore referral.<commit_after>require 'spec_helper'

describe Whois::Server::Adapters::Verisign do

  let(:definition) { [:tld, ".test", "whois.test", {}] }
  let(:server) { described_class.new(*definition) }


  describe "#lookup" do
    context "without referral" do
      it "returns the WHOIS record" do
        response = "No match for example.test."
        expected = response
        server.query_handler.expects(:call).with("=example.test", "whois.test", 43).returns(response)

        record = server.lookup("example.test")
        record.to_s.should  == expected
        record.parts.should have(1).part
        record.parts.should == [Whois::Record::Part.new(:body => response, :host => "whois.test")]
      end
    end

    context "with referral" do
      it "follows all referrals" do
        referral = File.read(fixture("referrals/crsnic.com.txt"))
        response = "Match for example.test."
        expected = referral + "\n" + response
        server.query_handler.expects(:call).with("=example.test", "whois.test", 43).returns(referral)
        server.query_handler.expects(:call).with("example.test", "whois.markmonitor.com", 43).returns(response)

        record = server.lookup("example.test")
        record.to_s.should  == expected
        record.parts.should have(2).parts
        record.parts.should == [Whois::Record::Part.new(:body => referral, :host => "whois.test"), Whois::Record::Part.new(:body => response, :host => "whois.markmonitor.com")]
      end

      it "extracts the closest referral if multiple referrals" do
        referral = File.read(fixture("referrals/crsnic.com_referral_multiple.txt"))
        server.query_handler.expects(:call).with("=example.test", "whois.test", 43).returns(referral)
        server.query_handler.expects(:call).with("example.test", "whois.markmonitor.com", 43).returns("")

        record = server.lookup("example.test")
        record.parts.should have(2).parts
      end

      it "ignores referral if is not defined" do
        referral = File.read(fixture("referrals/crsnic.com_referral_not_defined.txt"))
        server.query_handler.expects(:call).with("=example.test", "whois.test", 43).returns(referral)
        server.query_handler.expects(:call).never

        record = server.lookup("example.test")
        record.parts.should have(1).part
      end

      it "ignores referral if options[:referral] is false" do
        referral = File.read(fixture("referrals/crsnic.com.txt"))
        server.options[:referral] = false
        server.query_handler.expects(:call).with("=example.test", "whois.test", 43).returns(referral)
        server.query_handler.expects(:call).never

        record = server.lookup("example.test")
        record.parts.should have(1).part
      end

      # (see #103)
      # This is the case of vrsn-20100925-dnssecmonitor86.net
      it "ignores referral (gracefully) if missing" do
        referral = File.read(fixture("referrals/crsnic.com_referral_missing.txt"))
        server.query_handler.expects(:call).with("=example.test", "whois.test", 43).returns(referral)
        server.query_handler.expects(:call).never

{'fraction_non_alphanumeric': 0.14666666666666667, 'fraction_numerical': 0.010793650793650795, 'mean_word_length': 3.30396174863388, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1680050', 'n_tokens_mistral': 2013, 'n_tokens_neox': 1901, 'n_words': 347}