FIX: Appropriately assign values when fetching user details (#100)
FIX: Appropriately assign values when fetching user details
This commit is contained in:
parent
5cd7a79baf
commit
f11229a511
|
@ -84,7 +84,7 @@ class OAuth2BasicAuthenticator < Auth::ManagedAuthenticator
|
||||||
return nil unless fragment.is_a?(Hash) || fragment.is_a?(Array)
|
return nil unless fragment.is_a?(Hash) || fragment.is_a?(Array)
|
||||||
first_seg = segments[seg_index].scan(/([\d+])/).length > 0 ? first_seg.split("[")[0] : first_seg
|
first_seg = segments[seg_index].scan(/([\d+])/).length > 0 ? first_seg.split("[")[0] : first_seg
|
||||||
if fragment.is_a?(Hash)
|
if fragment.is_a?(Hash)
|
||||||
deref = fragment[first_seg] || fragment[first_seg.to_sym]
|
deref = fragment[first_seg]
|
||||||
else
|
else
|
||||||
array_index = 0
|
array_index = 0
|
||||||
if (seg_index > 0)
|
if (seg_index > 0)
|
||||||
|
@ -98,7 +98,7 @@ class OAuth2BasicAuthenticator < Auth::ManagedAuthenticator
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if (deref.blank? || seg_index == segments.size - 1)
|
if deref.blank? || seg_index == segments.size - 1
|
||||||
deref
|
deref
|
||||||
else
|
else
|
||||||
seg_index += 1
|
seg_index += 1
|
||||||
|
@ -113,7 +113,8 @@ class OAuth2BasicAuthenticator < Auth::ManagedAuthenticator
|
||||||
path = path.gsub(".[].", ".").gsub(".[", "[")
|
path = path.gsub(".[].", ".").gsub(".[", "[")
|
||||||
segments = parse_segments(path)
|
segments = parse_segments(path)
|
||||||
val = walk_path(user_json, segments)
|
val = walk_path(user_json, segments)
|
||||||
result[prop] = val if val.present?
|
# [] should be nil, false should be false
|
||||||
|
result[prop] = val.presence || (val == [] ? nil : val)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -312,6 +312,21 @@ describe OAuth2BasicAuthenticator do
|
||||||
expect(result).to eq "http://example.com/1.png"
|
expect(result).to eq "http://example.com/1.png"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "can walk json and appropriately assign a `false`" do
|
||||||
|
authenticator = OAuth2BasicAuthenticator.new
|
||||||
|
json_string = '{"user":{"id":1234, "data": {"address":"test@example.com", "is_cat": false}}}'
|
||||||
|
SiteSetting.oauth2_json_email_verified_path = "user.data.is_cat"
|
||||||
|
result =
|
||||||
|
authenticator.json_walk(
|
||||||
|
{},
|
||||||
|
JSON.parse(json_string),
|
||||||
|
"extra:user.data.is_cat",
|
||||||
|
custom_path: "user.data.is_cat",
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(result).to eq false
|
||||||
|
end
|
||||||
|
|
||||||
describe "token_callback" do
|
describe "token_callback" do
|
||||||
let(:user) { Fabricate(:user) }
|
let(:user) { Fabricate(:user) }
|
||||||
let(:strategy) { OmniAuth::Strategies::Oauth2Basic.new({}) }
|
let(:strategy) { OmniAuth::Strategies::Oauth2Basic.new({}) }
|
||||||
|
|
Loading…
Reference in New Issue