adsense_crawler_for_private 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +5 -5
  2. data/lib/adsense_crawler_for_private/version.rb +1 -1
  3. data/lib/adsense_crawler_for_private.rb +2 -2
  4. metadata +21 -89
  5. data/test/adsense_crawler_for_private_test.rb +0 -7
  6. data/test/dummy/Rakefile +0 -7
  7. data/test/dummy/app/controllers/application_controller.rb +0 -3
  8. data/test/dummy/app/controllers/main_controller.rb +0 -29
  9. data/test/dummy/app/helpers/application_helper.rb +0 -2
  10. data/test/dummy/config/application.rb +0 -52
  11. data/test/dummy/config/boot.rb +0 -10
  12. data/test/dummy/config/database.yml +0 -26
  13. data/test/dummy/config/environment.rb +0 -5
  14. data/test/dummy/config/environments/development.rb +0 -32
  15. data/test/dummy/config/environments/production.rb +0 -60
  16. data/test/dummy/config/environments/test.rb +0 -45
  17. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  18. data/test/dummy/config/initializers/inflections.rb +0 -10
  19. data/test/dummy/config/initializers/mime_types.rb +0 -5
  20. data/test/dummy/config/initializers/secret_token.rb +0 -7
  21. data/test/dummy/config/initializers/session_store.rb +0 -8
  22. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  23. data/test/dummy/config/locales/en.yml +0 -5
  24. data/test/dummy/config/routes.rb +0 -6
  25. data/test/dummy/config/secrets.yml +0 -22
  26. data/test/dummy/config.ru +0 -4
  27. data/test/dummy/db/development.sqlite3 +0 -0
  28. data/test/dummy/db/schema.rb +0 -16
  29. data/test/dummy/db/test.sqlite3 +0 -0
  30. data/test/dummy/log/development.log +0 -444
  31. data/test/dummy/log/test.log +0 -15367
  32. data/test/dummy/public/404.html +0 -26
  33. data/test/dummy/public/422.html +0 -26
  34. data/test/dummy/public/500.html +0 -26
  35. data/test/dummy/public/favicon.ico +0 -0
  36. data/test/dummy/script/rails +0 -6
  37. data/test/integration/adsense_crawler_for_private/filtering_helper_test.rb +0 -88
  38. data/test/integration/adsense_crawler_for_private/login_test.rb +0 -85
  39. data/test/test_helper.rb +0 -11
