rakismet 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NmQ3NDRlYjkxOTBkY2E4Zjk0YzUwMDlmYzI3NDI5NzQ4ZjlkM2NiZQ==
5
- data.tar.gz: !binary |-
6
- YTI5NTlkOGYxNTU4MGY5ZjZjYWZhMzg1NDU4NTJkNzJjMTRmZTQyZg==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- ZWY2Yzg3MTkzYzc5YWNjZjllYWE2NDg4ZTYyY2EyZGUyNTVhODY3OTA0ZDBj
10
- Y2UzZDc0YzM0ZjQ4MzhiODdmNmRmMzQ5ZmNkODBmZWZmZWRhOThmNjQ4MjRj
11
- OTg1YzdmZGY2ZGI1NmRmYjI0Y2UzYWMwMjY1YTU2OTk1YTIxNTk=
12
- data.tar.gz: !binary |-
13
- YjM2YTI3MGQwY2QwNWFmMDYxYWVjMGZhNWRkNjFkZDIwZGZiZjYwMWYxMDNm
14
- MDhmZTlhNDNjNTY0YjM4ZDQ5NTUwMGY5MjNlODFmZTA0ZGE5MjQ5ZGFiMDBh
15
- Mjc1ZjI5OTAwZTM0NjM2OWJjNDBlMTdmMzY3Yjk4MTFlNWY0OGQ=
2
+ SHA1:
3
+ metadata.gz: b122ee0148197e727f46656179a22582da4aab0f
4
+ data.tar.gz: e8d9b93c6bcb5de87c8717abc8037ce6ef7daf8a
5
+ SHA512:
6
+ metadata.gz: de495498ab349675fe5c49a486383925e848b5267976e63722869585b9e24508b44b489a082bb807c8b6574e21931efe7a38df234989c16274b6bfd7c0044484
7
+ data.tar.gz: 74ab9d5e48a07e48f0b66c8ef5907ed461508819547f15988e93f734c6ac5163731047535a5ae28bb32a1322f3ef675eb386c914646e89a87dd451c3eaa9310b
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ = 1.5.0
2
+ * Send HTTP_ env varialbes to Akismet [Eric Hochberger]
1
3
  = 1.4.0
2
4
  * Allow endpoint to be specified with a proc for multitenant applications [Bradly Feeley]
3
5
  * Add Akistmet permalink attribute [Eric Hochberger]
data/README.md CHANGED
@@ -156,6 +156,15 @@ your app initialization:
156
156
  config.rakismet.use_middleware = false
