mauth-client 6.3.0 → 6.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/mauth/rack.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mauth/middleware'
2
4
  require 'mauth/request_and_response'
3
5
  require 'rack/utils'
@@ -41,7 +43,7 @@ module MAuth
41
43
  # discards the body if REQUEST_METHOD is HEAD. sets the Content-Length.
42
44
  def handle_head(env)
43
45
  status, headers, body = *yield
44
- headers["Content-Length"] = body.map(&:bytesize).inject(0, &:+).to_s
46
+ headers['Content-Length'] = body.sum(&:bytesize).to_s
45
47
  [status, headers, env['REQUEST_METHOD'].casecmp('head').zero? ? [] : body]
46
48
  end
47
49
 
@@ -75,7 +77,8 @@ module MAuth
75
77
  handle_head(env) do
76
78
  body = {
77
79
  'type' => 'errors:mauth:missing_v2',
78
- 'title' => 'This service requires mAuth v2 mcc-authentication header. Upgrade your mAuth library and configure it properly.'
80
+ 'title' => 'This service requires mAuth v2 mcc-authentication header. Upgrade your mAuth library and ' \
81
+ 'configure it properly.'
79
82
  }
80
83
  [401, { 'Content-Type' => 'application/json' }, [JSON.pretty_generate(body)]]
81
84
  end
@@ -85,7 +88,7 @@ module MAuth
85
88
  # same as MAuth::Rack::RequestAuthenticator, but does not authenticate /app_status
86
89
  class RequestAuthenticatorNoAppStatus < RequestAuthenticator
87
90
  def should_authenticate?(env)
88
- env['PATH_INFO'] != "/app_status" && super
91
+ env['PATH_INFO'] != '/app_status' && super
89
92
  end
90
93
  end
91
94
 
@@ -95,9 +98,10 @@ module MAuth
95
98
  unsigned_response = @app.call(env)
96
99
 
97
100
  method =
98
- if env['mauth.protocol_version'] == 2
101
+ case env['mauth.protocol_version']
102
+ when 2
99
103
  :signed_v2
100
- elsif env['mauth.protocol_version'] == 1
104
+ when 1
101
105
  :signed_v1
102
106
  else
103
107
  # if no protocol was supplied then use `signed` which either signs
@@ -115,6 +119,7 @@ module MAuth
115
119
  class Request < MAuth::Request
116
120
  include Signed
117
121
  attr_reader :env
122
+
118
123
  def initialize(env)
119
124
  @env = env
120
125
  end
@@ -166,7 +171,10 @@ module MAuth
166
171
  def attributes_for_signing
167
172
  @attributes_for_signing ||= begin
168
173
  body = ''
169
- @body.each { |part| body << part } # note: rack only requires #each be defined on the body, so not using map or inject
174
+ # NOTE: rack only requires #each be defined on the body, so not using map or inject
175
+ @body.each do |part|
176
+ body << part
177
+ end
170
178
  { status_code: @status.to_i, body: body }
171
179
  end
172
180
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'openssl'
2
4
  require 'addressable'
3
5
 
@@ -31,11 +33,15 @@ module MAuth
31
33
  # current_seconds_since_epoch
32
34
  def string_to_sign_v1(more_attributes)
33
35
  attributes_for_signing = self.attributes_for_signing.merge(more_attributes)
34
- missing_attributes = self.class::SIGNATURE_COMPONENTS.select { |key| !attributes_for_signing.key?(key) || attributes_for_signing[key].nil? }
36
+ missing_attributes = self.class::SIGNATURE_COMPONENTS.select do |key|
37
+ !attributes_for_signing.key?(key) || attributes_for_signing[key].nil?
38
+ end
35
39
  missing_attributes.delete(:body) # body may be omitted
36
40
  if missing_attributes.any?
37
- raise(UnableToSignError, "Missing required attributes to sign: #{missing_attributes.inspect}\non object to sign: #{inspect}")
41
+ raise(UnableToSignError,
42
+ "Missing required attributes to sign: #{missing_attributes.inspect}\non object to sign: #{inspect}")
38
43
  end
44
+
39
45
  self.class::SIGNATURE_COMPONENTS.map { |k| attributes_for_signing[k].to_s }.join("\n")