@@ -1,26 +0,0 @@
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>
@@ -1,26 +0,0 @@
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>
@@ -1,26 +0,0 @@
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
@@ -1,6 +0,0 @@
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'
@@ -1,88 +0,0 @@
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 not allowed ip" do
40
- AdsenseCrawlerForPrivate.ip_ranges = [IPAddr.new("199.199.199.199")]
41
- set_login_cookie(@crawler_name, @crawler_password, "199.199.199.199")
42
-
43
- get '/forbidden_render'
44
-
45
- assert_response :redirect, "should not render private page"
46
- end
47
-
48
- #####################################
49
- # INVALID COOKIES TEST
50
-
51
- test "specific render for expired cookie" do
52
- cookies[AdsenseCrawlerForPrivate.cookie_name] =
53
- ActiveSupport::MessageVerifier.new(Dummy::Application.config.secret_token).generate(
54
- [@crawler_name, @crawler_password, 2.days.ago.httpdate, "127.0.0.1"].to_json)
55
- get '/forbidden_render'
56
- assert_response :redirect, "should not render private page"
57
- end
58
-
59
- test "specific render for not allowed crawler_name" do
60
- cookies[AdsenseCrawlerForPrivate.cookie_name] =
61
- ActiveSupport::MessageVerifier.new(Dummy::Application.config.secret_token).generate(
62
- ["not_allowed_crawler", @crawler_password, 2.days.from_now.httpdate, "127.0.0.1"].to_json)
63
- get '/forbidden_render'
64
- assert_response :redirect, "should not render private page"
65
- end
66
-
67
- test "specific render for enabled crawler but password has changed in config" do
68
- set_login_cookie
69
- AdsenseCrawlerForPrivate.crawler_password = "password_changed"
70
-
71
- get '/forbidden_render'
72
- assert_response :redirect, "should not render private page"
73
- end
74
-
75
- #####################################
76
- # HELPERS
77
-
78
- # This is basically setting a signed cookie
79
- def set_login_cookie(crawler_name=nil, crawler_password=nil, ip=nil)
80
- crawler_name ||= @crawler_name
81
- crawler_password ||= @crawler_password
82
- ip ||= "127.0.0.1"
83
- cookies[AdsenseCrawlerForPrivate.cookie_name] =
84
- ActiveSupport::MessageVerifier.new(Dummy::Application.config.secret_token).generate(
85
- AdsenseCrawlerForPrivate.cookie_str(crawler_name, crawler_password, 2.days.from_now, ip))
86
- end
87
-
88
- end
@@ -1,85 +0,0 @@
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_ip).returns(ip_used.to_s)
27
-
28
- get '/adsense_crawler_for_private/login', params: {name: @crawler_name, password: @crawler_password}
29
- assert_response :success
30
- assert_equal 'crawler login ok', @response.body
31
-
32
- cookie_str = @controller.send(:cookies).signed[@cookie_name].to_s
33
- assert cookie_str.include?(ip_used.to_s), "cookie should include current ip"
34
- assert cookie_str.include?(@crawler_name), "cookie should include crawler name"
35
- end
36
-
37
- test "login with right access code from right ip and with post-request" do
38
- ip_used = "199.199.199.199"
39
- AdsenseCrawlerForPrivate.ip_ranges = [IPAddr.new(ip_used.to_s)]
40
- ActionDispatch::Request.any_instance.stubs(:remote_ip).returns(ip_used.to_s)
41
-
42
- post '/adsense_crawler_for_private/login', params: {name: @crawler_name, password: @crawler_password}
43
- assert_response :success
44
- assert_equal 'crawler login ok', @response.body
45
-
46
- cookie_str = @controller.send(:cookies).signed[@cookie_name].to_s
47
- assert cookie_str.include?(ip_used.to_s), "cookie should include current ip"
48
- assert cookie_str.include?(@crawler_name), "cookie should include crawler name"
49
- end
50
-
51
- test "login with right access code and nil ip's" do
52
- ip_used = "123.123.123.123"
53
- ActionDispatch::Request.any_instance.stubs(:remote_ip).returns(ip_used.to_s)
54
-
55
- get '/adsense_crawler_for_private/login', params: {name: @crawler_name, password: @crawler_password}
56
- assert_response :success
57
- assert_equal 'crawler login ok', @response.body
58
-
59
- cookie_str = @controller.send(:cookies).signed[@cookie_name].to_s
60
- assert cookie_str.include?(ip_used.to_s), "cookie should include current ip"
61
- assert cookie_str.include?(@crawler_name), "cookie should include crawler name"
62
- end
63
-
64
- test "login from wrong ip" do
65
- AdsenseCrawlerForPrivate.ip_ranges = [IPAddr.new("199.199.199.199")]
66
- ActionDispatch::Request.any_instance.stubs(:remote_ip).returns("1.1.1.1")
67
-
68
- get '/adsense_crawler_for_private/login', params: {name: @crawler_name, password: @crawler_password}
69
-
70
- assert_response 401
71
- assert_equal 'crawler login unsuccessful', @response.body
72
-
73
- assert cookies[@cookie_name].blank?, "should delete cookie"
74
-
75
- end
76
-
77
- test "login with wrong access codes" do
78
-
79
- get '/adsense_crawler_for_private/login', params: {name: @crawler_name, password: "wrong_pass"}
80
- assert_response 401
81
- assert_equal 'crawler login unsuccessful', @response.body
82
-
83
- assert cookies[@cookie_name].blank?, "should delete cookie"
84
- end
85
- end
data/test/test_helper.rb DELETED
@@ -1,11 +0,0 @@
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
- require "mocha/setup"
7
-
8
- Rails.backtrace_cleaner.remove_silencers!
9
-
10
- # Load support files
11
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }