passwd 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +10 -17
- data/.travis.yml +3 -11
- data/Gemfile +3 -1
- data/LICENSE +21 -0
- data/README.md +39 -53
- data/Rakefile +6 -6
- data/bin/console +7 -0
- data/bin/setup +8 -0
- data/lib/generators/passwd/install/USAGE +5 -0
- data/lib/generators/passwd/install/install_generator.rb +10 -0
- data/lib/generators/passwd/install/templates/passwd.rb +27 -0
- data/lib/passwd.rb +33 -15
- data/lib/passwd/config.rb +29 -0
- data/lib/passwd/errors.rb +2 -7
- data/lib/passwd/rails/action_controller_ext.rb +77 -0
- data/lib/passwd/rails/active_record_ext.rb +37 -0
- data/lib/passwd/railtie.rb +5 -6
- data/lib/passwd/version.rb +2 -2
- data/passwd.gemspec +13 -14
- metadata +22 -156
- data/.coveralls.yml +0 -1
- data/CHANGELOG.md +0 -35
- data/LICENSE.txt +0 -23
- data/example/.gitignore +0 -16
- data/example/Gemfile +0 -25
- data/example/README.rdoc +0 -28
- data/example/Rakefile +0 -6
- data/example/app/assets/images/.keep +0 -0
- data/example/app/assets/javascripts/application.js +0 -16
- data/example/app/assets/stylesheets/application.css +0 -16
- data/example/app/controllers/application_controller.rb +0 -10
- data/example/app/controllers/concerns/.keep +0 -0
- data/example/app/controllers/profiles_controller.rb +0 -28
- data/example/app/controllers/root_controller.rb +0 -5
- data/example/app/controllers/sessions_controller.rb +0 -29
- data/example/app/helpers/application_helper.rb +0 -2
- data/example/app/mailers/.keep +0 -0
- data/example/app/models/.keep +0 -0
- data/example/app/models/concerns/.keep +0 -0
- data/example/app/models/user.rb +0 -4
- data/example/app/views/layouts/application.html.erb +0 -15
- data/example/app/views/profiles/edit.html.erb +0 -14
- data/example/app/views/profiles/show.html.erb +0 -12
- data/example/app/views/root/index.html.erb +0 -5
- data/example/app/views/sessions/new.html.erb +0 -6
- data/example/bin/bundle +0 -3
- data/example/bin/rails +0 -4
- data/example/bin/rake +0 -4
- data/example/config.ru +0 -4
- data/example/config/application.rb +0 -40
- data/example/config/boot.rb +0 -4
- data/example/config/database.yml +0 -26
- data/example/config/environment.rb +0 -5
- data/example/config/environments/development.rb +0 -37
- data/example/config/environments/production.rb +0 -78
- data/example/config/environments/test.rb +0 -39
- data/example/config/initializers/assets.rb +0 -8
- data/example/config/initializers/backtrace_silencers.rb +0 -7
- data/example/config/initializers/cookies_serializer.rb +0 -3
- data/example/config/initializers/filter_parameter_logging.rb +0 -4
- data/example/config/initializers/inflections.rb +0 -16
- data/example/config/initializers/mime_types.rb +0 -4
- data/example/config/initializers/passwd.rb +0 -41
- data/example/config/initializers/session_store.rb +0 -3
- data/example/config/initializers/wrap_parameters.rb +0 -14
- data/example/config/locales/en.yml +0 -23
- data/example/config/routes.rb +0 -16
- data/example/config/secrets.yml +0 -22
- data/example/db/migrate/20141122165914_create_users.rb +0 -13
- data/example/db/schema.rb +0 -25
- data/example/db/seeds.rb +0 -7
- data/example/lib/assets/.keep +0 -0
- data/example/lib/tasks/.keep +0 -0
- data/example/lib/tasks/user.rake +0 -12
- data/example/log/.keep +0 -0
- data/example/public/404.html +0 -67
- data/example/public/422.html +0 -67
- data/example/public/500.html +0 -66
- data/example/public/favicon.ico +0 -0
- data/example/public/robots.txt +0 -5
- data/example/vendor/assets/javascripts/.keep +0 -0
- data/example/vendor/assets/stylesheets/.keep +0 -0
- data/lib/generators/passwd/config_generator.rb +0 -13
- data/lib/generators/passwd/templates/passwd_config.rb +0 -41
- data/lib/passwd/action_controller_ext.rb +0 -48
- data/lib/passwd/active_record_ext.rb +0 -65
- data/lib/passwd/base.rb +0 -31
- data/lib/passwd/configuration.rb +0 -82
- data/lib/passwd/password.rb +0 -89
- data/lib/passwd/policy.rb +0 -28
- data/lib/passwd/salt.rb +0 -50
- data/spec/passwd/.keep +0 -0
- data/spec/passwd/active_record_ext_spec.rb +0 -80
- data/spec/passwd/base_spec.rb +0 -60
- data/spec/passwd/configuration_spec.rb +0 -50
- data/spec/passwd/password_spec.rb +0 -156
- data/spec/spec_helper.rb +0 -34
- data/spec/support/data_util.rb +0 -11
- data/spec/support/paths.rb +0 -2
data/spec/passwd/.keep
DELETED
File without changes
|
@@ -1,80 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Passwd::ActiveRecordExt do
|
4
|
-
describe ".with_authenticate" do
|
5
|
-
it { expect(ActiveRecord::Base).to respond_to(:with_authenticate) }
|
6
|
-
|
7
|
-
context User do
|
8
|
-
let(:new_pass) { "NewPassw0rd" }
|
9
|
-
let(:password) { Passwd::Password.new }
|
10
|
-
let(:user) {
|
11
|
-
User.create(
|
12
|
-
name: "i2bskn",
|
13
|
-
email: "i2bskn@example.com",
|
14
|
-
salt: password.salt.hash,
|
15
|
-
password: password.hash
|
16
|
-
)
|
17
|
-
}
|
18
|
-
|
19
|
-
it { is_expected.to respond_to(:passwd) }
|
20
|
-
it { is_expected.to respond_to(:authenticate) }
|
21
|
-
it { expect(User).to respond_to(:authenticate) }
|
22
|
-
it { is_expected.to respond_to(:set_password) }
|
23
|
-
it { is_expected.to respond_to(:update_password) }
|
24
|
-
|
25
|
-
context "#passwd" do
|
26
|
-
after { user.passwd }
|
27
|
-
|
28
|
-
it { expect(user.passwd.is_a?(Passwd::Password)).to be_truthy }
|
29
|
-
it { expect(user).to receive(:reload) }
|
30
|
-
it { expect(Passwd::Password).to receive(:from_hash) }
|
31
|
-
|
32
|
-
it {
|
33
|
-
user = User.new
|
34
|
-
expect(user).to receive(:set_password)
|
35
|
-
user.passwd
|
36
|
-
}
|
37
|
-
end
|
38
|
-
|
39
|
-
context ".authenticate" do
|
40
|
-
before { user }
|
41
|
-
|
42
|
-
it { expect(User.authenticate("i2bskn@example.com", password.plain)).not_to be_falsy }
|
43
|
-
it { expect(User.authenticate("i2bskn@example.com", "invalid")).to be_falsy }
|
44
|
-
end
|
45
|
-
|
46
|
-
context "#authenticate" do
|
47
|
-
it { expect(user.authenticate(password.plain)).not_to be_falsy }
|
48
|
-
it { expect(user.authenticate("invalid")).to be_falsy }
|
49
|
-
end
|
50
|
-
|
51
|
-
context "#set_password" do
|
52
|
-
it { expect { user.set_password }.to change { user.password } }
|
53
|
-
it { expect { user.set_password(new_pass) }.to change { user.password } }
|
54
|
-
end
|
55
|
-
|
56
|
-
context "#update_password" do
|
57
|
-
before { user }
|
58
|
-
|
59
|
-
it {
|
60
|
-
expect {
|
61
|
-
user.update_password(password.plain, new_pass)
|
62
|
-
}.to change { user.password }
|
63
|
-
}
|
64
|
-
|
65
|
-
it {
|
66
|
-
expect {
|
67
|
-
user.update_password(password.plain, "secret", true)
|
68
|
-
}.to raise_error(Passwd::PolicyNotMatch)
|
69
|
-
}
|
70
|
-
|
71
|
-
it {
|
72
|
-
expect {
|
73
|
-
user.update_password("invalid", new_pass)
|
74
|
-
}.to raise_error(Passwd::AuthenticationFails)
|
75
|
-
}
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
data/spec/passwd/base_spec.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Passwd::Base do
|
4
|
-
let(:plain) { "secret" }
|
5
|
-
|
6
|
-
context "#random" do
|
7
|
-
it { expect(Passwd).to respond_to(:random) }
|
8
|
-
it { expect(Passwd.random.is_a?(String)).to be_truthy }
|
9
|
-
it { expect(Passwd.random.size).to eq(Passwd::PwConfig.length) }
|
10
|
-
it { expect(Passwd.random(lower: false)).not_to include(*"a".."z") }
|
11
|
-
it { expect(Passwd.random(upper: false)).not_to include(*"A".."Z") }
|
12
|
-
it { expect(Passwd.random(number: false)).not_to include(*"0".."9") }
|
13
|
-
|
14
|
-
it {
|
15
|
-
length = Passwd::PwConfig.length + 1
|
16
|
-
expect(Passwd.random(length: length).size).to eq(length)
|
17
|
-
}
|
18
|
-
|
19
|
-
it {
|
20
|
-
lower = ["a"]
|
21
|
-
expect(
|
22
|
-
Passwd.random(letters_lower: lower, upper: false, number: false)
|
23
|
-
.chars.uniq
|
24
|
-
).to eq(lower)
|
25
|
-
}
|
26
|
-
end
|
27
|
-
|
28
|
-
context "#digest" do
|
29
|
-
it { expect(Passwd.respond_to?(:digest)).to be_truthy }
|
30
|
-
it { expect(Passwd.digest(plain).is_a?(String)).to be_truthy }
|
31
|
-
it { expect(Passwd.digest(plain)).not_to eq(plain) }
|
32
|
-
|
33
|
-
it {
|
34
|
-
hashed = Passwd.send(:algorithm, Passwd::PwConfig.algorithm).hexdigest plain
|
35
|
-
expect(Passwd.digest(plain)).to eq(hashed)
|
36
|
-
}
|
37
|
-
|
38
|
-
it {
|
39
|
-
not_default = :md5
|
40
|
-
hashed = Passwd.send(:algorithm, not_default).hexdigest plain
|
41
|
-
expect(Passwd.digest(plain, not_default)).to eq(hashed)
|
42
|
-
}
|
43
|
-
end
|
44
|
-
|
45
|
-
context "#algorithm" do
|
46
|
-
it { expect(Passwd.send(:algorithm, :sha1)).to eq(Digest::SHA1) }
|
47
|
-
it { expect(Passwd.send(:algorithm, :sha256)).to eq(Digest::SHA256) }
|
48
|
-
it { expect(Passwd.send(:algorithm, :sha384)).to eq(Digest::SHA384) }
|
49
|
-
it { expect(Passwd.send(:algorithm, :sha512)).to eq(Digest::SHA512) }
|
50
|
-
it { expect(Passwd.send(:algorithm, :md5)).to eq(Digest::MD5) }
|
51
|
-
it { expect(Passwd.send(:algorithm, :rmd160)).to eq(Digest::RMD160) }
|
52
|
-
|
53
|
-
it {
|
54
|
-
expect {
|
55
|
-
Passwd.send(:algorithm, :unknowAn)
|
56
|
-
}.to raise_error
|
57
|
-
}
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Passwd::Configuration do
|
4
|
-
describe "#initialize" do
|
5
|
-
subject { Passwd::PwConfig }
|
6
|
-
# defined options
|
7
|
-
it { is_expected.to respond_to(:algorithm) }
|
8
|
-
it { is_expected.to respond_to(:length) }
|
9
|
-
it { is_expected.to respond_to(:policy) }
|
10
|
-
it { is_expected.to respond_to(:stretching) }
|
11
|
-
it { is_expected.to respond_to(:lower) }
|
12
|
-
it { is_expected.to respond_to(:upper) }
|
13
|
-
it { is_expected.to respond_to(:number) }
|
14
|
-
it { is_expected.to respond_to(:letters_lower) }
|
15
|
-
it { is_expected.to respond_to(:letters_upper) }
|
16
|
-
it { is_expected.to respond_to(:letters_number) }
|
17
|
-
|
18
|
-
# default settings
|
19
|
-
it { is_expected.to have_attributes(algorithm: :sha512) }
|
20
|
-
it { is_expected.to have_attributes(length: 8) }
|
21
|
-
it { is_expected.to satisfy {|v| v.policy.is_a?(Passwd::Policy) } }
|
22
|
-
it { is_expected.to have_attributes(stretching: nil) }
|
23
|
-
it { is_expected.to have_attributes(lower: true) }
|
24
|
-
it { is_expected.to have_attributes(upper: true) }
|
25
|
-
it { is_expected.to have_attributes(number: true) }
|
26
|
-
it { is_expected.to have_attributes(letters_lower: [*"a".."z"]) }
|
27
|
-
it { is_expected.to have_attributes(letters_upper: [*"A".."Z"]) }
|
28
|
-
it { is_expected.to have_attributes(letters_number: [*"0".."9"]) }
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "Writable" do
|
32
|
-
subject { Passwd }
|
33
|
-
|
34
|
-
it {
|
35
|
-
klass = Class.new { extend Passwd::Configuration::Writable }
|
36
|
-
expect(defined?(klass::PwConfig)).to be_truthy
|
37
|
-
}
|
38
|
-
|
39
|
-
it { is_expected.to respond_to(:configure) }
|
40
|
-
it { is_expected.to respond_to(:policy_configure) }
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "Accessible" do
|
44
|
-
it {
|
45
|
-
klass = Class.new { include Passwd::Configuration::Accessible }
|
46
|
-
expect(klass::PwConfig.is_a?(Passwd::Configuration)).to be_truthy
|
47
|
-
}
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
@@ -1,156 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Passwd::Password do
|
4
|
-
let!(:pswd) { Passwd::Password.new }
|
5
|
-
|
6
|
-
describe "#initialize" do
|
7
|
-
context "without argument" do
|
8
|
-
subject { Passwd::Password.new }
|
9
|
-
|
10
|
-
it { is_expected.not_to have_attributes(plain: nil) }
|
11
|
-
it { is_expected.not_to have_attributes(hash: nil) }
|
12
|
-
it { is_expected.not_to have_attributes(salt: nil) }
|
13
|
-
it { is_expected.to satisfy {|v| v.salt.is_a?(Passwd::Salt) } }
|
14
|
-
end
|
15
|
-
|
16
|
-
context "with plain" do
|
17
|
-
subject { Passwd::Password.new(plain: pswd.plain) }
|
18
|
-
|
19
|
-
it { is_expected.to have_attributes(plain: pswd.plain) }
|
20
|
-
it { is_expected.not_to have_attributes(hash: nil) }
|
21
|
-
it { is_expected.not_to have_attributes(salt: nil) }
|
22
|
-
it { is_expected.to satisfy {|v| v.salt.is_a?(Passwd::Salt) } }
|
23
|
-
end
|
24
|
-
|
25
|
-
context "with plain and salt_plain" do
|
26
|
-
subject { Passwd::Password.new(plain: pswd.plain, salt_plain: pswd.salt.plain) }
|
27
|
-
|
28
|
-
it { is_expected.to have_attributes(plain: pswd.plain) }
|
29
|
-
it { is_expected.to have_attributes(hash: pswd.hash) }
|
30
|
-
it { is_expected.to satisfy {|v| v.salt.plain == pswd.salt.plain } }
|
31
|
-
it { is_expected.to satisfy {|v| v.salt.hash == pswd.salt.hash } }
|
32
|
-
end
|
33
|
-
|
34
|
-
context "with plain and salt_hash" do
|
35
|
-
subject { Passwd::Password.new(plain: pswd.plain, salt_hash: pswd.salt.hash) }
|
36
|
-
|
37
|
-
it { is_expected.to have_attributes(plain: pswd.plain) }
|
38
|
-
it { is_expected.to have_attributes(hash: pswd.hash) }
|
39
|
-
it { is_expected.to satisfy {|v| v.salt.plain.nil? } }
|
40
|
-
it { is_expected.to satisfy {|v| v.salt.hash == pswd.salt.hash } }
|
41
|
-
end
|
42
|
-
|
43
|
-
context "with hash and salt_hash" do
|
44
|
-
subject { Passwd::Password.new(hash: pswd.hash, salt_hash: pswd.salt.hash) }
|
45
|
-
|
46
|
-
it { is_expected.to have_attributes(plain: nil) }
|
47
|
-
it { is_expected.to have_attributes(hash: pswd.hash) }
|
48
|
-
it { is_expected.to satisfy {|v| v.salt.plain.nil? } }
|
49
|
-
it { is_expected.to satisfy {|v| v.salt.hash == pswd.salt.hash } }
|
50
|
-
end
|
51
|
-
|
52
|
-
it {
|
53
|
-
expect {
|
54
|
-
Passwd::Password.new(hash: pswd.hash)
|
55
|
-
}.to raise_error(ArgumentError)
|
56
|
-
}
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "#update_plain" do
|
60
|
-
it {
|
61
|
-
expect(pswd).to receive(:rehash)
|
62
|
-
pswd.update_plain("secret")
|
63
|
-
expect(pswd).to have_attributes(plain: "secret")
|
64
|
-
}
|
65
|
-
|
66
|
-
it {
|
67
|
-
expect {
|
68
|
-
pswd.update_plain("secret")
|
69
|
-
}.to change { pswd.plain }
|
70
|
-
}
|
71
|
-
end
|
72
|
-
|
73
|
-
describe "#update_hash" do
|
74
|
-
it {
|
75
|
-
expect(pswd).not_to receive(:rehash)
|
76
|
-
pswd.update_hash("hashed", "salt")
|
77
|
-
expect(pswd).to have_attributes(hash: "hashed")
|
78
|
-
expect(pswd.salt).to have_attributes(hash: "salt")
|
79
|
-
}
|
80
|
-
|
81
|
-
it {
|
82
|
-
expect {
|
83
|
-
pswd.update_hash("hashed", "salt")
|
84
|
-
}.to change { pswd.plain }
|
85
|
-
}
|
86
|
-
end
|
87
|
-
|
88
|
-
describe "#match?" do
|
89
|
-
it { expect(pswd.match?(pswd.plain)).to be_truthy }
|
90
|
-
|
91
|
-
it {
|
92
|
-
invalid = [pswd.plain, "invalid"].join
|
93
|
-
expect(pswd.match?(invalid)).to be_falsy
|
94
|
-
}
|
95
|
-
end
|
96
|
-
|
97
|
-
describe "#==" do
|
98
|
-
it {
|
99
|
-
expect(pswd).to receive(:match?)
|
100
|
-
pswd == pswd.plain
|
101
|
-
}
|
102
|
-
end
|
103
|
-
|
104
|
-
describe "#valid?" do
|
105
|
-
it {
|
106
|
-
pswd.update_plain("ValidPassw0rd")
|
107
|
-
expect(pswd.valid?).to be_truthy
|
108
|
-
}
|
109
|
-
|
110
|
-
it {
|
111
|
-
pswd.update_plain("a" * (Passwd::PwConfig.policy.min_length - 1))
|
112
|
-
expect(pswd.valid?).to be_falsy
|
113
|
-
}
|
114
|
-
|
115
|
-
it {
|
116
|
-
pswd.update_hash("hashed", "salt")
|
117
|
-
expect {
|
118
|
-
pswd.valid?
|
119
|
-
}.to raise_error(Passwd::PasswdError)
|
120
|
-
}
|
121
|
-
end
|
122
|
-
|
123
|
-
describe "#default_options" do
|
124
|
-
it {
|
125
|
-
expect(pswd.send(:default_options)).to satisfy {|v| v.has_key?(:plain) }
|
126
|
-
}
|
127
|
-
end
|
128
|
-
|
129
|
-
describe "#include_char?" do
|
130
|
-
it {
|
131
|
-
pswd.update_plain("secret")
|
132
|
-
expect(pswd.send(:include_char?, ["s"])).to be_truthy
|
133
|
-
}
|
134
|
-
|
135
|
-
it {
|
136
|
-
expect {
|
137
|
-
pswd.update_hash("hashed", "salt")
|
138
|
-
pswd.send(:include_char?, [])
|
139
|
-
}.to raise_error(Passwd::PasswdError)
|
140
|
-
}
|
141
|
-
end
|
142
|
-
|
143
|
-
describe ".from_plain" do
|
144
|
-
it {
|
145
|
-
expect(Passwd::Password).to receive(:new)
|
146
|
-
Passwd::Password.from_plain("secret")
|
147
|
-
}
|
148
|
-
end
|
149
|
-
|
150
|
-
describe ".from_hash" do
|
151
|
-
it {
|
152
|
-
expect(Passwd::Password).to receive(:new)
|
153
|
-
Passwd::Password.from_hash("hashed", "salt")
|
154
|
-
}
|
155
|
-
end
|
156
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require "simplecov"
|
2
|
-
require "coveralls"
|
3
|
-
Coveralls.wear!
|
4
|
-
|
5
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
6
|
-
SimpleCov::Formatter::HTMLFormatter,
|
7
|
-
Coveralls::SimpleCov::Formatter
|
8
|
-
]
|
9
|
-
|
10
|
-
SimpleCov.start do
|
11
|
-
add_filter "spec"
|
12
|
-
add_filter ".bundle"
|
13
|
-
add_filter "example"
|
14
|
-
end
|
15
|
-
|
16
|
-
ENV["RAILS_ENV"] ||= "test"
|
17
|
-
require File.expand_path("../../example/config/environment", __FILE__)
|
18
|
-
require "passwd"
|
19
|
-
|
20
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
21
|
-
|
22
|
-
RSpec.configure do |config|
|
23
|
-
config.order = "random"
|
24
|
-
|
25
|
-
config.before :all do
|
26
|
-
require "db/schema"
|
27
|
-
end
|
28
|
-
|
29
|
-
config.after :each do
|
30
|
-
Passwd::PwConfig.reset
|
31
|
-
DataUtil.clear
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
data/spec/support/data_util.rb
DELETED
data/spec/support/paths.rb
DELETED