machina-auth 0.1.7 → 0.1.8

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
  SHA256:
3
- metadata.gz: 376d280c6510f8afa38049e22a0c73df81355c57571b83ef571d547e340ee7c3
4
- data.tar.gz: 13ce052358975310f67e3b3a65daee423fb48ddc9e2490632b548c66aa0f32d9
3
+ metadata.gz: a6d8d740d4e6998400a56db8fe506ce1155221bb7ff216fedda0c48ced30aa06
4
+ data.tar.gz: bbaf611e06b06f3f8fdf767203ec2106504ba97d8cc4e548881ca5f6909df611
5
5
  SHA512:
6
- metadata.gz: 271245b4d9c4e3a28d4feafe688d9c3e1985d28566f5f86037ab68ef76fa246f266c67b5dad94ad0d23b111844f9c9e9224e656f97bdeaf9ef76efaf4f18311b
7
- data.tar.gz: f719e7340acaab6a85ea6b96408c639e0608c797dcbd64f57fa9f5fa76921c5a6ccaac3d0c2751932d77de0ca1019fd4f127479f9b461686b6b0b36c99206c95
6
+ metadata.gz: 3ca99f12ea236b7a17a84cadc439aa713344c37b2ba2d9a4f59c9d6938b3a7a92f9994f6e79ace9a52203ef64d8dbf3733978f53d70502e14b164efb2bd013f3
7
+ data.tar.gz: 0c01bf88a2ae86779fcbb2e73ddf94e3269169cade8ced2c50a308e10bd2f54d099c00d1c07fadcabaa2fe4a2ec258683e1b4285e227ad7b7d869f7ba9b80b31
@@ -66,12 +66,18 @@ module Machina
66
66
  end
67
67
 
68
68
  def extract_token(request)
69
- request.params['token']
69
+ extract_param_token(request)
70
70
  || request.cookies['machina_session']
71
71
  || extract_bearer(request)
72
72
  || request.headers['X-Api-Key']
73
73
  end
74
74
 
75
+ def extract_param_token(request)
76
+ request.params['token']
77
+ rescue ActionDispatch::Http::Parameters::ParseError
78
+ nil
79
+ end
80
+
75
81
  def extract_bearer(request)
76
82
  auth_header = request.headers['Authorization'].to_s
77
83
  match = auth_header.match(/\ABearer\s+(.+)\z/)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Machina
4
- VERSION = '0.1.7'
4
+ VERSION = '0.1.8'
5
5
  end
@@ -160,6 +160,26 @@ RSpec.describe Machina::Middleware::Authentication do
160
160
  expect(headers['set-cookie']).to be_nil
161
161
  end
162
162
 
163
+ it 'falls through to bearer token when request body is malformed JSON' do
164
+ mock = MockResponses.session_resolution
165
+ allow(identity_client).to receive(:resolve_session).with('ps_bearer').and_return(
166
+ Machina::IdentityClient::Response.new(status: 200, body: mock),
167
+ )
168
+
169
+ env = Rack::MockRequest.env_for(
170
+ '/resource',
171
+ method: 'POST',
172
+ input: 'not valid json',
173
+ 'CONTENT_TYPE' => 'application/json',
174
+ 'HTTP_AUTHORIZATION' => 'Bearer ps_bearer',
175
+ )
176
+
177
+ status, _headers, body = middleware.call(env)
178
+
179
+ expect(status).to eq(200)
180
+ expect(JSON.parse(body.first)['user_id']).to eq(mock['data']['user']['id'])
181
+ end
182
+
163
183
  it 'uses the cache on subsequent requests' do
164
184
  response = Machina::IdentityClient::Response.new(
165
185
  status: 200,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: machina-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - ZAR