passwd 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -1
  3. data/CHANGELOG.md +30 -1
  4. data/Gemfile +0 -5
  5. data/LICENSE.txt +2 -1
  6. data/README.md +96 -156
  7. data/Rakefile +2 -1
  8. data/example/.gitignore +16 -0
  9. data/example/Gemfile +25 -0
  10. data/example/README.rdoc +28 -0
  11. data/example/Rakefile +6 -0
  12. data/example/app/assets/images/.keep +0 -0
  13. data/example/app/assets/javascripts/application.js +16 -0
  14. data/example/app/assets/stylesheets/application.css +16 -0
  15. data/example/app/controllers/application_controller.rb +10 -0
  16. data/example/app/controllers/concerns/.keep +0 -0
  17. data/example/app/controllers/profiles_controller.rb +28 -0
  18. data/example/app/controllers/root_controller.rb +5 -0
  19. data/example/app/controllers/sessions_controller.rb +29 -0
  20. data/example/app/helpers/application_helper.rb +2 -0
  21. data/example/app/mailers/.keep +0 -0
  22. data/example/app/models/.keep +0 -0
  23. data/example/app/models/concerns/.keep +0 -0
  24. data/example/app/models/user.rb +4 -0
  25. data/example/app/views/layouts/application.html.erb +15 -0
  26. data/example/app/views/profiles/edit.html.erb +14 -0
  27. data/example/app/views/profiles/show.html.erb +12 -0
  28. data/example/app/views/root/index.html.erb +5 -0
  29. data/example/app/views/sessions/new.html.erb +6 -0
  30. data/example/bin/bundle +3 -0
  31. data/example/bin/rails +4 -0
  32. data/example/bin/rake +4 -0
  33. data/example/config.ru +4 -0
  34. data/example/config/application.rb +40 -0
  35. data/example/config/boot.rb +4 -0
  36. data/example/config/database.yml +26 -0
  37. data/example/config/environment.rb +5 -0
  38. data/example/config/environments/development.rb +37 -0
  39. data/example/config/environments/production.rb +78 -0
  40. data/example/config/environments/test.rb +39 -0
  41. data/example/config/initializers/assets.rb +8 -0
  42. data/example/config/initializers/backtrace_silencers.rb +7 -0
  43. data/example/config/initializers/cookies_serializer.rb +3 -0
  44. data/example/config/initializers/filter_parameter_logging.rb +4 -0
  45. data/example/config/initializers/inflections.rb +16 -0
  46. data/example/config/initializers/mime_types.rb +4 -0
  47. data/example/config/initializers/passwd.rb +41 -0
  48. data/example/config/initializers/session_store.rb +3 -0
  49. data/example/config/initializers/wrap_parameters.rb +14 -0
  50. data/example/config/locales/en.yml +23 -0
  51. data/example/config/routes.rb +16 -0
  52. data/example/config/secrets.yml +22 -0
  53. data/example/db/migrate/20141122165914_create_users.rb +13 -0
  54. data/example/db/schema.rb +25 -0
  55. data/example/db/seeds.rb +7 -0
  56. data/example/lib/assets/.keep +0 -0
  57. data/example/lib/tasks/.keep +0 -0
  58. data/example/lib/tasks/user.rake +12 -0
  59. data/example/log/.keep +0 -0
  60. data/example/public/404.html +67 -0
  61. data/example/public/422.html +67 -0
  62. data/example/public/500.html +66 -0
  63. data/example/public/favicon.ico +0 -0
  64. data/example/public/robots.txt +5 -0
  65. data/example/vendor/assets/javascripts/.keep +0 -0
  66. data/example/vendor/assets/stylesheets/.keep +0 -0
  67. data/lib/generators/passwd/config_generator.rb +13 -0
  68. data/lib/generators/passwd/templates/passwd_config.rb +41 -0
  69. data/lib/passwd.rb +18 -3
  70. data/lib/passwd/action_controller_ext.rb +48 -0
  71. data/lib/passwd/active_record_ext.rb +65 -0
  72. data/lib/passwd/base.rb +17 -62
  73. data/lib/passwd/configuration.rb +82 -0
  74. data/lib/passwd/errors.rb +6 -13
  75. data/lib/passwd/password.rb +73 -25
  76. data/lib/passwd/policy.rb +28 -0
  77. data/lib/passwd/railtie.rb +19 -0
  78. data/lib/passwd/salt.rb +50 -0
  79. data/lib/passwd/version.rb +2 -1
  80. data/passwd.gemspec +8 -2
  81. data/spec/passwd/.keep +0 -0
  82. data/spec/passwd/active_record_ext_spec.rb +80 -0
  83. data/spec/passwd/base_spec.rb +55 -231
  84. data/spec/passwd/configuration_spec.rb +50 -0
  85. data/spec/passwd/password_spec.rb +129 -123
  86. data/spec/spec_helper.rb +14 -3
  87. data/spec/support/data_util.rb +11 -0
  88. data/spec/support/paths.rb +2 -0
  89. metadata +164 -30
  90. data/lib/passwd/active_record.rb +0 -62
  91. data/lib/passwd/configuration/abstract_config.rb +0 -37
  92. data/lib/passwd/configuration/config.rb +0 -24
  93. data/lib/passwd/configuration/policy.rb +0 -46
  94. data/lib/passwd/configuration/tmp_config.rb +0 -18
  95. data/spec/passwd/active_record_spec.rb +0 -163
  96. data/spec/passwd/configuration/config_spec.rb +0 -250
  97. data/spec/passwd/configuration/policy_spec.rb +0 -133
  98. data/spec/passwd/configuration/tmp_config_spec.rb +0 -265
