zero_auth 0.0.2.beta → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zero_auth.rb +21 -1
- data/lib/zero_auth/config.rb +22 -0
- data/lib/zero_auth/model/password.rb +1 -0
- data/lib/zero_auth/password.rb +10 -5
- data/lib/zero_auth/utils.rb +3 -0
- data/lib/zero_auth/version.rb +1 -1
- data/spec/lib/zero_auth/configuration_spec.rb +30 -0
- data/spec/lib/zero_auth/password_spec.rb +7 -0
- data/spec/spec_helper.rb +4 -0
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cbb0922638b9a01abf7e9621a870ae1b0d57667
|
4
|
+
data.tar.gz: ae5e0cd3fb41ec43ad920f5d0fa7e936f53b8521
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af57951c911288bbf78e0e607983e2a035d8f0bf9404ea95ffeaf92b05afaca4c4a05fd348db5932e9f91667592d8262d4d839f17105e25717e3218dd29b49a4
|
7
|
+
data.tar.gz: 28e1a5f264f5bd9fd7d5e1e701bea45eaadc5c9098f5b3e35a5af13bfaff32d70ecb8a17e50ce0f5e02d1c57987dc7d53d37f4150097c19677fb0b5f087e62a6
|
data/lib/zero_auth.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require 'thread'
|
2
|
+
require 'zero_auth/version'
|
3
|
+
require 'zero_auth/config'
|
2
4
|
|
5
|
+
# Namespace for the ZeroAuth library
|
6
|
+
#
|
3
7
|
module ZeroAuth
|
4
8
|
autoload :Utils, 'zero_auth/utils'
|
5
9
|
autoload :Password, 'zero_auth/password'
|
@@ -8,6 +12,22 @@ module ZeroAuth
|
|
8
12
|
autoload :Password, 'zero_auth/model/password'
|
9
13
|
end
|
10
14
|
|
15
|
+
# The current {ZeroAuth::Config} object for the thread.
|
16
|
+
#
|
17
|
+
# @return [ZeroAuth::Config]
|
18
|
+
#
|
19
|
+
def self.config
|
20
|
+
Thread.current[:zero_auth_config] ||= Config.new
|
21
|
+
end
|
22
|
+
|
23
|
+
# Enables configuration of the ZeroAuth library.
|
24
|
+
#
|
25
|
+
# @yieldparam [ZeroAuth::Config] config
|
26
|
+
#
|
27
|
+
def self.configure
|
28
|
+
yield config
|
29
|
+
end
|
30
|
+
|
11
31
|
# Exception raised througout the library when a method expected to
|
12
32
|
# perform some type of authentication on user supplied parameters cannot be
|
13
33
|
# authenticated.
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ZeroAuth
|
2
|
+
|
3
|
+
# Holds configuration values for the ZeroAuth library.
|
4
|
+
#
|
5
|
+
class Config
|
6
|
+
|
7
|
+
# @return [Integer] The cost param when generating BCrypt passwords.
|
8
|
+
# Defaults to 9.
|
9
|
+
#
|
10
|
+
attr_accessor :password_cost
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
reset!
|
14
|
+
end
|
15
|
+
|
16
|
+
# Resets the current configuration values to their defaults.
|
17
|
+
#
|
18
|
+
def reset!
|
19
|
+
self.password_cost = 9
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/zero_auth/password.rb
CHANGED
@@ -1,16 +1,20 @@
|
|
1
1
|
require 'bcrypt'
|
2
|
-
|
3
2
|
module ZeroAuth
|
3
|
+
|
4
|
+
# Provides helper methods for generating and comparing BCrypt passwords
|
5
|
+
#
|
4
6
|
class Password
|
5
7
|
|
6
|
-
#
|
8
|
+
# Generates a password salt using `BCrypt::Engine.generate_salt`
|
9
|
+
#
|
10
|
+
# @return [String] the password salt
|
7
11
|
#
|
8
12
|
def self.generate_salt
|
9
13
|
BCrypt::Engine.generate_salt
|
10
14
|
end
|
11
15
|
|
12
|
-
# Generates a `BCrypt::Password`
|
13
|
-
#
|
16
|
+
# Generates a `BCrypt::Password` using they {ZeroAuth::Config#password_cost}
|
17
|
+
# configuration value.
|
14
18
|
#
|
15
19
|
# @param password [String] the given password
|
16
20
|
# @param salt [Sting] the password salt
|
@@ -18,7 +22,8 @@ module ZeroAuth
|
|
18
22
|
# @return [BCrypt::Password]
|
19
23
|
#
|
20
24
|
def self.create(password, salt)
|
21
|
-
|
25
|
+
cost = ZeroAuth.config.password_cost
|
26
|
+
BCrypt::Password.create("#{password}#{salt}", cost: cost)
|
22
27
|
end
|
23
28
|
|
24
29
|
# Compares a given encrypted password and the salt used to generate it with
|
data/lib/zero_auth/utils.rb
CHANGED
data/lib/zero_auth/version.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe ZeroAuth::Config do
|
4
|
+
|
5
|
+
let(:config) { described_class.new }
|
6
|
+
|
7
|
+
describe "#reset!" do
|
8
|
+
it "resets the configuration" do
|
9
|
+
old_cost = config.password_cost
|
10
|
+
config.password_cost = 25
|
11
|
+
config.reset!
|
12
|
+
expect(config.password_cost).to eq(old_cost)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
shared_examples_for :config_attribute do |config_name, default_value|
|
17
|
+
describe "##{config_name}" do
|
18
|
+
it "has a default_value of #{default_value.inspect}" do
|
19
|
+
expect(config.send(config_name)).to eq(default_value)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "can be set to a new value" do
|
23
|
+
config.send("#{config_name}=", :test)
|
24
|
+
expect(config.send(config_name)).to eq(:test)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
include_examples :config_attribute, :password_cost, 9
|
30
|
+
end
|
@@ -9,6 +9,13 @@ RSpec.describe ZeroAuth::Password do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
describe ".create" do
|
12
|
+
it 'creates the password correctly' do
|
13
|
+
expect(BCrypt::Password).to receive(:create)
|
14
|
+
.with("passwordsalt", {cost: ZeroAuth.config.password_cost})
|
15
|
+
|
16
|
+
ZeroAuth::Password.create("password", "salt")
|
17
|
+
end
|
18
|
+
|
12
19
|
it "returns a BCrypt::Password" do
|
13
20
|
password = ZeroAuth::Password.create("password", "salt")
|
14
21
|
expect(password).to be_a(BCrypt::Password)
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zero_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Braden Schaeffer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bcrypt
|
@@ -110,10 +110,12 @@ files:
|
|
110
110
|
- README.md
|
111
111
|
- Rakefile
|
112
112
|
- lib/zero_auth.rb
|
113
|
+
- lib/zero_auth/config.rb
|
113
114
|
- lib/zero_auth/model/password.rb
|
114
115
|
- lib/zero_auth/password.rb
|
115
116
|
- lib/zero_auth/utils.rb
|
116
117
|
- lib/zero_auth/version.rb
|
118
|
+
- spec/lib/zero_auth/configuration_spec.rb
|
117
119
|
- spec/lib/zero_auth/model/password_spec.rb
|
118
120
|
- spec/lib/zero_auth/password_spec.rb
|
119
121
|
- spec/lib/zero_auth/utils_spec.rb
|
@@ -134,18 +136,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
134
136
|
version: '0'
|
135
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
138
|
requirements:
|
137
|
-
- - "
|
139
|
+
- - ">="
|
138
140
|
- !ruby/object:Gem::Version
|
139
|
-
version:
|
141
|
+
version: '0'
|
140
142
|
requirements: []
|
141
143
|
rubyforge_project:
|
142
|
-
rubygems_version: 2.
|
144
|
+
rubygems_version: 2.4.8
|
143
145
|
signing_key:
|
144
146
|
specification_version: 4
|
145
147
|
summary: Zero configuration authentication starter for Rails.
|
146
148
|
test_files:
|
149
|
+
- spec/lib/zero_auth/configuration_spec.rb
|
147
150
|
- spec/lib/zero_auth/model/password_spec.rb
|
148
151
|
- spec/lib/zero_auth/password_spec.rb
|
149
152
|
- spec/lib/zero_auth/utils_spec.rb
|
150
153
|
- spec/spec_helper.rb
|
151
|
-
has_rdoc:
|