flex_pass 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/Rakefile +32 -0
  3. data/lib/flex_pass/coders/sha256_hash.rb +23 -0
  4. data/lib/flex_pass/coders/sha2_hash.rb +23 -0
  5. data/lib/flex_pass/coders/sha512_hash.rb +23 -0
  6. data/lib/flex_pass/flex_secure_password.rb +75 -0
  7. data/lib/flex_pass/version.rb +3 -0
  8. data/lib/flex_pass.rb +9 -0
  9. data/lib/tasks/flex_pass_tasks.rake +4 -0
  10. data/test/dummy/README.rdoc +28 -0
  11. data/test/dummy/Rakefile +6 -0
  12. data/test/dummy/app/assets/javascripts/application.js +13 -0
  13. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  14. data/test/dummy/app/controllers/application_controller.rb +5 -0
  15. data/test/dummy/app/helpers/application_helper.rb +2 -0
  16. data/test/dummy/app/models/user.rb +5 -0
  17. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  18. data/test/dummy/bin/bundle +3 -0
  19. data/test/dummy/bin/rails +4 -0
  20. data/test/dummy/bin/rake +4 -0
  21. data/test/dummy/config/application.rb +23 -0
  22. data/test/dummy/config/boot.rb +5 -0
  23. data/test/dummy/config/database.yml +25 -0
  24. data/test/dummy/config/environment.rb +5 -0
  25. data/test/dummy/config/environments/development.rb +29 -0
  26. data/test/dummy/config/environments/production.rb +80 -0
  27. data/test/dummy/config/environments/test.rb +36 -0
  28. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  29. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  30. data/test/dummy/config/initializers/inflections.rb +16 -0
  31. data/test/dummy/config/initializers/mime_types.rb +5 -0
  32. data/test/dummy/config/initializers/secret_token.rb +12 -0
  33. data/test/dummy/config/initializers/session_store.rb +3 -0
  34. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  35. data/test/dummy/config/locales/en.yml +23 -0
  36. data/test/dummy/config/routes.rb +56 -0
  37. data/test/dummy/config.ru +4 -0
  38. data/test/dummy/db/migrate/20130626105648_create_users.rb +10 -0
  39. data/test/dummy/db/schema.rb +23 -0
  40. data/test/dummy/db/test.sqlite3 +0 -0
  41. data/test/dummy/lib/user1.rb +12 -0
  42. data/test/dummy/log/test.log +225 -0
  43. data/test/dummy/public/404.html +58 -0
  44. data/test/dummy/public/422.html +58 -0
  45. data/test/dummy/public/500.html +57 -0
  46. data/test/dummy/public/favicon.ico +0 -0
  47. data/test/dummy/test/fixtures/users.yml +9 -0
  48. data/test/dummy/test/models/user_test.rb +7 -0
  49. data/test/flex_pass_test.rb +122 -0
  50. data/test/models/administrator.rb +12 -0
  51. data/test/models/oauthed_user.rb +12 -0
  52. data/test/models/user.rb +12 -0
  53. data/test/models/user_non_existent_column.rb +12 -0
  54. data/test/models/user_not_valid_coder.rb +12 -0
  55. data/test/models/user_other_column.rb +12 -0
  56. data/test/models/user_sha.rb +12 -0
  57. data/test/models/visitor.rb +12 -0
  58. data/test/test_helper.rb +15 -0
  59. metadata +186 -0
