auth_strategist 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e232cd5cbd26ba7c2b716eb360a2f19536aabd9a
4
- data.tar.gz: ec9865919ffbc0661b69bcd0bfe1fb11e4dab246
3
+ metadata.gz: 07d66deb03bf384671d5622aee616fd13adb2897
4
+ data.tar.gz: e3f3e66267fbf073375ed49bd396636c692826b9
5
5
  SHA512:
6
- metadata.gz: 13ecf77a210589567110e931fc1ceb81c161043cd9144ad80692da405c4ead8303e16b104ef8bd179af05e8ae89ad625dbcbb63e3af1a7631f202d07067990a6
7
- data.tar.gz: fb58cc96b63a54e0b7c8159037b2f40e0c52842723c22fe1a32e9b4e7600e283d96ac7b2f6a53159da4fcaea8501456c636bcf6c816a52005aba35d4a6711487
6
+ metadata.gz: 51d781f1d8e9e8e464f33b0961316f161aba8872da8b9955d512db56daaa5f1910729260356f586d50c34f14b99d3fd48fc1655a687b5d874be9d242cbde8080
7
+ data.tar.gz: 6bed7d0bd697858927e38bd1ae1eae45ef154d2b59fe13ee0cd1cda44745e5b85a9a5a0b0e632dadb293713996b1e57c893a44e64bf861ea4dd2593ef4458857
data/README.md CHANGED
@@ -4,6 +4,7 @@
4
4
  AuthStrategist
5
5
  ======