@@ -1,133 +0,0 @@
1
- # coding: utf-8
2
-
3
- require "spec_helper"
4
-
5
- describe Passwd::Policy do
6
- let(:policy) {Passwd::Policy.instance}
7
-
8
- describe "defined accessors" do
9
- it "defined min_length" do
10
- expect(policy.respond_to? :min_length).to be_true
11
- end
12
-
13
- it "defined require_lower" do
14
- expect(policy.respond_to? :require_lower).to be_true
15
- end
16
-
17
- it "defined require_upper" do
18
- expect(policy.respond_to? :require_upper).to be_true
19
- end
20
-
21
- it "defined require_number" do
22
- expect(policy.respond_to? :require_number).to be_true
23
- end
24
- end
25
-
26
- describe "#initialize" do
27
- it "min_length should be a default" do
28
- expect(policy.min_length).to eq(8)
29
- end
30
-
31
- it "require_lower should be a default" do
32
- expect(policy.require_lower).to be_true
33
- end
34
-
35
- it "require_upper should be a default" do
36
- expect(policy.require_upper).to be_false
37
- end
38
-
39
- it "require_number should be a default" do
40
- expect(policy.require_number).to be_true
41
- end
42
- end
43
-
44
- describe "#configure" do
45
- before {
46
- policy.configure do |c|
47
- c.min_length = 20
48
- c.require_lower = false
49
- c.require_upper = true
50
- c.require_number = false
51
- end
52
- }
53
-
54
- it "set min_length from block" do
55
- expect(policy.min_length).to eq(20)
56
- end
57
-
58
- it "set require_lower from block" do
59
- expect(policy.require_lower).to be_false
60
- end
61
-
62
- it "set require_upper from block" do
63
- expect(policy.require_upper).to be_true
64
- end
65
-
66
- it "set require_number from block" do
67
- expect(policy.require_number).to be_false
68
- end
69
- end
70
-
71
- describe "#valid?" do
72
- let(:config) {Passwd::Config.instance}
73
-
74
- it "valid password should be valid" do
75
- expect(policy.valid?("secret1234", config)).to be_true
76
- end
77
-
78
- it "short password should not valid" do
79
- expect(policy.valid?("short1", config)).to be_false
80
- end
81
-
82
- it "password should not valid if not contain lower case" do
83
- expect(policy.valid?("NOTLOWER12", config)).to be_false
84
- end
85
-
86
- it "password should not valid if not contain upper case" do
87
- policy.configure {|c| c.require_upper = true}
88
- expect(policy.valid?("notupper12", config)).to be_false
89
- end
90
-
91
- it "password should not valid if not contain number" do
92
- expect(policy.valid?("notnumber", config)).to be_false
93
- end
94
- end
95
-
96
- describe "#include_char?" do
97
- it "should be return true if contains" do
98
- expect(policy.include_char?(("a".."z").to_a, "contains")).to be_true
99
- end
100
-
101
- it "should be return false if not contains" do
102
- expect(policy.include_char?(("a".."z").to_a, "NOTCONTAINS")).to be_false
103
- end
104
- end
105
-
106
- describe "#reset" do
107
- before {
108
- policy.configure do |c|
109
- c.min_length = 20
110
- c.require_lower = false
111
- c.require_upper = true
112
- c.require_number = false
113
- end
114
- policy.reset
115
- }
116
-
117
- it "min_length should be a default" do
118
- expect(policy.min_length).to eq(8)
119
- end
120
-
121
- it "require_lower should be a default" do
122
- expect(policy.require_lower).to be_true
123
- end
124
-
125
- it "require_upper should be a default" do
126
- expect(policy.require_upper).to be_false
127
- end
128
-
129
- it "require_number should be a default" do
130
- expect(policy.require_number).to be_true
131
- end
132
- end
133
- end
@@ -1,265 +0,0 @@
1
- # coding: utf-8
2
-
3
- require "spec_helper"
4
-
5
- describe Passwd::TmpConfig do
6
- let(:config) {Passwd::Config.instance}
7
-
8
- def tmp_config(options={})
9
- Passwd::TmpConfig.new(Passwd::Config.instance, options)
10
- end
11
-
12
- describe "defined accessors" do
13
- it "defined algorithm" do
14
- expect(config.respond_to? :algorithm).to be_true
15
- end
16
-
17
- it "defined length" do
18
- expect(tmp_config.respond_to? :length).to be_true
19
- end
20
-
21
- it "defined lower" do
22
- expect(tmp_config.respond_to? :lower).to be_true
23
- end
24
-
25
- it "defined upper" do
26
- expect(tmp_config.respond_to? :upper).to be_true
27
- end
28
-
29
- it "defined number" do
30
- expect(tmp_config.respond_to? :number).to be_true
31
- end
32
-
33
- it "defined letters_lower" do
34
- expect(tmp_config.respond_to? :letters_lower).to be_true
35
- end
36
-
37
- it "defined letters_upper" do
38
- expect(tmp_config.respond_to? :letters_upper).to be_true
39
- end
40
-
41
- it "defined letters_number" do
42
- expect(tmp_config.respond_to? :letters_number).to be_true
43
- end
44
- end
45
-
46
- describe "#initialize" do
47
- context "with empty options" do
48
- it "algorithm should be a default" do
49
- expect(config.algorithm).to eq(:sha512)
50
- end
51
-
52
- it "length should be a default" do
53
- expect(tmp_config.length).to eq(8)
54
- end
55
-
56
- it "lower should be a default" do
57
- expect(tmp_config.lower).to be_true
58
- end
59
-
60
- it "upper should be a default" do
61
- expect(tmp_config.upper).to be_true
62
- end
63
-
64
- it "number should be a default" do
65
- expect(tmp_config.number).to be_true
66
- end
67
-
68
- it "letters_lower should be a default" do
69
- expect(tmp_config.letters_lower).to eq(("a".."z").to_a)
70
- end
71
-
72
- it "letters_upper should be a default" do
73
- expect(tmp_config.letters_upper).to eq(("A".."Z").to_a)
74
- end
75
-
76
- it "letters_number should be a default" do
77
- expect(tmp_config.letters_number).to eq(("0".."9").to_a)
78
- end
79
- end
80
-
81
- context "with options" do
82
- it "length should be a specified params" do
83
- expect(tmp_config(length: 10).length).to eq(10)
84
- expect(config.length).to eq(8)
85
- end
86
-
87
- it "lower should be a specified params" do
88
- expect(tmp_config(lower: false).lower).to be_false
89
- expect(config.lower).to be_true
90
- end
91
-
92
- it "upper should be a specified params" do
93
- expect(tmp_config(upper: false).upper).to be_false
94
- expect(config.upper).to be_true
95
- end
96
-
97
- it "number should be a specified params" do
98
- expect(tmp_config(number: false).number).to be_false
99
- expect(config.number).to be_true
100
- end
101
-
102
- it "letters_lower should be a specified params" do
103
- expect(tmp_config(letters_lower: ["a"]).letters_lower).to eq(["a"])
104
- expect(config.letters_lower).to eq(("a".."z").to_a)
105
- end
106
-
107
- it "letters_upper should be a specified params" do
108
- expect(tmp_config(letters_upper: ["A"]).letters_upper).to eq(["A"])
109
- expect(config.letters_upper).to eq(("A".."Z").to_a)
110
- end
111
-
112
- it "letters_number should be a specified params" do
113
- expect(tmp_config(letters_number: ["0"]).letters_number).to eq(["0"])
114
- expect(config.letters_number).to eq(("0".."9").to_a)
115
- end
116
- end
117
- end
118
-
119
- describe "#configure" do
120
- let(:changed_tmp_config) do
121
- tconf = tmp_config
122
- tconf.configure do |c|
123
- c.length = 20
124
- c.lower = false
125
- c.upper = false
126
- c.number = false
127
- c.letters_lower = ["a"]
128
- c.letters_upper = ["A"]
129
- c.letters_number = ["0"]
130
- end
131
- tconf
132
- end
133
-
134
- it "set length from block" do
135
- expect(changed_tmp_config.length).to eq(20)
136
- expect(config.length).to eq(8)
137
- end
138
-
139
- it "set lower from block" do
140
- expect(changed_tmp_config.lower).to be_false
141
- expect(config.lower).to be_true
142
- end
143
-
144
- it "set upper from block" do
145
- expect(changed_tmp_config.upper).to be_false
146
- expect(config.upper).to be_true
147
- end
148
-
149
- it "set number from block" do
150
- expect(changed_tmp_config.number).to be_false
151
- expect(config.number).to be_true
152
- end
153
-
154
- it "set letters_lower from block" do
155
- expect(changed_tmp_config.letters_lower).to eq(["a"])
156
- expect(config.letters_lower).to eq(("a".."z").to_a)
157
- end
158
-
159
- it "set letters_upper from block" do
160
- expect(changed_tmp_config.letters_upper).to eq(["A"])
161
- expect(config.letters_upper).to eq(("A".."Z").to_a)
162
- end
163
-
164
- it "set letters_number from block" do
165
- expect(changed_tmp_config.letters_number).to eq(["0"])
166
- expect(config.letters_number).to eq(("0".."9").to_a)
167
- end
168
-
169
- it "raise error unknown setting" do
170
- expect {
171
- tmp_config.configure do |c|
172
- c.unknown = true
173
- end
174
- }.to raise_error
175
- end
176
- end
177
-
178
- describe "#merge" do
179
- let(:default_tmp_config) {tmp_config}
180
-
181
- it "set length from hash" do
182
- default_tmp_config.merge(length: 10)
183
- expect(default_tmp_config.length).to eq(10)
184
- expect(config.length).to eq(8)
185
- end
186
-
187
- it "set lower from hash" do
188
- default_tmp_config.merge(lower: false)
189
- expect(default_tmp_config.lower).to be_false
190
- expect(config.lower).to be_true
191
- end
192
-
193
- it "set upper from hash" do
194
- default_tmp_config.merge(upper: false)
195
- expect(default_tmp_config.upper).to be_false
196
- expect(config.upper).to be_true
197
- end
198
-
199
- it "set number from hash" do
200
- default_tmp_config.merge(number: false)
201
- expect(default_tmp_config.number).to be_false
202
- expect(config.number).to be_true
203
- end
204
-
205
- it "set letters_lower from hash" do
206
- default_tmp_config.merge(letters_lower: ["a"])
207
- expect(default_tmp_config.letters_lower).to eq(["a"])
208
- expect(config.letters_lower).to eq(("a".."z").to_a)
209
- end
210
-
211
- it "set letters_upper from hash" do
212
- default_tmp_config.merge(letters_upper: ["A"])
213
- expect(default_tmp_config.letters_upper).to eq(["A"])
214
- expect(config.letters_upper).to eq(("A".."Z").to_a)
215
- end
216
-
217
- it "set letters_number from hash" do
218
- default_tmp_config.merge(letters_number: ["0"])
219
- expect(default_tmp_config.letters_number).to eq(["0"])
220
- expect(config.letters_number).to eq(("0".."9").to_a)
221
- end
222
-
223
- it "raise error unknown setting" do
224
- expect {
225
- tmp_config.merge(unknown: true)
226
- }.to raise_error
227
- end
228
- end
229
-
230
- describe "#letters" do
231
- it "return Array object" do
232
- expect(tmp_config.letters.is_a? Array).to be_true
233
- end
234
-
235
- it "all elements of the string" do
236
- tmp_config.letters.each do |l|
237
- expect(l.is_a? String).to be_true
238
- end
239
- end
240
-
241
- it "return all letters" do
242
- all_letters = ("a".."z").to_a.concat(("A".."Z").to_a).concat(("0".."9").to_a)
243
- expect(tmp_config.letters).to eq(all_letters)
244
- end
245
-
246
- it "return except for the lower case" do
247
- expect(tmp_config(lower: false).letters.include? "a").to be_false
248
- end
249
-
250
- it "return except for the upper case" do
251
- expect(tmp_config(upper: false).letters.include? "A").to be_false
252
- end
253
-
254
- it "return except for the number case" do
255
- expect(tmp_config(number: false).letters.include? "0").to be_false
256
- end
257
-
258
- it "raise error if letters is empty" do
259
- tconf = tmp_config(lower: false, upper: false, number: false)
260
- expect {
261
- tconf.letters
262
- }.to raise_error
263
- end
264
- end
265
- end