40
46
  end
41
47
 
@@ -56,23 +62,25 @@ module MAuth
56
62
  # app_uuid + <LF> +
57
63
  # current_seconds_since_epoch
58
64
  def string_to_sign_v2(override_attrs)
59
- attrs_with_overrides = self.attributes_for_signing.merge(override_attrs)
65
+ attrs_with_overrides = attributes_for_signing.merge(override_attrs)
60
66
 
61
67
  # memoization of body_digest to avoid hashing three times when we call
62
68
  # string_to_sign_v2 three times in client#signature_valid_v2!
63
69
  # note that if :body is nil we hash an empty string ('')
64
- attrs_with_overrides[:body_digest] ||= OpenSSL::Digest::SHA512.hexdigest(attrs_with_overrides[:body] || '')
65
- attrs_with_overrides[:encoded_query_params] = unescape_encode_query_string(attrs_with_overrides[:query_string] || '')
70
+ attrs_with_overrides[:body_digest] ||= OpenSSL::Digest.hexdigest('SHA512', attrs_with_overrides[:body] || '')
71
+ attrs_with_overrides[:encoded_query_params] =
72
+ unescape_encode_query_string(attrs_with_overrides[:query_string] || '')
66
73
  attrs_with_overrides[:request_url] = normalize_path(attrs_with_overrides[:request_url])
67
74
 
68
75
  missing_attributes = self.class::SIGNATURE_COMPONENTS_V2.reject do |key|
69
- attrs_with_overrides.dig(key)
76
+ attrs_with_overrides[key]
70
77
  end
71
78
 
72
79
  missing_attributes.delete(:body_digest) # body may be omitted
73
80
  missing_attributes.delete(:encoded_query_params) # query_string may be omitted
74
81
  if missing_attributes.any?
75
- raise(UnableToSignError, "Missing required attributes to sign: #{missing_attributes.inspect}\non object to sign: #{inspect}")
82
+ raise(UnableToSignError,
83
+ "Missing required attributes to sign: #{missing_attributes.inspect}\non object to sign: #{inspect}")
76
84
  end
77
85
 
78
86
  self.class::SIGNATURE_COMPONENTS_V2.map do |k|
@@ -88,17 +96,17 @@ module MAuth
88
96
  # i.e. /./example => /example ; /example/.. => /
89
97
  # String#squeeze removes duplicated slahes i.e. /// => /
90
98
  # String#gsub normalizes percent encoding to uppercase i.e. %cf%80 => %CF%80
91
- Addressable::URI.normalize_path(path).squeeze('/').
92
- gsub(/%[a-f0-9]{2}/, &:upcase)
99
+ Addressable::URI.normalize_path(path).squeeze('/')
100
+ .gsub(/%[a-f0-9]{2}/, &:upcase)
93
101
  end
94
102
 
95
103
  # sorts query string parameters by codepoint, uri encodes keys and values,
96
104
  # and rejoins parameters into a query string
97
105
  def unescape_encode_query_string(q_string)
98
- fir = q_string.split('&').map do |part|
106
+ q_string.split('&').map do |part|
99
107
  k, _eq, v = part.partition('=')
100
108
  [CGI.unescape(k), CGI.unescape(v)]
101
- end.sort.map do |k, v|
109
+ end.sort.map do |k, v| # rubocop:disable Style/MultilineBlockChain
102
110
  "#{uri_escape(k)}=#{uri_escape(v)}"
103
111
  end.join('&')
104
112
  end
@@ -172,7 +180,7 @@ module MAuth
172
180
 
173
181
  def mcc_data
