Normalise syntax with Rubocop

Signed-off-by: Alex Coles <alex@alexbcoles.com>
pull/6827/head
Alex Coles 10 years ago
parent b209564e22
commit 30ca520202
  1. 16
      lib/omniauth/openid_connect/google.rb
  2. 12
      lib/omniauth/openid_connect/heroku.rb
  3. 32
      lib/omniauth/openid_connect/provider.rb
  4. 2
      lib/open_project/openid_connect.rb
  5. 3
      lib/open_project/openid_connect/engine.rb
  6. 2
      lib/open_project/openid_connect/version.rb
  7. 24
      openproject-openid_connect.gemspec
  8. 62
      spec/requests/openid_connect_spec.rb
  9. 4
      spec/requests/openid_connect_spec_helpers.rb

@ -30,23 +30,23 @@
module OmniAuth::OpenIDConnect module OmniAuth::OpenIDConnect
class Google < Provider class Google < Provider
def host def host
"accounts.google.com" 'accounts.google.com'
end end
def options def options
super.merge({ super.merge(
client_auth_method: :not_basic, client_auth_method: :not_basic,
send_nonce: false, # use state instead of nonce send_nonce: false, # use state instead of nonce
state: lambda { SecureRandom.hex(42) } state: lambda { SecureRandom.hex(42) }
}) )
end end
def client_options def client_options
super.merge({ super.merge(
authorization_endpoint: "/o/oauth2/auth", authorization_endpoint: '/o/oauth2/auth',
token_endpoint: "/o/oauth2/token", token_endpoint: '/o/oauth2/token',
userinfo_endpoint: "https://www.googleapis.com/plus/v1/people/me/openIdConnect" userinfo_endpoint: 'https://www.googleapis.com/plus/v1/people/me/openIdConnect'
}) )
end end
end end
end end

@ -30,15 +30,15 @@
module OmniAuth::OpenIDConnect module OmniAuth::OpenIDConnect
class Heroku < Provider class Heroku < Provider
def host def host
"connect-op.heroku.com" 'connect-op.heroku.com'
end end
def client_options def client_options
super.merge({ super.merge(
authorization_endpoint: "/authorizations/new", authorization_endpoint: '/authorizations/new',
token_endpoint: "/access_tokens", token_endpoint: '/access_tokens',
userinfo_endpoint: "/user_info" userinfo_endpoint: '/user_info'
}) )
end end
end end
end end

