From b36e1d35c615fdfb72ea5e074e0851e455c213d1 Mon Sep 17 00:00:00 2001 From: Robert Rawlins <robrawlins@gmail.com> Date: Wed, 16 May 2018 09:37:25 +0100 Subject: [PATCH] Fix: Moved the Google Omniauth key id_info from root into extra (#1181) * 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. --- lib/faker/omniauth.rb | 26 +++++++++++++------------- test/test_faker_omniauth.rb | 12 ++++++------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/faker/omniauth.rb b/lib/faker/omniauth.rb index d1c43b9352..82b5566c44 100644 --- a/lib/faker/omniauth.rb +++ b/lib/faker/omniauth.rb @@ -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, @@ -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 diff --git a/test/test_faker_omniauth.rb b/test/test_faker_omniauth.rb index 87e3905b1f..fdf3fb9754 100644 --- a/test/test_faker_omniauth.rb +++ b/test/test_faker_omniauth.rb @@ -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]}" @@ -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] @@ -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 @@ -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]