drillbit 2.4.0 → 2.5.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: d29c3be0431dc83e7edb1c1cf2d0844b93ea086a
4
- data.tar.gz: c5e5a28648fc56cd51731f5b698da2756bed6b86
3
+ metadata.gz: 7c46b75100d524c1e99a08d7b3c19642e6772743
4
+ data.tar.gz: 64ca903e7fe42f35463cfd41738a70fd7860f052
5
5
  SHA512:
6
- metadata.gz: 2b471ef7bf9d5854779359cbe78a23c024fd2410abdc7a141c93796a084ebeec30c9fe05c3d9a0d05e8ef39b364d02d3ba4bf66253c7bee8009573f594246bcb
7
- data.tar.gz: 81300a8c464efc2c6323319b2da243870f17b2f3acc17490c3bfe9b33d60d14c54c15d421f16d51ad7ab89ca0f61541dff161a69d6a032b4056ada9cc8d8b97c
6
+ metadata.gz: 3d7fb6d5553790fb4010b8132333f6d82117d89ce363f65732aecd4626a3e1a7536f8fe8703c3351649c4b4b65cfce4434587fbfe7dff72ac7bfc8ac7d997058
7
+ data.tar.gz: 2f25c8001b902dfc800d37a4708adecdc10168ef47bad529bc6f0cdbc9d8720b7876b7a37660bff0d5ae9c10c4232f2d7eb3642c66475b6abc7391a4f1af612f
checksums.yaml.gz.sig CHANGED
Binary file
@@ -75,6 +75,7 @@ module AuthorizableResource
75
75
  authorizer_class.
76
76
  new(token: token,
77
77
  user: authorized_user,
78
+ issuer: authorized_issuer,
78
79
  params: authorized_params,
79
80
  resource: authorized_resource)
80
81
  end
@@ -85,6 +86,7 @@ module AuthorizableResource
85
86
  authorizer_scope_class.
86
87
  new(token: token,
87
88
  user: authorized_user,
89
+ issuer: authorized_issuer,
88
90
  params: authorized_params,
89
91
  scope_root: authorized_scope_root).
90
92
  call
@@ -94,11 +96,12 @@ module AuthorizableResource
94
96
  @authorized_params ||= authorizer_params_class.
95
97
  new(token: token,
96
98
  user: authorized_user,
99
+ issuer: authorized_issuer,
97
100
  params: params).
98
101
  call
99
102
  end
100
103
 
101
- # rubocop:disable Style/EmptyLinesAroundBlockBody, Metrics/AbcSize
104
+ # rubocop:disable Metrics/AbcSize
102
105
  def authorized_attributes
103
106
  @authorized_attributes ||= begin
104
107
  attributes = authorized_params.
@@ -163,6 +166,10 @@ module AuthorizableResource
163
166
  current_user
164
167
  end
165
168
 
169
+ def authorized_issuer
170
+ current_issuer
171
+ end
172
+
166
173
  def authorization_query
167
174
  @authorization_query ||= "able_to_#{action_name}?"
168
175
  end
@@ -46,18 +46,24 @@ class Filtering < Authorizers::Parameters
46
46
  end
47
47
  end
48
48
 
49
- def override_filter_parameter(name:,
50
- value:,
51
- only_when_present: false,
52
- override_if_admin: false)
49
+ def add_filter_override(name:,
50
+ value:,
51
+ only_when_present: false,
52
+ override_if_admin: false)
53
53
 
54
54
  add_filterable_parameter name
55
55
 
56
56
  return true if !override_if_admin && token.admin?
57
57
 
58
+ param = params.
59
+ fetch(:filter, {}).
60
+ fetch(name, nil)
61
+
62
+ return if !param && only_when_present
63
+
58
64
  params[:filter] ||= {}
59
65
 
60
- params[:filter][name] = value if params[:filter][name] || !only_when_present
66
+ params[:filter][name] = value
61
67
  end
62
68
  end
63
69
  end
@@ -65,6 +65,28 @@ class Resource < Authorizers::Parameters
65
65
  add_authorized_relationship(name)
66
66
  end
67
67
  end
68
+
69
+ def add_attribute_override(name:,
70
+ value:,
71
+ only_when_present: false,
72
+ override_if_admin: false)
73
+
74
+ add_authorized_attribute name
75
+
76
+ return true if !override_if_admin && token.admin?
77
+
78
+ param = params.
79
+ fetch(:data, {}).
80
+ fetch(:attributes, {}).
81
+ fetch(name, nil)
82
+
83
+ return if !param && only_when_present
84
+
85
+ params[:data] ||= {}
86
+ params[:data][:attributes] ||= {}
87
+
88
+ params[:data][:attributes][name] = value
89
+ end
68
90
  end
69
91
  end
70
92
  end
@@ -6,7 +6,7 @@ class Parameters
6
6
  :user,
7
7
  :params
8
8
 
9
- def initialize(token:, user:, params:, **other)
9
+ def initialize(token:, user:, issuer:, params:, **other)
10
10
  self.token = token
11
11
  self.user = user
12
12
  self.params = params
@@ -7,7 +7,8 @@ class Query
7
7
  :params,
8
8
  :resource
9
9
 
10
- def initialize(token:, user:, params:, resource:, **other)
10
+ # rubocop:disable Metrics/ParameterLists
11
+ def initialize(token:, user:, issuer:, params:, resource:, **other)
11
12
  self.token = token
12
13
  self.user = user
13
14
  self.params = params
@@ -17,6 +18,7 @@ class Query
17
18
  public_send("#{name}=", value)
18
19
  end
19
20
  end
21
+ # rubocop:enable Metrics/ParameterLists
20
22
 
21
23
  def able_to_index?
22
24
  false
@@ -9,7 +9,8 @@ class Scope
9
9
  :params,
10
10
  :scope_root
11
11
 
12
- def initialize(token:, user:, params:, scope_root:, **other)
12
+ # rubocop:disable Metrics/ParameterLists
13
+ def initialize(token:, user:, issuer:, params:, scope_root:, **other)
13
14
  self.token = token
14
15
  self.user = user
15
16
  self.params = params
@@ -19,6 +20,7 @@ class Scope
19
20
  public_send("#{name}=", value)
20
21
  end
21
22
  end
23
+ # rubocop:enable Metrics/ParameterLists
22
24
 
23
25
  def user_scope
24
26
  scope_root.public_send("for_#{user_underscored_class_name}", scope_user_id)
@@ -14,7 +14,7 @@ class ParameterParser
14
14
  def call(env)
15
15
  env['QUERY_STRING'] = underscore_query_string(env['QUERY_STRING'])
16
16
 
17
- if env['CONTENT_LENGTH'].to_i > 0 && env['CONTENT_TYPE'] =~ /json/
17
+ if env['CONTENT_LENGTH'].to_i.positive? && env['CONTENT_TYPE'] =~ /json/
18
18
  if env['rack.input']
19
19
  underscored_input = underscore_request_parameters(env['rack.input'])
20
20
  env['rack.input'] = StringIO.new(underscored_input)
@@ -33,7 +33,7 @@ class ParameterParser
33
33
  private
34
34
 
35
35
  def underscore_request_parameters(request_parameters)
36
- data = JSON.load(request_parameters)
36
+ data = JSON.parse(request_parameters)
37
37
  data = underscore_parameters(data)
38
38
 
39
39
  JSON.dump(data)
@@ -5,6 +5,7 @@ require 'drillbit/accept_header'
5
5
  require 'drillbit/tokens/json_web_token'
6
6
  require 'drillbit/tokens/base64'
7
7
 
8
+ # rubocop:disable Style/VariableNumber
8
9
  module Drillbit
9
10
  module Requests
10
11
  class Rack < Base
@@ -49,3 +50,4 @@ class Rack < Base
49
50
  end
50
51
  end
51
52
  end
53
+ # rubocop:enable Style/VariableNumber
@@ -9,13 +9,13 @@ module Drillbit
9
9
  module Requests
10
10
  class Rails < Base
11
11
  def authorization_token_from_params
12
- if request.params.key?(JSON_WEB_TOKEN_PARAM_NAME)
12
+ if request.params.has_key?(JSON_WEB_TOKEN_PARAM_NAME)
13
13
  Tokens::JsonWebToken.__send__(
14
14
  "from_#{Drillbit.configuration.token_type.downcase}",
15
15
  request.params[JSON_WEB_TOKEN_PARAM_NAME] || '',
16
16
  private_key: token_private_key,
17
17
  )
18
- elsif request.params.key?(BASE64_TOKEN_PARAM_NAME)
18
+ elsif request.params.has_key?(BASE64_TOKEN_PARAM_NAME)
19
19
  Tokens::Base64.convert(raw_token: request.params[BASE64_TOKEN_PARAM_NAME] || '')
