google_sign_in 1.2.1 → 1.3.0
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.
Potentially problematic release.
This version of google_sign_in might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +24 -1
- data/app/controllers/google_sign_in/base_controller.rb +1 -8
- data/app/controllers/google_sign_in/callbacks_controller.rb +7 -0
- data/lib/google_sign_in/engine.rb +12 -1
- data/lib/google_sign_in/redirect_protector.rb +5 -2
- data/lib/google_sign_in.rb +15 -1
- metadata +7 -201
- data/.gitignore +0 -13
- data/.travis.yml +0 -16
- data/CHANGELOG.md +0 -3
- data/Gemfile +0 -6
- data/Gemfile.lock +0 -178
- data/Rakefile +0 -40
- data/bin/rails +0 -16
- data/google_sign_in.gemspec +0 -22
- data/test/certificate.pem +0 -19
- data/test/controllers/authorizations_controller_test.rb +0 -26
- data/test/controllers/callbacks_controller_test.rb +0 -133
- data/test/dummy/.ruby-version +0 -1
- data/test/dummy/Rakefile +0 -6
- data/test/dummy/app/assets/config/manifest.js +0 -3
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +0 -15
- data/test/dummy/app/assets/javascripts/cable.js +0 -13
- data/test/dummy/app/assets/javascripts/channels/.keep +0 -0
- data/test/dummy/app/assets/stylesheets/application.css +0 -15
- data/test/dummy/app/channels/application_cable/channel.rb +0 -4
- data/test/dummy/app/channels/application_cable/connection.rb +0 -4
- data/test/dummy/app/controllers/application_controller.rb +0 -2
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/jobs/application_job.rb +0 -2
- data/test/dummy/app/mailers/application_mailer.rb +0 -4
- data/test/dummy/app/models/application_record.rb +0 -3
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +0 -15
- data/test/dummy/app/views/layouts/mailer.html.erb +0 -13
- data/test/dummy/app/views/layouts/mailer.text.erb +0 -1
- data/test/dummy/bin/bundle +0 -3
- data/test/dummy/bin/rails +0 -4
- data/test/dummy/bin/rake +0 -4
- data/test/dummy/bin/setup +0 -36
- data/test/dummy/bin/update +0 -31
- data/test/dummy/bin/yarn +0 -11
- data/test/dummy/config/application.rb +0 -20
- data/test/dummy/config/boot.rb +0 -5
- data/test/dummy/config/cable.yml +0 -10
- data/test/dummy/config/database.yml +0 -25
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -32
- data/test/dummy/config/environments/production.rb +0 -57
- data/test/dummy/config/environments/test.rb +0 -33
- data/test/dummy/config/initializers/application_controller_renderer.rb +0 -8
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/content_security_policy.rb +0 -25
- data/test/dummy/config/initializers/cookies_serializer.rb +0 -5
- data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/test/dummy/config/initializers/google_sign_in.rb +0 -4
- data/test/dummy/config/initializers/inflections.rb +0 -16
- data/test/dummy/config/initializers/mime_types.rb +0 -4
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -33
- data/test/dummy/config/puma.rb +0 -34
- data/test/dummy/config/routes.rb +0 -2
- data/test/dummy/config/spring.rb +0 -6
- data/test/dummy/config/storage.yml +0 -34
- data/test/dummy/config.ru +0 -5
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/package.json +0 -5
- data/test/dummy/public/404.html +0 -67
- data/test/dummy/public/422.html +0 -67
- data/test/dummy/public/500.html +0 -66
- data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/test/dummy/public/apple-touch-icon.png +0 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/storage/.keep +0 -0
- data/test/dummy/tmp/.keep +0 -0
- data/test/dummy/tmp/storage/.keep +0 -0
- data/test/helpers/button_helper_test.rb +0 -33
- data/test/key.pem +0 -27
- data/test/models/identity_test.rb +0 -88
- data/test/models/redirect_protector_test.rb +0 -40
- data/test/test_helper.rb +0 -28
@@ -1,88 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'jwt'
|
3
|
-
|
4
|
-
class GoogleSignIn::IdentityTest < ActiveSupport::TestCase
|
5
|
-
test "client_id must be set" do
|
6
|
-
switch_client_id_to nil do
|
7
|
-
assert_raises(ArgumentError) { GoogleSignIn::Identity.new("some_fake_token") }
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
test "client_id must be in the token audience" do
|
12
|
-
assert_raises GoogleSignIn::Identity::ValidationError do
|
13
|
-
GoogleSignIn::Identity.new(token_with(aud: "invalid"))
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
test "token must have a valid issuer" do
|
18
|
-
assert_raises GoogleSignIn::Identity::ValidationError do
|
19
|
-
GoogleSignIn::Identity.new(token_with(iss: "invalid"))
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
test "token must be signed with the correct key" do
|
24
|
-
assert_raises GoogleSignIn::Identity::ValidationError do
|
25
|
-
GoogleSignIn::Identity.new(token_with(key: OpenSSL::PKey::RSA.new(2048)))
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
test "token must not be expired" do
|
30
|
-
freeze_time do
|
31
|
-
assert_raises GoogleSignIn::Identity::ValidationError do
|
32
|
-
GoogleSignIn::Identity.new(token_with(iat: 10.minutes.ago.to_i, exp: 5.minutes.ago.to_i))
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
test "extracting user ID" do
|
38
|
-
assert_equal "573222559223877", GoogleSignIn::Identity.new(token_with(sub: "573222559223877")).user_id
|
39
|
-
end
|
40
|
-
|
41
|
-
test "extracting name" do
|
42
|
-
assert_equal "George Claghorn", GoogleSignIn::Identity.new(token_with(name: "George Claghorn")).name
|
43
|
-
end
|
44
|
-
|
45
|
-
test "extracting email address" do
|
46
|
-
assert_equal "george@basecamp.com", GoogleSignIn::Identity.new(token_with(email: "george@basecamp.com")).email_address
|
47
|
-
end
|
48
|
-
|
49
|
-
test "extracting email verification status" do
|
50
|
-
assert GoogleSignIn::Identity.new(token_with(email: "george@basecamp.com", email_verified: true)).email_verified?
|
51
|
-
assert_not GoogleSignIn::Identity.new(token_with(email: "george@basecamp.com", email_verified: false)).email_verified?
|
52
|
-
assert_not GoogleSignIn::Identity.new(token_with(email: "george@basecamp.com")).email_verified?
|
53
|
-
end
|
54
|
-
|
55
|
-
test "extracting avatar URL" do
|
56
|
-
assert_equal "https://example.com/avatar.png",
|
57
|
-
GoogleSignIn::Identity.new(token_with(picture: "https://example.com/avatar.png")).avatar_url
|
58
|
-
end
|
59
|
-
|
60
|
-
test "extracting locale" do
|
61
|
-
assert_equal "en-US", GoogleSignIn::Identity.new(token_with(locale: "en-US")).locale
|
62
|
-
end
|
63
|
-
|
64
|
-
test "extracting hosted G Suite domain" do
|
65
|
-
assert_equal "basecamp.com", GoogleSignIn::Identity.new(token_with(hd: "basecamp.com")).hosted_domain
|
66
|
-
end
|
67
|
-
|
68
|
-
test "extracting given name" do
|
69
|
-
assert_equal "George", GoogleSignIn::Identity.new(token_with(given_name: "George")).given_name
|
70
|
-
end
|
71
|
-
|
72
|
-
test "extracting family name" do
|
73
|
-
assert_equal "Claghorn", GoogleSignIn::Identity.new(token_with(family_name: "Claghorn")).family_name
|
74
|
-
end
|
75
|
-
|
76
|
-
private
|
77
|
-
def switch_client_id_to(value)
|
78
|
-
previous_value = GoogleSignIn.client_id
|
79
|
-
GoogleSignIn.client_id = value
|
80
|
-
yield
|
81
|
-
ensure
|
82
|
-
GoogleSignIn.client_id = previous_value
|
83
|
-
end
|
84
|
-
|
85
|
-
def token_with(aud: FAKE_GOOGLE_CLIENT_ID, iss: "https://accounts.google.com", key: GOOGLE_PRIVATE_KEY, **payload)
|
86
|
-
JWT.encode(payload.merge(aud: aud, iss: iss), key, "RS256")
|
87
|
-
end
|
88
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'google_sign_in/redirect_protector'
|
3
|
-
|
4
|
-
class GoogleSignIn::RedirectProtectorTest < ActiveSupport::TestCase
|
5
|
-
test "disallows URL target with different host than source" do
|
6
|
-
assert_raises GoogleSignIn::RedirectProtector::Violation do
|
7
|
-
GoogleSignIn::RedirectProtector.ensure_same_origin 'https://malicious.example.com', 'https://basecamp.com'
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
test "disallows URL target with different port than source" do
|
12
|
-
assert_raises GoogleSignIn::RedirectProtector::Violation do
|
13
|
-
GoogleSignIn::RedirectProtector.ensure_same_origin 'https://basecamp.com:10443', 'https://basecamp.com'
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
test "disallows URL target with different protocol than source" do
|
18
|
-
assert_raises GoogleSignIn::RedirectProtector::Violation do
|
19
|
-
GoogleSignIn::RedirectProtector.ensure_same_origin 'http://basecamp.com', 'https://basecamp.com'
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
test "disallows empty URL target" do
|
24
|
-
assert_raises GoogleSignIn::RedirectProtector::Violation do
|
25
|
-
GoogleSignIn::RedirectProtector.ensure_same_origin nil, 'https://basecamp.com'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
test "allows URL target with same origin as source" do
|
30
|
-
assert_nothing_raised do
|
31
|
-
GoogleSignIn::RedirectProtector.ensure_same_origin 'https://basecamp.com', 'https://basecamp.com'
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
test "allows path target" do
|
36
|
-
assert_nothing_raised do
|
37
|
-
GoogleSignIn::RedirectProtector.ensure_same_origin '/callback', 'https://basecamp.com'
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
ENV['RAILS_ENV'] = 'test'
|
2
|
-
|
3
|
-
FAKE_GOOGLE_CLIENT_ID = '86179201039-eks5VfVc46WoFYyZVUDpQHeZFDRCqno3.apps.googleusercontent.com'
|
4
|
-
FAKE_GOOGLE_CLIENT_SECRET = 'r(XsBajmyMddruvf$jDgLyPK'
|
5
|
-
|
6
|
-
require_relative '../test/dummy/config/environment'
|
7
|
-
|
8
|
-
require 'rails/test_help'
|
9
|
-
require 'webmock/minitest'
|
10
|
-
require 'byebug'
|
11
|
-
|
12
|
-
require 'openssl'
|
13
|
-
GOOGLE_PRIVATE_KEY = OpenSSL::PKey::RSA.new(File.read(File.expand_path('key.pem', __dir__)))
|
14
|
-
GOOGLE_X509_CERTIFICATE = OpenSSL::X509::Certificate.new(File.read(File.expand_path('certificate.pem', __dir__)))
|
15
|
-
|
16
|
-
if GOOGLE_X509_CERTIFICATE.not_after <= Time.now
|
17
|
-
raise "Test certificate is expired. Generate a new one and run the tests again: `bundle exec rake test:certificate:generate`."
|
18
|
-
end
|
19
|
-
|
20
|
-
require 'google-id-token'
|
21
|
-
GoogleSignIn::Identity.validator = GoogleIDToken::Validator.new(x509_cert: GOOGLE_X509_CERTIFICATE)
|
22
|
-
|
23
|
-
class ActionView::TestCase
|
24
|
-
private
|
25
|
-
def assert_dom_equal(expected, actual, message = nil)
|
26
|
-
super expected.remove(/(\A|\n)\s*/), actual, message
|
27
|
-
end
|
28
|
-
end
|