passwd 0.1.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +28 -0
  3. data/.gitignore +11 -17
  4. data/.rubocop.yml +168 -0
  5. data/.ruby-version +1 -0
  6. data/Gemfile +3 -6
  7. data/LICENSE +21 -0
  8. data/README.md +89 -138
  9. data/Rakefile +5 -6
  10. data/bin/console +7 -0
  11. data/bin/setup +8 -0
  12. data/lib/generators/passwd/install/USAGE +5 -0
  13. data/lib/generators/passwd/install/install_generator.rb +10 -0
  14. data/lib/generators/passwd/install/templates/passwd.rb +21 -0
  15. data/lib/passwd.rb +33 -6
  16. data/lib/passwd/config.rb +27 -0
  17. data/lib/passwd/errors.rb +4 -0
  18. data/lib/passwd/rails/action_controller_ext.rb +78 -0
  19. data/lib/passwd/rails/active_record_ext.rb +35 -0
  20. data/lib/passwd/railtie.rb +18 -0
  21. data/lib/passwd/version.rb +2 -4
  22. data/passwd.gemspec +20 -11
  23. metadata +83 -53
  24. data/.coveralls.yml +0 -1
  25. data/.travis.yml +0 -10
  26. data/LICENSE.txt +0 -22
  27. data/lib/passwd/active_record.rb +0 -58
  28. data/lib/passwd/base.rb +0 -72
  29. data/lib/passwd/configuration/abstract_config.rb +0 -36
  30. data/lib/passwd/configuration/config.rb +0 -23
  31. data/lib/passwd/configuration/policy.rb +0 -46
  32. data/lib/passwd/configuration/tmp_config.rb +0 -18
  33. data/lib/passwd/password.rb +0 -41
  34. data/samples/activerecord/user.rake +0 -28
  35. data/spec/passwd/active_record_spec.rb +0 -142
  36. data/spec/passwd/base_spec.rb +0 -224
  37. data/spec/passwd/configuration/config_spec.rb +0 -242
  38. data/spec/passwd/configuration/policy_spec.rb +0 -133
  39. data/spec/passwd/configuration/tmp_config_spec.rb +0 -257
  40. data/spec/passwd/password_spec.rb +0 -150
  41. data/spec/spec_helper.rb +0 -23