@ -39,12 +39,12 @@ module OmniAuth
end end
def self.load_generic_providers def self.load_generic_providers
providers = configs.reject do |pro, config| providers = configs.reject do |pro, _config|
all.any? { |p| p.provider_name == pro } all.any? { |p| p.provider_name == pro }
end end
providers.each do |name, config| providers.each do |name, config|
host = config["host"] || URI.parse(config["authorization_endpoint"]).host host = config['host'] || URI.parse(config['authorization_endpoint']).host
if host if host
create(name, host) create(name, host)
@ -75,11 +75,11 @@ module OmniAuth
end end
def self.available? def self.available?
!!config["secret"] && !!config["identifier"] !!config['secret'] && !!config['identifier']
end end
def self.provider_name def self.provider_name
self.name.demodulize.downcase name.demodulize.downcase
end end
def self.config def self.config
@ -88,12 +88,12 @@ module OmniAuth
def self.configs def self.configs
from_settings = if Setting.plugin_openproject_openid_connect.is_a? Hash from_settings = if Setting.plugin_openproject_openid_connect.is_a? Hash
Hash(Setting.plugin_openproject_openid_connect["providers"]) Hash(Setting.plugin_openproject_openid_connect['providers'])
else else
{} {}
end end
# Settings override configuration.yml # Settings override configuration.yml
Hash(OpenProject::Configuration["openid_connect"]).deep_merge(from_settings) Hash(OpenProject::Configuration['openid_connect']).deep_merge(from_settings)
end end
def to_hash def to_hash
@ -108,12 +108,12 @@ module OmniAuth
{ {
name: name, name: name,
scope: [:openid, :email, :profile], scope: [:openid, :email, :profile],
icon: config["icon"], icon: config['icon'],
display_name: config["display_name"], display_name: config['display_name'],
client_options: client_options.merge( # override with configuration client_options: client_options.merge( # override with configuration
Hash[ Hash[
config.reject do |key, value| config.reject do |key, _value|
["identifier", "secret", "icon", "display_name"].include? key ['identifier', 'secret', 'icon', 'display_name'].include? key
end.map do |key, value| end.map do |key, value|
[key.to_sym, value] [key.to_sym, value]
end end
@ -125,7 +125,7 @@ module OmniAuth
def client_options def client_options
{ {
port: 443, port: 443,
scheme: "https", scheme: 'https',
host: host, host: host,
identifier: identifier, identifier: identifier,
secret: secret, secret: secret,
@ -134,15 +134,15 @@ module OmniAuth
end end
def host def host
raise NotImplemented("Host required") raise NotImplemented('Host required')
end end
def identifier def identifier
config("identifier") config('identifier')
end end
def secret def secret
config("secret") config('secret')
end end
def config(key = nil) def config(key = nil)

@ -1,5 +1,5 @@
module OpenProject module OpenProject
module OpenIDConnect module OpenIDConnect
require "open_project/openid_connect/engine" require 'open_project/openid_connect/engine'
end end
end end

@ -43,7 +43,7 @@ module OpenProject::OpenIDConnect
secure_cookie = Rails.env.production? secure_cookie = Rails.env.production?
# register an #after_login callback which sets a cookie containing the access token # register an #after_login callback which sets a cookie containing the access token
OpenProject::OmniAuth::Authorization.after_login do |user, auth_hash, context| OpenProject::OmniAuth::Authorization.after_login do |_user, auth_hash, context|
# check the configuration # check the configuration
if store_access_token? if store_access_token?
# fetch the access token if it's present # fetch the access token if it's present
@ -65,6 +65,5 @@ module OpenProject::OpenIDConnect
true true
end end
end end
end end
end end

@ -1,5 +1,5 @@
module OpenProject module OpenProject
module OpenIDConnect module OpenIDConnect
VERSION = "4.0.0" VERSION = '4.0.0'
end end
end end

@ -1,23 +1,23 @@
# encoding: UTF-8 # encoding: UTF-8
$:.push File.expand_path("../lib", __FILE__) $:.push File.expand_path('../lib', __FILE__)
require 'open_project/openid_connect/version' require 'open_project/openid_connect/version'
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = "openproject-openid_connect" s.name = 'openproject-openid_connect'
s.version = OpenProject::OpenIDConnect::VERSION s.version = OpenProject::OpenIDConnect::VERSION
s.authors = "Finn GmbH" s.authors = 'Finn GmbH'
s.email = "info@finn.de" s.email = 'info@finn.de'
s.homepage = "https://www.openproject.org/projects/openid-connect" # TODO check this URL s.homepage = 'https://www.openproject.org/projects/openid-connect' # TODO check this URL
s.summary = 'OpenProject OpenID Connect' s.summary = 'OpenProject OpenID Connect'
s.description = "Adds OmniAuth OpenID Connect strategy providers to Openproject." s.description = 'Adds OmniAuth OpenID Connect strategy providers to Openproject.'
s.license = "GPLv3" s.license = 'GPLv3'
s.files = Dir["{app,config,db,lib}/**/*"] + %w(CHANGELOG.md README.md) s.files = Dir['{app,config,db,lib}/**/*'] + %w(CHANGELOG.md README.md)
s.add_dependency "rails", "~> 3.2.14" s.add_dependency 'rails', '~> 3.2.14'
s.add_dependency "openproject-auth_plugins", "~> 4.0.0" s.add_dependency 'openproject-auth_plugins', '~> 4.0.0'
s.add_dependency "omniauth", "~> 1.0" s.add_dependency 'omniauth', '~> 1.0'
s.add_development_dependency "rspec", "~> 2.99" s.add_development_dependency 'rspec', '~> 2.99'
end end

@ -33,15 +33,15 @@ RSpec.configure do |c|
c.include OpenIDConnectSpecHelpers c.include OpenIDConnectSpecHelpers
end end
describe "OpenID Connect" do describe 'OpenID Connect' do
let(:provider) { OmniAuth::OpenIDConnect::Heroku.new } let(:provider) { OmniAuth::OpenIDConnect::Heroku.new }
let(:user_info) do let(:user_info) do
{ {
sub: "87117114115116", sub: '87117114115116',
name: "Hans Wurst", name: 'Hans Wurst',
email: "h.wurst@finn.de", email: 'h.wurst@finn.de',
given_name: "Hans", given_name: 'Hans',
family_name: "Wurst" family_name: 'Wurst'
} }
end end
@ -49,7 +49,7 @@ describe "OpenID Connect" do
# The redirect will include an authorisation code. # The redirect will include an authorisation code.
# Since we don't actually get a valid code in the test we will stub the resulting AccessToken. # Since we don't actually get a valid code in the test we will stub the resulting AccessToken.
OpenIDConnect::Client.any_instance.stub(:access_token!) do OpenIDConnect::Client.any_instance.stub(:access_token!) do
OpenIDConnect::AccessToken.new client: self, access_token: "foo bar baz" OpenIDConnect::AccessToken.new client: self, access_token: 'foo bar baz'
end end
# Using the granted AccessToken the client then performs another request to the OpenID Connect # Using the granted AccessToken the client then performs another request to the OpenID Connect
@ -62,17 +62,17 @@ describe "OpenID Connect" do
OpenProject::Configuration['omniauth_store_access_token_in_cookie'] = true OpenProject::Configuration['omniauth_store_access_token_in_cookie'] = true
end end
describe "sign-up and login" do describe 'sign-up and login' do
before do before do
Setting.stub(:plugin_openproject_openid_connect).and_return( Setting.stub(:plugin_openproject_openid_connect).and_return(
{
"providers" => { 'providers' => {
"heroku" => { 'heroku' => {
"identifier" => "does not", 'identifier' => 'does not',
"secret" => "matter" 'secret' => 'matter'
} }
} }
}
) )
end end
@ -92,11 +92,11 @@ describe "OpenID Connect" do
expect(response.status).to be 302 expect(response.status).to be 302
expect(response.location).to match /https:\/\/#{provider.host}.*$/ expect(response.location).to match /https:\/\/#{provider.host}.*$/
params = Rack::Utils.parse_nested_query(response.location.gsub(/^.*\?/, "")) params = Rack::Utils.parse_nested_query(response.location.gsub(/^.*\?/, ''))
expect(params).to include "client_id" expect(params).to include 'client_id'
expect(params["redirect_uri"]).to match /^.*\/auth\/#{provider.class.provider_name}\/callback$/ expect(params['redirect_uri']).to match /^.*\/auth\/#{provider.class.provider_name}\/callback$/
expect(params["scope"]).to include "openid" expect(params['scope']).to include 'openid'
## ##
# it should redirect back from the provider to the login page # it should redirect back from the provider to the login page
@ -141,30 +141,30 @@ describe "OpenID Connect" do
end end
end end
context "provider configuration through the settings" do context 'provider configuration through the settings' do
it "should make providers that are not configured unavailable" do it 'should make providers that are not configured unavailable' do
get "/login" get '/login'
expect(response.body).not_to match /Google/i expect(response.body).not_to match /Google/i
expect{click_on_signin("google")}.to raise_error(ActionController::RoutingError) expect { click_on_signin('google') }.to raise_error(ActionController::RoutingError)
end end
it "should make providers that have been configured through settings available without requiring a restart" do it 'should make providers that have been configured through settings available without requiring a restart' do
Setting.stub(:plugin_openproject_openid_connect).and_return( Setting.stub(:plugin_openproject_openid_connect).and_return(
{
"providers" => { 'providers' => {
"google" => { 'google' => {
"identifier" => "does not", 'identifier' => 'does not',
"secret" => "matter" 'secret' => 'matter'
} }
} }
}
) )
get "/login" get '/login'
expect(response.body).to match /Google/i expect(response.body).to match /Google/i
expect{click_on_signin("google")}.not_to raise_error expect { click_on_signin('google') }.not_to raise_error
expect(response.status).to be 302 expect(response.status).to be 302
end end
end end

@ -2,8 +2,8 @@ module OpenIDConnectSpecHelpers
def redirect_from_provider def redirect_from_provider
# Emulate the provider's redirect with a nonsense code. # Emulate the provider's redirect with a nonsense code.
get "/auth/#{provider.class.provider_name}/callback", get "/auth/#{provider.class.provider_name}/callback",
code: "foobar", code: 'foobar',
redirect_uri: "http://localhost:3000/auth/#{provider.class.provider_name}/callack" redirect_uri: "http://localhost:3000/auth/#{provider.class.provider_name}/callack"
end end
def click_on_signin(pro_name = provider.class.provider_name) def click_on_signin(pro_name = provider.class.provider_name)

Loading…
Cancel
Save