6
6
  [![Code Climate](https://codeclimate.com/github/buszu/auth_strategist/badges/gpa.svg)](https://codeclimate.com/github/buszu/auth_strategist)
7
+ [![Gem Version](https://badge.fury.io/rb/auth_strategist.svg)](http://badge.fury.io/rb/auth_strategist)
7
8
 
8
9
  AuthStrategist is a simple gem to define and use authorization strategies.
9
10
 
@@ -40,8 +41,8 @@ AuthStrategist.configure do |c|
40
41
  # Register your strategies
41
42
  # Required for each strategy you have defined
42
43
  c.strategies do |s|
43
- # E.g. PasswordStrategy will be available under :password key
44
- s.password = PasswordStrategy
44
+ # E.g. OwnershipAuthStrategy will be available under :ownership key
45
+ s.ownership = OwnershipAuthStrategy
45
46
  end
46
47
  end
47
48
  ```
@@ -51,36 +52,36 @@ end
51
52
  ### Defining a Strategy
52
53
  * Define a strategy
53
54
  ```ruby
54
- class PasswordStrategy
55
+ class OwnershipAuthStrategy
55
56
  include AuthStrategist::StrategyInterface
56
57
 
57
- define_components :user, :password
58
+ define_components :user, :item
58
59
 
59
60
  def authorize!
60
- raise StandardError unless user.password == password
61
+ raise unauthorized if item.user_id != user.id
61
62
  end
62
63
  end
63
64
  ```
64
65
  * Register it
65
66
  ```ruby
66
67
  AuthStrategist.strategies do |s|
67
- s.password = PasswordStrategy
68
+ s.ownership = OwnershipAuthStrategy
68
69
  end
69
70
  ```
70
71
  or
71
72
  ```ruby
72
73
  AuthStrategist.configure do |c|
73
74
  c.strategies do |s|
74
- s.password = PasswordStrategy
75
+ s.ownership = OwnershipAuthStrategy
75
76
  end
76
77
  end
77
78
  ```
78
79
  ### Using strategies
79
80
  * Using strategy by calling authorization Service Object
80
81
  ```ruby
81
- AuthStrategist::Authorize.call strategy: :password,
82
+ AuthStrategist::Authorize.call strategy: :ownership,
82
83
  user: current_user,
83
- password: password
84
+ item: book
84
85
  ```
85
86
  * Using strategy with authorize! method
86
87
  ```ruby
@@ -88,7 +89,7 @@ class SomethingsController < ApplicationController
88
89
  include AuthStrategist::Authorization
89
90
 
90
91
  def show
91
- authorize! strategy: :password, user: current_user, password: password
92
+ authorize! strategy: :ownership, user: current_user, item: book
92
93
  end
93
94
  end
94
95
  ```
@@ -21,4 +21,5 @@ Gem::Specification.new do |s|
21
21
  s.add_development_dependency 'bundler', '~> 1.9'
22
22
  s.add_development_dependency 'factory_girl'
23
23
  s.add_development_dependency 'rake', '~> 10.0'
24
+ s.add_development_dependency 'rspec-its'
24
25
  end
@@ -1,6 +1,7 @@
1
1
  require 'auth_strategist/version'
2
2
  require 'auth_strategist/configuration'
3
3
  require 'auth_strategist/configuration/strategies_registry'
4
+ require 'auth_strategist/errors/unauthorized'
4
5
  require 'auth_strategist/strategy_interface'
5
6
  require 'auth_strategist/authorize'
6
7
  require 'auth_strategist/authorization'
@@ -0,0 +1,9 @@
1
+ module AuthStrategist
2
+ module Errors
3
+ class Unauthorized < StandardError
4
+ def initialize
5
+ super('You are not authorized to perform this action.')
6
+ end
7
+ end
8
+ end
9
+ end
@@ -33,6 +33,10 @@ module AuthStrategist
33
33
  warn("#{self.class}#authorize! was not implemented.")
34
34
  end
35
35
 
36
+ def unauthorized
37
+ AuthStrategist::Errors::Unauthorized
38
+ end
39
+
36
40
  private
37
41
 
38
42
  def assign_component_values(attributes = {})
@@ -1,3 +1,3 @@
1
1
  module AuthStrategist
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -29,6 +29,10 @@ describe AuthStrategist::StrategyInterface do
29
29
  expect(strategy_class.new).to respond_to(:authorize!)
30
30
  end
31
31
 
32
+ it 'adds #unauthorized method to base' do
33
+ expect(strategy_class.new).to respond_to(:unauthorized)
34
+ end
35
+
32
36
  it 'adds getters for default components to base' do
33
37
  default_components.each do |c|
34
38
  expect(strategy_class.new).to respond_to(c)
@@ -128,7 +132,7 @@ describe AuthStrategist::StrategyInterface do
128
132
  it 'assigns components values properly' do
129
133
  expect(subject.user).to eq('john')
130
134
  expect(subject.password).to eq('rambo')
131
- expect { subject.missing_component }.to raise_error
135
+ expect { subject.missing_component }.to raise_error(NoMethodError)
132
136
  end
133
137
  end
134
138
 
@@ -162,5 +166,11 @@ describe AuthStrategist::StrategyInterface do
162
166
  end
163
167
  end
164
168
  end
169
+
170
+ describe '#unauthorized' do
171
+ subject { strategy_class.new }
172
+
173
+ it { expect(subject.unauthorized).to eq(AuthStrategist::Errors::Unauthorized) }
174
+ end
165
175
  end
166
176
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auth_strategist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Krzysztof Buszewicz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-07 00:00:00.000000000 Z
11
+ date: 2018-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-its
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description:
56
70
  email:
57
71
  - krzysztof.buszewicz@gmail.com
@@ -75,6 +89,7 @@ files:
75
89
  - lib/auth_strategist/authorize.rb
76
90
  - lib/auth_strategist/configuration.rb
77
91
  - lib/auth_strategist/configuration/strategies_registry.rb
92
+ - lib/auth_strategist/errors/unauthorized.rb
78
93
  - lib/auth_strategist/strategy_interface.rb
79
94
  - lib/auth_strategist/version.rb
80
95
  - lib/generators/auth_strategist/install_generator.rb
@@ -110,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
125
  version: '0'
111
126
  requirements: []
112
127
  rubyforge_project:
113
- rubygems_version: 2.4.5
128
+ rubygems_version: 2.6.8
114
129
  signing_key:
115
130
  specification_version: 4
116
131
  summary: Simple gem to realize API actions authorization with different strategies.
@@ -126,4 +141,3 @@ test_files:
126
141
  - spec/factories/authorize.rb
127
142
  - spec/spec_helper.rb
128
143
  - spec/strategy_interface_spec.rb
129
- has_rdoc: