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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a6d8d740d4e6998400a56db8fe506ce1155221bb7ff216fedda0c48ced30aa06
|
|
4
|
+
data.tar.gz: bbaf611e06b06f3f8fdf767203ec2106504ba97d8cc4e548881ca5f6909df611
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
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/)
|
data/lib/machina/version.rb
CHANGED
|
@@ -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,
|