diff --git a/.rspec b/.rspec old mode 100755 new mode 100644 index 53607ea..0d786ba --- a/.rspec +++ b/.rspec @@ -1 +1,3 @@ ---colour +--color +--warnings +--require spec_helper diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..5724097 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,103 @@ +# This is the configuration used to check the rubocop source code. + +inherit_from: .rubocop_todo.yml +require: + - rubocop/cop/internal_affairs + +AllCops: + Exclude: + - 'vendor/**/*' + - 'spec/fixtures/**/*' + - 'tmp/**/*' + TargetRubyVersion: 2.1 + +Naming/PredicateName: + # Method define macros for dynamically generated method. + MethodDefinitionMacros: + - define_method + - define_singleton_method + - def_node_matcher + - def_node_search + +# Override +Style/BracesAroundHashParameters: + Enabled: false + +Style/FrozenStringLiteralComment: + EnforcedStyle: always + +Style/FormatStringToken: + # Because we parse a lot of source codes from strings. Percent arrays + # look like unannotated format string tokens to this cop. + Exclude: + - spec/**/* + +# Override, less diff +Style/TrailingCommaInArguments: + EnforcedStyleForMultiline: comma + +# Override, less diff +Style/TrailingCommaInLiteral: + EnforcedStyleForMultiline: comma + +Layout/EndOfLine: + EnforcedStyle: lf + +Layout/ClassStructure: + Enabled: true + Categories: + module_inclusion: + - include + - prepend + - extend + ExpectedOrder: + - module_inclusion + - constants + - public_class_methods + - initializer + - instance_methods + - protected_methods + - private_methods + +Layout/IndentHeredoc: + EnforcedStyle: powerpack + +Lint/AmbiguousBlockAssociation: + Exclude: + - 'spec/**/*.rb' + +Lint/InterpolationCheck: + Exclude: + - 'spec/**/*.rb' + +Lint/UselessAccessModifier: + MethodCreatingMethods: + - 'def_matcher' + - 'def_node_matcher' + +Lint/BooleanSymbol: + Enabled: false + +Metrics/BlockLength: + Exclude: + - 'Rakefile' + - '**/*.rake' + - 'spec/**/*.rb' + +# Override +Metrics/LineLength: + Max: 120 + +Metrics/ModuleLength: + Exclude: + - 'spec/**/*.rb' + +Performance/Caller: + Exclude: + - spec/rubocop/cop/performance/caller_spec.rb + +RSpec/PredicateMatcher: + EnforcedStyle: explicit + +RSpec/NestedGroups: + Max: 7 diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..2703f6f --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,102 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2018-01-20 17:50:24 -0500 using RuboCop version 0.52.1. +# 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: 76 +Metrics/AbcSize: + Max: 18 + +# Offense count: 42 +# Configuration parameters: CountComments. +Metrics/ClassLength: + Max: 174 + +# Offense count: 195 +# Configuration parameters: CountComments. +Metrics/MethodLength: + Max: 14 + +# Offense count: 7 +# Configuration parameters: CountComments. +Metrics/ModuleLength: + Max: 139 + +# Offense count: 10 +RSpec/AnyInstance: + Exclude: + - 'spec/rubocop/cli_spec.rb' + - 'spec/rubocop/cop/lint/duplicate_methods_spec.rb' + - 'spec/rubocop/target_finder_spec.rb' + +# Offense count: 1036 +# Configuration parameters: Prefixes. +# Prefixes: when, with +RSpec/ContextWording: + Enabled: false + +# Offense count: 2845 +# Configuration parameters: Max. +RSpec/ExampleLength: + Enabled: false + +# Offense count: 43 +RSpec/ExpectOutput: + Exclude: + - 'spec/rubocop/cli/cli_auto_gen_config_spec.rb' + - 'spec/rubocop/cli/cli_options_spec.rb' + - 'spec/rubocop/config_spec.rb' + - 'spec/rubocop/cop/cop_spec.rb' + - 'spec/rubocop/formatter/base_formatter_spec.rb' + - 'spec/rubocop/formatter/disabled_config_formatter_spec.rb' + - 'spec/rubocop/formatter/formatter_set_spec.rb' + - 'spec/rubocop/options_spec.rb' + - 'spec/rubocop/path_util_spec.rb' + - 'spec/rubocop/rake_task_spec.rb' + - 'spec/rubocop/result_cache_spec.rb' + - 'spec/rubocop/target_finder_spec.rb' + - 'spec/support/cli_spec_behavior.rb' + +# Offense count: 38 +# Configuration parameters: EnforcedStyle. +# SupportedStyles: have_received, receive +RSpec/MessageSpies: + Exclude: + - 'spec/rubocop/cli_spec.rb' + - 'spec/rubocop/config_loader_spec.rb' + - 'spec/rubocop/config_store_spec.rb' + - 'spec/rubocop/cop/commissioner_spec.rb' + - 'spec/rubocop/cop/cop_spec.rb' + - 'spec/rubocop/cop/force_spec.rb' + - 'spec/rubocop/cop/generator_spec.rb' + - 'spec/rubocop/formatter/base_formatter_spec.rb' + - 'spec/rubocop/formatter/colorizable_spec.rb' + - 'spec/rubocop/formatter/formatter_set_spec.rb' + - 'spec/rubocop/formatter/progress_formatter_spec.rb' + - 'spec/rubocop/rake_task_spec.rb' + +# Offense count: 1 +RSpec/MultipleDescribes: + Exclude: + - 'spec/rubocop/string_util_spec.rb' + +# Offense count: 921 +RSpec/MultipleExpectations: + Max: 25 + +# Offense count: 21 +RSpec/SubjectStub: + Exclude: + - 'spec/rubocop/config_spec.rb' + - 'spec/rubocop/cop/cop_spec.rb' + - 'spec/rubocop/formatter/base_formatter_spec.rb' + - 'spec/rubocop/formatter/json_formatter_spec.rb' + - 'spec/rubocop/formatter/progress_formatter_spec.rb' + +# Offense count: 37 +# Configuration parameters: IgnoreSymbolicNames. +RSpec/VerifiedDoubles: + Enabled: false diff --git a/.rvmrc b/.rvmrc deleted file mode 100644 index 39f2436..0000000 --- a/.rvmrc +++ /dev/null @@ -1 +0,0 @@ -rvm use 1.9.2-p290@omniauth-salesforce --create \ No newline at end of file diff --git a/Gemfile b/Gemfile index 8d9f06c..bdafcc9 100755 --- a/Gemfile +++ b/Gemfile @@ -6,10 +6,8 @@ group :development do gem 'rubocop', '~> 0.52.1', require: false end -group :development, :test do - gem 'guard' - gem 'guard-rspec' - gem 'guard-bundler' - gem 'rb-fsevent' - gem 'growl' +group :test do + gem 'coveralls', '~> 0.8.21', require: false + gem 'rspec', '~> 3.5', require: false + gem 'simplecov', '~> 0.14.1', require: false end diff --git a/Guardfile b/Guardfile deleted file mode 100755 index 2aaba26..0000000 --- a/Guardfile +++ /dev/null @@ -1,10 +0,0 @@ -guard 'rspec', :version => 2 do - watch(%r{^spec/.+_spec\.rb$}) - watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } - watch('spec/spec_helper.rb') { "spec" } -end - -guard 'bundler' do - watch('Gemfile') - watch('omniauth-salesforce.gemspec') -end diff --git a/Rakefile b/Rakefile index ca978a9..01c0e6f 100755 --- a/Rakefile +++ b/Rakefile @@ -1,12 +1,12 @@ #!/usr/bin/env rake -require "bundler/gem_tasks" +require 'bundler/gem_tasks' require 'rspec/core/rake_task' desc 'Default: run specs.' -task :default => :spec +task default: :spec -desc "Run specs" +desc 'Run specs' RSpec::Core::RakeTask.new desc 'Run specs' -task :default => :spec +task default: :spec diff --git a/omniauth-salesforce.gemspec b/omniauth-salesforce.gemspec index 03ab427..83247bb 100755 --- a/omniauth-salesforce.gemspec +++ b/omniauth-salesforce.gemspec @@ -18,8 +18,4 @@ Gem::Specification.new do |gem| gem.add_dependency 'omniauth', '~> 1.0' gem.add_dependency 'omniauth-oauth2', '>= 1.5.0' gem.required_ruby_version = '>= 2.1.0' - gem.add_development_dependency 'rack-test' - gem.add_development_dependency 'rspec', '~> 2.7' - gem.add_development_dependency 'simplecov' - gem.add_development_dependency 'webmock' end diff --git a/spec/omniauth/strategies/salesforce_spec.rb b/spec/omniauth/strategies/salesforce_spec.rb index c3e32fd..dedf223 100755 --- a/spec/omniauth/strategies/salesforce_spec.rb +++ b/spec/omniauth/strategies/salesforce_spec.rb @@ -1,217 +1,256 @@ require 'spec_helper' describe OmniAuth::Strategies::Salesforce do - strategy = nil - before do - OmniAuth.config.test_mode = true - rack_app = [] - rack_app.stub :call - strategy = OmniAuth::Strategies::Salesforce.new rack_app, 'Consumer Key', 'Consumer Secret' - end - describe "request_phase" do - env = nil - before do - env = { - 'rack.session' => {}, - 'HTTP_USER_AGENT' => 'unknown', - 'REQUEST_METHOD' => 'GET', - 'rack.input' => '', - 'rack.url_scheme' => 'http', - 'SERVER_NAME' => 'server.example', - 'QUERY_STRING' => 'code=xxxx', - 'SCRIPT_NAME' => '', - 'SERVER_PORT' => 80 - } - end - context "when using a mobile browser" do - user_agents = { - :Pre => "Mozilla/5.0 (webOS/1.4.0; U; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Version/1.0 Safari/532.2 Pre/1.1", - :iPod => "Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/4A93 Safari/419.3", - :iPhone => "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3", - :iPad => "Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10", - :Nexus => "Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1", - :myTouch => "Mozilla/5.0 (Linux; U; Android 1.6; en-us; WOWMobile myTouch 3G Build/unknown) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1", - :Storm => "BlackBerry9530/4.7.0.148 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/105", - :Torch => "Mozilla/5.0 (BlackBerry; U; BlackBerry 9810; en-US) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0 Mobile Safari/534.11+", - :generic_mobile => "some mobile device" - } - user_agents.each_pair do |name, agent| - context "with the user agent from a #{name.to_s}" do - before do - env['HTTP_USER_AGENT'] = agent - strategy.call!(env) - strategy.request_phase - end - subject {strategy.options} - it "sets the :display option to 'touch'" do - subject[:display].should == 'touch' - end - end - end - end - context "when using a desktop browser" do - user_agents = { - :Chrome => "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21", - :Safari => "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1", - :IE => "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)", - :anything_else => "unknown" - } - user_agents.each_pair do |name, agent| - context "with the user agent from #{name.to_s}" do - before do - env['HTTP_USER_AGENT'] = agent - strategy.call!(env) - strategy.request_phase - end - subject {strategy.options} - it "sets the :display option to 'page'" do - subject[:display].should == 'page' - end - end - end - end - end - describe "callback phase" do - raw_info = nil - before do - raw_info = { - 'id' => 'salesforce id', - 'display_name' => 'display name', - 'email' => 'email', - 'nick_name' => 'nick name', - 'first_name' => 'first name', - 'last_name' => 'last name', - 'photos' => {'thumbnail' => '/thumbnail/url'}, - 'urls'=> { - "enterprise" => "https://salesforce.example/services", - "metadata" => "https://salesforce.example/services" - } - } - client = OAuth2::Client.new 'id', 'secret', {:site => 'example.com'} - access_token = OAuth2::AccessToken.from_hash client, { - 'access_token' => 'token', - 'instance_url' => 'http://instance.salesforce.example', - 'signature' => 'invalid', - 'issued_at' => '1296458209517' - } - strategy.stub(:raw_info) { raw_info } - strategy.stub(:access_token) { access_token } - end - describe "uid" do - it "sets the id" do - strategy.uid.should == raw_info['id'] - end - end - describe "info" do - subject { strategy.info } - it "returns an info hash" do - subject.should_not be_nil - end - it "sets name" do - subject['name'].should == raw_info['display_name'] - end - it "sets email" do - subject['email'].should == raw_info['email'] - end - it "sets nickname" do - subject['nickname'].should == raw_info['nick_name'] - end - it "sets first_name" do - subject['first_name'].should == raw_info['first_name'] - end - it "sets last_name" do - subject['last_name'].should == raw_info['last_name'] - end - it "sets location" do - subject['location'].should == '' - end - it "sets description" do - subject['description'].should == '' - end - it "sets image" do - subject['image'].should == raw_info['photos']['thumbnail'] + "?oauth_token=#{strategy.access_token.token}" - end - it "sets phone" do - subject['phone'].should == '' - end - it "sets urls" do - subject['urls'].should == raw_info['urls'] - end - end - describe "credentials" do - subject { strategy.credentials } - it "sets token" do - subject['token'].should == strategy.access_token.token - end - it "sets instance_url" do - subject['instance_url'].should == strategy.access_token.params["instance_url"] - end - context "given a refresh token" do - it "sets refresh_token" do - subject['refresh_token'].should == strategy.access_token.refresh_token - end - end - context "when not given a refresh token" do - it "does not set a refresh token" do - subject['refresh_token'].should be_nil - end - end - end - describe "extra" do - subject { strategy.extra } - it "sets instance_url" do - subject['instance_url'].should == strategy.access_token.params['instance_url'] - end - it "sets pod" do - subject['pod'].should == strategy.access_token.params['instance_url'] - end - it "sets signature" do - subject['signature'].should == strategy.access_token.params['signature'] - end - it "sets issued_at" do - subject['issued_at'].should == strategy.access_token.params['issued_at'] - end - end - describe "user id validation" do - client_id = nil - issued_at = nil - signature = nil - instance_url = 'http://instance.salesforce.example' - before do - client_id = "https://login.salesforce.com/id/00Dd0000000d45TEBQ/005d0000000fyGPCCY" - issued_at = "1331142541514" - signature = Base64.strict_encode64(OpenSSL::HMAC.digest('sha256', strategy.options.client_secret.to_s, client_id + issued_at)) - end - context "when the signature does not match" do - before do - access_token = OAuth2::AccessToken.from_hash strategy.access_token.client, { - 'id' => 'forged client id', - 'issued_at' => issued_at, - 'instance_url' => 'http://instance.salesforce.example', - 'signature' => signature - } - strategy.stub(:access_token) { access_token } - end - it "should call fail!" do - strategy.should_receive(:fail!) - strategy.auth_hash - end - end - context "when the signature does match" do - before do - access_token = OAuth2::AccessToken.from_hash strategy.access_token.client, { - 'id' => client_id, - 'issued_at' => issued_at, - 'instance_url' => 'http://instance.salesforce.example', - 'signature' => signature - } - strategy.stub(:access_token) { access_token } - end - it "should not fail" do - strategy.should_not_receive(:fail!) - strategy.auth_hash - end - end - end - end + strategy = nil + before do + OmniAuth.config.test_mode = true + rack_app = [] + allow(rack_app).to receive(:call) + strategy = OmniAuth::Strategies::Salesforce.new rack_app, 'Consumer Key', 'Consumer Secret' + end + + describe 'request_phase' do + env = nil + before do + env = { + 'rack.session' => {}, + 'HTTP_USER_AGENT' => 'unknown', + 'REQUEST_METHOD' => 'GET', + 'rack.input' => '', + 'rack.url_scheme' => 'http', + 'SERVER_NAME' => 'server.example', + 'QUERY_STRING' => 'code=xxxx', + 'SCRIPT_NAME' => '', + 'SERVER_PORT' => 80, + } + end + + context 'when using a mobile browser' do + user_agents = { + Pre: 'Mozilla/5.0 (webOS/1.4.0; U; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Version/1.0 Safari/532.2 Pre/1.1', + iPod: 'Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/4A93 Safari/419.3', + iPhone: 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3', + iPad: 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10', + Nexus: 'Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1', + myTouch: 'Mozilla/5.0 (Linux; U; Android 1.6; en-us; WOWMobile myTouch 3G Build/unknown) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1', + Storm: 'BlackBerry9530/4.7.0.148 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/105', + Torch: 'Mozilla/5.0 (BlackBerry; U; BlackBerry 9810; en-US) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0 Mobile Safari/534.11+', + generic_mobile: 'some mobile device', + } + + user_agents.each_pair do |name, agent| + context "with the user agent from a #{name}" do + before do + env['HTTP_USER_AGENT'] = agent + strategy.call!(env) + strategy.request_phase + end + + subject { strategy.options } + + it "sets the :display option to 'touch'" do + expect(subject[:display]) == 'touch' + end + end + end + end + + context 'when using a desktop browser' do + user_agents = { + Chrome: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21', + Safari: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1', + IE: 'Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)', + anything_else: 'unknown', + } + + user_agents.each_pair do |name, agent| + context "with the user agent from #{name}" do + before do + env['HTTP_USER_AGENT'] = agent + strategy.call!(env) + strategy.request_phase + end + subject { strategy.options } + + it "sets the :display option to 'page'" do + expect(subject[:display]) == 'page' + end + end + end + end + end + + describe 'callback phase' do + raw_info = nil + + before do + raw_info = { + 'id' => 'salesforce id', + 'display_name' => 'display name', + 'email' => 'email', + 'nick_name' => 'nick name', + 'first_name' => 'first name', + 'last_name' => 'last name', + 'photos' => { 'thumbnail' => '/thumbnail/url' }, + 'urls' => { + 'enterprise' => 'https://salesforce.example/services', + 'metadata' => 'https://salesforce.example/services', + }, + } + client = OAuth2::Client.new 'id', 'secret', { site: 'example.com' } + access_token = OAuth2::AccessToken.from_hash client, { + 'access_token' => 'token', + 'instance_url' => 'http://instance.salesforce.example', + 'signature' => 'invalid', + 'issued_at' => '1296458209517', + } + allow(strategy).to receive(:raw_info).and_return(raw_info) + allow(strategy).to receive(:access_token).and_return(access_token) + end + + describe 'uid' do + it 'sets the id' do + expect(strategy.uid) == raw_info['id'] + end + end + + describe 'info' do + subject { strategy.info } + + it 'returns an info hash' do + expect(subject).not_to be_nil + end + + it 'sets name' do + expect(subject['name']) == raw_info['display_name'] + end + + it 'sets email' do + expect(subject['email']) == raw_info['email'] + end + + it 'sets nickname' do + expect(subject['nickname']) == raw_info['nick_name'] + end + + it 'sets first_name' do + expect(subject['first_name']) == raw_info['first_name'] + end + + it 'sets last_name' do + expect(subject['last_name']) == raw_info['last_name'] + end + + it 'sets location' do + expect(subject['location']) == '' + end + + it 'sets description' do + expect(subject['description']) == '' + end + + it 'sets image' do + expect(subject['image']) == raw_info['photos']['thumbnail'] + "?oauth_token=#{strategy.access_token.token}" + end + + it 'sets phone' do + expect(subject['phone']) == '' + end + + it 'sets urls' do + expect(subject['urls']) == raw_info['urls'] + end + end + + describe 'credentials' do + subject { strategy.credentials } + + it 'sets token' do + expect(subject['token']) == strategy.access_token.token + end + + it 'sets instance_url' do + expect(subject['instance_url']) == strategy.access_token.params['instance_url'] + end + + context 'given a refresh token' do + it 'sets refresh_token' do + expect(subject['refresh_token']) == strategy.access_token.refresh_token + end + end + + context 'when not given a refresh token' do + it 'does not set a refresh token' do + expect(subject['refresh_token']).to be_nil + end + end + end + + describe 'extra' do + subject { strategy.extra } + + it 'sets instance_url' do + expect(subject['instance_url']) == strategy.access_token.params['instance_url'] + end + + it 'sets pod' do + expect(subject['pod']) == strategy.access_token.params['instance_url'] + end + + it 'sets signature' do + expect(subject['signature']) == strategy.access_token.params['signature'] + end + + it 'sets issued_at' do + expect(subject['issued_at']) == strategy.access_token.params['issued_at'] + end + end + + describe 'user id validation' do + client_id = nil + issued_at = nil + signature = nil + # instance_url = 'http://instance.salesforce.example' + + before do + client_id = 'https://login.salesforce.com/id/00Dd0000000d45TEBQ/005d0000000fyGPCCY' + issued_at = '1331142541514' + signature = Base64.strict_encode64(OpenSSL::HMAC.digest('sha256', strategy.options.client_secret.to_s, client_id + issued_at)) + end + + context 'when the signature does not match' do + before do + access_token = OAuth2::AccessToken.from_hash strategy.access_token.client, { + 'id' => 'forged client id', + 'issued_at' => issued_at, + 'instance_url' => 'http://instance.salesforce.example', + 'signature' => signature, + } + allow(strategy).to receive(:access_token).and_return(access_token) + end + + it 'should call fail!' do + expect(strategy).to receive(:fail!) + strategy.auth_hash + end + end + + context 'when the signature does match' do + before do + access_token = OAuth2::AccessToken.from_hash strategy.access_token.client, { + 'id' => client_id, + 'issued_at' => issued_at, + 'instance_url' => 'http://instance.salesforce.example', + 'signature' => signature, + } + allow(strategy).to receive(:access_token).and_return(access_token) + end + + it 'should not fail' do + expect(strategy).not_to receive(:fail!) + strategy.auth_hash + end + end + end + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 19fa399..739af19 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,16 +1,22 @@ -$LOAD_PATH.unshift File.expand_path('..', __FILE__) -$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) - require 'simplecov' -SimpleCov.start +require 'coveralls' + +SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new( + [ + SimpleCov::Formatter::HTMLFormatter, + Coveralls::SimpleCov::Formatter, + ], +) + +SimpleCov.start do + add_filter 'spec' + minimum_coverage(76) +end + require 'rspec' -require 'rack/test' -require 'webmock/rspec' require 'omniauth' require 'omniauth-salesforce' RSpec.configure do |config| - config.include WebMock::API - config.include Rack::Test::Methods - config.extend OmniAuth::Test::StrategyMacros, type: :strategy + config.extend OmniAuth::Test::StrategyMacros, type: :strategy end