@@ -1,224 +0,0 @@
1
- # coding: utf-8
2
-
3
- require "spec_helper"
4
-
5
- describe Passwd do
6
- describe "extended Base" do
7
- describe "#create" do
8
- context "without arguments" do
9
- let(:password) {Passwd.create}
10
-
11
- it "TmpConfig should not be generated" do
12
- Passwd::TmpConfig.should_not_receive(:new)
13
- expect{password}.not_to raise_error
14
- end
15
-
16
- it "created password should be String object" do
17
- expect(password.is_a? String).to be_true
18
- end
19
-
20
- it "created password length should be default length" do
21
- expect(password.size).to eq(8)
22
- end
23
- end
24
-
25
- context "with arguments" do
26
- it "TmpConfig should be generated" do
27
- tmp_config = double("tmp_config mock", length: 8, letters: ["a", "b"])
28
- Passwd::TmpConfig.should_receive(:new).and_return(tmp_config)
29
- expect{Passwd.create(length: 10)}.not_to raise_error
30
- end
31
-
32
- it "password was created specified characters" do
33
- expect(Passwd.create(length: 10).size).to eq(10)
34
- end
35
-
36
- it "password create without lower case" do
37
- expect(("a".."z").to_a.include? Passwd.create(lower: false)).to be_false
38
- end
39
-
40
- it "password create without upper case" do
41
- expect(("A".."Z").to_a.include? Passwd.create(upper: false)).to be_false
42
- end
43
-
44
- it "password create without number" do
45
- expect(("0".."9").to_a.include? Passwd.create(number: false)).to be_false
46
- end
47
- end
48
- end
49
-
50
- describe "#auth" do
51
- let!(:password) do
52
- password = Passwd.create
53
- salt_hash = Passwd.hashing(Time.now.to_s)
54
- password_hash = Passwd.hashing("#{salt_hash}#{password}")
55
- {text: password, salt: salt_hash, hash: password_hash}
56
- end
57
-
58
- it "return true with valid password" do
59
- expect(Passwd.auth(password[:text], password[:salt], password[:hash])).to be_true
60
- end
61
-
62
- it "return false with invalid password" do
63
- expect(Passwd.auth("invalid", password[:salt], password[:hash])).to be_false
64
- end
65
-
66
- it "should create exception if not specified arguments" do
67
- expect(proc{Passwd.auth}).to raise_error
68
- end
69
- end
70
-
71
- describe "#hashing" do
72
- it "return hashed password" do
73
- Digest::SHA1.should_receive(:hexdigest).with("secret").and_return("hash")
74
- expect(Passwd.hashing("secret")).to eq("hash")
75
- end
76
-
77
- it "should create exception if not specified argument" do
78
- expect(proc{Passwd.hashing}).to raise_error
79
- end
80
- end
81
-
82
- describe "#confirm_check" do
83
- context "with out policy check" do
84
- it "return false if password don't match" do
85
- expect(Passwd.confirm_check("secret", "invalid")).to be_false
86
- end
87
-
88
- it "return true if password matches" do
89
- expect(Passwd.confirm_check("secret", "secret")).to be_true
90
- end
91
- end
92
-
93
- context "with policy check" do
94
- it "return false if invalid password by policy" do
95
- expect(Passwd.confirm_check("secret", "secret", true)).to be_false
96
- end
97
-
98
- it "return true if valid password by policy" do
99
- expect(Passwd.confirm_check("secretpass", "secretpass", true)).to be_false
100
- end
101
- end
102
- end
103
-
104
- describe "#configure" do
105
- it "return configuration object" do
106
- expect(Passwd.configure.is_a? Passwd::Config).to be_true
107
- end
108
-
109
- it "set config value from block" do
110
- Passwd.configure do |c|
111
- c.length = 10
112
- end
113
- expect(Passwd.configure.length).not_to eq(8)
114
- expect(Passwd.configure.length).to eq(10)
115
- end
116
-
117
- it "set config value from hash" do
118
- Passwd.configure length: 20
119
- expect(Passwd.config.length).not_to eq(8)
120
- expect(Passwd.config.length).to eq(20)
121
- end
122
-
123
- it "alias of configure as config" do
124
- expect(Passwd.configure.object_id).to eq(Passwd.config.object_id)
125
- end
126
- end
127
-
128
- describe "#policy_configure" do
129
- it "return policy object" do
130
- expect(Passwd.policy_configure.is_a? Passwd::Policy).to be_true
131
- end
132
-
133
- it "set policy value from block" do
134
- Passwd.policy_configure do |c|
135
- c.min_length = 10
136
- end
137
- expect(Passwd.policy_configure.min_length).not_to eq(8)
138
- expect(Passwd.policy_configure.min_length).to eq(10)
139
- end
140
- end
141
-
142
- describe "#policy_check" do
143
- it "Policy#valid? should be called" do
144
- Passwd::Policy.instance.should_receive(:valid?).with("secret1234" ,Passwd::Config.instance)
145
- expect(Passwd.policy_check("secret1234")).not_to raise_error
146
- end
147
- end
148
-
149
- describe "#reset_policy" do
150
- let(:policy) {Passwd::Policy.instance}
151
-
152
- before {
153
- policy.configure do |c|
154
- c.min_length = 20
155
- c.require_lower = false
156
- c.require_upper = true
157
- c.require_number = false
158
- end
159
- Passwd.reset_policy
160
- }
161
-
162
- it "min_length should be a default" do
163
- expect(policy.min_length).to eq(8)
164
- end
165
-
166
- it "require_lower should be a default" do
167
- expect(policy.require_lower).to be_true
168
- end
169
-
170
- it "upper should be a default" do
171
- expect(policy.require_upper).to be_false
172
- end
173
-
174
- it "number should be a default" do
175
- expect(policy.require_number).to be_true
176
- end
177
- end
178
-
179
- describe "#reset_config" do
180
- let(:config) {Passwd::Config.instance}
181
-
182
- before {
183
- config.configure do |c|
184
- c.length = 20
185
- c.lower = false
186
- c.upper = false
187
- c.number = false
188
- c.letters_lower = ["a"]
189
- c.letters_upper = ["A"]
190
- c.letters_number = ["0"]
191
- end
192
- Passwd.reset_config
193
- }
194
-
195
- it "length should be a default" do
196
- expect(config.length).to eq(8)
197
- end
198
-
199
- it "lower should be a default" do
200
- expect(config.lower).to be_true
201
- end
202
-
203
- it "upper should be a default" do
204
- expect(config.upper).to be_true
205
- end
206
-
207
- it "number should be a default" do
208
- expect(config.number).to be_true
209
- end
210
-
211
- it "letters_lower should be a default" do
212
- expect(config.letters_lower).to eq(("a".."z").to_a)
213
- end
214
-
215
- it "letters_upper should be a default" do
216
- expect(config.letters_upper).to eq(("A".."Z").to_a)
217
- end
218
-
219
- it "letters_number should be a default" do
220
- expect(config.letters_number).to eq(("0".."9").to_a)
221
- end
222
- end
223
- end
224
- end
@@ -1,242 +0,0 @@
1
- # coding: utf-8
2
-
3
- require "spec_helper"
4
-
5
- describe Passwd::Config do
6
- let(:config) {Passwd::Config.instance}
7
-
8
- describe "defined accessors" do
9
- it "defined length" do
10
- expect(config.respond_to? :length).to be_true
11
- end
12
-
13
- it "defined lower" do
14
- expect(config.respond_to? :lower).to be_true
15
- end
16
-
17
- it "defined upper" do
18
- expect(config.respond_to? :upper).to be_true
19
- end
20
-
21
- it "defined number" do
22
- expect(config.respond_to? :number).to be_true
23
- end
24
-
25
- it "defined letters_lower" do
26
- expect(config.respond_to? :letters_lower).to be_true
27
- end
28
-
29
- it "defined letters_upper" do
30
- expect(config.respond_to? :letters_upper).to be_true
31
- end
32
-
33
- it "defined letters_number" do
34
- expect(config.respond_to? :letters_number).to be_true
35
- end
36
- end
37
-
38
- describe "#initialize" do
39
- it "length should be a default" do
40
- expect(config.length).to eq(8)
41
- end
42
-
43
- it "lower should be a default" do
44
- expect(config.lower).to be_true
45
- end
46
-
47
- it "upper should be a default" do
48
- expect(config.upper).to be_true
49
- end
50
-
51
- it "number should be a default" do
52
- expect(config.number).to be_true
53
- end
54
-
55
- it "letters_lower should be a default" do
56
- expect(config.letters_lower).to eq(("a".."z").to_a)
57
- end
58
-
59
- it "letters_upper should be a default" do
60
- expect(config.letters_upper).to eq(("A".."Z").to_a)
61
- end
62
-
63
- it "letters_number should be a default" do
64
- expect(config.letters_number).to eq(("0".."9").to_a)
65
- end
66
- end
67
-
68
- describe "#configure" do
69
- before {
70
- config.configure do |c|
71
- c.length = 20
72
- c.lower = false
73
- c.upper = false
74
- c.number = false
75
- c.letters_lower = ["a"]
76
- c.letters_upper = ["A"]
77
- c.letters_number = ["0"]
78
- end
79
- }
80
-
81
- it "set length from block" do
82
- expect(config.length).to eq(20)
83
- end
84
-
85
- it "set lower from block" do
86
- expect(config.lower).to be_false
87
- end
88
-
89
- it "set upper from block" do
90
- expect(config.upper).to be_false
91
- end
92
-
93
- it "set number from block" do
94
- expect(config.number).to be_false
95
- end
96
-
97
- it "set letters_lower from block" do
98
- expect(config.letters_lower).to eq(["a"])
99
- end
100
-
101
- it "set letters_upper from block" do
102
- expect(config.letters_upper).to eq(["A"])
103
- end
104
-
105
- it "set letters_number from block" do
106
- expect(config.letters_number).to eq(["0"])
107
- end
108
-
109
- it "raise error unknown setting" do
110
- expect {
111
- config.configure do |c|
112
- c.unknown = true
113
- end
114
- }.to raise_error
115
- end
116
- end
117
-
118
- describe "#merge" do
119
- it "set length from hash" do
120
- config.merge(length: 10)
121
- expect(config.length).to eq(10)
122
- end
123
-
124
- it "set lower from hash" do
125
- config.merge(lower: false)
126
- expect(config.lower).to be_false
127
- end
128
-
129
- it "set upper from hash" do
130
- config.merge(upper: false)
131
- expect(config.upper).to be_false
132
- end
133
-
134
- it "set number from hash" do
135
- config.merge(number: false)
136
- expect(config.number).to be_false
137
- end
138
-
139
- it "set letters_lower from hash" do
140
- config.merge(letters_lower: ["a"])
141
- expect(config.letters_lower).to eq(["a"])
142
- end
143
-
144
- it "set letters_upper from hash" do
145
- config.merge(letters_upper: ["A"])
146
- expect(config.letters_upper).to eq(["A"])
147
- end
148
-
149
- it "set letters_number from hash" do
150
- config.merge(letters_number: ["0"])
151
- expect(config.letters_number).to eq(["0"])
152
- end
153
-
154
- it "raise error unknown setting" do
155
- expect {
156
- config.merge(unknown: true)
157
- }.to raise_error
158
- end
159
- end
160
-
161
- describe "#letters" do
162
- it "return Array object" do
163
- expect(config.letters.is_a? Array).to be_true
164
- end
165
-
166
- it "all elements of the string" do
167
- config.letters.each do |l|
168
- expect(l.is_a? String).to be_true
169
- end
170
- end
171
-
172
- it "return all letters" do
173
- all_letters = ("a".."z").to_a.concat(("A".."Z").to_a).concat(("0".."9").to_a)
174
- expect(config.letters).to eq(all_letters)
175
- end
176
-
177
- it "return except for the lower case" do
178
- config.merge(lower: false)
179
- expect(config.letters.include? "a").to be_false
180
- end
181
-
182
- it "return except for the upper case" do
183
- config.merge(upper: false)
184
- expect(config.letters.include? "A").to be_false
185
- end
186
-
187
- it "return except for the number case" do
188
- config.merge(number: false)
189
- expect(config.letters.include? "0").to be_false
190
- end
191
-
192
- it "raise error if letters is empty" do
193
- config.merge(lower: false, upper: false, number: false)
194
- expect {
195
- config.letters
196
- }.to raise_error
197
- end
198
- end
199
-
200
- describe "#reset" do
201
- before {
202
- config.configure do |c|
203
- c.length = 20
204
- c.lower = false
205
- c.upper = false
206
- c.number = false
207
- c.letters_lower = ["a"]
208
- c.letters_upper = ["A"]
209
- c.letters_number = ["0"]
210
- end
211
- config.reset
212
- }
213
-
214
- it "length should be a default" do
215
- expect(config.length).to eq(8)
216
- end
217
-
218
- it "lower should be a default" do
219
- expect(config.lower).to be_true
220
- end
221
-
222
- it "upper should be a default" do
223
- expect(config.upper).to be_true
224
- end
225
-
226
- it "number should be a default" do
227
- expect(config.number).to be_true
228
- end
229
-
230
- it "letters_lower should be a default" do
231
- expect(config.letters_lower).to eq(("a".."z").to_a)
232
- end
233
-
234
- it "letters_upper should be a default" do
235
- expect(config.letters_upper).to eq(("A".."Z").to_a)
236
- end
237
-
238
- it "letters_number should be a default" do
239
- expect(config.letters_number).to eq(("0".."9").to_a)
240
- end
241
- end
242
- end