157
157
  ```
158
158
 
159
+ Additionally, the middleware will send along additional env variables starting with
160
+ HTTP_ to Akismet. If you wish to block any sensitive user information, use:
161
+
162
+ ```ruby
163
+ config.rakismet.excluded_headers = ['HTTP_COOKIE','HTTP_SENSITIVE']
164
+ ```
165
+
166
+ excluded_headers will default to ['HTTP_COOKIE']
167
+
159
168
  Testing
160
169
  -------
161
170
 
@@ -9,11 +9,15 @@ require 'rakismet/version'
9
9
  require 'rakismet/railtie.rb' if defined?(Rails)
10
10
 
11
11
  module Rakismet
12
- Request = Struct.new(:user_ip, :user_agent, :referrer)
12
+ Request = Struct.new(:user_ip, :user_agent, :referrer, :http_headers)
13
13
  Undefined = Class.new(NameError)
14
14
 
15
15
  class << self
16
- attr_accessor :key, :url, :host, :proxy_host, :proxy_port, :test
16
+ attr_accessor :key, :url, :host, :proxy_host, :proxy_port, :test, :excluded_headers
17
+
18
+ def excluded_headers
19
+ @excluded_headers || ['HTTP_COOKIE']
20
+ end
17
21
 
18
22
  def request
19
23
  @request ||= Request.new
@@ -26,6 +30,9 @@ module Rakismet
26
30
  def set_request_vars(env)
27
31
  request.user_ip, request.user_agent, request.referrer =
28
32
  env['REMOTE_ADDR'], env['HTTP_USER_AGENT'], env['HTTP_REFERER']
33
+
34
+ # Collect all CGI-style HTTP_ headers except cookies for privacy..
35
+ request.http_headers = env.select { |k,v| k =~ /^HTTP_/ }.reject { |k,v| excluded_headers.include? k }
29
36
  end
30
37
 
31
38
  def clear_request
@@ -38,7 +38,7 @@ module Rakismet
38
38
  if instance_variable_defined? :@_spam
39
39
  @_spam
40
40
  else
41
- data = akismet_data
41
+ data = akismet_data(true) # Only spam? check should include http_headers
42
42
  self.akismet_response = Rakismet.akismet_call('comment-check', data)
43
43
  @_spam = self.akismet_response == 'true'
44
44
  end
@@ -56,7 +56,7 @@ module Rakismet
56
56
 
57
57
  private
58
58
 
59
- def akismet_data
59
+ def akismet_data(include_http_headers = false)
60
60
  akismet = self.class.akismet_attrs.keys.inject({}) do |data,attr|
61
61
  mapped_field = self.class.akismet_attrs[attr]
62
62
  data.merge attr => if mapped_field.is_a?(Proc)
@@ -76,6 +76,7 @@ module Rakismet
76
76
  Rakismet.request.send(attr)
77
77
  end
78
78
  end
79
+ akismet.merge! Rakismet.request.http_headers if include_http_headers and Rakismet.request.http_headers
79
80
  akismet.delete_if { |k,v| v.nil? || v.empty? }
80
81
  akismet[:comment_type] ||= 'comment'
81
82
  akismet
@@ -1,3 +1,3 @@
1
1
  module Rakismet
2
- VERSION = "1.4.0"
2
+ VERSION = "1.5.0"
3
3
  end
@@ -38,6 +38,17 @@ describe AkismetModel do
38
38
  @model.spam?
39
39
  end
40
40
 
41
+ it "should send http_headers from Rakismet.request if present" do
42
+ Rakismet.stub!(:request).and_return(request_with_headers)
43
+ Rakismet.should_receive(:akismet_call).
44
+ with('comment-check', akismet_attrs.merge(:user_ip => '127.0.0.1',
45
+ :user_agent => 'RSpec',
46
+ :referrer => 'http://test.host/referrer',
47
+ 'HTTP_USER_AGENT' => 'RSpec',
48
+ 'HTTP_REFERER' => 'http://test.host/referrer'))
49
+ @model.spam?
50
+ end
51
+
41
52
  it "should cache result of #spam?" do
42
53
  Rakismet.should_receive(:akismet_call).once
43
54
  @model.spam?
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Rakismet::Middleware do
4
4
 
5
- let(:env) { { 'REMOTE_ADDR' => '127.0.0.1', 'HTTP_USER_AGENT' => 'RSpec', 'HTTP_REFERER' => 'http://test.host/referrer' } }
5
+ let(:env) { { 'REMOTE_ADDR' => '127.0.0.1', 'HTTP_USER_AGENT' => 'RSpec', 'HTTP_REFERER' => 'http://test.host/referrer', 'HTTP_COOKIE' => "Don't violate my privacy" } }
6
6
  let(:app) { double(:app, :call => nil) }
7
7
  let(:request) { double(:request).as_null_object }
8
8
 
@@ -18,10 +18,18 @@ describe Rakismet::Middleware do
18
18
  @middleware.call(env)
19
19
  end
20
20
 
21
+ it "should set set Rakismet.request http_headers" do
22
+ Rakismet.stub(:request).and_return(request)
23
+ request.should_receive(:http_headers=).with({ 'HTTP_USER_AGENT' => 'RSpec', 'HTTP_REFERER' => 'http://test.host/referrer' })
24
+ @middleware.call(env)
25
+ end
26
+
21
27
  it "should clear Rakismet.request after request is complete" do
22
28
  @middleware.call(env)
23
29
  Rakismet.request.user_ip.should be_nil
24
30
  Rakismet.request.user_agent.should be_nil
25
31
  Rakismet.request.referrer.should be_nil
32
+ Rakismet.request.http_headers.should be_nil
26
33
  end
34
+
27
35
  end
@@ -82,6 +82,12 @@ describe Rakismet do
82
82
  Rakismet.validate_key
83
83
  end
84
84
  end
85
+
86
+ describe '.excluded_headers' do
87
+ it "should default to ['HTTP_COOKIE']" do
88
+ Rakismet.excluded_headers.should eq ['HTTP_COOKIE']
89
+ end
90
+ end
85
91
 
86
92
  describe ".akismet_call" do
87
93
  before do
@@ -27,8 +27,16 @@ def request
27
27
  :referrer => 'http://test.host/referrer')
28
28
  end
29
29
 
30
+ def request_with_headers
31
+ OpenStruct.new(:user_ip => '127.0.0.1',
32
+ :user_agent => 'RSpec',
33
+ :referrer => 'http://test.host/referrer',
34
+ :http_headers => { 'HTTP_USER_AGENT' => 'RSpec', 'HTTP_REFERER' => 'http://test.host/referrer' } )
35
+ end
36
+
30
37
  def empty_request
31
38
  OpenStruct.new(:user_ip => nil,
32
39
  :user_agent => nil,
33
- :referrer => nil)
40
+ :referrer => nil,
41
+ :http_headers => nil)
34
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rakismet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh French
@@ -14,14 +14,14 @@ dependencies:
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
@@ -77,17 +77,17 @@ require_paths:
77
77
  - lib
78
78
  required_ruby_version: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  requirements:
85
- - - ! '>='
85
+ - - '>='
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  requirements: []
89
89
  rubyforge_project: rakismet
90
- rubygems_version: 2.0.2
90
+ rubygems_version: 2.0.3
91
91
  signing_key:
92
92
  specification_version: 4
93
93
  summary: Akismet and TypePad AntiSpam integration for Rails.