pwned 1.2.1 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml DELETED
@@ -1,23 +0,0 @@
1
- sudo: false
2
- language: ruby
3
-
4
- env:
5
- matrix:
6
- - RAILS_VERSION=4.2.0
7
- - RAILS_VERSION=5.0.0
8
- - RAILS_VERSION=5.1.0
9
- - RAILS_VERSION=5.2.0.rc1
10
-
11
- rvm:
12
- - 2.5.0
13
- - 2.4.0
14
- - 2.3.0
15
- - jruby
16
- - ruby-head
17
-
18
- before_install: gem install bundler -v 1.16.1
19
-
20
- matrix:
21
- allow_failures:
22
- - rvm: ruby-head
23
- - env: RAILS_VERSION=5.2.0.rc1
@@ -1,488 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>
7
- Class: NotPwnedValidator
8
-
9
- &mdash; Documentation by YARD 0.9.12
10
-
11
- </title>
12
-
13
- <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
14
-
15
- <link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
16
-
17
- <script type="text/javascript" charset="utf-8">
18
- pathId = "NotPwnedValidator";
19
- relpath = '';
20
- </script>
21
-
22
-
23
- <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
24
-
25
- <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
26
-
27
-
28
- </head>
29
- <body>
30
- <div class="nav_wrap">
31
- <iframe id="nav" src="class_list.html?1"></iframe>
32
- <div id="resizer"></div>
33
- </div>
34
-
35
- <div id="main" tabindex="-1">
36
- <div id="header">
37
- <div id="menu">
38
-
39
- <a href="_index.html">Index (N)</a> &raquo;
40
-
41
-
42
- <span class="title">NotPwnedValidator</span>
43
-
44
- </div>
45
-
46
- <div id="search">
47
-
48
- <a class="full_list_link" id="class_list_link"
49
- href="class_list.html">
50
-
51
- <svg width="24" height="24">
52
- <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
- <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
- <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
- </svg>
56
- </a>
57
-
58
- </div>
59
- <div class="clear"></div>
60
- </div>
61
-
62
- <div id="content"><h1>Class: NotPwnedValidator
63
-
64
-
65
-
66
- </h1>
67
- <div class="box_info">
68
-
69
- <dl>
70
- <dt>Inherits:</dt>
71
- <dd>
72
- <span class="inheritName">ActiveModel::EachValidator</span>
73
-
74
- <ul class="fullTree">
75
- <li>Object</li>
76
-
77
- <li class="next">ActiveModel::EachValidator</li>
78
-
79
- <li class="next">NotPwnedValidator</li>
80
-
81
- </ul>
82
- <a href="#" class="inheritanceTree">show all</a>
83
-
84
- </dd>
85
- </dl>
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
- <dl>
98
- <dt>Defined in:</dt>
99
- <dd>lib/pwned/not_pwned_validator.rb</dd>
100
- </dl>
101
-
102
- </div>
103
-
104
- <h2>Overview</h2><div class="docstring">
105
- <div class="discussion">
106
-
107
- <p>An <code>ActiveModel</code> validator to check passwords against the Pwned
108
- Passwords API.</p>
109
-
110
-
111
- </div>
112
- </div>
113
- <div class="tags">
114
-
115
- <div class="examples">
116
- <p class="tag_title">Examples:</p>
117
-
118
-
119
- <p class="example_title"><div class='inline'>
120
- <p>Validate a password on a <code>User</code> model with the default options.</p>
121
- </div></p>
122
-
123
- <pre class="example code"><code><span class='kw'>class</span> <span class='const'>User</span> <span class='op'>&lt;</span> <span class='const'>ApplicationRecord</span>
124
- <span class='id identifier rubyid_validates'>validates</span> <span class='symbol'>:password</span><span class='comma'>,</span> <span class='label'>not_pwned:</span> <span class='kw'>true</span>
125
- <span class='kw'>end</span></code></pre>
126
-
127
-
128
- <p class="example_title"><div class='inline'>
129
- <p>Validate a password on a <code>User</code> model with a custom error
130
- message.</p>
131
- </div></p>
132
-
133
- <pre class="example code"><code><span class='kw'>class</span> <span class='const'>User</span> <span class='op'>&lt;</span> <span class='const'>ApplicationRecord</span>
134
- <span class='id identifier rubyid_validates'>validates</span> <span class='symbol'>:password</span><span class='comma'>,</span> <span class='label'>not_pwned:</span> <span class='lbrace'>{</span> <span class='label'>message:</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>has been pwned %{count} times</span><span class='tstring_end'>&quot;</span></span> <span class='rbrace'>}</span>
135
- <span class='kw'>end</span></code></pre>
136
-
137
-
138
- <p class="example_title"><div class='inline'>
139
- <p>Validate a password on a <code>User</code> model that allows the password
140
- to have been breached once.</p>
141
- </div></p>
142
-
143
- <pre class="example code"><code><span class='kw'>class</span> <span class='const'>User</span> <span class='op'>&lt;</span> <span class='const'>ApplicationRecord</span>
144
- <span class='id identifier rubyid_validates'>validates</span> <span class='symbol'>:password</span><span class='comma'>,</span> <span class='label'>not_pwned:</span> <span class='lbrace'>{</span> <span class='label'>threshold:</span> <span class='int'>1</span> <span class='rbrace'>}</span>
145
- <span class='kw'>end</span></code></pre>
146
-
147
-
148
- <p class="example_title"><div class='inline'>
149
- <p>Validate a password on a <code>User</code> model, handling API errors in
150
- various ways</p>
151
- </div></p>
152
-
153
- <pre class="example code"><code><span class='kw'>class</span> <span class='const'>User</span> <span class='op'>&lt;</span> <span class='const'>ApplicationRecord</span>
154
- <span class='comment'># The record is marked as invalid on network errors
155
- </span> <span class='comment'># (error message &quot;could not be verified against the past data breaches&quot;.)
156
- </span> <span class='id identifier rubyid_validates'>validates</span> <span class='symbol'>:password</span><span class='comma'>,</span> <span class='label'>not_pwned:</span> <span class='lbrace'>{</span> <span class='label'>on_error:</span> <span class='symbol'>:invalid</span> <span class='rbrace'>}</span>
157
-
158
- <span class='comment'># The record is marked as invalid on network errors with custom error.
159
- </span> <span class='id identifier rubyid_validates'>validates</span> <span class='symbol'>:password</span><span class='comma'>,</span> <span class='label'>not_pwned:</span> <span class='lbrace'>{</span> <span class='label'>on_error:</span> <span class='symbol'>:invalid</span><span class='comma'>,</span> <span class='label'>error_message:</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>might be pwned</span><span class='tstring_end'>&quot;</span></span> <span class='rbrace'>}</span>
160
-
161
- <span class='comment'># An error is raised on network errors.
162
- </span> <span class='comment'># This means that `record.valid?` will raise `Pwned::Error`.
163
- </span> <span class='comment'># Not recommended to use in production.
164
- </span> <span class='id identifier rubyid_validates'>validates</span> <span class='symbol'>:password</span><span class='comma'>,</span> <span class='label'>not_pwned:</span> <span class='lbrace'>{</span> <span class='label'>on_error:</span> <span class='symbol'>:raise_error</span> <span class='rbrace'>}</span>
165
-
166
- <span class='comment'># Call custom proc on error. For example, capture errors in Sentry,
167
- </span> <span class='comment'># but do not mark the record as invalid.
168
- </span> <span class='id identifier rubyid_validates'>validates</span> <span class='symbol'>:password</span><span class='comma'>,</span> <span class='label'>not_pwned:</span> <span class='lbrace'>{</span>
169
- <span class='label'>on_error:</span> <span class='tlambda'>-&gt;</span><span class='lparen'>(</span><span class='id identifier rubyid_record'>record</span><span class='comma'>,</span> <span class='id identifier rubyid_error'>error</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> <span class='const'>Raven</span><span class='period'>.</span><span class='id identifier rubyid_capture_exception'>capture_exception</span><span class='lparen'>(</span><span class='id identifier rubyid_error'>error</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
170
- <span class='rbrace'>}</span>
171
- <span class='kw'>end</span></code></pre>
172
-
173
- </div>
174
-
175
- <p class="tag_title">Since:</p>
176
- <ul class="since">
177
-
178
- <li>
179
-
180
-
181
-
182
-
183
-
184
- <div class='inline'>
185
- <p>1.2.0</p>
186
- </div>
187
-
188
- </li>
189
-
190
- </ul>
191
-
192
- </div><div id="subclasses">
193
- <h2>Direct Known Subclasses</h2>
194
- <p class="children"><span class='object_link'><a href="PwnedValidator.html" title="PwnedValidator (class)">PwnedValidator</a></span></p>
195
- </div>
196
-
197
- <h2>Constant Summary</h2>
198
- <dl class="constants">
199
-
200
- <dt id="DEFAULT_ON_ERROR-constant" class="">DEFAULT_ON_ERROR =
201
- <div class="docstring">
202
- <div class="discussion">
203
-
204
- <p>The default behaviour of this validator in the case of an API failure. The
205
- default will mean that if the API fails the object will not be marked
206
- invalid.</p>
207
-
208
-
209
- </div>
210
- </div>
211
- <div class="tags">
212
-
213
- <p class="tag_title">Since:</p>
214
- <ul class="since">
215
-
216
- <li>
217
-
218
-
219
-
220
-
221
-
222
- <div class='inline'>
223
- <p>1.2.0</p>
224
- </div>
225
-
226
- </li>
227
-
228
- </ul>
229
-
230
- </div>
231
- </dt>
232
- <dd><pre class="code"><span class='symbol'>:valid</span></pre></dd>
233
-
234
- <dt id="DEFAULT_THRESHOLD-constant" class="">DEFAULT_THRESHOLD =
235
- <div class="docstring">
236
- <div class="discussion">
237
-
238
- <p>The default threshold for whether a breach is considered pwned. The default
239
- is 0, so any password that appears in a breach will mark the record as
240
- invalid.</p>
241
-
242
-
243
- </div>
244
- </div>
245
- <div class="tags">
246
-
247
- <p class="tag_title">Since:</p>
248
- <ul class="since">
249
-
250
- <li>
251
-
252
-
253
-
254
-
255
-
256
- <div class='inline'>
257
- <p>1.2.0</p>
258
- </div>
259
-
260
- </li>
261
-
262
- </ul>
263
-
264
- </div>
265
- </dt>
266
- <dd><pre class="code"><span class='int'>0</span></pre></dd>
267
-
268
- </dl>
269
-
270
-
271
-
272
-
273
-
274
-
275
-
276
-
277
- <h2>
278
- Instance Method Summary
279
- <small><a href="#" class="summary_toggle">collapse</a></small>
280
- </h2>
281
-
282
- <ul class="summary">
283
-
284
- <li class="public ">
285
- <span class="summary_signature">
286
-
287
- <a href="#validate_each-instance_method" title="#validate_each (instance method)">#<strong>validate_each</strong>(record, attribute, value) &#x21d2; Object </a>
288
-
289
-
290
-
291
- </span>
292
-
293
-
294
-
295
-
296
-
297
-
298
-
299
-
300
-
301
- <span class="summary_desc"><div class='inline'>
302
- <p>Validates the <code>value</code> against the Pwned Passwords API.</p>
303
- </div></span>
304
-
305
- </li>
306
-
307
-
308
- </ul>
309
-
310
-
311
-
312
-
313
-
314
- <div id="instance_method_details" class="method_details_list">
315
- <h2>Instance Method Details</h2>
316
-
317
-
318
- <div class="method_details first">
319
- <h3 class="signature first" id="validate_each-instance_method">
320
-
321
- #<strong>validate_each</strong>(record, attribute, value) &#x21d2; <tt>Object</tt>
322
-
323
-
324
-
325
-
326
-
327
- </h3><div class="docstring">
328
- <div class="discussion">
329
-
330
- <p>Validates the <code>value</code> against the Pwned Passwords API. If the
331
- <code>pwned_count</code> is higher than the optional <code>threshold</code>
332
- then the record is marked as invalid.</p>
333
-
334
- <p>In the case of an API error the validator will either mark the record as
335
- valid or invalid. Alternatively it will run an associated proc or re-raise
336
- the original error.</p>
337
-
338
- <p>The validation will short circuit and return with no errors added if the
339
- password is blank. The <code>Pwned::Password</code> initializer expects the
340
- password to be a string and will throw a <code>TypeError</code> if it is
341
- <code>nil</code>. Also, technically the empty string is not a password that
342
- is reported to be found in data breaches, so returns <code>false</code>,
343
- short circuiting that using <code>value.blank?</code> saves us a trip to
344
- the API.</p>
345
-
346
-
347
- </div>
348
- </div>
349
- <div class="tags">
350
- <p class="tag_title">Parameters:</p>
351
- <ul class="param">
352
-
353
- <li>
354
-
355
- <span class='name'>record</span>
356
-
357
-
358
- <span class='type'>(<tt>ActiveModel::Validations</tt>)</span>
359
-
360
-
361
-
362
- &mdash;
363
- <div class='inline'>
364
- <p>The object being validated</p>
365
- </div>
366
-
367
- </li>
368
-
369
- <li>
370
-
371
- <span class='name'>attribute</span>
372
-
373
-
374
- <span class='type'>(<tt>Symbol</tt>)</span>
375
-
376
-
377
-
378
- &mdash;
379
- <div class='inline'>
380
- <p>The attribute on the record that is currently being validated.</p>
381
- </div>
382
-
383
- </li>
384
-
385
- <li>
386
-
387
- <span class='name'>value</span>
388
-
389
-
390
- <span class='type'>(<tt>String</tt>)</span>
391
-
392
-
393
-
394
- &mdash;
395
- <div class='inline'>
396
- <p>The value of the attribute on the record that is the subject of the
397
- validation</p>
398
- </div>
399
-
400
- </li>
401
-
402
- </ul>
403
-
404
- <p class="tag_title">Since:</p>
405
- <ul class="since">
406
-
407
- <li>
408
-
409
-
410
-
411
-
412
-
413
- <div class='inline'>
414
- <p>1.2.0</p>
415
- </div>
416
-
417
- </li>
418
-
419
- </ul>
420
-
421
- </div><table class="source_code">
422
- <tr>
423
- <td>
424
- <pre class="lines">
425
-
426
-
427
- 77
428
- 78
429
- 79
430
- 80
431
- 81
432
- 82
433
- 83
434
- 84
435
- 85
436
- 86
437
- 87
438
- 88
439
- 89
440
- 90
441
- 91
442
- 92
443
- 93
444
- 94
445
- 95
446
- 96</pre>
447
- </td>
448
- <td>
449
- <pre class="code"><span class="info file"># File 'lib/pwned/not_pwned_validator.rb', line 77</span>
450
-
451
- <span class='kw'>def</span> <span class='id identifier rubyid_validate_each'>validate_each</span><span class='lparen'>(</span><span class='id identifier rubyid_record'>record</span><span class='comma'>,</span> <span class='id identifier rubyid_attribute'>attribute</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
452
- <span class='kw'>return</span> <span class='kw'>if</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span>
453
- <span class='kw'>begin</span>
454
- <span class='id identifier rubyid_pwned_check'>pwned_check</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Pwned.html" title="Pwned (module)">Pwned</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Pwned/Password.html" title="Pwned::Password (class)">Password</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Pwned/Password.html#initialize-instance_method" title="Pwned::Password#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='comma'>,</span> <span class='id identifier rubyid_request_options'>request_options</span><span class='rparen'>)</span>
455
- <span class='kw'>if</span> <span class='id identifier rubyid_pwned_check'>pwned_check</span><span class='period'>.</span><span class='id identifier rubyid_pwned_count'>pwned_count</span> <span class='op'>&gt;</span> <span class='id identifier rubyid_threshold'>threshold</span>
456
- <span class='id identifier rubyid_record'>record</span><span class='period'>.</span><span class='id identifier rubyid_errors'>errors</span><span class='period'>.</span><span class='id identifier rubyid_add'>add</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute'>attribute</span><span class='comma'>,</span> <span class='symbol'>:not_pwned</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='label'>count:</span> <span class='id identifier rubyid_pwned_check'>pwned_check</span><span class='period'>.</span><span class='id identifier rubyid_pwned_count'>pwned_count</span><span class='rparen'>)</span><span class='rparen'>)</span>
457
- <span class='kw'>end</span>
458
- <span class='kw'>rescue</span> <span class='const'><span class='object_link'><a href="Pwned.html" title="Pwned (module)">Pwned</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Pwned/Error.html" title="Pwned::Error (class)">Error</a></span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_error'>error</span>
459
- <span class='kw'>case</span> <span class='id identifier rubyid_on_error'>on_error</span>
460
- <span class='kw'>when</span> <span class='symbol'>:invalid</span>
461
- <span class='id identifier rubyid_record'>record</span><span class='period'>.</span><span class='id identifier rubyid_errors'>errors</span><span class='period'>.</span><span class='id identifier rubyid_add'>add</span><span class='lparen'>(</span><span class='id identifier rubyid_attribute'>attribute</span><span class='comma'>,</span> <span class='symbol'>:pwned_error</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='label'>message:</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:error_message</span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='rparen'>)</span>
462
- <span class='kw'>when</span> <span class='symbol'>:valid</span>
463
- <span class='comment'># Do nothing, consider the record valid
464
- </span> <span class='kw'>when</span> <span class='const'>Proc</span>
465
- <span class='id identifier rubyid_on_error'>on_error</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='id identifier rubyid_record'>record</span><span class='comma'>,</span> <span class='id identifier rubyid_error'>error</span><span class='rparen'>)</span>
466
- <span class='kw'>else</span>
467
- <span class='id identifier rubyid_raise'>raise</span>
468
- <span class='kw'>end</span>
469
- <span class='kw'>end</span>
470
- <span class='kw'>end</span></pre>
471
- </td>
472
- </tr>
473
- </table>
474
- </div>
475
-
476
- </div>
477
-
478
- </div>
479
-
480
- <div id="footer">
481
- Generated on Sat Mar 17 09:15:06 2018 by
482
- <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
483
- 0.9.12 (ruby-2.5.0).
484
- </div>
485
-
486
- </div>
487
- </body>
488
- </html>