adsense_crawler_for_private 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +112 -0
  3. data/Rakefile +39 -0
  4. data/app/controllers/adsense_crawler_for_private/adsense_crawler_login_controller.rb +39 -0
  5. data/app/controllers/adsense_crawler_for_private/application_controller.rb +6 -0
  6. data/app/helpers/adsense_crawler_for_private/application_helper.rb +4 -0
  7. data/config/routes.rb +3 -0
  8. data/lib/adsense_crawler_for_private/engine.rb +6 -0
  9. data/lib/adsense_crawler_for_private/version.rb +3 -0
  10. data/lib/adsense_crawler_for_private.rb +84 -0
  11. data/lib/tasks/adsense_crawler_for_private_tasks.rake +4 -0
  12. data/test/adsense_crawler_for_private_test.rb +7 -0
  13. data/test/dummy/Rakefile +7 -0
  14. data/test/dummy/app/controllers/application_controller.rb +3 -0
  15. data/test/dummy/app/controllers/main_controller.rb +29 -0
  16. data/test/dummy/app/helpers/application_helper.rb +2 -0
  17. data/test/dummy/config/application.rb +50 -0
  18. data/test/dummy/config/boot.rb +10 -0
  19. data/test/dummy/config/database.yml +25 -0
  20. data/test/dummy/config/environment.rb +5 -0
  21. data/test/dummy/config/environments/development.rb +30 -0
  22. data/test/dummy/config/environments/production.rb +60 -0
  23. data/test/dummy/config/environments/test.rb +39 -0
  24. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  25. data/test/dummy/config/initializers/inflections.rb +10 -0
  26. data/test/dummy/config/initializers/mime_types.rb +5 -0
  27. data/test/dummy/config/initializers/secret_token.rb +7 -0
  28. data/test/dummy/config/initializers/session_store.rb +8 -0
  29. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  30. data/test/dummy/config/locales/en.yml +5 -0
  31. data/test/dummy/config/routes.rb +6 -0
  32. data/test/dummy/config.ru +4 -0
  33. data/test/dummy/db/development.sqlite3 +0 -0
  34. data/test/dummy/db/test.sqlite3 +0 -0
  35. data/test/dummy/log/development.log +436 -0
  36. data/test/dummy/log/test.log +6831 -0
  37. data/test/dummy/public/404.html +26 -0
  38. data/test/dummy/public/422.html +26 -0
  39. data/test/dummy/public/500.html +26 -0
  40. data/test/dummy/public/favicon.ico +0 -0
  41. data/test/dummy/script/rails +6 -0
  42. data/test/integration/adsense_crawler_for_private/filtering_helper_test.rb +98 -0
  43. data/test/integration/adsense_crawler_for_private/login_test.rb +77 -0
  44. data/test/test_helper.rb +10 -0
  45. metadata +187 -0
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
24
+ </div>
25
+ </body>
26
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,98 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ class FilteringHelperTest < ActionDispatch::IntegrationTest
4
+
5
+ def setup
6
+ AdsenseCrawlerForPrivate.ip_ranges = nil
7
+
8
+ @cookie_name = AdsenseCrawlerForPrivate.cookie_name = "adsense_crawler"
9
+ @cookie_domain = AdsenseCrawlerForPrivate.cookie_domain = :all
10
+
11
+ @crawler_name = AdsenseCrawlerForPrivate.crawler_name = "craw_name_TEST"
12
+ @crawler_password = AdsenseCrawlerForPrivate.crawler_password = "crawler_password_TEST"
13
+ end
14
+
15
+ test "normal_render as normal for testing dummy application itself" do
16
+ get 'normal_render'
17
+ assert_response :success
18
+ assert_equal "this is rendered normally", @response.body
19
+ end
20
+
21
+ test "forbidden_render" do
22
+ get 'forbidden_render'
23
+ assert_redirected_to "http://www.you-were-not-logged-in.inv"
24
+ end
25
+
26
+
27
+ test "specific render for logged crawler" do
28
+ set_login_cookie
29
+
30
+ get 'forbidden_render'
31
+
32
+ assert_response :success
33
+ assert_equal "private render for crawler", @response.body
34
+ end
35
+
36
+ ####################################
37
+ # INVALID IP TESTS
38
+
39
+ test "specific render for logged crawler but with changed ip" do
40
+ set_login_cookie
41
+
42
+ ActionDispatch::Request.any_instance.stubs(:remote_addr).returns("192.168.0.1")
43
+
44
+ get 'forbidden_render'
45
+
46
+ assert_response :redirect, "should not render private page"
47
+ end
48
+
49
+ test "specific render for logged crawler but with not allowed ip" do
50
+ set_login_cookie
51
+ AdsenseCrawlerForPrivate.ip_ranges = [IPAddr.new("199.199.199.199")]
52
+
53
+ get 'forbidden_render'
54
+
55
+ assert_response :redirect, "should not render private page"
56
+ end
57
+
58
+ #####################################
59
+ # INVALID COOKIES TEST
60
+
61
+ test "specific render for expired cookie" do
62
+ cookies[AdsenseCrawlerForPrivate.cookie_name] =
63
+ ActiveSupport::MessageVerifier.new(Dummy::Application.config.secret_token).generate(
64
+ [@crawler_name, @crawler_password, 2.days.ago.httpdate, "127.0.0.1"].to_json)
65
+ get 'forbidden_render'
66
+ assert_response :redirect, "should not render private page"
67
+ end
68
+
69
+ test "specific render for not allowed crawler_name" do
70
+ cookies[AdsenseCrawlerForPrivate.cookie_name] =
71
+ ActiveSupport::MessageVerifier.new(Dummy::Application.config.secret_token).generate(
72
+ ["not_allowed_crawler", @crawler_password, 2.days.from_now.httpdate, "127.0.0.1"].to_json)
73
+ get 'forbidden_render'
74
+ assert_response :redirect, "should not render private page"
75
+ end
76
+
77
+ test "specific render for enabled crawler but password has changed in config" do
78
+ set_login_cookie
79
+ AdsenseCrawlerForPrivate.crawler_password = "password_changed"
80
+
81
+ get 'forbidden_render'
82
+ assert_response :redirect, "should not render private page"
83
+ end
84
+
85
+ #####################################
86
+ # HELPERS
87
+
88
+ # This is basically setting a signed cookie
89
+ def set_login_cookie(crawler_name=nil, crawler_password=nil, ip=nil)
90
+ crawler_name ||= @crawler_name
91
+ crawler_password ||= @crawler_password
92
+ ip ||= "127.0.0.1"
93
+ cookies[AdsenseCrawlerForPrivate.cookie_name] =
94
+ ActiveSupport::MessageVerifier.new(Dummy::Application.config.secret_token).generate(
95
+ AdsenseCrawlerForPrivate.cookie_str(crawler_name, crawler_password, 2.days.from_now, ip))
96
+ end
97
+
98
+ end
@@ -0,0 +1,77 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ class LoginTest < ActionDispatch::IntegrationTest
4
+ #fixtures :all
5
+
6
+ def setup
7
+ AdsenseCrawlerForPrivate.ip_ranges = nil
8
+
9
+ @cookie_name = AdsenseCrawlerForPrivate.cookie_name = "adsense_crawler"
10
+ @cookie_domain = AdsenseCrawlerForPrivate.cookie_domain = :all
11
+
12
+ @crawler_name = AdsenseCrawlerForPrivate.crawler_name = "craw_name_TEST"
13
+ @crawler_password = AdsenseCrawlerForPrivate.crawler_password = "crawler_password_TEST"
14
+ end
15
+
16
+ test "login without right setup (password nil)" do
17
+ AdsenseCrawlerForPrivate.crawler_password = nil
18
+ get 'adsense_crawler_for_private/login'
19
+ assert_response 401
20
+ assert_equal 'AdsenseCrawlerForPrivate not configured, no password given.', @response.body
21
+ end
22
+
23
+ test "login with right access code from right ip" do
24
+ ip_used = "199.199.199.199"
25
+ AdsenseCrawlerForPrivate.ip_ranges = [IPAddr.new(ip_used.to_s)]
26
+ ActionDispatch::Request.any_instance.stubs(:remote_addr).returns(ip_used.to_s)
27
+
28
+ get 'adsense_crawler_for_private/login',
29
+ :name => @crawler_name, :password => @crawler_password
30
+ assert_response :success
31
+ assert_equal 'crawler login ok', @response.body
32
+
33
+ cookie_str = cookies[@cookie_name]
34
+ cookie_str = ActiveSupport::MessageVerifier.new(Dummy::Application.config.secret_token).verify(cookie_str)
35
+ assert cookie_str.include?(ip_used.to_s), "cookie should include current ip"
36
+ assert cookie_str.include?(@crawler_name), "cookie should include crawler name"
37
+ end
38
+
39
+ test "login with right access code and nil ip's" do
40
+ ip_used = "123.123.123.123"
41
+ ActionDispatch::Request.any_instance.stubs(:remote_addr).returns(ip_used.to_s)
42
+
43
+ get 'adsense_crawler_for_private/login',
44
+ :name => @crawler_name, :password => @crawler_password
45
+ assert_response :success
46
+ assert_equal 'crawler login ok', @response.body
47
+
48
+ cookie_str = cookies[@cookie_name]
49
+ cookie_str = ActiveSupport::MessageVerifier.new(Dummy::Application.config.secret_token).verify(cookie_str)
50
+ assert cookie_str.include?(ip_used.to_s), "cookie should include current ip"
51
+ assert cookie_str.include?(@crawler_name), "cookie should include crawler name"
52
+ end
53
+
54
+ test "login from wrong ip" do
55
+ AdsenseCrawlerForPrivate.ip_ranges = [IPAddr.new("199.199.199.199")]
56
+ ActionDispatch::Request.any_instance.stubs(:remote_addr).returns("1.1.1.1")
57
+
58
+ get 'adsense_crawler_for_private/login',
59
+ :name => @crawler_name, :password => @crawler_password
60
+
61
+ assert_response 401
62
+ assert_equal 'crawler login unsuccessful', @response.body
63
+
64
+ assert_equal "", cookies[@cookie_name], "should delete cookie"
65
+
66
+ end
67
+
68
+ test "login with wrong access codes" do
69
+
70
+ get 'adsense_crawler_for_private/login',
71
+ :name => @crawler_name, :password => "wrong_pass"
72
+ assert_response 401
73
+ assert_equal 'crawler login unsuccessful', @response.body
74
+
75
+ assert_equal "", cookies[@cookie_name], "should delete cookie"
76
+ end
77
+ end
@@ -0,0 +1,10 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+
7
+ Rails.backtrace_cleaner.remove_silencers!
8
+
9
+ # Load support files
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: adsense_crawler_for_private
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Olli Huotari
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-12-29 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rails
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">"
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 3
31
+ - 1
32
+ - 0
33
+ version: 3.1.0
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: sqlite3
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: mocha
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 47
59
+ segments:
60
+ - 0
61
+ - 9
62
+ - 10
63
+ version: 0.9.10
64
+ type: :development
65
+ version_requirements: *id003
66
+ description: Easy way to enable adsense crawler to login and see private or custom pages. Basically one custom login filter with documentation.
67
+ email:
68
+ - olli.huotari@iki.fi
69
+ executables: []
70
+
71
+ extensions: []
72
+
73
+ extra_rdoc_files: []
74
+
75
+ files:
76
+ - app/helpers/adsense_crawler_for_private/application_helper.rb
77
+ - app/controllers/adsense_crawler_for_private/application_controller.rb
78
+ - app/controllers/adsense_crawler_for_private/adsense_crawler_login_controller.rb
79
+ - config/routes.rb
80
+ - lib/tasks/adsense_crawler_for_private_tasks.rake
81
+ - lib/adsense_crawler_for_private/engine.rb
82
+ - lib/adsense_crawler_for_private/version.rb
83
+ - lib/adsense_crawler_for_private.rb
84
+ - MIT-LICENSE
85
+ - Rakefile
86
+ - README.md
87
+ - test/integration/adsense_crawler_for_private/filtering_helper_test.rb
88
+ - test/integration/adsense_crawler_for_private/login_test.rb
89
+ - test/dummy/script/rails
90
+ - test/dummy/db/development.sqlite3
91
+ - test/dummy/db/test.sqlite3
92
+ - test/dummy/config/boot.rb
93
+ - test/dummy/config/locales/en.yml
94
+ - test/dummy/config/initializers/secret_token.rb
95
+ - test/dummy/config/initializers/mime_types.rb
96
+ - test/dummy/config/initializers/inflections.rb
97
+ - test/dummy/config/initializers/session_store.rb
98
+ - test/dummy/config/initializers/wrap_parameters.rb
99
+ - test/dummy/config/initializers/backtrace_silencers.rb
100
+ - test/dummy/config/database.yml
101
+ - test/dummy/config/environments/production.rb
102
+ - test/dummy/config/environments/test.rb
103
+ - test/dummy/config/environments/development.rb
104
+ - test/dummy/config/routes.rb
105
+ - test/dummy/config/environment.rb
106
+ - test/dummy/config/application.rb
107
+ - test/dummy/config.ru
108
+ - test/dummy/public/500.html
109
+ - test/dummy/public/favicon.ico
110
+ - test/dummy/public/422.html
111
+ - test/dummy/public/404.html
112
+ - test/dummy/log/development.log
113
+ - test/dummy/log/test.log
114
+ - test/dummy/app/helpers/application_helper.rb
115
+ - test/dummy/app/controllers/application_controller.rb
116
+ - test/dummy/app/controllers/main_controller.rb
117
+ - test/dummy/Rakefile
118
+ - test/test_helper.rb
119
+ - test/adsense_crawler_for_private_test.rb
120
+ homepage: https://github.com/holli/adsense_crawler_for_private/
121
+ licenses: []
122
+
123
+ post_install_message:
124
+ rdoc_options: []
125
+
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ hash: 3
134
+ segments:
135
+ - 0
136
+ version: "0"
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ hash: 3
143
+ segments:
144
+ - 0
145
+ version: "0"
146
+ requirements: []
147
+
148
+ rubyforge_project:
149
+ rubygems_version: 1.8.6
150
+ signing_key:
151
+ specification_version: 3
152
+ summary: Easy way to enable adsense crawler to login and see private or custom pages. Basically one custom login filter.
153
+ test_files:
154
+ - test/integration/adsense_crawler_for_private/filtering_helper_test.rb
155
+ - test/integration/adsense_crawler_for_private/login_test.rb
156
+ - test/dummy/script/rails
157
+ - test/dummy/db/development.sqlite3
158
+ - test/dummy/db/test.sqlite3
159
+ - test/dummy/config/boot.rb
160
+ - test/dummy/config/locales/en.yml
161
+ - test/dummy/config/initializers/secret_token.rb
162
+ - test/dummy/config/initializers/mime_types.rb
163
+ - test/dummy/config/initializers/inflections.rb
164
+ - test/dummy/config/initializers/session_store.rb
165
+ - test/dummy/config/initializers/wrap_parameters.rb
166
+ - test/dummy/config/initializers/backtrace_silencers.rb
167
+ - test/dummy/config/database.yml
168
+ - test/dummy/config/environments/production.rb
169
+ - test/dummy/config/environments/test.rb
170
+ - test/dummy/config/environments/development.rb
171
+ - test/dummy/config/routes.rb
172
+ - test/dummy/config/environment.rb
173
+ - test/dummy/config/application.rb
174
+ - test/dummy/config.ru
175
+ - test/dummy/public/500.html
176
+ - test/dummy/public/favicon.ico
177
+ - test/dummy/public/422.html
178
+ - test/dummy/public/404.html
179
+ - test/dummy/log/development.log
180
+ - test/dummy/log/test.log
181
+ - test/dummy/app/helpers/application_helper.rb
182
+ - test/dummy/app/controllers/application_controller.rb
183
+ - test/dummy/app/controllers/main_controller.rb
184
+ - test/dummy/Rakefile
185
+ - test/test_helper.rb
186
+ - test/adsense_crawler_for_private_test.rb
187
+ has_rdoc: