captchachacha 0.0.3 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/.gitignore +3 -0
- data/CHANGES +10 -0
- data/README +4 -6
- data/captchachacha.gemspec +5 -5
- data/lib/rack/captchachacha.rb +10 -8
- data/lib/rack/captchachacha/helpers.rb +5 -5
- data/lib/rack/captchachacha/version.rb +2 -2
- data/spec/captchachacha_spec.rb +5 -4
- metadata +10 -9
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/.gitignore
CHANGED
data/CHANGES
CHANGED
@@ -1 +1,11 @@
|
|
1
|
+
v0.4.2 Fixed ultra stupid bug with names of params.
|
2
|
+
|
3
|
+
v0.4.1 Changes to gemspec to get rid of YAML Psyck errors when installing gem.
|
4
|
+
|
5
|
+
v0.4.0 Using secure random lib to generate better session id's; using X-... for non standard headers.
|
6
|
+
|
7
|
+
v0.0.3 Rebuild of v0.0.2 but without development dependencies, as one of them was causing errors via a bug with YAML Psyck::Syck
|
8
|
+
|
9
|
+
v0.0.2 Working, with tests for rack portion.
|
10
|
+
|
1
11
|
v0.0.1 Start of project.
|
data/README
CHANGED
@@ -1,22 +1,20 @@
|
|
1
1
|
## Rack::Captchachacha ##
|
2
2
|
|
3
|
-
Rack middleware for using the
|
3
|
+
Rack middleware for using the captchator.com service http://captchator.com/.
|
4
4
|
|
5
5
|
### Usage ###
|
6
6
|
|
7
7
|
#### Sinatra ####
|
8
8
|
|
9
9
|
## app.rb
|
10
|
+
require 'rack/captchachacha'
|
10
11
|
use Rack::Captchachacha
|
11
12
|
helpers Rack::Recaptcha::Helpers
|
12
13
|
|
14
|
+
There is a longer example on my blog, http://iainbarnett.me.uk/posts/Using-rack-captchachacha/
|
13
15
|
|
14
16
|
### Acknowledgments ###
|
15
17
|
|
16
|
-
The vast majority of this code comes from
|
18
|
+
The vast majority of this code comes from sinatra-captcha https://github.com/bmizerany/sinatra-captcha and rack-recaptcha https://github.com/achiu/rack-recaptcha
|
17
19
|
|
18
20
|
Many thanks to Blake Mizerany, the author of sinatra-captcha, and Arthur Chiu, author of rack-recaptcha for making their code public.
|
19
|
-
|
20
|
-
[1]: http://captchator.com/
|
21
|
-
[2]: https://github.com/bmizerany/sinatra-captcha
|
22
|
-
[3]: https://github.com/achiu/rack-recaptcha
|
data/captchachacha.gemspec
CHANGED
@@ -11,13 +11,13 @@ Gem::Specification.new do |s|
|
|
11
11
|
EOF
|
12
12
|
s.version = Rack::Captchachacha::VERSION
|
13
13
|
s.platform = Gem::Platform::RUBY
|
14
|
-
s.require_path =
|
14
|
+
s.require_path = "lib"
|
15
15
|
s.required_ruby_version = ">= 1.9.2"
|
16
|
-
s.
|
16
|
+
s.authors = ["Iain Barnett"]
|
17
17
|
s.files = `git ls-files`.split("\n")
|
18
|
-
s.add_dependency(
|
19
|
-
s.add_dependency(
|
20
|
-
s.email = "iainspeed @nospam@ gmail.com"
|
18
|
+
s.add_dependency("rack", "~> 1.3.0")
|
19
|
+
s.add_dependency("curb", "~> 0.7.15")
|
20
|
+
s.email = ["iainspeed @nospam@ gmail.com"]
|
21
21
|
s.homepage = "https://github.com/yb66/Captchachacha"
|
22
22
|
s.test_files = `git ls-files -- {test,spec,features}`.split("\n")
|
23
23
|
s.signing_key = ENV['HOME'] + '/.ssh/gem-private_key.pem'
|
data/lib/rack/captchachacha.rb
CHANGED
@@ -8,8 +8,10 @@ module Rack
|
|
8
8
|
|
9
9
|
VERIFY_URL = "http://captchator.com/captcha/check_answer"
|
10
10
|
CHALLENGE_FIELD = 'captcha_session'
|
11
|
-
RESPONSE_FIELD = '
|
12
|
-
|
11
|
+
RESPONSE_FIELD = 'captcha'
|
12
|
+
DEFAULT_MESSAGE = "Incorrect response, please try again."
|
13
|
+
RESULT_HEADER = 'X-Captcha-Valid'
|
14
|
+
RESULT_MESSAGE = 'X-Captcha-Msg'
|
13
15
|
|
14
16
|
# @param app Rack application
|
15
17
|
# @param [optional,Hash] options Hash of options
|
@@ -28,9 +30,8 @@ module Rack
|
|
28
30
|
# @param env Rack environment
|
29
31
|
def _call(env)
|
30
32
|
request = Request.new(env)
|
31
|
-
|
32
33
|
if request.params[CHALLENGE_FIELD] && request.params[RESPONSE_FIELD]
|
33
|
-
|
34
|
+
|
34
35
|
result, msg = verify(
|
35
36
|
request.params[CHALLENGE_FIELD].to_i,
|
36
37
|
request.params[RESPONSE_FIELD] )
|
@@ -41,20 +42,21 @@ module Rack
|
|
41
42
|
# If it's a fail then the usual course of action would be to redirect back to the
|
42
43
|
# captcha form, but on success to continue, so the error message will be ignored unless
|
43
44
|
# of failure.
|
44
|
-
msg ||=
|
45
|
+
msg ||= DEFAULT_MESSAGE
|
45
46
|
|
46
|
-
env.merge!(
|
47
|
+
env.merge!(RESULT_HEADER => result == true, RESULT_MESSAGE => msg )
|
47
48
|
end
|
49
|
+
|
48
50
|
@app.call(env)
|
49
51
|
end
|
50
52
|
|
51
53
|
|
52
54
|
def verify( session_id, answer )
|
53
|
-
return false if session_id == 0
|
55
|
+
return false if session_id == 0 || session_id.nil?
|
54
56
|
return false if answer.nil?
|
55
57
|
|
56
58
|
require 'curb'
|
57
|
-
Curl::Easy.perform("#{VERIFY_URL}/#{session_id}/#{answer}").body_str
|
59
|
+
Curl::Easy.perform("#{VERIFY_URL}/#{session_id}/#{answer}").body_str == "1"
|
58
60
|
end # def
|
59
61
|
|
60
62
|
end # class
|
@@ -7,25 +7,25 @@
|
|
7
7
|
module Rack
|
8
8
|
class Captchachacha
|
9
9
|
module Helpers
|
10
|
-
|
10
|
+
require 'securerandom'
|
11
11
|
|
12
12
|
def captcha_valid?
|
13
|
-
request.env['
|
13
|
+
request.env['X-Captcha-Valid']
|
14
14
|
end # def
|
15
15
|
|
16
16
|
|
17
17
|
def captcha_session
|
18
|
-
@captcha_session ||=
|
18
|
+
@captcha_session ||= SecureRandom.random_number.to_s[2..-1]
|
19
19
|
end
|
20
20
|
|
21
21
|
|
22
22
|
def captcha_answer_tag
|
23
|
-
%Q!<input id="
|
23
|
+
%Q!<input id="captcha_answer" name="captcha_answer" type="text" size="6"/>!
|
24
24
|
end
|
25
25
|
|
26
26
|
|
27
27
|
def captcha_image_tag
|
28
|
-
%Q!<input name="captcha_session" type="hidden" value="#{captcha_session}"
|
28
|
+
%Q!<input id="captcha_session" name="captcha_session" type="hidden" value="#{captcha_session}"/><img id="captcha_image" src="http://captchator.com/captcha/image/#{captcha_session}"/>!
|
29
29
|
end
|
30
30
|
|
31
31
|
end # Helpers
|
data/spec/captchachacha_spec.rb
CHANGED
@@ -3,6 +3,7 @@ require 'rack/test'
|
|
3
3
|
require 'rack/mock'
|
4
4
|
require 'curb'
|
5
5
|
require 'webmock/rspec'
|
6
|
+
require 'securerandom'
|
6
7
|
|
7
8
|
require_relative '../lib/rack/captchachacha.rb'
|
8
9
|
|
@@ -23,7 +24,7 @@ include Rack::Test::Methods
|
|
23
24
|
when '/' then [200,'Hello world']
|
24
25
|
when '/login'
|
25
26
|
if request.post?
|
26
|
-
env['
|
27
|
+
env['X-Captcha-Valid'] ? [200, 'post login'] : [200, 'post fail']
|
27
28
|
else
|
28
29
|
[200,'login']
|
29
30
|
end
|
@@ -51,12 +52,12 @@ include Rack::Test::Methods
|
|
51
52
|
end # context
|
52
53
|
|
53
54
|
context "a page that requires a captcha" do
|
54
|
-
let(:session_id){
|
55
|
+
let(:session_id){ SecureRandom.random_number.to_s[2..-1] }
|
55
56
|
let(:url_to_request) { "#{Rack::Captchachacha::VERIFY_URL}/#{session_id}/response" }
|
56
57
|
|
57
58
|
it "should pass the captcha" do
|
58
59
|
stub_request(:get, url_to_request).to_return({:body => "1"})
|
59
|
-
post "/login", {'captcha_session' => session_id, '
|
60
|
+
post "/login", {'captcha_session' => session_id, 'captcha' => 'response'}
|
60
61
|
|
61
62
|
WebMock.should have_requested(:get, url_to_request)
|
62
63
|
|
@@ -67,7 +68,7 @@ include Rack::Test::Methods
|
|
67
68
|
|
68
69
|
it "should fail the captcha" do
|
69
70
|
stub_request(:get, url_to_request).to_return({:body => "0"})
|
70
|
-
post "/login", {'captcha_session' => session_id, '
|
71
|
+
post "/login", {'captcha_session' => session_id, 'captcha' => 'response'}
|
71
72
|
|
72
73
|
WebMock.should have_requested(:get, url_to_request)
|
73
74
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: captchachacha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -50,34 +50,35 @@ cert_chain:
|
|
50
50
|
-----END CERTIFICATE-----
|
51
51
|
|
52
52
|
'
|
53
|
-
date: 2011-06-
|
53
|
+
date: 2011-06-28 00:00:00.000000000Z
|
54
54
|
dependencies:
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rack
|
57
|
-
requirement: &
|
57
|
+
requirement: &2156651920 !ruby/object:Gem::Requirement
|
58
58
|
none: false
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - ~>
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: 1.3.0
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
|
-
version_requirements: *
|
65
|
+
version_requirements: *2156651920
|
66
66
|
- !ruby/object:Gem::Dependency
|
67
67
|
name: curb
|
68
|
-
requirement: &
|
68
|
+
requirement: &2156651460 !ruby/object:Gem::Requirement
|
69
69
|
none: false
|
70
70
|
requirements:
|
71
|
-
- -
|
71
|
+
- - ~>
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: 0.7.15
|
74
74
|
type: :runtime
|
75
75
|
prerelease: false
|
76
|
-
version_requirements: *
|
76
|
+
version_requirements: *2156651460
|
77
77
|
description: ! ' Captchator as Rack middleware, and helpers for sinatra.
|
78
78
|
|
79
79
|
'
|
80
|
-
email:
|
80
|
+
email:
|
81
|
+
- iainspeed @nospam@ gmail.com
|
81
82
|
executables: []
|
82
83
|
extensions: []
|
83
84
|
extra_rdoc_files: []
|
metadata.gz.sig
CHANGED
Binary file
|