Fix rubocop violations. Fix Travis build.
This commit is contained in:
parent
4cece8bd80
commit
822435f616
19
.rubocop.yml
19
.rubocop.yml
|
@ -1,6 +1,19 @@
|
||||||
inherit_from: .rubocop_todo.yml
|
AllCops:
|
||||||
|
Exclude:
|
||||||
|
- "spec/**/*"
|
||||||
|
|
||||||
|
Metrics/AbcSize:
|
||||||
|
Max: 25
|
||||||
Metrics/BlockLength:
|
Metrics/BlockLength:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'spec/**/*.rb'
|
- "googleauth.gemspec"
|
||||||
- 'googleauth.gemspec'
|
Metrics/CyclomaticComplexity:
|
||||||
|
Max: 8
|
||||||
|
Metrics/MethodLength:
|
||||||
|
Max: 20
|
||||||
|
Metrics/ClassLength:
|
||||||
|
Enabled: false
|
||||||
|
Style/IndentHeredoc:
|
||||||
|
Enabled: false
|
||||||
|
Style/FormatString:
|
||||||
|
Enabled: false
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
# This configuration was generated by
|
|
||||||
# `rubocop --auto-gen-config`
|
|
||||||
# on 2017-02-25 23:23:21 +0900 using RuboCop version 0.46.0.
|
|
||||||
# The point is for the user to remove these configuration records
|
|
||||||
# one by one as the offenses are removed from the code base.
|
|
||||||
# Note that changes in the inspected code, or installation of new
|
|
||||||
# versions of RuboCop, may require this file to be generated again.
|
|
||||||
|
|
||||||
# Offense count: 5
|
|
||||||
# Configuration parameters: Include.
|
|
||||||
# Include: **/Gemfile, **/gems.rb
|
|
||||||
Bundler/OrderedGems:
|
|
||||||
Exclude:
|
|
||||||
- 'Gemfile'
|
|
||||||
|
|
||||||
# Offense count: 3
|
|
||||||
Metrics/AbcSize:
|
|
||||||
Max: 27
|
|
||||||
|
|
||||||
# Offense count: 1
|
|
||||||
Metrics/CyclomaticComplexity:
|
|
||||||
Max: 7
|
|
||||||
|
|
||||||
# Offense count: 18
|
|
||||||
# Configuration parameters: CountComments.
|
|
||||||
Metrics/MethodLength:
|
|
||||||
Max: 22
|
|
||||||
|
|
||||||
# Offense count: 3
|
|
||||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
|
||||||
# SupportedStyles: format, sprintf, percent
|
|
||||||
Style/FormatString:
|
|
||||||
Exclude:
|
|
||||||
- 'lib/googleauth/user_authorizer.rb'
|
|
||||||
- 'lib/googleauth/web_user_authorizer.rb'
|
|
||||||
|
|
||||||
# Offense count: 1
|
|
||||||
# Configuration parameters: MinBodyLength.
|
|
||||||
Style/GuardClause:
|
|
||||||
Exclude:
|
|
||||||
- 'lib/googleauth/web_user_authorizer.rb'
|
|
|
@ -1,6 +1,7 @@
|
||||||
sudo: false
|
sudo: false
|
||||||
language: ruby
|
language: ruby
|
||||||
rvm:
|
rvm:
|
||||||
|
- 2.4
|
||||||
- 2.3.3
|
- 2.3.3
|
||||||
- 2.2
|
- 2.2
|
||||||
- 2.0.0
|
- 2.0.0
|
||||||
|
@ -33,6 +34,6 @@ before_install:
|
||||||
notifications:
|
notifications:
|
||||||
email:
|
email:
|
||||||
recipients:
|
recipients:
|
||||||
- temiola@google.com
|
- ruby-cloud-eng@google.com
|
||||||
on_success: change
|
on_success: change
|
||||||
on_failure: change
|
on_failure: change
|
||||||
|
|
12
Gemfile
12
Gemfile
|
@ -5,17 +5,17 @@ gemspec
|
||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
gem 'bundler', '~> 1.9'
|
gem 'bundler', '~> 1.9'
|
||||||
gem 'simplecov', '~> 0.9'
|
|
||||||
gem 'coveralls', '~> 0.7'
|
gem 'coveralls', '~> 0.7'
|
||||||
gem 'fakefs', '~> 0.6'
|
gem 'fakefs', '~> 0.6'
|
||||||
gem 'rake', '~> 10.0'
|
|
||||||
gem 'rubocop', '~> 0.30'
|
|
||||||
gem 'rspec', '~> 3.0'
|
|
||||||
gem 'redis', '~> 3.2'
|
|
||||||
gem 'fakeredis', '~> 0.5'
|
gem 'fakeredis', '~> 0.5'
|
||||||
gem 'webmock', '~> 1.21'
|
|
||||||
gem 'rack-test', '~> 0.6'
|
gem 'rack-test', '~> 0.6'
|
||||||
|
gem 'rake', '~> 10.0'
|
||||||
|
gem 'redis', '~> 3.2'
|
||||||
|
gem 'rspec', '~> 3.0'
|
||||||
|
gem 'rubocop', '~> 0.30'
|
||||||
|
gem 'simplecov', '~> 0.9'
|
||||||
gem 'sinatra'
|
gem 'sinatra'
|
||||||
|
gem 'webmock', '~> 1.21'
|
||||||
end
|
end
|
||||||
|
|
||||||
platforms :jruby do
|
platforms :jruby do
|
||||||
|
|
2
Rakefile
2
Rakefile
|
@ -10,6 +10,6 @@ desc 'Run rake task'
|
||||||
RSpec::Core::RakeTask.new(:spec)
|
RSpec::Core::RakeTask.new(:spec)
|
||||||
|
|
||||||
desc 'Does rubocop lint and runs the specs'
|
desc 'Does rubocop lint and runs the specs'
|
||||||
task all: [:rubocop, :spec]
|
task all: %i[rubocop spec]
|
||||||
|
|
||||||
task default: :all
|
task default: :all
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# -*- ruby -*-
|
# -*- ruby -*-
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
||||||
require 'googleauth/version'
|
require 'googleauth/version'
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ require 'multi_json'
|
||||||
require 'googleauth/signet'
|
require 'googleauth/signet'
|
||||||
require 'googleauth/user_refresh'
|
require 'googleauth/user_refresh'
|
||||||
|
|
||||||
# rubocop:disable ClassLength
|
|
||||||
module Google
|
module Google
|
||||||
module Auth
|
module Auth
|
||||||
# Handles an interactive 3-Legged-OAuth2 (3LO) user consent authorization.
|
# Handles an interactive 3-Legged-OAuth2 (3LO) user consent authorization.
|
||||||
|
@ -125,11 +124,7 @@ module Google
|
||||||
# @return [Google::Auth::UserRefreshCredentials]
|
# @return [Google::Auth::UserRefreshCredentials]
|
||||||
# Stored credentials, nil if none present
|
# Stored credentials, nil if none present
|
||||||
def get_credentials(user_id, scope = nil)
|
def get_credentials(user_id, scope = nil)
|
||||||
raise NIL_USER_ID_ERROR if user_id.nil?
|
saved_token = stored_token(user_id)
|
||||||
raise NIL_TOKEN_STORE_ERROR if @token_store.nil?
|
|
||||||
|
|
||||||
scope ||= @scope
|
|
||||||
saved_token = @token_store.load(user_id)
|
|
||||||
return nil if saved_token.nil?
|
return nil if saved_token.nil?
|
||||||
data = MultiJson.load(saved_token)
|
data = MultiJson.load(saved_token)
|
||||||
|
|
||||||
|
@ -146,6 +141,7 @@ module Google
|
||||||
refresh_token: data['refresh_token'],
|
refresh_token: data['refresh_token'],
|
||||||
expires_at: data.fetch('expiration_time_millis', 0) / 1000
|
expires_at: data.fetch('expiration_time_millis', 0) / 1000
|
||||||
)
|
)
|
||||||
|
scope ||= @scope
|
||||||
if credentials.includes_scope?(scope)
|
if credentials.includes_scope?(scope)
|
||||||
return monitor_credentials(user_id, credentials)
|
return monitor_credentials(user_id, credentials)
|
||||||
end
|
end
|
||||||
|
@ -245,6 +241,18 @@ module Google
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
# @private Fetch stored token with given user_id
|
||||||
|
#
|
||||||
|
# @param [String] user_id
|
||||||
|
# Unique ID of the user for loading/storing credentials.
|
||||||
|
# @return [String] The saved token from @token_store
|
||||||
|
def stored_token(user_id)
|
||||||
|
raise NIL_USER_ID_ERROR if user_id.nil?
|
||||||
|
raise NIL_TOKEN_STORE_ERROR if @token_store.nil?
|
||||||
|
|
||||||
|
@token_store.load(user_id)
|
||||||
|
end
|
||||||
|
|
||||||
# Begin watching a credential for refreshes so the access token can be
|
# Begin watching a credential for refreshes so the access token can be
|
||||||
# saved.
|
# saved.
|
||||||
#
|
#
|
||||||
|
@ -268,14 +276,10 @@ module Google
|
||||||
def redirect_uri_for(base_url)
|
def redirect_uri_for(base_url)
|
||||||
return @callback_uri unless URI(@callback_uri).scheme.nil?
|
return @callback_uri unless URI(@callback_uri).scheme.nil?
|
||||||
if base_url.nil? || URI(base_url).scheme.nil?
|
if base_url.nil? || URI(base_url).scheme.nil?
|
||||||
raise sprintf(
|
raise sprintf(ISSING_ABSOLUTE_URL_ERROR, @callback_uri)
|
||||||
MISSING_ABSOLUTE_URL_ERROR,
|
|
||||||
@callback_uri
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
URI.join(base_url, @callback_uri).to_s
|
URI.join(base_url, @callback_uri).to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# rubocop:enable ClassLength
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ module Google
|
||||||
# JSON key.
|
# JSON key.
|
||||||
def self.read_json_key(json_key_io)
|
def self.read_json_key(json_key_io)
|
||||||
json_key = MultiJson.load(json_key_io.read)
|
json_key = MultiJson.load(json_key_io.read)
|
||||||
wanted = %w(client_id client_secret refresh_token)
|
wanted = %w[client_id client_secret refresh_token]
|
||||||
wanted.each do |key|
|
wanted.each do |key|
|
||||||
raise "the json is missing the #{key} field" unless json_key.key?(key)
|
raise "the json is missing the #{key} field" unless json_key.key?(key)
|
||||||
end
|
end
|
||||||
|
|
|
@ -227,7 +227,7 @@ module Google
|
||||||
# @param [Rack::Request] request
|
# @param [Rack::Request] request
|
||||||
# Current request
|
# Current request
|
||||||
def self.validate_callback_state(state, request)
|
def self.validate_callback_state(state, request)
|
||||||
if state[AUTH_CODE_KEY].nil?
|
if state[AUTH_CODE_KEY].nil? # rubocop:disable Style/GuardClause
|
||||||
raise Signet::AuthorizationError, MISSING_AUTH_CODE_ERROR
|
raise Signet::AuthorizationError, MISSING_AUTH_CODE_ERROR
|
||||||
elsif state[ERROR_CODE_KEY]
|
elsif state[ERROR_CODE_KEY]
|
||||||
raise Signet::AuthorizationError,
|
raise Signet::AuthorizationError,
|
||||||
|
|
|
@ -70,7 +70,7 @@ describe Google::Auth::ScopeUtil do
|
||||||
|
|
||||||
context 'with scope as Array' do
|
context 'with scope as Array' do
|
||||||
let(:source) do
|
let(:source) do
|
||||||
%w(email profile openid https://www.googleapis.com/auth/drive)
|
%w[email profile openid https://www.googleapis.com/auth/drive]
|
||||||
end
|
end
|
||||||
it_behaves_like 'normalizes scopes'
|
it_behaves_like 'normalizes scopes'
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,7 +41,7 @@ describe Google::Auth::UserAuthorizer do
|
||||||
include TestHelpers
|
include TestHelpers
|
||||||
|
|
||||||
let(:client_id) { Google::Auth::ClientId.new('testclient', 'notasecret') }
|
let(:client_id) { Google::Auth::ClientId.new('testclient', 'notasecret') }
|
||||||
let(:scope) { %w(email profile) }
|
let(:scope) { %w[email profile] }
|
||||||
let(:token_store) { DummyTokenStore.new }
|
let(:token_store) { DummyTokenStore.new }
|
||||||
let(:callback_uri) { 'https://www.example.com/oauth/callback' }
|
let(:callback_uri) { 'https://www.example.com/oauth/callback' }
|
||||||
let(:authorizer) do
|
let(:authorizer) do
|
||||||
|
@ -173,7 +173,7 @@ describe Google::Auth::UserAuthorizer do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return credentials with a valid scope' do
|
it 'should return credentials with a valid scope' do
|
||||||
expect(credentials.scope).to eq %w(email profile)
|
expect(credentials.scope).to eq %w[email profile]
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return credentials with a valid expiration time' do
|
it 'should return credentials with a valid expiration time' do
|
||||||
|
|
|
@ -115,7 +115,7 @@ describe Google::Auth::UserRefreshCredentials do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'fails if the GOOGLE_APPLICATION_CREDENTIALS path file is invalid' do
|
it 'fails if the GOOGLE_APPLICATION_CREDENTIALS path file is invalid' do
|
||||||
needed = %w(client_id client_secret refresh_token)
|
needed = %w[client_id client_secret refresh_token]
|
||||||
needed.each do |missing|
|
needed.each do |missing|
|
||||||
Dir.mktmpdir do |dir|
|
Dir.mktmpdir do |dir|
|
||||||
key_path = File.join(dir, 'my_cert_file')
|
key_path = File.join(dir, 'my_cert_file')
|
||||||
|
@ -169,7 +169,7 @@ describe Google::Auth::UserRefreshCredentials do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'fails if the file is invalid' do
|
it 'fails if the file is invalid' do
|
||||||
needed = %w(client_id client_secret refresh_token)
|
needed = %w[client_id client_secret refresh_token]
|
||||||
needed.each do |missing|
|
needed.each do |missing|
|
||||||
Dir.mktmpdir do |dir|
|
Dir.mktmpdir do |dir|
|
||||||
key_path = File.join(dir, '.config', @known_path)
|
key_path = File.join(dir, '.config', @known_path)
|
||||||
|
@ -208,7 +208,7 @@ describe Google::Auth::UserRefreshCredentials do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'fails if the file is invalid' do
|
it 'fails if the file is invalid' do
|
||||||
needed = %w(client_id client_secret refresh_token)
|
needed = %w[client_id client_secret refresh_token]
|
||||||
needed.each do |missing|
|
needed.each do |missing|
|
||||||
FakeFS do
|
FakeFS do
|
||||||
FileUtils.mkdir_p(File.dirname(@path))
|
FileUtils.mkdir_p(File.dirname(@path))
|
||||||
|
|
|
@ -42,7 +42,7 @@ describe Google::Auth::WebUserAuthorizer do
|
||||||
include TestHelpers
|
include TestHelpers
|
||||||
|
|
||||||
let(:client_id) { Google::Auth::ClientId.new('testclient', 'notasecret') }
|
let(:client_id) { Google::Auth::ClientId.new('testclient', 'notasecret') }
|
||||||
let(:scope) { %w(email profile) }
|
let(:scope) { %w[email profile] }
|
||||||
let(:token_store) { DummyTokenStore.new }
|
let(:token_store) { DummyTokenStore.new }
|
||||||
let(:authorizer) do
|
let(:authorizer) do
|
||||||
Google::Auth::WebUserAuthorizer.new(client_id, scope, token_store)
|
Google::Auth::WebUserAuthorizer.new(client_id, scope, token_store)
|
||||||
|
|
Loading…
Reference in New Issue