ruby-recaptcha 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,117 +1,291 @@
1
- changeset: 49:201f032ce586
2
- user: m@loonsoft.com
3
- date: Tue Sep 02 10:59:53 2008 -0500
4
- summary: removed test code which seems to cause trouble with the masses
5
-
6
- changeset: 48:297ed7ad0790
7
- user: m@loonsoft.com
8
- date: Fri May 30 09:04:24 2008 -0500
9
- summary: fix for loopback addr requests
10
-
11
- changeset: 47:143671e3abb0
12
- user: m@loonsoft.com
13
- date: Mon Apr 07 23:24:24 2008 -0500
14
- summary: fix for kim griggs
15
-
16
- changeset: 46:52e0ff173f56
17
- user: m@loonsoft.com
18
- date: Wed Mar 05 20:27:58 2008 -0600
19
- summary: fixed bug when nil challenge string
20
-
21
- changeset: 45:f63d820d97f9
22
- user: m@loonsoft.com
23
- date: Sat Mar 01 08:40:33 2008 -0600
24
- summary: integrated more patches from pv
25
-
26
- changeset: 44:4964962ea7be
27
- user: m@loonsoft.com
28
- date: Sun Feb 24 13:59:27 2008 -0600
29
- summary: reapplied missing patch
30
-
31
- changeset: 43:299402495d48
32
- user: m@loonsoft.com
33
- date: Sun Feb 24 08:25:04 2008 -0600
34
- summary: patch from peter vandenberk
35
-
36
- changeset: 40:e55d02f563e4
37
- user: m@loonsoft.com
38
- date: Sat Jan 12 11:33:35 2008 -0600
39
- summary: proxy support
40
-
41
- changeset: 34:24e4ed5017bc
42
- user: m@loonsoft.com
43
- date: Thu Aug 23 15:01:14 2007 -0500
44
- summary: fix from joey geiger
45
-
46
- changeset: 33:310e75fbd650
47
- user: m@loonsoft.com
48
- date: Sat Jun 09 08:10:38 2007 -0500
49
- summary: error parameter no longer included when the error is blank or nil
50
-
51
- changeset: 31:ed21f08b6331
52
- parent: 27:5a6746ce03f7
53
- user: m@loonsoft.com
54
- date: Wed Jun 06 22:36:58 2007 -0500
55
- summary: Backed out changeset 5a6746ce03f73d0dd02db155816500870088bf6e
56
-
57
- changeset: 27:5a6746ce03f7
58
- parent: 25:d614a6a28630
59
- user: m@loonsoft.com
60
- date: Wed Jun 06 22:02:37 2007 -0500
61
- summary: Backed out changeset d614a6a28630eb4dba913739518dbdc6d3aaa410
62
-
63
- changeset: 25:d614a6a28630
64
- user: m@loonsoft.com
65
- date: Wed May 30 14:28:25 2007 -0500
66
- summary: patch from victor cosby
67
-
68
- changeset: 24:d1dc394b249b
69
- user: m@loonsoft.com
70
- date: Tue May 29 09:57:04 2007 -0500
71
- summary: Backed out changeset 1086e6e6217f85433cc539e6d687880adc421c2f
72
-
73
- changeset: 23:1086e6e6217f
74
- user: m@loonsoft.com
75
- date: Tue May 29 09:47:38 2007 -0500
76
- summary: reworked error handling
77
-
78
- changeset: 22:5497521e6a01
79
- user: m@loonsoft.com
80
- date: Sun May 27 17:21:16 2007 -0500
81
- summary: removed bogon method stub
82
-
83
- changeset: 19:943383442ab0
84
- user: m@loonsoft.com
85
- date: Sun May 27 15:21:27 2007 -0500
86
- summary: mailhide supported
87
-
88
- changeset: 16:a9f834ef0ffb
89
- user: m@loonsoft.com
90
- date: Fri May 25 19:22:49 2007 -0500
91
- summary: added cgi module, some tests
92
-
93
- changeset: 11:d7dcf24bb808
94
- user: m@loonsoft.com
95
- date: Fri May 25 11:58:27 2007 -0500
96
- summary: changed license
97
-
98
- changeset: 9:8047f6e7eceb
99
- user: m@loonsoft.com
100
- date: Fri May 25 11:46:12 2007 -0500
101
- summary: turned off ssl
102
-
103
- changeset: 4:d28f38ac7cde
104
- user: m@loonsoft.com
105
- date: Fri May 25 11:18:07 2007 -0500
106
- summary: updated
107
-
108
- changeset: 1:146d97cc2e51
109
- user: m@loonsoft.com
110
- date: Fri May 25 10:41:52 2007 -0500
111
- summary: fixed license
112
-
113
- changeset: 0:1f1ba6ed3ef1
114
- user: m@loonsoft.com
115
- date: Fri May 25 10:41:35 2007 -0500
116
- summary: initial
1
+ 2009-07-24 mml <mml>
2
+
3
+ * Rakefile, lib/ruby-recaptcha.rb, test/test_recaptcha.rb:
4
+ fixed some randomly failing tests
5
+ [31a822ec2421] [tip]
6
+
7
+ 2009-02-15 m <m@loonsoft.com>
8
+
9
+ * .hgtags:
10
+ Added tag 1.0.0 release for changeset 19f9c037e388
11
+ [d4de467a907f]
12
+
13
+ * lib/ruby-recaptcha.rb:
14
+ fixed require line
15
+ [19f9c037e388] [1.0.0 release]
16
+
17
+ 2009-02-13 m <m@loonsoft.com>
18
+
19
+ * Manifest.txt, README.txt, Rakefile, lib/recaptcha.rb,
20
+ lib/recaptcha/version.rb, lib/ruby-recaptcha.rb, script/console,
21
+ script/destroy, script/generate, test/test_helper.rb,
22
+ website/index.txt, website/javascripts/rounded_corners_lite.inc.js,
23
+ website/stylesheets/screen.css, website/template.rhtml:
24
+ updated to new version of newgem
25
+ [de8078de5372]
26
+
27
+ 2008-12-08 m <m@loonsoft.com>
28
+
29
+ * website/index.txt, website/template.rhtml:
30
+ fixed js
31
+ [3cb43baa75ef]
32
+
33
+ * website/index.txt:
34
+ updated site
35
+ [353af929586d]
36
+
37
+ * Rakefile:
38
+ fix uploaded perms
39
+ [1bfdbd7dbf58]
40
+
41
+ * Rakefile, website/index.txt:
42
+ updated deploy script & site template
43
+ [0ed40a3c44bc]
44
+
45
+ 2008-12-05 m <m@loonsoft.com>
46
+
47
+ * website/index.txt, website/template.rhtml:
48
+ updated website
49
+ [cb2384317947]
50
+
51
+ 2008-09-02 m <m@loonsoft.com>
52
+
53
+ * README.txt, lib/recaptcha.rb, test/test_recaptcha.rb:
54
+ removed test code which seems to cause trouble with the masses
55
+ [201f032ce586]
56
+
57
+ 2008-05-30 m <m@loonsoft.com>
58
+
59
+ * README.txt, lib/recaptcha.rb:
60
+ fix for loopback addr requests
61
+ [297ed7ad0790]
62
+
63
+ 2008-04-07 m <m@loonsoft.com>
64
+
65
+ * lib/recaptcha.rb, test/test_recaptcha.rb, website/index.txt:
66
+ fix for kim griggs
67
+ [143671e3abb0]
68
+
69
+ 2008-03-05 m <m@loonsoft.com>
70
+
71
+ * lib/recaptcha.rb, test/test_recaptcha.rb:
72
+ fixed bug when nil challenge string
73
+ [52e0ff173f56]
74
+
75
+ 2008-03-01 m <m@loonsoft.com>
76
+
77
+ * lib/recaptcha.rb, test/test_recaptcha.rb, website/index.txt:
78
+ integrated more patches from pv
79
+ [f63d820d97f9]
80
+
81
+ 2008-02-24 m <m@loonsoft.com>
82
+
83
+ * lib/recaptcha.rb, website/index.txt:
84
+ reapplied missing patch
85
+ [4964962ea7be]
86
+
87
+ * lib/recaptcha.rb, test/test_recaptcha.rb, website/index.txt:
88
+ patch from peter vandenberk
89
+ [299402495d48]
90
+
91
+ 2008-01-12 m <m@loonsoft.com>
92
+
93
+ * website/index.txt:
94
+ website formatting
95
+ [0c065e76a6a8]
96
+
97
+ * website/index.txt:
98
+ website formatting
99
+ [79fe86cded6a]
100
+
101
+ * lib/recaptcha.rb, test/test_recaptcha.rb, website/index.txt:
102
+ proxy support
103
+ [e55d02f563e4]
104
+
105
+ 2007-12-30 m <m@loonsoft.com>
106
+
107
+ * scripts/txt2html, website/index.txt:
108
+ updated website
109
+ [aa2897a0b6fd]
110
+
111
+ * website/index.txt:
112
+ Backed out changeset 0cc68aefef09
113
+ [770296229d47]
114
+
115
+ * website/index.txt:
116
+ fixed uri
117
+ [0cc68aefef09]
118
+
119
+ 2007-12-26 m <m@loonsoft.com>
120
+
121
+ * Rakefile, website/index.txt:
122
+ bleh
123
+ [62edd6a24d72]
124
+
125
+ 2007-10-08 m <m@loonsoft.com>
126
+
127
+ * website/template.rhtml:
128
+ modified coda
129
+ [d0102db1ece1]
130
+
131
+ 2007-08-23 m <m@loonsoft.com>
132
+
133
+ * lib/recaptcha.rb:
134
+ fix from joey geiger
135
+ [24e4ed5017bc]
136
+
137
+ 2007-06-09 m <m@loonsoft.com>
138
+
139
+ * lib/recaptcha.rb, test/test_recaptcha.rb:
140
+ error parameter no longer included when the error is blank or nil
141
+ [310e75fbd650]
142
+
143
+ 2007-06-06 m <m@loonsoft.com>
144
+
145
+ * website/index.txt:
146
+ merge
147
+ [13de70beb380]
148
+
149
+ * lib/recaptcha.rb, test/test_recaptcha.rb, website/index.txt:
150
+ Backed out changeset 5a6746ce03f73d0dd02db155816500870088bf6e
151
+ backout of the backout, cosby patch back in
152
+ [ed21f08b6331]
153
+
154
+ * website/index.txt:
155
+ further clarification
156
+ [db3308cd9f2b]
157
+
158
+ * lib/recaptcha/version.rb, website/index.txt:
159
+ clarification to doc
160
+ [0ce238b954ed]
161
+
162
+ * website/index.txt:
163
+ updated site
164
+ [b798dbd756f5]
165
+
166
+ * lib/recaptcha.rb, test/test_recaptcha.rb, website/index.txt:
167
+ Backed out changeset d614a6a28630eb4dba913739518dbdc6d3aaa410
168
+
169
+ seems to be causing issues
170
+ [5a6746ce03f7]
171
+
172
+ * website/index.txt:
173
+ clarification
174
+ [9d2ff1293a4e]
175
+
176
+ 2007-05-30 m <m@loonsoft.com>
177
+
178
+ * lib/recaptcha.rb, test/test_recaptcha.rb, website/index.txt:
179
+ patch from victor cosby
180
+ [d614a6a28630]
181
+
182
+ 2007-05-29 m <m@loonsoft.com>
183
+
184
+ * lib/recaptcha.rb, test/test_recaptcha.rb, website/index.txt:
185
+ Backed out changeset 1086e6e6217f85433cc539e6d687880adc421c2f
186
+ [d1dc394b249b]
187
+
188
+ * lib/recaptcha.rb, test/test_recaptcha.rb, website/index.txt:
189
+ reworked error handling
190
+ [1086e6e6217f]
191
+
192
+ 2007-05-27 m <m@loonsoft.com>
193
+
194
+ * lib/recaptcha.rb:
195
+ removed bogon method stub
196
+ [5497521e6a01]
197
+
198
+ * website/index.txt:
199
+ fixup page
200
+ [99665cb4b9a1]
201
+
202
+ * website/index.txt:
203
+ mailhide supported
204
+ [4a0b9f72eede]
205
+
206
+ * lib/recaptcha.rb, test/test_recaptcha.rb:
207
+ mailhide supported
208
+ [943383442ab0]
209
+
210
+ 2007-05-25 m <m@loonsoft.com>
211
+
212
+ * website/index.txt:
213
+ pointer to code
214
+ [848e1a4c0b17]
215
+
216
+ * website/template.rhtml:
217
+ urchin
218
+ [e2b1d5e77f97]
219
+
220
+ * lib/recaptcha.rb, test/test_recaptcha.rb:
221
+ added cgi module, some tests
222
+ [a9f834ef0ffb]
223
+
224
+ * Rakefile, website/index.txt:
225
+ updates
226
+ [5f41c4ec54b2]
227
+
228
+ * Rakefile, lib/recaptcha/version.rb, scripts/txt2html:
229
+ updates
230
+ [ef9516789992]
231
+
232
+ * .hgignore, History.txt, Rakefile:
233
+ updates
234
+ [976727776d37]
235
+
236
+ * website/index.txt:
237
+ changed license
238
+ [63e4d638cbea]
239
+
240
+ * lib/recaptcha.rb, website/index.txt:
241
+ changed license
242
+ [d7dcf24bb808]
243
+
244
+ * lib/recaptcha/version.rb:
245
+ turned off ssl
246
+ [5ae4c8024402]
247
+
248
+ * lib/recaptcha.rb:
249
+ turned off ssl
250
+ [8047f6e7eceb]
251
+
252
+ * .hgtags:
253
+ Added tag release 1.1.2 for changeset cd3bd3392418
254
+ [844ac63dfb5a]
255
+
256
+ * Rakefile, scripts/txt2html:
257
+ update
258
+ [cd3bd3392418] [release 1.1.2]
259
+
260
+ * .hgignore, Rakefile, website/index.txt:
261
+ update
262
+ [3d15d7d8ff91]
263
+
264
+ * Rakefile, website/index.html, website/index.txt:
265
+ update
266
+ [6af50b34c9fa]
267
+
268
+ * lib/recaptcha.rb, lib/recaptcha/version.rb:
269
+ updated
270
+ [d28f38ac7cde]
271
+
272
+ * .hgignore:
273
+ ignore packages
274
+ [1c4ea4c672d2]
275
+
276
+ * .hgignore:
277
+ hgignore
278
+ [57e762617a54]
279
+
280
+ * lib/recaptcha.rb:
281
+ fixed license
282
+ [146d97cc2e51]
283
+
284
+ * History.txt, Manifest.txt, README.txt, Rakefile, lib/recaptcha.rb,
285
+ lib/recaptcha/version.rb, scripts/txt2html, setup.rb,
286
+ test/test_helper.rb, test/test_recaptcha.rb, website/index.html,
287
+ website/index.txt, website/javascripts/rounded_corners_lite.inc.js,
288
+ website/stylesheets/screen.css, website/template.rhtml:
289
+ initial
290
+ [1f1ba6ed3ef1]
117
291
 