174
182
  mcc_authentication&.match(
175
- /\A(#{MAuth::Client::MWSV2_TOKEN}) ([^:]+):([^:]+)#{MAuth::Client::AUTH_HEADER_DELIMITER}\z/
183
+ /\A(#{MAuth::Client::MWSV2_TOKEN}) ([^:]+):([^:]+)#{MAuth::Client::AUTH_HEADER_DELIMITER}\z/o
176
184
  )
177
185
  end
178
186
 
data/lib/mauth/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MAuth
4
- VERSION = '6.3.0'
4
+ VERSION = '6.4.0'
5
5
  end
data/lib/mauth-client.rb CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mauth/client'
data/lib/rack/mauth.rb CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mauth/rack'
data/mauth-client.gemspec CHANGED
@@ -1,4 +1,6 @@
1
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'mauth/version'
4
6
 
@@ -8,33 +10,36 @@ Gem::Specification.new do |spec|
8
10
  spec.authors = ['Matthew Szenher', 'Aaron Suggs', 'Geoffrey Ducharme', 'Ethan']
9
11
  spec.email = ['mszenher@mdsol.com']
10
12
  spec.summary = 'Sign and authenticate requests and responses with mAuth authentication.'
11
- spec.description = 'Client for signing and authentication of requests and responses with mAuth authentication. Includes middleware for Rack and Faraday for incoming and outgoing requests and responses.'
13
+ spec.description = 'Client for signing and authentication of requests and responses with mAuth authentication. ' \
14
+ 'Includes middleware for Rack and Faraday for incoming and outgoing requests and responses.'
12
15
  spec.homepage = 'https://github.com/mdsol/mauth-client-ruby'
13
16
  spec.license = 'MIT'
14
- spec.required_ruby_version = '>= 2.5.0'
17
+ spec.required_ruby_version = '>= 2.6.0'
15
18
 
16
19
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
20
  spec.bindir = 'exe'
18
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
22
  spec.require_paths = ['lib']
20
23
 
21
- spec.add_dependency 'faraday', '>= 0.9', '< 2.0'
22
- spec.add_dependency 'faraday_middleware', '>= 0.9', '< 2.0'
23
- spec.add_dependency 'faraday-http-cache', '>= 2.0', '< 3.0'
24
- spec.add_dependency 'term-ansicolor', '~> 1.0'
24
+ spec.add_dependency 'addressable', '~> 2.0'
25
25
  spec.add_dependency 'coderay', '~> 1.0'
26
- spec.add_dependency 'rack'
27
26
  spec.add_dependency 'dice_bag', '>= 0.9', '< 2.0'
28
- spec.add_dependency 'addressable', '~> 2.0'
27
+ spec.add_dependency 'faraday', '>= 0.9', '< 3.0'
28
+ spec.add_dependency 'faraday-http-cache', '>= 2.0', '< 3.0'
29
+ spec.add_dependency 'rack'
30
+ spec.add_dependency 'term-ansicolor', '~> 1.0'
29
31
 
30
32
  spec.add_development_dependency 'appraisal'
33
+ spec.add_development_dependency 'benchmark-ips', '~> 2.7'
31
34
  spec.add_development_dependency 'bundler', '>= 1.17'
32
35
  spec.add_development_dependency 'byebug'
33
36
  spec.add_development_dependency 'rack-test', '~> 1.1.0'
34
37
  spec.add_development_dependency 'rake', '~> 12.0'
35
38
  spec.add_development_dependency 'rspec', '~> 3.8'
39
+ spec.add_development_dependency 'rubocop', '= 1.25.1'
40
+ spec.add_development_dependency 'rubocop-mdsol', '~> 0.1'
41
+ spec.add_development_dependency 'rubocop-performance', '= 1.13.2'
36
42
  spec.add_development_dependency 'simplecov', '~> 0.16'
37
43
  spec.add_development_dependency 'timecop', '~> 0.9'
38
- spec.add_development_dependency 'benchmark-ips', '~> 2.7'
39
44
  spec.add_development_dependency 'webmock', '~> 3.0'
40
45
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mauth-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.3.0
4
+ version: 6.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Szenher
@@ -11,10 +11,38 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2021-10-20 00:00:00.000000000 Z
14
+ date: 2022-02-25 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
- name: faraday
17
+ name: addressable
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: coderay
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - "~>"
35
+ - !ruby/object:Gem::Version
36
+ version: '1.0'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.0'
44
+ - !ruby/object:Gem::Dependency
45
+ name: dice_bag
18
46
  requirement: !ruby/object:Gem::Requirement
19
47
  requirements:
20
48
  - - ">="
@@ -34,7 +62,7 @@ dependencies:
34
62
  - !ruby/object:Gem::Version
35
63
  version: '2.0'
36
64
  - !ruby/object:Gem::Dependency
37
- name: faraday_middleware
65
+ name: faraday
38
66
  requirement: !ruby/object:Gem::Requirement
39
67
  requirements:
40
68
  - - ">="
@@ -42,7 +70,7 @@ dependencies:
42
70
  version: '0.9'
43
71
  - - "<"
44
72
  - !ruby/object:Gem::Version
45
- version: '2.0'
73
+ version: '3.0'
46
74
  type: :runtime
47
75
  prerelease: false
48
76
  version_requirements: !ruby/object:Gem::Requirement
@@ -52,7 +80,7 @@ dependencies:
52
80
  version: '0.9'
53
81
  - - "<"
54
82
  - !ruby/object:Gem::Version
55
- version: '2.0'
83
+ version: '3.0'
56
84
  - !ruby/object:Gem::Dependency
57
85
  name: faraday-http-cache
58
86
  requirement: !ruby/object:Gem::Requirement
@@ -74,21 +102,21 @@ dependencies:
74
102
  - !ruby/object:Gem::Version
75
103
  version: '3.0'
76
104
  - !ruby/object:Gem::Dependency
77
- name: term-ansicolor
105
+ name: rack
78
106
  requirement: !ruby/object:Gem::Requirement
79
107
  requirements:
80
- - - "~>"
108
+ - - ">="
81
109
  - !ruby/object:Gem::Version
82
- version: '1.0'
110
+ version: '0'
83
111
  type: :runtime
84
112
  prerelease: false
85
113
  version_requirements: !ruby/object:Gem::Requirement
86
114
  requirements:
87
- - - "~>"
115
+ - - ">="
88
116
  - !ruby/object:Gem::Version
89
- version: '1.0'
117
+ version: '0'
90
118
  - !ruby/object:Gem::Dependency
91
- name: coderay
119
+ name: term-ansicolor
92
120
  requirement: !ruby/object:Gem::Requirement
93
121
  requirements:
94
122
  - - "~>"
@@ -102,13 +130,13 @@ dependencies:
102
130
  - !ruby/object:Gem::Version
103
131
  version: '1.0'
104
132
  - !ruby/object:Gem::Dependency
105
- name: rack
133
+ name: appraisal
106
134
  requirement: !ruby/object:Gem::Requirement
107
135
  requirements:
108
136
  - - ">="
109
137
  - !ruby/object:Gem::Version
110
138
  version: '0'
111
- type: :runtime
139
+ type: :development
112
140
  prerelease: false
113
141
  version_requirements: !ruby/object:Gem::Requirement
114
142
  requirements:
@@ -116,53 +144,19 @@ dependencies:
116
144
  - !ruby/object:Gem::Version
117
145
  version: '0'
118
146
  - !ruby/object:Gem::Dependency
119
- name: dice_bag
120
- requirement: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0.9'
125
- - - "<"
126
- - !ruby/object:Gem::Version
127
- version: '2.0'
128
- type: :runtime
129
- prerelease: false
130
- version_requirements: !ruby/object:Gem::Requirement
131
- requirements:
132
- - - ">="
133
- - !ruby/object:Gem::Version
134
- version: '0.9'
135
- - - "<"
136
- - !ruby/object:Gem::Version
137
- version: '2.0'
138
- - !ruby/object:Gem::Dependency
139
- name: addressable
147
+ name: benchmark-ips
140
148
  requirement: !ruby/object:Gem::Requirement
141
149
  requirements:
142
150
  - - "~>"
143
151
  - !ruby/object:Gem::Version
144
- version: '2.0'
145
- type: :runtime
146
- prerelease: false
147
- version_requirements: !ruby/object:Gem::Requirement
148
- requirements:
149
- - - "~>"
150
- - !ruby/object:Gem::Version
151
- version: '2.0'
152
- - !ruby/object:Gem::Dependency
153
- name: appraisal
154
- requirement: !ruby/object:Gem::Requirement
155
- requirements:
156
- - - ">="
157
- - !ruby/object:Gem::Version
158
- version: '0'
152
+ version: '2.7'
159
153
  type: :development
160
154
  prerelease: false
161
155
  version_requirements: !ruby/object:Gem::Requirement
162
156
  requirements:
163
- - - ">="
157
+ - - "~>"
164
158
  - !ruby/object:Gem::Version
165
- version: '0'
159
+ version: '2.7'
166
160
  - !ruby/object:Gem::Dependency
167
161
  name: bundler
168
162
  requirement: !ruby/object:Gem::Requirement
@@ -234,47 +228,75 @@ dependencies:
234
228
  - !ruby/object:Gem::Version
235
229
  version: '3.8'
236
230
  - !ruby/object:Gem::Dependency
237
- name: simplecov
231
+ name: rubocop
232
+ requirement: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - '='
235
+ - !ruby/object:Gem::Version
236
+ version: 1.25.1
237
+ type: :development
238
+ prerelease: false
239
+ version_requirements: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - '='
242
+ - !ruby/object:Gem::Version
243
+ version: 1.25.1
244
+ - !ruby/object:Gem::Dependency
245
+ name: rubocop-mdsol
238
246
  requirement: !ruby/object:Gem::Requirement
239
247
  requirements:
240
248
  - - "~>"
241
249
  - !ruby/object:Gem::Version
242
- version: '0.16'
250
+ version: '0.1'
243
251
  type: :development
244
252
  prerelease: false
245
253
  version_requirements: !ruby/object:Gem::Requirement
246
254
  requirements:
247
255
  - - "~>"
248
256
  - !ruby/object:Gem::Version
249
- version: '0.16'
257
+ version: '0.1'
250
258
  - !ruby/object:Gem::Dependency
251
- name: timecop
259
+ name: rubocop-performance
260
+ requirement: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - '='
263
+ - !ruby/object:Gem::Version
264
+ version: 1.13.2
265
+ type: :development
266
+ prerelease: false
267
+ version_requirements: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - '='
270
+ - !ruby/object:Gem::Version
271
+ version: 1.13.2
272
+ - !ruby/object:Gem::Dependency
273
+ name: simplecov
252
274
  requirement: !ruby/object:Gem::Requirement
253
275
  requirements:
254
276
  - - "~>"
255
277
  - !ruby/object:Gem::Version
256
- version: '0.9'
278
+ version: '0.16'
257
279
  type: :development
258
280
  prerelease: false
259
281
  version_requirements: !ruby/object:Gem::Requirement
260
282
  requirements:
261
283
  - - "~>"
262
284
  - !ruby/object:Gem::Version
263
- version: '0.9'
285
+ version: '0.16'
264
286
  - !ruby/object:Gem::Dependency
265
- name: benchmark-ips
287
+ name: timecop
266
288
  requirement: !ruby/object:Gem::Requirement
267
289
  requirements:
268
290
  - - "~>"
269
291
  - !ruby/object:Gem::Version
270
- version: '2.7'
292
+ version: '0.9'
271
293
  type: :development
272
294
  prerelease: false
273
295
  version_requirements: !ruby/object:Gem::Requirement
274
296
  requirements:
275
297
  - - "~>"
276
298
  - !ruby/object:Gem::Version
277
- version: '2.7'
299
+ version: '0.9'
278
300
  - !ruby/object:Gem::Dependency
279
301
  name: webmock
280
302
  requirement: !ruby/object:Gem::Requirement
@@ -304,6 +326,8 @@ files:
304
326
  - ".gitignore"
305
327
  - ".gitmodules"
306
328
  - ".rspec"
329
+ - ".rubocop.yml"
330
+ - ".ruby-version"
307
331
  - ".travis.yml"
308
332
  - ".yardopts"
309
333
  - Appraisals
@@ -327,6 +351,7 @@ files:
327
351
  - exe/mauth-proxy
328
352
  - gemfiles/faraday_0.x.gemfile
329
353
  - gemfiles/faraday_1.x.gemfile
354
+ - gemfiles/faraday_2.x.gemfile
330
355
  - lib/mauth-client.rb
331
356
  - lib/mauth/autoload.rb
332
357
  - lib/mauth/client.rb
@@ -362,7 +387,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
362
387
  requirements:
363
388
  - - ">="
364
389
  - !ruby/object:Gem::Version
365
- version: 2.5.0
390
+ version: 2.6.0
366
391
  required_rubygems_version: !ruby/object:Gem::Requirement
367
392
  requirements:
368
393
  - - ">="