trackback_spec.rb
上传用户:netsea168
上传日期:2022-07-22
资源大小:4652k
文件大小:2k
源码类别:

Ajax

开发平台:

Others

  1. require File.dirname(__FILE__) + '/../spec_helper'
  2. describe Trackback, 'With the various trackback filters loaded and DNS mocked out appropriately' do
  3.   before(:each) do
  4.     IPSocket.stub!(:getaddress).and_return { raise SocketError.new("getaddrinfo: Name or service not known") }
  5.     @blog = Blog.default
  6.     @blog.sp_global = true
  7.     @blog.default_moderate_comments = false
  8.     @blog.save!
  9.   end
  10.   it 'Incomplete trackbacks should not be accepted' do
  11.     tb = Trackback.new(:blog_name => 'Blog name', 
  12.                        :title => 'Title', 
  13.                        :excerpt => 'Excerpt',
  14.                        :article_id => contents(:article1).id)
  15.     tb.should_not be_valid
  16.     tb.errors.should be_invalid('url')
  17.     tb.url = 'http://foo.com'
  18.     tb.should be_valid
  19.     tb.save
  20.     tb.guid.size.should be > 15
  21.     tb.should_not be_spam
  22.   end
  23.   it 'Trackbacks with a spammy link in the excerpt should be rejected' do
  24.     IPSocket.should_receive(:getaddress).with('chinaaircatering.com.bsb.empty.us').at_least(:once).and_return('127.0.0.2')
  25.     tb = Trackback.new(ham_params.merge(:excerpt => '<a href="http://chinaaircatering.com">spam</a>'))
  26.     tb.should be_spam
  27.   end
  28.   it 'Trackbacks with a spammy source url should be rejected' do
  29.     add_spam_domain
  30.     tb = Trackback.new(ham_params.merge(:url => 'http://www.chinaircatering.com'))
  31.     tb.should be_spam
  32.   end
  33.   it 'Trackbacks from a spammy ip address should be rejected' do
  34.     add_spam_ip('212.42.230.207')
  35.     tb = Trackback.new(ham_params.merge(:ip => '212.42.230.207'))
  36.     tb.should be_spam
  37.   end
  38.   def add_spam_domain(domain = 'chinaircatering.com')
  39.     IPSocket.should_receive(:getaddress).with("#{domain}.bsb.empty.us").at_least(:once).and_return('127.0.0.2')
  40.   end
  41.   def add_spam_ip(addr = '212.42.230.206')
  42.     rbl_domain = addr.split(/./).reverse.join('.') + '.opm.blitzed.us'
  43.     IPSocket.should_receive(:getaddress).with(rbl_domain).at_least(:once).and_return('127.0.0.2')
  44.   end
  45.   def ham_params
  46.     { :blog_name => 'Blog', :title => 'trackback', :excerpt => 'bland',
  47.       :url => 'http://notaspammer.com', :ip => '212.42.230.206',
  48.       :blog => @blog }
  49.   end
  50. end