data/README.txt CHANGED
@@ -1,21 +1,21 @@
1
1
  = ruby-recaptcha
2
2
 
3
- h2. What
3
+ * http://www.bitbucket.org/mml/ruby-recaptcha
4
4
 
5
- h2. Installing
5
+ == Installing
6
6
 
7
7
  <pre>
8
8
  gem install recaptcha
9
9
  </pre>
10
10
 
11
- h2. The basics
11
+ == The basics
12
12
 
13
13
  The ReCaptchaClient abstracts the ReCaptcha API for use in Rails Applications
14
14
 
15
15
 
16
- h2. Demonstration of usage
16
+ == Demonstration of usage
17
17
 
18
- h3. reCAPTCHA
18
+ === reCAPTCHA
19
19
 
20
20
  First, create an account at "ReCaptcha.net":http://www.recaptcha.net.
21
21
 
@@ -64,14 +64,14 @@ To customize theme and tabindex of the widget, you can include an options hash:
64
64
 
65
65
  See the "reCAPTCHA API Documentation":http://recaptcha.net/apidocs/captcha/ under "Look and Feel Customization" for more information.
66
66
 
67
- h3. Proxy support
67
+ === Proxy support
68
68
 
69
69
  If your rails application requires the use of a proxy, set proxy_host into your environment:
70
70
  <pre>
71
71
  ENV['proxy_host']='foo.example.com:8080'
72
72
  </pre>
73
73
 
74
- h3. Mail Hide
74
+ === Mail Hide
75
75
 
76
76
  When you mix in ViewHelper as above, you also get <pre> mail_hide(address, contents)</pre>, which you can call in your view thusly:
77
77
 
@@ -82,11 +82,11 @@ When you mix in ViewHelper as above, you also get <pre> mail_hide(address, conte
82
82
 
83
83
  Contents defaults to the first few characters of the email address.
84
84
 
85
- h2. Bugs
85
+ == Bugs
86
86
 
87
87
  http://www.bitbucket.org/mml/ruby-recaptcha/issues
88
88
 
89
- h2. Code
89
+ == Code
90
90
 
91
91
  Get it "here":http://www.bitbucket.org/mml/ruby-recaptcha
92
92
 
@@ -94,15 +94,15 @@ Note the wiki & forum & such there...
94
94
 
95
95
 
96
96
 
97
- h2. License
97
+ == License
98
98
 
99
99
  This code is free to use under the terms of the MIT License.
100
100
 
101
- h2. Contact
101
+ == Contact
102
102
 
103
103
  Comments are welcome. Send an email to "McClain Looney":mailto:mlooney@gmail.com.
104
104
 
105
- h2. Contributors:
105
+ == Contributors:
106
106
 
107
107
  Victor Cosby (test cleanup, additional code to style widget)
108
108
  <br>
data/lib/recaptcha.rb CHANGED
@@ -1,4 +1,4 @@
1
- #Copyright (c) 2007, 2008, 2009 McClain Looney
1
+ #Copyright (c) 2007, 2008, 2009, 2010 McClain Looney
2
2
  #
3
3
  #Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  #of this software and associated documentation files (the "Software"), to deal
@@ -17,23 +17,44 @@
17
17
  #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
18
  #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  #THE SOFTWARE.
20
+
20
21
  require 'openssl'
21
22
  require 'base64'
22
23
  require 'cgi'
23
24
  require 'net/http'
24
25
  require 'net/https'
26
+
25
27
  module ReCaptcha
28
+ # Some simple view helpers. Include this module in your own helper to pull in macros to spit out view code.
29
+ # include Recaptcha
26
30
  module ViewHelper
31
+ # Call this to generate the actual ReCaptcha script into your template.
32
+ # Options can include
33
+ # [rcc_pub] public recaptcha key (defaults to RCC_PUB constant)
34
+ # [rcc_priv] privte recaptcha key (defaults to RCC_PRIV constant)
35
+ # [ssl] generate ssl-based output, defaults to false
36
+ #
37
+ # This method also sets :rcc_err into the session.
38
+ # Example (rcc_pub and rcc_private not required if RCC_PUB & RCC_PRIV constants are used):
39
+ # = get_captcha(:rcc_pub => 'foobar', :rcc_priv => 'blegga', :ssl => true)
40
+ #
27
41
  def get_captcha(options={})
28
- k = ReCaptcha::Client.new(options[:rcc_pub] || RCC_PUB, options[:rcc_priv] || RCC_PRIV, options[:ssl] || false)
42
+ k = ReCaptcha::Client.new((options[:rcc_pub] || RCC_PUB), (options[:rcc_priv] || RCC_PRIV), (options[:ssl] || false))
29
43
  r = k.get_challenge(session[:rcc_err] || '', options)
30
44
  session[:rcc_err]=''
31
45
  r
32
46
  end
47
+
48
+ # Call this to generate the MailHide view code.
49
+ #
50
+ # Note: doesn't currently support ssl for some reason.
51
+ # [address] the email address you want to hide
52
+ # [contents] optional string to display as the text of the mailhide link
53
+ #
33
54
  def mail_hide(address, contents=nil)
34
55
  contents = truncate(address,10) if contents.nil?
35
- k = ReCaptcha::MHClient.new(MH_PUB, MH_PRIV)
36
- enciphered = k.encrypt(address)
56
+ k = ReCaptcha::MHClient.new(MH_PUB, MH_PRIV, address)
57
+ enciphered = k.crypted_address
37
58
  uri = "http://mailhide.recaptcha.net/d?k=#{MH_PUB}&c=#{enciphered}"
38
59
  t =<<-EOF
39
60
  <a href="#{uri}"
@@ -42,22 +63,40 @@ module ReCaptcha
42
63
  end
43
64
 
44
65
  end
66
+
67
+ # This module provides a simple helper for use in your controller
68
+ # to determine whether the ReCaptcha challenge was completed successfully.
69
+ # Simply include this module in your controller class
45
70
  module AppHelper
46
- private
71
+ # Validate recaptcha from passed in params. Sets errors into the errors hash.
72
+ #
73
+ # [p] request parameters. Requires :recaptcha_challenge_field and :recaptcha_response_field
74
+ # [errors] errors hash-like thing. Usually ActiveRecord::Base.errors
75
+ # [options] Options hash. currently only uses :rcc_pub and :rcc_priv options for passing in ReCaptcha keys.
47
76
  def validate_recap(p, errors, options = {})
48
77
  rcc=ReCaptcha::Client.new(options[:rcc_pub] || RCC_PUB, options[:rcc_priv] || RCC_PRIV)
49
78
  res = rcc.validate(request.remote_ip, p[:recaptcha_challenge_field], p[:recaptcha_response_field], errors)
50
79
  session[:rcc_err]=rcc.last_error
51
-
52
80
  res
53
81
  end
54
82
  end
83
+
84
+ # Mail hide client. Provides interfaceto ReCaptcha MailHide API
55
85
  class MHClient
56
- def initialize(pubkey, privkey)
86
+ # [pubkey] MailHide public key
87
+ # [privkey] MailHide private key
88
+ # [address] the address you want to hide.
89
+ def initialize(pubkey, privkey, address)
57
90
  @pubkey=pubkey
58
91
  @privkey=privkey
92
+ @address = address
59
93
  @host='mailhide.recaptcha.net'
60
94
  end
95
+ #The encrypted address
96
+ def crypted_address
97
+ encrypt(@address)
98
+ end
99
+ private
61
100
  def encrypt(string)
62
101
  padded = pad(string)
63
102
  iv="\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@@ -80,8 +119,16 @@ module ReCaptcha
80
119
  str
81
120
  end
82
121
  end
83
- class Client
84
122
 
123
+ # This class implements a client object capable of communicating ReCaptcha validation requests to the
124
+ # ReCaptcha service.
125
+ #
126
+ class Client
127
+ #last recaptcha error
128
+ attr_reader :last_error
129
+ # [pubkey] public ReCaptcha key
130
+ # [privkey] private ReCaptcha key (keep this a secret!)
131
+ # [ssl?] use https for requests when set. defaults to false.
85
132
  def initialize(pubkey, privkey, ssl=false)
86
133
  @pubkey = pubkey
87
134
  @privkey=privkey
@@ -92,6 +139,10 @@ module ReCaptcha
92
139
  @last_error=nil
93
140
  end
94
141
 
142
+ # get ReCaptcha challenge text, optionally setting the error message displayed on failure.
143
+ # [error] error message to be displayed on error
144
+ # [options] options hash. This is translated into a javascript hash and sent along to the ReCaptcha service as RecaptchaOptions
145
+ #
95
146
  def get_challenge(error='', options={})
96
147
  s=''
97
148
  if options[:options]
@@ -117,9 +168,11 @@ module ReCaptcha
117
168
  EOF
118
169
  end
119
170
 
120
- def last_error
121
- @last_error
122
- end
171
+ # Validate request. Note that this function actually makes a network request.
172
+ # [remoteip] request remote ip address
173
+ # [challenge] reCaptcha challenge
174
+ # [response] reCaptcha response
175
+ # [errors] errors hash-likethingy (usually from ActiveRecord::Base.errors)
123
176
  def validate(remoteip, challenge, response, errors)
124
177
  msg = "Captcha failed."
125
178
  unless response and challenge
@@ -1,7 +1,4 @@
1
- $:.unshift(File.dirname(__FILE__)) unless
2
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
-
4
1
  require 'recaptcha'
5
2
  module RubyRecaptcha
6
- VERSION = '1.0.0'
3
+ VERSION = '1.0.2'
7
4
  end
data/test/test_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
+ $:<< File.dirname(__FILE__)+'/../lib'
1
2
  require 'stringio'
2
3
  require 'test/unit'
3
4
  require File.dirname(__FILE__) + '/../lib/ruby-recaptcha'
@@ -67,17 +67,16 @@ class TestRecaptcha < Test::Unit::TestCase
67
67
  end
68
68
 
69
69
  def test_encrypt
70
- mhc = ReCaptcha::MHClient.new('01S1TOX9aibKxfC9oJlp8IeA==', 'deadbeefdeadbeefdeadbeefdeadbeef')
71
- z =mhc.encrypt('x@example.com')
70
+ mhc = ReCaptcha::MHClient.new('01S1TOX9aibKxfC9oJlp8IeA==', 'deadbeefdeadbeefdeadbeefdeadbeef', 'x@example.com')
71
+ z =mhc.crypted_address
72
72
  assert_equal 'wBG7nOgntKqWeDpF9ucVNQ==', z
73
- z =mhc.encrypt('johndoe@example.com')
74
- assert_equal 'whWIqk0r4urZ-3S7y7uSceC9_ECd3hpAGy71E2o0HpI=', z
75
73
  end
76
74
  def test_encrypt_long
77
- mhc = ReCaptcha::MHClient.new('01S1TOX9aibKxfC9oJlp8IeA==', 'deadbeefdeadbeefdeadbeefdeadbeef')
78
- z =mhc.encrypt('averylongemailaddressofmorethan32cdharactersx@example.com')
75
+ mhc = ReCaptcha::MHClient.new('01S1TOX9aibKxfC9oJlp8IeA==', 'deadbeefdeadbeefdeadbeefdeadbeef', 'averylongemailaddressofmorethan32cdharactersx@example.com')
76
+ z =mhc.crypted_address
79
77
  assert_equal "q-0LLVT2bIxWbFpfLfpNhJAGadkfWXVk4hAxSlVaLrdnXrsB1NKNubavS5N-7PBued3K531vifN6NB3iz3W7qQ==",z
80
- z =mhc.encrypt('johndoe@example.com')
78
+ mhc = ReCaptcha::MHClient.new('01S1TOX9aibKxfC9oJlp8IeA==', 'deadbeefdeadbeefdeadbeefdeadbeef', 'johndoe@example.com')
79
+ z = mhc.crypted_address
81
80
  assert_equal 'whWIqk0r4urZ-3S7y7uSceC9_ECd3hpAGy71E2o0HpI=', z
82
81
  end
83
82
 
@@ -109,10 +108,7 @@ class TestRecaptcha < Test::Unit::TestCase
109
108
  def test_constructor_with_recaptcha_options
110
109
  # "Look and Feel Customization" per http://recaptcha.net/apidocs/captcha/
111
110
  client = new_client
112
- expected= <<-EOF
113
- <script type=\"text/javascript\">\nvar RecaptchaOptions = { theme : \"white\", tabindex : 10};\n</script>\n <script type=\"text/javascript\" src=\"http://api.recaptcha.net/challenge?k=abc&error=somerror\"> </script>\n <noscript>\n <iframe src=\"http://api.recaptcha.net/noscript?k=abc&error=somerror\"\n height=\"300\" width=\"500\" frameborder=\"0\"></iframe><br>\n <textarea name=\"recaptcha_challenge_field\" rows=\"3\" cols=\"40\">\n </textarea>\n <input type=\"hidden\" name=\"recaptcha_response_field\" \n value=\"manual_challenge\">\n </noscript>
114
- EOF
115
- assert_equal expected.strip, client.get_challenge('somerror', :options => {:theme => 'white', :tabindex => 10}).strip
111
+ assert_match(/theme \: \"white\"/, client.get_challenge('somerror', :options => {:theme => 'white', :tabindex => 10}))
116
112
  end
117
113
 
118
114
  def test_validate_fails
@@ -222,12 +218,12 @@ class TestRecaptcha < Test::Unit::TestCase
222
218
  ReCaptcha::ViewHelper.define_public_key # 'foo'
223
219
  ReCaptcha::ViewHelper.define_private_key # 'bar'
224
220
  actual = @vf.get_captcha
225
- assert_equal(((expected % ['foo', 'foo']).strip), actual.strip)
221
+ assert_match(/k=foo/, actual)
226
222
  ReCaptcha::ViewHelper.undefine_public_key
227
223
  ReCaptcha::ViewHelper.undefine_private_key
228
224
  # next, with options
229
225
  actual = @vf.get_captcha(:rcc_pub => 'foobar', :rcc_priv => 'blegga')
230
- assert_equal(((expected % ['foobar', 'foobar']).strip), actual.strip)
226
+ assert_match(/k=foobar/, actual)
231
227
  end
232
228
 
233
229
  #
@@ -241,6 +237,7 @@ class TestRecaptcha < Test::Unit::TestCase
241
237
  @cf.validate_recap({}, {})
242
238
  end
243
239
  end
240
+
244
241
  def test_validate_recap_fails_without_public_key_constant
245
242
  assert !ReCaptcha::AppHelper.const_defined?(:RCC_PUB)
246
243
  assert !ReCaptcha::AppHelper.const_defined?(:RCC_PRIV)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-recaptcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - McClain Looney
@@ -9,18 +9,18 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-13 00:00:00 -06:00
12
+ date: 2010-02-10 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: newgem
16
+ name: hoe
17
17
  type: :development
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.2.3
23
+ version: 2.5.0
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hoe
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.8.0
33
+ version: 2.5.0
34
34
  version:
35
35
  description: ""
36
36
  email:
@@ -48,7 +48,9 @@ files:
48
48
  - lib/recaptcha.rb
49
49
  - lib/ruby-recaptcha.rb
50
50
  has_rdoc: true
51
- homepage: h2. What
51
+ homepage: http://www.bitbucket.org/mml/ruby-recaptcha
52
+ licenses: []
53
+
52
54
  post_install_message:
53
55
  rdoc_options:
54
56
  - --main
@@ -70,9 +72,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
72
  requirements: []
71
73
 
72
74
  rubyforge_project: ruby-recaptcha
73
- rubygems_version: 1.3.1
75
+ rubygems_version: 1.3.5
74
76
  signing_key:
75
- specification_version: 2
77
+ specification_version: 3
76
78
  summary: ""
77
79
  test_files:
78
80
  - test/test_helper.rb