@@ -0,0 +1,56 @@
1
+ Dummy::Application.routes.draw do
2
+ # The priority is based upon order of creation: first created -> highest priority.
3
+ # See how all your routes lay out with "rake routes".
4
+
5
+ # You can have the root of your site routed with "root"
6
+ # root 'welcome#index'
7
+
8
+ # Example of regular route:
9
+ # get 'products/:id' => 'catalog#view'
10
+
11
+ # Example of named route that can be invoked with purchase_url(id: product.id)
12
+ # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
13
+
14
+ # Example resource route (maps HTTP verbs to controller actions automatically):
15
+ # resources :products
16
+
17
+ # Example resource route with options:
18
+ # resources :products do
19
+ # member do
20
+ # get 'short'
21
+ # post 'toggle'
22
+ # end
23
+ #
24
+ # collection do
25
+ # get 'sold'
26
+ # end
27
+ # end
28
+
29
+ # Example resource route with sub-resources:
30
+ # resources :products do
31
+ # resources :comments, :sales
32
+ # resource :seller
33
+ # end
34
+
35
+ # Example resource route with more complex sub-resources:
36
+ # resources :products do
37
+ # resources :comments
38
+ # resources :sales do
39
+ # get 'recent', on: :collection
40
+ # end
41
+ # end
42
+
43
+ # Example resource route with concerns:
44
+ # concern :toggleable do
45
+ # post 'toggle'
46
+ # end
47
+ # resources :posts, concerns: :toggleable
48
+ # resources :photos, concerns: :toggleable
49
+
50
+ # Example resource route within a namespace:
51
+ # namespace :admin do
52
+ # # Directs /admin/products/* to Admin::ProductsController
53
+ # # (app/controllers/admin/products_controller.rb)
54
+ # resources :products
55
+ # end
56
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
@@ -0,0 +1,10 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table :users do |t|
4
+ t.string :name
5
+ t.string :password_digest
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended that you check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(version: 20130626105648) do
15
+
16
+ create_table "users", force: true do |t|
17
+ t.string "name"
18
+ t.string "password_digest"
19
+ t.datetime "created_at"
20
+ t.datetime "updated_at"
21
+ end
22
+
23
+ end
File without changes
@@ -0,0 +1,12 @@
1
+ class User1
2
+ extend ActiveModel::Callbacks
3
+ include ActiveModel::Validations
4
+ include FlexPass::FlexSecurePassword
5
+
6
+ attr_accessor :password_digest, :password_salt
7
+
8
+ define_model_callbacks :create
9
+
10
+ has_flexible_secure_password
11
+
12
+ end
@@ -0,0 +1,225 @@
1
+  (0.4ms) begin transaction
2
+ ----------------------------------------------------------------
3
+ FlexPassTest: test_Oauthed_user_can_be_created_with_blank_digest
4
+ ----------------------------------------------------------------
5
+  (0.1ms) rollback transaction
6
+  (0.1ms) begin transaction
7
+ ---------------------------------------------------------------
8
+ FlexPassTest: test_User_should_not_be_created_with_blank_digest
9
+ ---------------------------------------------------------------
10
+  (0.1ms) rollback transaction
11
+  (0.1ms) begin transaction
12
+ ---------------------------------------------------------------
13
+ FlexPassTest: test_authenticate_using_a_different_digest_column
14
+ ---------------------------------------------------------------
15
+  (0.1ms) rollback transaction
16
+  (0.1ms) begin transaction
17
+ -------------------------------------------
18
+ FlexPassTest: test_authenticate_with_BCrypt
19
+ -------------------------------------------
20
+  (0.1ms) rollback transaction
21
+  (0.1ms) begin transaction
22
+ -----------------------------------------
23
+ FlexPassTest: test_authenticate_with_SHA2
24
+ -----------------------------------------
25
+  (0.1ms) rollback transaction
26
+  (0.1ms) begin transaction
27
+ ---------------------------------
28
+ FlexPassTest: test_blank_password
29
+ ---------------------------------
30
+  (0.1ms) rollback transaction
31
+  (0.1ms) begin transaction
32
+ --------------------------------------------------------------------------------------
33
+ FlexPassTest: test_blank_password_confirmation_does_not_result_in_a_confirmation_error
34
+ --------------------------------------------------------------------------------------
35
+  (0.0ms) rollback transaction
36
+  (0.1ms) begin transaction
37
+ --------------------------------------------------------------------
38
+ FlexPassTest: test_blank_password_doesn't_override_previous_password
39
+ --------------------------------------------------------------------
40
+  (0.1ms) rollback transaction
41
+  (0.1ms) begin transaction
42
+ ----------------------------------------------------------
43
+ FlexPassTest: test_invalid_coder_should_use_Bcrypt_instead
44
+ ----------------------------------------------------------
45
+  (0.1ms) rollback transaction
46
+  (0.0ms) begin transaction
47
+ -------------------------------------
48
+ FlexPassTest: test_match_confirmation
49
+ -------------------------------------
50
+  (0.1ms) rollback transaction
51
+  (0.1ms) begin transaction
52
+ -------------------------------
53
+ FlexPassTest: test_nil_password
54
+ -------------------------------
55
+  (0.1ms) rollback transaction
56
+  (0.1ms) begin transaction
57
+ -------------------------------------------
58
+ FlexPassTest: test_password_must_be_present
59
+ -------------------------------------------
60
+  (0.0ms) rollback transaction
61
+  (0.1ms) begin transaction
62
+ ------------------------
63
+ FlexPassTest: test_truth
64
+ ------------------------
65
+  (0.0ms) rollback transaction
66
+  (0.1ms) begin transaction
67
+ -----------------------------------------------------------------
68
+ FlexPassTest: test_using_a_non_existent_digest_column_should_fail
69
+ -----------------------------------------------------------------
70
+  (0.1ms) rollback transaction
71
+  (0.1ms) begin transaction
72
+ -----------------------------------------------------------------------------
73
+ FlexPassTest: test_will_not_save_if_confirmation_is_blank_but_password_is_not
74
+ -----------------------------------------------------------------------------
75
+  (0.1ms) rollback transaction
76
+  (0.4ms) begin transaction
77
+ ----------------------------------------------------------------
78
+ FlexPassTest: test_Oauthed_user_can_be_created_with_blank_digest
79
+ ----------------------------------------------------------------
80
+  (0.1ms) rollback transaction
81
+  (0.1ms) begin transaction
82
+ ---------------------------------------------------------------
83
+ FlexPassTest: test_User_should_not_be_created_with_blank_digest
84
+ ---------------------------------------------------------------
85
+  (0.1ms) rollback transaction
86
+  (0.1ms) begin transaction
87
+ ---------------------------------------------------------------
88
+ FlexPassTest: test_authenticate_using_a_different_digest_column
89
+ ---------------------------------------------------------------
90
+  (0.1ms) rollback transaction
91
+  (0.0ms) begin transaction
92
+ -------------------------------------------
93
+ FlexPassTest: test_authenticate_with_BCrypt
94
+ -------------------------------------------
95
+  (0.1ms) rollback transaction
96
+  (0.1ms) begin transaction
97
+ -----------------------------------------
98
+ FlexPassTest: test_authenticate_with_SHA2
99
+ -----------------------------------------
100
+  (0.1ms) rollback transaction
101
+  (0.1ms) begin transaction
102
+ ---------------------------------
103
+ FlexPassTest: test_blank_password
104
+ ---------------------------------
105
+  (0.1ms) rollback transaction
106
+  (0.1ms) begin transaction
107
+ --------------------------------------------------------------------------------------
108
+ FlexPassTest: test_blank_password_confirmation_does_not_result_in_a_confirmation_error
109
+ --------------------------------------------------------------------------------------
110
+  (0.0ms) rollback transaction
111
+  (0.0ms) begin transaction
112
+ --------------------------------------------------------------------
113
+ FlexPassTest: test_blank_password_doesn't_override_previous_password
114
+ --------------------------------------------------------------------
115
+  (0.1ms) rollback transaction
116
+  (0.0ms) begin transaction
117
+ ----------------------------------------------------------
118
+ FlexPassTest: test_invalid_coder_should_use_Bcrypt_instead
119
+ ----------------------------------------------------------
120
+  (0.0ms) rollback transaction
121
+  (0.0ms) begin transaction
122
+ -------------------------------------
123
+ FlexPassTest: test_match_confirmation
124
+ -------------------------------------
125
+  (0.1ms) rollback transaction
126
+  (0.0ms) begin transaction
127
+ -------------------------------
128
+ FlexPassTest: test_nil_password
129
+ -------------------------------
130
+  (0.0ms) rollback transaction
131
+  (0.0ms) begin transaction
132
+ -------------------------------------------
133
+ FlexPassTest: test_password_must_be_present
134
+ -------------------------------------------
135
+  (0.0ms) rollback transaction
136
+  (0.0ms) begin transaction
137
+ ------------------------
138
+ FlexPassTest: test_truth
139
+ ------------------------
140
+  (0.0ms) rollback transaction
141
+  (0.0ms) begin transaction
142
+ -----------------------------------------------------------------
143
+ FlexPassTest: test_using_a_non_existent_digest_column_should_fail
144
+ -----------------------------------------------------------------
145
+  (0.1ms) rollback transaction
146
+  (0.1ms) begin transaction
147
+ -----------------------------------------------------------------------------
148
+ FlexPassTest: test_will_not_save_if_confirmation_is_blank_but_password_is_not
149
+ -----------------------------------------------------------------------------
150
+  (0.1ms) rollback transaction
151
+  (0.4ms) begin transaction
152
+ ----------------------------------------------------------------
153
+ FlexPassTest: test_Oauthed_user_can_be_created_with_blank_digest
154
+ ----------------------------------------------------------------
155
+  (0.1ms) rollback transaction
156
+  (0.1ms) begin transaction
157
+ ---------------------------------------------------------------
158
+ FlexPassTest: test_User_should_not_be_created_with_blank_digest
159
+ ---------------------------------------------------------------
160
+  (0.1ms) rollback transaction
161
+  (0.1ms) begin transaction
162
+ ---------------------------------------------------------------
163
+ FlexPassTest: test_authenticate_using_a_different_digest_column
164
+ ---------------------------------------------------------------
165
+  (0.1ms) rollback transaction
166
+  (0.1ms) begin transaction
167
+ -------------------------------------------
168
+ FlexPassTest: test_authenticate_with_BCrypt
169
+ -------------------------------------------
170
+  (0.1ms) rollback transaction
171
+  (0.1ms) begin transaction
172
+ -----------------------------------------
173
+ FlexPassTest: test_authenticate_with_SHA2
174
+ -----------------------------------------
175
+  (0.1ms) rollback transaction
176
+  (0.1ms) begin transaction
177
+ ---------------------------------
178
+ FlexPassTest: test_blank_password
179
+ ---------------------------------
180
+  (0.1ms) rollback transaction
181
+  (0.1ms) begin transaction
182
+ --------------------------------------------------------------------------------------
183
+ FlexPassTest: test_blank_password_confirmation_does_not_result_in_a_confirmation_error
184
+ --------------------------------------------------------------------------------------
185
+  (0.0ms) rollback transaction
186
+  (0.1ms) begin transaction
187
+ --------------------------------------------------------------------
188
+ FlexPassTest: test_blank_password_doesn't_override_previous_password
189
+ --------------------------------------------------------------------
190
+  (0.1ms) rollback transaction
191
+  (0.1ms) begin transaction
192
+ ----------------------------------------------------------
193
+ FlexPassTest: test_invalid_coder_should_use_Bcrypt_instead
194
+ ----------------------------------------------------------
195
+  (0.1ms) rollback transaction
196
+  (0.0ms) begin transaction
197
+ -------------------------------------
198
+ FlexPassTest: test_match_confirmation
199
+ -------------------------------------
200
+  (0.1ms) rollback transaction
201
+  (0.1ms) begin transaction
202
+ -------------------------------
203
+ FlexPassTest: test_nil_password
204
+ -------------------------------
205
+  (0.0ms) rollback transaction
206
+  (0.0ms) begin transaction
207
+ -------------------------------------------
208
+ FlexPassTest: test_password_must_be_present
209
+ -------------------------------------------
210
+  (0.1ms) rollback transaction
211
+  (0.0ms) begin transaction
212
+ ------------------------
213
+ FlexPassTest: test_truth
214
+ ------------------------
215
+  (0.0ms) rollback transaction
216
+  (0.1ms) begin transaction
217
+ -----------------------------------------------------------------
218
+ FlexPassTest: test_using_a_non_existent_digest_column_should_fail
219
+ -----------------------------------------------------------------
220
+  (0.1ms) rollback transaction
221
+  (0.1ms) begin transaction
222
+ -----------------------------------------------------------------------------
223
+ FlexPassTest: test_will_not_save_if_confirmation_is_blank_but_password_is_not
224
+ -----------------------------------------------------------------------------
225
+  (0.1ms) rollback transaction
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/404.html -->
52
+ <div class="dialog">
53
+ <h1>The page you were looking for doesn't exist.</h1>
54
+ <p>You may have mistyped the address or the page may have moved.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/422.html -->
52
+ <div class="dialog">
53
+ <h1>The change you wanted was rejected.</h1>
54
+ <p>Maybe you tried to change something you didn't have access to.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/500.html -->
52
+ <div class="dialog">
53
+ <h1>We're sorry, but something went wrong.</h1>
54
+ </div>
55
+ <p>If you are the application owner check the logs for more information.</p>
56
+ </body>
57
+ </html>
File without changes
@@ -0,0 +1,9 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ one:
4
+ name: MyString
5
+ password_digest: MyString
6
+
7
+ two:
8
+ name: MyString
9
+ password_digest: MyString
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class UserTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,122 @@
1
+ require 'test_helper'
2
+ require 'models/user'
3
+ require 'models/user_sha'
4
+ require 'models/user_other_column'
5
+ require 'models/user_not_valid_coder'
6
+ require 'models/oauthed_user'
7
+ require 'models/visitor'
8
+ require 'models/administrator'
9
+
10
+ class FlexPassTest < ActiveSupport::TestCase
11
+ setup do
12
+ @user = User.new
13
+ @user_sha = UserSHA.new
14
+ @user_other_column = UserOtherColumn.new
15
+ @visitor = Visitor.new
16
+ @oauthed_user = OauthedUser.new
17
+ end
18
+
19
+ test "truth" do
20
+ assert_kind_of Module, FlexPass
21
+ end
22
+ test "blank password" do
23
+ @user.password = @visitor.password = ''
24
+ assert !@user.valid?(:create), 'user should be invalid'
25
+ assert @visitor.valid?(:create), 'visitor should be valid'
26
+ end
27
+
28
+ test "nil password" do
29
+ @user.password = @visitor.password = nil
30
+ assert !@user.valid?(:create), 'user should be invalid'
31
+ assert @visitor.valid?(:create), 'visitor should be valid'
32
+ end
33
+
34
+ test "blank password doesn't override previous password" do
35
+ @user.password = 'test'
36
+ @user.password = ''
37
+ assert_equal @user.password, 'test'
38
+ end
39
+
40
+ test "password must be present" do
41
+ assert !@user.valid?(:create)
42
+ assert_equal 1, @user.errors.size
43
+ end
44
+
45
+ test "match confirmation" do
46
+ @user.password = @visitor.password = "thiswillberight"
47
+ @user.password_confirmation = @visitor.password_confirmation = "wrong"
48
+
49
+ assert !@user.valid?
50
+ assert @visitor.valid?
51
+
52
+ @user.password_confirmation = "thiswillberight"
53
+
54
+ assert @user.valid?
55
+ end
56
+
57
+ test "authenticate with BCrypt" do
58
+ @user.password = "secret"
59
+
60
+ assert_not_equal @user.password, @user.password_digest.to_s, 'Password digest should not be equal to the password'
61
+ assert !@user.authenticate("wrong")
62
+ assert @user.authenticate("secret")
63
+ end
64
+
65
+ test "authenticate with SHA2" do
66
+ @user_sha.password = "secret"
67
+
68
+ assert_not_equal @user_sha.password, @user_sha.password_digest.to_s, 'Password digest should not be equal to the password'
69
+ assert !@user_sha.authenticate("wrong"), '"wrong" should be wrong'
70
+ assert @user_sha.authenticate("secret"), '"secret" should be right'
71
+ end
72
+
73
+ test "using a non existent digest column should fail" do
74
+ assert_raise RuntimeError do
75
+ require 'models/user_non_existent_column'
76
+ end
77
+ end
78
+
79
+ test "authenticate using a different digest column" do
80
+ @user_other_column.password = "secret"
81
+
82
+ assert_not_equal @user_other_column.password, @user_other_column.other_digest_column.to_s, 'Password digest should not be equal to the password'
83
+ assert_nil @user_other_column.password_digest
84
+ assert !@user_other_column.authenticate("wrong"), '"wrong" should be wrong'
85
+ assert @user_other_column.authenticate("secret"), '"secret" should be right'
86
+ end
87
+
88
+ test "invalid coder should use Bcrypt instead" do
89
+ assert_equal UserNotValidCoder.coder, BCrypt::Password, 'When invalid coder is specified, BCrypt should be used instead'
90
+ end
91
+
92
+ test "User should not be created with blank digest" do
93
+ assert_raise RuntimeError do
94
+ @user.run_callbacks :create
95
+ end
96
+ @user.password = "supersecretpassword"
97
+ assert_nothing_raised do
98
+ @user.run_callbacks :create
99
+ end
100
+ end
101
+
102
+ test "Oauthed user can be created with blank digest" do
103
+ assert_nothing_raised do
104
+ @oauthed_user.run_callbacks :create
105
+ end
106
+ end
107
+
108
+ test "blank password_confirmation does not result in a confirmation error" do
109
+ @user.password = ""
110
+ @user.password_confirmation = ""
111
+ assert @user.valid?(:update), "user should be valid"
112
+ end
113
+
114
+ test "will not save if confirmation is blank but password is not" do
115
+ @user.password = "password"
116
+ @user.password_confirmation = ""
117
+ assert_not @user.valid?(:create)
118
+
119
+ @user.password_confirmation = "password"
120
+ assert @user.valid?(:create)
121
+ end
122
+ end
@@ -0,0 +1,12 @@
1
+ class Administrator
2
+ extend ActiveModel::Callbacks
3
+ include ActiveModel::Validations
4
+ include FlexPass::FlexSecurePassword
5
+
6
+ define_model_callbacks :create
7
+
8
+ attr_accessor :name, :password_digest
9
+
10
+ has_flexible_secure_password
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ class OauthedUser
2
+ extend ActiveModel::Callbacks
3
+ include ActiveModel::Validations
4
+ include FlexPass::FlexSecurePassword
5
+
6
+ define_model_callbacks :create
7
+
8
+ attr_accessor :password_digest, :password_salt
9
+
10
+ has_flexible_secure_password(validations: false)
11
+
12
+ end