20
20
  else
21
21
  Tokens::Null.instance
@@ -29,7 +29,7 @@ class Filtering
29
29
 
30
30
  if !filter_method
31
31
  filtered_resource
32
- elsif filter_method.arity == 0
32
+ elsif filter_method.arity.zero?
33
33
  filtered_resource.public_send(filter_method.name)
34
34
  else
35
35
  filtered_resource.public_send(filter_method.name, value)
@@ -9,7 +9,7 @@ class PasswordReset < JsonWebToken
9
9
  roles: ['password_reset'],
10
10
  **attrs)
11
11
 
12
- super(expiration: expiration, roles: roles, **attrs)
12
+ super(:expiration => expiration, :roles => roles, **attrs)
13
13
  end
14
14
  end
15
15
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Drillbit
3
- VERSION = '2.4.0'
3
+ VERSION = '2.5.0'
4
4
  end
@@ -11,6 +11,7 @@ describe Filtering do
11
11
  it 'can authorize new filter parameters', verify: false do
12
12
  filter_params = Filtering.new(token: '1234',
13
13
  user: '1234',
14
+ issuer: 'my_issuer',
14
15
  params: params)
15
16
 
16
17
  allow(params).to receive(:permit)
@@ -31,6 +32,7 @@ describe Filtering do
31
32
  }
32
33
  filter_params = Filtering.new(token: '1234',
33
34
  user: '1234',
35
+ issuer: 'my_issuer',
34
36
  params: params)
35
37
 
36
38
  allow(params).to receive(:permit)
@@ -45,6 +47,7 @@ describe Filtering do
45
47
  it 'has default authorized parameters', verify: false do
46
48
  filter_params = Filtering.new(token: '1234',
47
49
  user: '1234',
50
+ issuer: 'my_issuer',
48
51
  params: params)
49
52
 
50
53
  allow(params).to receive(:permit)
@@ -8,6 +8,7 @@ describe Parameters do
8
8
  it 'defaults to nothing' do
9
9
  parameters = Parameters.new(token: '123',
10
10
  user: 'my_user',
11
+ issuer: 'my_issuer',
11
12
  params: { foo: 'bar' })
12
13
 
13
14
  expect(parameters.call).to eql(foo: 'bar')
@@ -8,6 +8,7 @@ describe Query do
8
8
  it 'does not authorize the resource by default' do
9
9
  authorizer = Query.new(token: '123',
10
10
  user: 'my_user',
11
+ issuer: 'my_issuer',
11
12
  resource: 'my_resource',
12
13
  params: 'my_params')
13
14
 
@@ -9,6 +9,7 @@ describe Scope do
9
9
  it 'defaults to nothing' do
10
10
  scope = Scope.new(token: '123',
11
11
  user: Object.new,
12
+ issuer: 'my_issuer',
12
13
  params: {},
13
14
  scope_root: OpenStruct.new(none: []))
14
15
 
@@ -33,6 +33,7 @@ def invalid_jwe_token
33
33
  @invalid_jwe_token ||= valid_jwe_token.tr('a', 'f')
34
34
  end
35
35
 
36
+ # rubocop:disable Style/VariableNumber
36
37
  def valid_b64_token(payload = 'hereisacoollittlestring')
37
38
  @valid_b64_token ||= Base64.encode64(payload).chomp
38
39
  end
@@ -40,3 +41,4 @@ end
40
41
  def invalid_b64_token
41
42
  @invalid_b64_token ||= valid_b64_token.tr('abcdefghijklmnop', '$o#m$k#i$g#e$c#a')
42
43
  end
44
+ # rubocop:enable Style/VariableNumber
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drillbit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thegranddesign
@@ -31,7 +31,7 @@ cert_chain:
31
31
  zRIv8lqQM8QFT76rzP5SBCERwN+ltKAFbQ5/FwmZNGWYnmCP3RZMQiRnbh+9H9lh
32
32
  mlbwaYZTjgsXq6cy8N38EecewgBbZYS1IYJraE/M
33
33
  -----END CERTIFICATE-----
34
- date: 2016-09-07 00:00:00.000000000 Z
34
+ date: 2016-10-17 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: erratum
@@ -269,4 +269,3 @@ test_files:
269
269
  - spec/fixtures/test_rsa_key.pub
270
270
  - spec/spec_helper.rb
271
271
  - spec/support/private_keys.rb
272
- has_rdoc:
metadata.gz.sig CHANGED
Binary file