passwd 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ gemfile:
6
+ - Gemfile
7
+ script: bundle exec rspec
8
+ branches:
9
+ only:
10
+ - master
11
+ notifications:
12
+ mails:
13
+ - i2bskn@gmail.com
14
+ on_sucess: always
15
+ on_failure: always
data/README.md CHANGED
@@ -2,13 +2,15 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/i2bskn/passwd.png?branch=master)](https://travis-ci.org/i2bskn/passwd)
4
4
 
5
- Password utility
5
+ Password utilities.
6
6
 
7
7
  ## Installation
8
8
 
9
9
  Add this line to your application's Gemfile:
10
10
 
11
- gem 'passwd'
11
+ ```ruby
12
+ gem 'passwd'
13
+ ```
12
14
 
13
15
  And then execute:
14
16
 
@@ -20,11 +22,33 @@ Or install it yourself as:
20
22
 
21
23
  ## Usage
22
24
 
23
- require 'passwd'
25
+ ```ruby
26
+ require 'passwd'
27
+ ```
24
28
 
25
- Create random password:
29
+ ### Create random password
26
30
 
27
- password = Passwd.create
31
+ ```ruby
32
+ password = Passwd.create
33
+ ```
34
+
35
+ ### Hashing password
36
+
37
+ Hashing with SHA1.
38
+
39
+ ```ruby
40
+ password_hash = Passwd.hashing(password)
41
+ ```
42
+
43
+ ### Password settings
44
+
45
+ Default config is stored in the class variable. (@@config)
46
+ Changing the default configs are as follows:
47
+
48
+ ```ruby
49
+ Passwd.config => Get config hash.
50
+ Passwd.config(length: 10) => Change to the default length.
51
+ ```
28
52
 
29
53
  Options that can be specified:
30
54
 
@@ -36,19 +60,21 @@ Options that can be specified:
36
60
  * :letters_upper => Define an array of upper case. default is ("A".."Z").to_a
37
61
  * :letters_number => Define an array of numbers. default is ("0".."9").to_a
38
62
 
39
- Default config is stored in the class variable. (@@config)
40
- Changing the default configs are as follows:
41
-
42
- Passwd.config => Get config hash.
43
- Passwd.config(length: 10) => Change to the default length.
63
+ ### Password policy check
44
64
 
45
- Password hashing:
65
+ ```ruby
66
+ Passwd.policy_check(password)
67
+ ```
46
68
 
47
- password_hash = Passwd.hashing(password)
69
+ ### Policy settings
48
70
 
49
- Password policy check:
71
+ Default policy is stored in the class variable. (@@policy)
72
+ Changing the default policy are as follows:
50
73
 
51
- Passwd.policy_check(password)
74
+ ```ruby
75
+ Passwd.policy => Get policy hash.
76
+ Passwd.policy(min_length: 10) => Change to the default min_length.
77
+ ```
52
78
 
53
79
  Options that can be specified:
54
80
 
@@ -59,22 +85,18 @@ Options that can be specified:
59
85
  * :require_upper => Require upper case if set true. specify_type enabled when true.
60
86
  * :require_number => Require number case if set true. specify_type enabled when true.
61
87
 
62
- Default policy is stored in the class variable. (@@policy)
63
- Changing the default policy are as follows:
64
-
65
- Passwd.policy => Get policy hash.
66
- Passwd.policy(min_length: 10) => Change to the default min_length.
67
-
68
- Passwd object:
88
+ ### Password object
69
89
 
70
90
  Default password is randomly generated.
71
91
  Default salt is "#{Time.now.to_s}".
72
92
 
73
- password = Passwd::Password.new
74
- password.text # return text password.
75
- password.salt_text # return text salt.
76
- password.salt_hash # return hash salt.
77
- password.hash # return hash password.
93
+ ```ruby
94
+ password = Passwd::Password.new
95
+ password.text # return text password.
96
+ password.salt_text # return text salt.
97
+ password.salt_hash # return hash salt.
98
+ password.hash # return hash password.
99
+ ```
78
100
 
79
101
  Options that can be specified:
80
102
 
@@ -83,12 +105,75 @@ Options that can be specified:
83
105
 
84
106
  Password authenticate:
85
107
 
86
- password = Passwd::Password.new
87
- Passwd.auth(password.text, password.salt_hash, password.hash) # => true
88
- Passwd.auth("invalid!!", password.salt_hash, password.hash) # => false
89
-
90
- password == password.text # => true
91
- password == "invalid!!" # => false
108
+ ```ruby
109
+ password = Passwd::Password.new
110
+ Passwd.auth(password.text, password.salt_hash, password.hash) # => true
111
+ Passwd.auth("invalid!!", password.salt_hash, password.hash) # => false
112
+
113
+ password == password.text # => true
114
+ password == "invalid!!" # => false
115
+ ```
116
+
117
+ ## For ActiveRecord User model
118
+
119
+ model:
120
+
121
+ ```ruby
122
+ class User < ActiveRecord::Base
123
+ include Passwd::ActiveRecord
124
+ # if not specified arguments for define_column => {id: :email, salt: :salt, password: :password}
125
+ define_column id: :id_colname, salt: :salt_colname, password: :password_colname
126
+
127
+ ...
128
+ end
129
+ ```
130
+
131
+ Authentication:
132
+
133
+ ```ruby
134
+ user = User.authenticate("foo@example.com", "secret") # => return user object or nil.
135
+
136
+ if user
137
+ puts "Hello #{user.name}!"
138
+ else
139
+ puts "Authentication failed"
140
+ end
141
+ ```
142
+
143
+ ```ruby
144
+ user = User.find(params[:id])
145
+ if user.authenticate("secret") # => return true or false
146
+ puts "Authentication is successful!"
147
+ else
148
+ puts "Authentication failed!"
149
+ end
150
+ ```
151
+
152
+ Change passowrd:
153
+
154
+ ```ruby
155
+ user = User.find(params[:id])
156
+ # set random password. (salt also set if salt is nil)
157
+ # return set password text.
158
+ # set specified password if specified argument.
159
+ # user.set_password("secret")
160
+ password_text = user.set_password
161
+
162
+ if user.save
163
+ NoticeMailer.change_mail(user, password_text).deliver
164
+ end
165
+ ```
166
+
167
+ ```ruby
168
+ user.find(params[:id])
169
+ if user.update_password(old_pass, new_pass) # => return new password(text) or false
170
+ if user.save
171
+ NoticeMailer.change_mail(user, password_text).deliver
172
+ end
173
+ else
174
+ puts "Authentication failed!"
175
+ end
176
+ ```
92
177
 
93
178
  ## Contributing
94
179
 
@@ -96,4 +181,4 @@ Password authenticate:
96
181
  2. Create your feature branch (`git checkout -b my-new-feature`)
97
182
  3. Commit your changes (`git commit -am 'Added some feature'`)
98
183
  4. Push to the branch (`git push origin my-new-feature`)
99
- 5. Create new Pull Request
184
+ 5. Create new Pull Request
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rspec/core/rake_task'
5
5
 
6
6
  task default: [:spec]
7
7
 
8
- desc "run spec"
8
+ desc "Run all specs"
9
9
  RSpec::Core::RakeTask.new(:spec) do |t|
10
10
  t.rspec_opts = ["-c", "-fs"]
11
11
  end
@@ -0,0 +1,44 @@
1
+ # coding: utf-8
2
+
3
+ module Passwd
4
+ module ActiveRecord
5
+ module ClassMethods
6
+ def define_column(options={})
7
+ idc = options[:id] || :email
8
+ saltc = options[:salt] || :salt
9
+ passwordc = options[:password] || :password
10
+
11
+ define_singleton_method :authenticate do |id, pass|
12
+ user = self.where(idc => id).first
13
+ user if user && Passwd.auth(pass, user.send(saltc), user.send(passwordc))
14
+ end
15
+
16
+ define_method :authenticate do |pass|
17
+ Passwd.auth(pass, self.send(saltc), self.send(passwordc))
18
+ end
19
+
20
+ define_method :set_password do |pass=nil|
21
+ password = pass || Passwd.create
22
+ salt = self.send(saltc) || Passwd.hashing("#{self.send(idc)}#{Time.now.to_s}")
23
+ self.send("#{saltc.to_s}=", salt)
24
+ self.send("#{passwordc.to_s}=", Passwd.hashing("#{salt}#{password}"))
25
+ password
26
+ end
27
+
28
+ define_method :update_password do |old, new|
29
+ if Passwd.auth(old, self.send(saltc), self.send(passwordc))
30
+ set_password(new)
31
+ else
32
+ false
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ class << self
39
+ def included(klass)
40
+ klass.extend ClassMethods
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,45 @@
1
+ # coding: utf-8
2
+
3
+ module Passwd
4
+ class Password
5
+ attr_reader :text, :hash, :salt_text, :salt_hash
6
+
7
+ def initialize(options={})
8
+ @text = options[:password] || Passwd.create
9
+ @salt_text = options[:salt_text] || Time.now.to_s
10
+ @salt_hash = Passwd.hashing(@salt_text)
11
+ @hash = Passwd.hashing("#{@salt_hash}#{@text}")
12
+ end
13
+
14
+ def text=(password)
15
+ @hash = Passwd.hashing("#{@salt_hash}#{password}")
16
+ @text = password
17
+ end
18
+
19
+ def hash=(password_hash)
20
+ @text = nil
21
+ @hash = password_hash
22
+ end
23
+
24
+ def salt_text=(salt_text)
25
+ @salt_hash = Passwd.hashing(salt_text)
26
+ @hash = Passwd.hashing("#{@salt_hash}#{@text}")
27
+ @salt_text = salt_text
28
+ end
29
+
30
+ def salt_hash=(salt_hash)
31
+ @salt_text = nil
32
+ @hash = Passwd.hashing("#{salt_hash}#{@text}")
33
+ @salt_hash = salt_hash
34
+ end
35
+
36
+ def policy_check
37
+ Passwd.policy_check @text
38
+ end
39
+
40
+ def ==(password)
41
+ enc_pass = Passwd.hashing("#{@salt_hash}#{password}")
42
+ @hash == enc_pass
43
+ end
44
+ end
45
+ end
@@ -1,3 +1,3 @@
1
1
  module Passwd
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/passwd.rb CHANGED
@@ -1,8 +1,11 @@
1
1
  # coding: utf-8
2
2
 
3
- require "passwd/version"
4
3
  require "digest/sha1"
5
4
 
5
+ require "passwd/version"
6
+ require "passwd/password"
7
+ require "passwd/active_record"
8
+
6
9
  module Passwd
7
10
  @@config = {
8
11
  length: 8,
@@ -23,48 +26,6 @@ module Passwd
23
26
  require_number: true
24
27
  }
25
28
 
26
- class Password
27
- attr_reader :text, :hash, :salt_text, :salt_hash
28
-
29
- def initialize(options={password: nil, salt_text: Time.now.to_s})
30
- @text = options[:password].nil? ? Passwd.create : options[:password]
31
- @salt_text = options[:salt_text] || Time.now.to_s
32
- @salt_hash = Passwd.hashing(@salt_text)
33
- @hash = Passwd.hashing("#{@salt_hash}#{@text}")
34
- end
35
-
36
- def text=(password)
37
- @hash = Passwd.hashing("#{@salt_hash}#{password}")
38
- @text = password
39
- end
40
-
41
- def hash=(password_hash)
42
- @text = nil
43
- @hash = password_hash
44
- end
45
-
46
- def salt_text=(salt_text)
47
- @salt_hash = Passwd.hashing(salt_text)
48
- @hash = Passwd.hashing("#{@salt_hash}#{@text}")
49
- @salt_text = salt_text
50
- end
51
-
52
- def salt_hash=(salt_hash)
53
- @salt_text = nil
54
- @hash = Passwd.hashing("#{salt_hash}#{@text}")
55
- @salt_hash = salt_hash
56
- end
57
-
58
- def policy_check
59
- Passwd.policy_check @text
60
- end
61
-
62
- def ==(password)
63
- enc_pass = Passwd.hashing("#{@salt_hash}#{password}")
64
- @hash == enc_pass
65
- end
66
- end
67
-
68
29
  class << self
69
30
  def create(options={})
70
31
  config = @@config.merge(options)
data/passwd.gemspec CHANGED
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'passwd/version'
@@ -0,0 +1,142 @@
1
+ # coding: utf-8
2
+
3
+ require "spec_helper"
4
+
5
+ describe Passwd::ActiveRecord do
6
+ class User
7
+ include Passwd::ActiveRecord
8
+ define_column
9
+ end
10
+
11
+ let(:salt) {Digest::SHA1.hexdigest("salt")}
12
+ let(:password_text) {"secret"}
13
+ let(:password_hash) {Digest::SHA1.hexdigest("#{salt}#{password_text}")}
14
+
15
+ describe ".included" do
16
+ it "define singleton methods" do
17
+ expect(User.respond_to? :define_column).to be_true
18
+ end
19
+ end
20
+
21
+ describe "extend methods" do
22
+ describe ".define_column" do
23
+ let(:user) {User.new}
24
+
25
+ it "define singleton methods" do
26
+ expect(User.respond_to? :authenticate).to be_true
27
+ end
28
+
29
+ it "define authenticate method" do
30
+ expect(user.respond_to? :authenticate).to be_true
31
+ end
32
+
33
+ it "define set_password method" do
34
+ expect(user.respond_to? :set_password).to be_true
35
+ end
36
+
37
+ it "define update_password" do
38
+ expect(user.respond_to? :update_password).to be_true
39
+ end
40
+ end
41
+ end
42
+
43
+ describe "defined methods from define_column" do
44
+ describe ".authenticate" do
45
+ let!(:record) {
46
+ record = double("record mock")
47
+ record.stub(:salt).and_return(salt)
48
+ record.stub(:password).and_return(password_hash)
49
+ response = [record]
50
+ User.stub(:where).and_return(response)
51
+ record
52
+ }
53
+
54
+ it "user should be returned if authentication is successful" do
55
+ User.should_receive(:where)
56
+ expect(User.authenticate("valid_id", password_text)).to eq(record)
57
+ end
58
+
59
+ it "should return nil if authentication failed" do
60
+ User.should_receive(:where)
61
+ expect(User.authenticate("valid_id", "invalid_secret")).to be_nil
62
+ end
63
+
64
+ it "should return nil if user not found" do
65
+ User.should_receive(:where).with(:email => "invalid_id").and_return([])
66
+ expect(User.authenticate("invalid_id", password_text)).to be_nil
67
+ end
68
+ end
69
+
70
+ describe "#authenticate" do
71
+ let!(:user) {
72
+ user = User.new
73
+ user.stub(:salt).and_return(salt)
74
+ user.stub(:password).and_return(password_hash)
75
+ user
76
+ }
77
+
78
+ it "should return true if authentication is successful" do
79
+ expect(user.authenticate(password_text)).to be_true
80
+ end
81
+
82
+ it "should return false if authentication failed" do
83
+ expect(user.authenticate("invalid_pass")).to be_false
84
+ end
85
+ end
86
+
87
+ describe "#set_password" do
88
+ let!(:user) {
89
+ user = User.new
90
+ user.stub(:salt).and_return(salt)
91
+ user
92
+ }
93
+
94
+ it "should return set password" do
95
+ user.should_receive(:salt=).with(salt)
96
+ user.should_receive(:password=).with(Passwd.hashing("#{salt}#{password_text}"))
97
+ expect(user.set_password(password_text)).to eq(password_text)
98
+ end
99
+
100
+ it "should set random password if not specified" do
101
+ user.should_receive(:salt=).with(salt)
102
+ random_password = Passwd.create
103
+ Passwd.should_receive(:create).and_return(random_password)
104
+ user.should_receive(:password=).with(Passwd.hashing("#{salt}#{random_password}"))
105
+ user.set_password
106
+ end
107
+
108
+ it "should set salt if salt is nil" do
109
+ mail_addr = "foo@example.com"
110
+ time_now = Time.now
111
+ salt2 = Passwd.hashing("#{mail_addr}#{time_now.to_s}")
112
+ Time.stub(:now).and_return(time_now)
113
+ user.stub(:email).and_return(mail_addr)
114
+ user.should_receive(:salt).and_return(nil)
115
+ user.should_receive(:salt=).with(salt2)
116
+ user.should_receive(:password=).with(Passwd.hashing("#{salt2}#{password_text}"))
117
+ user.set_password(password_text)
118
+ end
119
+ end
120
+
121
+ describe "#update_password" do
122
+ let!(:user) {
123
+ user = User.new
124
+ user.stub(:salt).and_return(salt)
125
+ user.stub(:password).and_return(password_hash)
126
+ user
127
+ }
128
+
129
+ it "should return update password" do
130
+ pass = "new_password"
131
+ user.should_receive(:set_password).with(pass).and_return(pass)
132
+ expect(user.update_password(password_text, pass)).to eq(pass)
133
+ end
134
+
135
+ it "should return false if authentication failed" do
136
+ Passwd.should_receive(:auth).and_return(false)
137
+ user.should_not_receive(:set_password)
138
+ user.update_password("invalid_password", "new_password")
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,147 @@
1
+ # coding: utf-8
2
+
3
+ require "spec_helper"
4
+
5
+ describe Passwd::Password do
6
+ context "#initialize" do
7
+ it "set instance valiables" do
8
+ password = Passwd::Password.new
9
+ expect(password.text.size).to eq(8)
10
+ expect(password.text.class).to eq(String)
11
+ expect(password.hash.class).to eq(String)
12
+ expect(password.salt_text.class).to eq(String)
13
+ expect(password.salt_hash.class).to eq(String)
14
+ end
15
+
16
+ it "@text is specified password" do
17
+ pass_text = Passwd.create
18
+ password = Passwd::Password.new(password: pass_text)
19
+ expect(password.text).to eq(pass_text)
20
+ end
21
+
22
+ it "@hash is hash of specified password" do
23
+ pass_text = Passwd.create
24
+ password = Passwd::Password.new(password: pass_text)
25
+ pass_hash = Passwd.hashing("#{password.salt_hash}#{pass_text}")
26
+ expect(password.hash).to eq(pass_hash)
27
+ end
28
+
29
+ it "@salt_text is specified salt" do
30
+ salt_text = "salt"
31
+ password = Passwd::Password.new(salt_text: salt_text)
32
+ expect(password.salt_text).to eq(salt_text)
33
+ end
34
+
35
+ it "@salt_hash is hash of specified salt" do
36
+ salt_text = "salt"
37
+ salt_hash = Passwd.hashing(salt_text)
38
+ password = Passwd::Password.new(salt_text: salt_text)
39
+ expect(password.salt_hash).to eq(salt_hash)
40
+ end
41
+ end
42
+
43
+ context "#text=" do
44
+ before(:each) do
45
+ @password = Passwd::Password.new(password: "Secret!!")
46
+ end
47
+
48
+ it "@text is changed" do
49
+ old_password = @password.text
50
+ @password.text = Passwd.create
51
+ expect(@password.text).not_to eq(old_password)
52
+ end
53
+
54
+ it "@hash is changed" do
55
+ old_hash = @password.hash
56
+ @password.text = Passwd.create
57
+ expect(@password.hash).not_to eq(old_hash)
58
+ end
59
+ end
60
+
61
+ context "#hash=" do
62
+ before(:each) do
63
+ @password = Passwd::Password.new
64
+ end
65
+
66
+ it "@text is nil" do
67
+ @password.hash = Passwd.hashing("Secret!!")
68
+ expect(@password.text).to eq(nil)
69
+ end
70
+
71
+ it "@hash is changed" do
72
+ old_hash = @password.hash
73
+ @password.hash = Passwd.hashing("Secret!!")
74
+ expect(@password.hash).not_to eq(old_hash)
75
+ end
76
+ end
77
+
78
+ context "#salt_text=" do
79
+ before(:each) do
80
+ @password = Passwd::Password.new
81
+ end
82
+
83
+ it "@salt_text is changed" do
84
+ old_salt_text = @password.salt_text
85
+ @password.salt_text = "salt"
86
+ expect(@password.salt_text).not_to eq(old_salt_text)
87
+ end
88
+
89
+ it "@salt_hash is changed" do
90
+ old_salt_hash = @password.salt_hash
91
+ @password.salt_text = "salt"
92
+ expect(@password.salt_hash).not_to eq(old_salt_hash)
93
+ end
94
+
95
+ it "@hash is changed" do
96
+ old_hash = @password.hash
97
+ @password.salt_text = "salt"
98
+ expect(@password.hash).not_to eq(old_hash)
99
+ end
100
+ end
101
+
102
+ context "#salt_hash=" do
103
+ before(:each) do
104
+ @password = Passwd::Password.new
105
+ end
106
+
107
+ it "@salt_text is nil" do
108
+ @password.salt_hash = Passwd.hashing("salt")
109
+ expect(@password.salt_text).to eq(nil)
110
+ end
111
+
112
+ it "@salt_hash is changed" do
113
+ old_salt_hash = @password.salt_hash
114
+ @password.salt_hash = Passwd.hashing("salt")
115
+ expect(@password.salt_hash).not_to eq(old_salt_hash)
116
+ end
117
+
118
+ it "@hash is changed" do
119
+ old_hash = @password.hash
120
+ @password.salt_hash = Passwd.hashing("salt")
121
+ expect(@password.hash).not_to eq(old_hash)
122
+ end
123
+ end
124
+
125
+ context "#policy_check" do
126
+ it "Passwd.policy_check is called with pass_text" do
127
+ pass_text = Passwd.create
128
+ Passwd.should_receive(:policy_check).with(pass_text)
129
+ password = Passwd::Password.new(password: pass_text)
130
+ password.policy_check
131
+ end
132
+ end
133
+
134
+ context "#==" do
135
+ before(:each) do
136
+ @password = Passwd::Password.new
137
+ end
138
+
139
+ it "return true with valid password" do
140
+ expect(@password == @password.text).to eq(true)
141
+ end
142
+
143
+ it "return false with invalid password" do
144
+ expect(@password == "Secret!!").to eq(false)
145
+ end
146
+ end
147
+ end
data/spec/passwd_spec.rb CHANGED
@@ -1,9 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
- $:.unshift File.join(File.dirname(__FILE__),'..','lib')
4
-
5
- require "passwd"
6
- require "digest/sha1"
3
+ require "spec_helper"
7
4
 
8
5
  describe Passwd do
9
6
  describe "singleton methods" do
@@ -139,148 +136,4 @@ describe Passwd do
139
136
  end
140
137
  end
141
138
  end
142
-
143
- describe 'Password' do
144
- context "#initialize" do
145
- it "set instance valiables" do
146
- password = Passwd::Password.new
147
- expect(password.text.size).to eq(8)
148
- expect(password.text.class).to eq(String)
149
- expect(password.hash.class).to eq(String)
150
- expect(password.salt_text.class).to eq(String)
151
- expect(password.salt_hash.class).to eq(String)
152
- end
153
-
154
- it "@text is specified password" do
155
- pass_text = Passwd.create
156
- password = Passwd::Password.new(password: pass_text)
157
- expect(password.text).to eq(pass_text)
158
- end
159
-
160
- it "@hash is hash of specified password" do
161
- pass_text = Passwd.create
162
- password = Passwd::Password.new(password: pass_text)
163
- pass_hash = Passwd.hashing("#{password.salt_hash}#{pass_text}")
164
- expect(password.hash).to eq(pass_hash)
165
- end
166
-
167
- it "@salt_text is specified salt" do
168
- salt_text = "salt"
169
- password = Passwd::Password.new(salt_text: salt_text)
170
- expect(password.salt_text).to eq(salt_text)
171
- end
172
-
173
- it "@salt_hash is hash of specified salt" do
174
- salt_text = "salt"
175
- salt_hash = Passwd.hashing(salt_text)
176
- password = Passwd::Password.new(salt_text: salt_text)
177
- expect(password.salt_hash).to eq(salt_hash)
178
- end
179
- end
180
-
181
- context "#text=" do
182
- before(:each) do
183
- @password = Passwd::Password.new(password: "Secret!!")
184
- end
185
-
186
- it "@text is changed" do
187
- old_password = @password.text
188
- @password.text = Passwd.create
189
- expect(@password.text).not_to eq(old_password)
190
- end
191
-
192
- it "@hash is changed" do
193
- old_hash = @password.hash
194
- @password.text = Passwd.create
195
- expect(@password.hash).not_to eq(old_hash)
196
- end
197
- end
198
-
199
- context "#hash=" do
200
- before(:each) do
201
- @password = Passwd::Password.new
202
- end
203
-
204
- it "@text is nil" do
205
- @password.hash = Passwd.hashing("Secret!!")
206
- expect(@password.text).to eq(nil)
207
- end
208
-
209
- it "@hash is changed" do
210
- old_hash = @password.hash
211
- @password.hash = Passwd.hashing("Secret!!")
212
- expect(@password.hash).not_to eq(old_hash)
213
- end
214
- end
215
-
216
- context "#salt_text=" do
217
- before(:each) do
218
- @password = Passwd::Password.new
219
- end
220
-
221
- it "@salt_text is changed" do
222
- old_salt_text = @password.salt_text
223
- @password.salt_text = "salt"
224
- expect(@password.salt_text).not_to eq(old_salt_text)
225
- end
226
-
227
- it "@salt_hash is changed" do
228
- old_salt_hash = @password.salt_hash
229
- @password.salt_text = "salt"
230
- expect(@password.salt_hash).not_to eq(old_salt_hash)
231
- end
232
-
233
- it "@hash is changed" do
234
- old_hash = @password.hash
235
- @password.salt_text = "salt"
236
- expect(@password.hash).not_to eq(old_hash)
237
- end
238
- end
239
-
240
- context "#salt_hash=" do
241
- before(:each) do
242
- @password = Passwd::Password.new
243
- end
244
-
245
- it "@salt_text is nil" do
246
- @password.salt_hash = Passwd.hashing("salt")
247
- expect(@password.salt_text).to eq(nil)
248
- end
249
-
250
- it "@salt_hash is changed" do
251
- old_salt_hash = @password.salt_hash
252
- @password.salt_hash = Passwd.hashing("salt")
253
- expect(@password.salt_hash).not_to eq(old_salt_hash)
254
- end
255
-
256
- it "@hash is changed" do
257
- old_hash = @password.hash
258
- @password.salt_hash = Passwd.hashing("salt")
259
- expect(@password.hash).not_to eq(old_hash)
260
- end
261
- end
262
-
263
- context "#policy_check" do
264
- it "Passwd.policy_check is called with pass_text" do
265
- pass_text = Passwd.create
266
- Passwd.should_receive(:policy_check).with(pass_text)
267
- password = Passwd::Password.new(password: pass_text)
268
- password.policy_check
269
- end
270
- end
271
-
272
- context "#==" do
273
- before(:each) do
274
- @password = Passwd::Password.new
275
- end
276
-
277
- it "return true with valid password" do
278
- expect(@password == @password.text).to eq(true)
279
- end
280
-
281
- it "return false with invalid password" do
282
- expect(@password == "Secret!!").to eq(false)
283
- end
284
- end
285
- end
286
139
  end
@@ -0,0 +1 @@
1
+ require "passwd"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passwd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-23 00:00:00.000000000 Z
12
+ date: 2013-05-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -67,14 +67,20 @@ extensions: []
67
67
  extra_rdoc_files: []
68
68
  files:
69
69
  - .gitignore
70
+ - .travis.yml
70
71
  - Gemfile
71
72
  - LICENSE.txt
72
73
  - README.md
73
74
  - Rakefile
74
75
  - lib/passwd.rb
76
+ - lib/passwd/active_record.rb
77
+ - lib/passwd/password.rb
75
78
  - lib/passwd/version.rb
76
79
  - passwd.gemspec
80
+ - spec/passwd/active_record_spec.rb
81
+ - spec/passwd/password_spec.rb
77
82
  - spec/passwd_spec.rb
83
+ - spec/spec_helper.rb
78
84
  homepage: https://github.com/i2bskn/passwd
79
85
  licenses:
80
86
  - MIT
@@ -90,7 +96,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
96
  version: '0'
91
97
  segments:
92
98
  - 0
93
- hash: 2599599372076087466
99
+ hash: 109903666620076134
94
100
  required_rubygems_version: !ruby/object:Gem::Requirement
95
101
  none: false
96
102
  requirements:
@@ -99,12 +105,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
105
  version: '0'
100
106
  segments:
101
107
  - 0
102
- hash: 2599599372076087466
108
+ hash: 109903666620076134
103
109
  requirements: []
104
110
  rubyforge_project:
105
- rubygems_version: 1.8.23
111
+ rubygems_version: 1.8.25
106
112
  signing_key:
107
113
  specification_version: 3
108
114
  summary: Password utility
109
115
  test_files:
116
+ - spec/passwd/active_record_spec.rb
117
+ - spec/passwd/password_spec.rb
110
118
  - spec/passwd_spec.rb
119
+ - spec/spec_helper.rb