zero_auth 0.0.2.beta → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e5293b8a8a5c64cb80f819e0afc5fe0da191223
4
- data.tar.gz: 52511c99d61691eaf31db9a9effb837ef285ed0d
3
+ metadata.gz: 9cbb0922638b9a01abf7e9621a870ae1b0d57667
4
+ data.tar.gz: ae5e0cd3fb41ec43ad920f5d0fa7e936f53b8521
5
5
  SHA512:
6
- metadata.gz: 32125971bae43ce2cae06f9dab77afae3eb58daa9f834ad288024067facd7afff2d5c1a9793e2c8e881419c6e30809ea7076203fc7dc4937cff7b40e7cac8c3a
7
- data.tar.gz: 84c2a65e27f0a4d64f642196fdff381fb76105141633b3400fe6882879c766ae13b92c2255d87919e0e531968264bc29a54e3673275a3feddf235d24cf9072c3
6
+ metadata.gz: af57951c911288bbf78e0e607983e2a035d8f0bf9404ea95ffeaf92b05afaca4c4a05fd348db5932e9f91667592d8262d4d839f17105e25717e3218dd29b49a4
7
+ data.tar.gz: 28e1a5f264f5bd9fd7d5e1e701bea45eaadc5c9098f5b3e35a5af13bfaff32d70ecb8a17e50ce0f5e02d1c57987dc7d53d37f4150097c19677fb0b5f087e62a6
@@ -1,5 +1,9 @@
1
- require "zero_auth/version"
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
@@ -121,6 +121,7 @@ module ZeroAuth
121
121
  module Password
122
122
 
123
123
  # Calls `attr_reader :password` on the including class.
124
+ # @!visibility private
124
125
  #
125
126
  def self.included(base)
126
127
  base.class_eval { attr_reader :password }
@@ -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
- # @return [String] a salt created by `BCrypt::Engine.generate_salt`
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` with a hard-coded cost of **9** (which
13
- # will probably change soon).
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
- BCrypt::Password.create("#{password}#{salt}", cost: 9)
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
@@ -1,6 +1,9 @@
1
1
  require 'bcrypt'
2
2
 
3
3
  module ZeroAuth
4
+
5
+ # Provides general helper methods used throughout the ZeroAuth library.
6
+ #
4
7
  class Utils
5
8
 
6
9
  # Uses a "constant time" comparison algorithm I would never have thought
@@ -1,3 +1,3 @@
1
1
  module ZeroAuth
2
- VERSION = "0.0.2.beta"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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)
@@ -19,4 +19,8 @@ RSpec.configure do |config|
19
19
  mocks.syntax = :expect
20
20
  mocks.verify_partial_doubles = true
21
21
  end
22
+
23
+ config.after(:each) do
24
+ ZeroAuth.config.reset!
25
+ end
22
26
  end
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.2.beta
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: 2014-08-27 00:00:00.000000000 Z
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: 1.3.1
141
+ version: '0'
140
142
  requirements: []
141
143
  rubyforge_project:
142
- rubygems_version: 2.2.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: