Skip to content

Commit

Permalink
Fix: Moved the Google Omniauth key id_info from root into extra (#1181)
Browse files Browse the repository at this point in the history
* Moved the Google Omniauth key id_info from root into extra as this is where it rightfully belongs. Here's the details from the omniauth-google-oauth2 docs about the hash structure https://github.com/zquestz/omniauth-google-oauth2#auth-hash

* Omniauth types changes, some booleans should have been strings, some strings should have been booleans and fixnums, these types were taken from the omniauth-google docs. https://github.com/zquestz/omniauth-google-oauth2#auth-hash - I found my code which was passing tests was failing in production because the real life auth hash didn't match that faked.

* Fixed rubocop violations.
  • Loading branch information
SirRawlins authored and vbrazo committed May 16, 2018
1 parent e1f6395 commit b36e1d3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
26 changes: 13 additions & 13 deletions lib/faker/omniauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def google(name: nil, email: nil, uid: Number.number(9))
raw_info: {
sub: uid,
email: auth.email,
email_verified: random_boolean,
email_verified: random_boolean.to_s,
name: auth.name,
given_name: auth.first_name,
family_name: auth.last_name,
Expand All @@ -45,19 +45,19 @@ def google(name: nil, email: nil, uid: Number.number(9))
birthday: Date.backward(36_400).strftime('%Y-%m-%d'),
local: 'en',
hd: "#{Company.name.downcase}.com"
},
id_info: {
'iss' => 'accounts.google.com',
'at_hash' => Crypto.md5,
'email_verified' => true,
'sub' => Number.number(28).to_s,
'azp' => 'APP_ID',
'email' => auth.email,
'aud' => 'APP_ID',
'iat' => Time.forward.to_i,
'exp' => Time.forward.to_i,
'openid_id' => "https://www.google.com/accounts/o8/id?id=#{uid}"
}
},
id_info: {
'iss' => 'accounts.google.com',
'at_hash' => Crypto.md5,
'email_verified' => 'true',
'sub' => Number.number(28).to_s,
'azp' => 'APP_ID',
'email' => auth.email,
'aud' => 'APP_ID',
'iat' => Number.number(10),
'exp' => Time.forward.to_i.to_s,
'openid_id' => "https://www.google.com/accounts/o8/id?id=#{uid}"
}
}
end
Expand Down
12 changes: 6 additions & 6 deletions test/test_faker_omniauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_omniauth_google
info = auth[:info]
credentials = auth[:credentials]
extra_raw_info = auth[:extra][:raw_info]
id_info = auth[:id_info]
id_info = auth[:extra][:id_info]
plus_url = "https://plus.google.com/#{auth[:uid]}"
openid_id = "https://www.google.com/accounts/o8/id?id=#{auth[:uid]}"

Expand All @@ -34,7 +34,7 @@ def test_omniauth_google
assert_equal true, credentials[:expires]
assert_equal 9, extra_raw_info[:sub].length
assert_equal info[:email], extra_raw_info[:email]
assert [true, false].include? extra_raw_info[:email_verified]
assert %w[true false].include? extra_raw_info[:email_verified]
assert_equal info[:name], extra_raw_info[:name]
assert_equal info[:first_name], extra_raw_info[:given_name]
assert_equal info[:last_name], extra_raw_info[:family_name]
Expand All @@ -46,13 +46,13 @@ def test_omniauth_google
assert_instance_of String, extra_raw_info[:hd]
assert_equal 'accounts.google.com', id_info['iss']
assert_instance_of String, id_info['at_hash']
assert_instance_of String, id_info['email_verified']
assert [true, false].include? id_info['email_verified']
assert_equal 28, id_info['sub'].length
assert_equal 'APP_ID', id_info['azp']
assert_equal info[:email], id_info['email']
assert_equal 'APP_ID', id_info['aud']
assert_instance_of String, id_info['iat']
assert_instance_of String, id_info['exp']
assert_instance_of Fixnum, id_info['iat']
assert_instance_of Fixnum, id_info['exp']
assert_equal openid_id, id_info['openid_id']
end

Expand All @@ -79,7 +79,7 @@ def test_omniauth_google_with_email
auth = @tester.google(email: custom_email)
info = auth[:info]
extra_raw_info = auth[:extra][:raw_info]
id_info = auth[:id_info]
id_info = auth[:extra][:id_info]

assert_instance_of String, info[:email]
assert_equal custom_email, info[:email]
Expand Down

0 comments on commit b36e1d3

Please sign in to comment.