From 9d8e5f6bb840410b0d61a015b4025348936942d0 Mon Sep 17 00:00:00 2001
From: Jessie Young <jessieyoung@gitlab.com>
Date: Mon, 22 Aug 2022 15:54:18 -0700
Subject: [PATCH] Vendor omniauth-salesforce gem

* Our ultimate goal is to upgrade `omniauth` to v2.0. See the related
  issue: https://gitlab.com/gitlab-org/gitlab/-/issues/30073
* In order to upgrade `omniauth` to v2.0, we need to upgrade
  `omniauth-salesforce` because the latter has a dependency on the former.
* There is an open issue asking the maintainer to make
  `omniauth-salesforce` compatible with `omniauth` v2.0 but that hasn't
  happened yet: https://github.com/realdoug/omniauth-salesforce/issues/31
* We are actively emailing with the gem owner about transferring or
  adding additional contributors to the gem but in the meantime this
  will unblock the upgrade.
* This MR vendors the gem and updates its `.gemspec` file so that it is
  compatible with `omniauth` v2.0
---
 .gitlab/ci/rules.gitlab-ci.yml                |   6 +
 .gitlab/ci/vendored-gems.gitlab-ci.yml        |   8 +
 Gemfile                                       |   2 +-
 Gemfile.lock                                  |  12 +-
 .../gems/omniauth-salesforce/.gitlab-ci.yml   |  28 +++
 vendor/gems/omniauth-salesforce/Gemfile       |  12 +
 vendor/gems/omniauth-salesforce/Gemfile.lock  | 121 ++++++++++
 vendor/gems/omniauth-salesforce/Guardfile     |  10 +
 vendor/gems/omniauth-salesforce/LICENSE.md    |   5 +
 vendor/gems/omniauth-salesforce/README.md     |  60 +++++
 vendor/gems/omniauth-salesforce/Rakefile      |  12 +
 .../lib/omniauth-salesforce.rb                |   2 +
 .../lib/omniauth-salesforce/version.rb        |   5 +
 .../lib/omniauth/strategies/salesforce.rb     |  97 ++++++++
 .../omniauth-salesforce.gemspec               |  24 ++
 .../omniauth/strategies/salesforce_spec.rb    | 219 ++++++++++++++++++
 .../omniauth-salesforce/spec/spec_helper.rb   |  16 ++
 17 files changed, 634 insertions(+), 5 deletions(-)
 create mode 100644 vendor/gems/omniauth-salesforce/.gitlab-ci.yml
 create mode 100755 vendor/gems/omniauth-salesforce/Gemfile
 create mode 100644 vendor/gems/omniauth-salesforce/Gemfile.lock
 create mode 100755 vendor/gems/omniauth-salesforce/Guardfile
 create mode 100644 vendor/gems/omniauth-salesforce/LICENSE.md
 create mode 100755 vendor/gems/omniauth-salesforce/README.md
 create mode 100755 vendor/gems/omniauth-salesforce/Rakefile
 create mode 100755 vendor/gems/omniauth-salesforce/lib/omniauth-salesforce.rb
 create mode 100755 vendor/gems/omniauth-salesforce/lib/omniauth-salesforce/version.rb
 create mode 100755 vendor/gems/omniauth-salesforce/lib/omniauth/strategies/salesforce.rb
 create mode 100755 vendor/gems/omniauth-salesforce/omniauth-salesforce.gemspec
 create mode 100755 vendor/gems/omniauth-salesforce/spec/omniauth/strategies/salesforce_spec.rb
 create mode 100755 vendor/gems/omniauth-salesforce/spec/spec_helper.rb

diff --git a/.gitlab/ci/rules.gitlab-ci.yml b/.gitlab/ci/rules.gitlab-ci.yml
index e9b557f7f6314..15f72970a92aa 100644
--- a/.gitlab/ci/rules.gitlab-ci.yml
+++ b/.gitlab/ci/rules.gitlab-ci.yml
@@ -1497,6 +1497,12 @@
       changes: ["vendor/gems/omniauth-gitlab/**/*"]
     - <<: *if-merge-request-labels-run-all-rspec
 
+.vendor:rules:omniauth-salesforce:
+  rules:
+    - <<: *if-merge-request
+      changes: ["vendor/gems/omniauth-salesforce/**/*"]
+    - <<: *if-merge-request-labels-run-all-rspec
+
 .vendor:rules:devise-pbkdf2-encryptable:
   rules:
     - <<: *if-merge-request
diff --git a/.gitlab/ci/vendored-gems.gitlab-ci.yml b/.gitlab/ci/vendored-gems.gitlab-ci.yml
index 4408a6e4624a5..03a6d1bcc0e13 100644
--- a/.gitlab/ci/vendored-gems.gitlab-ci.yml
+++ b/.gitlab/ci/vendored-gems.gitlab-ci.yml
@@ -46,6 +46,14 @@ vendor omniauth-gitlab:
     include: vendor/gems/omniauth-gitlab/.gitlab-ci.yml
     strategy: depend
 
+vendor omniauth-salesforce:
+  extends:
+    - .vendor:rules:omniauth-salesforce
+  needs: []
+  trigger:
+    include: vendor/gems/omniauth-salesforce/.gitlab-ci.yml
+    strategy: depend
+
 vendor devise-pbkdf2-encryptable:
   extends:
     - .vendor:rules:devise-pbkdf2-encryptable
diff --git a/Gemfile b/Gemfile
index 411d450e71ed2..2bedb3234fc5b 100644
--- a/Gemfile
+++ b/Gemfile
@@ -54,7 +54,7 @@ gem 'omniauth-twitter', '~> 1.4'
 gem 'omniauth_crowd', '~> 2.4.0', path: 'vendor/gems/omniauth_crowd' # See vendor/gems/omniauth_crowd/README.md
 gem 'omniauth-authentiq', '~> 0.3.3'
 gem 'gitlab-omniauth-openid-connect', '~> 0.9.0', require: 'omniauth_openid_connect'
-gem 'omniauth-salesforce', '~> 1.0.5'
+gem 'omniauth-salesforce', '~> 1.0.5', path: 'vendor/gems/omniauth-salesforce' # See gem README.md
 gem 'omniauth-atlassian-oauth2', '~> 0.2.0'
 gem 'rack-oauth2', '~> 1.21.2'
 gem 'jwt', '~> 2.1.0'
diff --git a/Gemfile.lock b/Gemfile.lock
index 2fa7558578b74..941d9cb1538b6 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -39,6 +39,13 @@ PATH
       omniauth (~> 1.0)
       omniauth-oauth2 (~> 1.7.1)
 
+PATH
+  remote: vendor/gems/omniauth-salesforce
+  specs:
+    omniauth-salesforce (1.0.5)
+      omniauth (~> 1.0, < 3)
+      omniauth-oauth2 (~> 1.0)
+
 PATH
   remote: vendor/gems/omniauth_crowd
   specs:
@@ -926,9 +933,6 @@ GEM
       omniauth (>= 1.9, < 3)
     omniauth-oauth2-generic (0.2.2)
       omniauth-oauth2 (~> 1.0)
-    omniauth-salesforce (1.0.5)
-      omniauth (~> 1.0)
-      omniauth-oauth2 (~> 1.0)
     omniauth-saml (1.10.0)
       omniauth (~> 1.3, >= 1.3.2)
       ruby-saml (~> 1.7)
@@ -1667,7 +1671,7 @@ DEPENDENCIES
   omniauth-gitlab (~> 4.0.0)!
   omniauth-google-oauth2 (~> 0.6.0)
   omniauth-oauth2-generic (~> 0.2.2)
-  omniauth-salesforce (~> 1.0.5)
+  omniauth-salesforce (~> 1.0.5)!
   omniauth-saml (~> 1.10)
   omniauth-shibboleth (~> 1.3.0)
   omniauth-twitter (~> 1.4)
diff --git a/vendor/gems/omniauth-salesforce/.gitlab-ci.yml b/vendor/gems/omniauth-salesforce/.gitlab-ci.yml
new file mode 100644
index 0000000000000..4e18980d01c93
--- /dev/null
+++ b/vendor/gems/omniauth-salesforce/.gitlab-ci.yml
@@ -0,0 +1,28 @@
+workflow:
+  rules:
+    - if: $CI_MERGE_REQUEST_ID
+
+.rspec:
+  cache:
+    key: omniauth-salesforce
+    paths:
+      - vendor/gems/omniauth-salesforce/vendor/ruby
+  before_script:
+    - cd vendor/gems/omniauth-salesforce
+    - ruby -v                                   # Print out ruby version for debugging
+    - gem install bundler --no-document         # Bundler is not installed with the image
+    - bundle config set --local path 'vendor'   # Install dependencies into ./vendor/ruby
+    - bundle config set with 'development'
+    - bundle config set --local frozen 'true'   # Disallow Gemfile.lock changes on CI
+    - bundle config                             # Show bundler configuration
+    - bundle install -j $(nproc)
+  script:
+    - bundle exec rspec
+
+rspec-2.7:
+  image: "ruby:2.7"
+  extends: .rspec
+
+rspec-3.0:
+  image: "ruby:3.0"
+  extends: .rspec
diff --git a/vendor/gems/omniauth-salesforce/Gemfile b/vendor/gems/omniauth-salesforce/Gemfile
new file mode 100755
index 0000000000000..0ac6c2141a787
--- /dev/null
+++ b/vendor/gems/omniauth-salesforce/Gemfile
@@ -0,0 +1,12 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in omniauth-salesforce.gemspec
+gemspec
+
+group :development, :test do
+  gem 'guard'
+  gem 'guard-rspec'
+  gem 'guard-bundler'
+  gem 'rb-fsevent'
+  gem 'growl'
+end
diff --git a/vendor/gems/omniauth-salesforce/Gemfile.lock b/vendor/gems/omniauth-salesforce/Gemfile.lock
new file mode 100644
index 0000000000000..0eb983bcd76e8
--- /dev/null
+++ b/vendor/gems/omniauth-salesforce/Gemfile.lock
@@ -0,0 +1,121 @@
+PATH
+  remote: .
+  specs:
+    omniauth-salesforce (1.0.5)
+      omniauth (~> 1.0, < 3)
+      omniauth-oauth2 (~> 1.0)
+
+GEM
+  remote: https://rubygems.org/
+  specs:
+    addressable (2.8.1)
+      public_suffix (>= 2.0.2, < 6.0)
+    coderay (1.1.3)
+    crack (0.4.5)
+      rexml
+    diff-lcs (1.5.0)
+    docile (1.4.0)
+    faraday (2.5.2)
+      faraday-net_http (>= 2.0, < 3.1)
+      ruby2_keywords (>= 0.0.4)
+    faraday-net_http (3.0.0)
+    ffi (1.15.5)
+    formatador (1.1.0)
+    growl (1.0.3)
+    guard (2.18.0)
+      formatador (>= 0.2.4)
+      listen (>= 2.7, < 4.0)
+      lumberjack (>= 1.0.12, < 2.0)
+      nenv (~> 0.1)
+      notiffany (~> 0.0)
+      pry (>= 0.13.0)
+      shellany (~> 0.0)
+      thor (>= 0.18.1)
+    guard-bundler (3.0.0)
+      bundler (>= 2.1, < 3)
+      guard (~> 2.2)
+      guard-compat (~> 1.1)
+    guard-compat (1.2.1)
+    guard-rspec (4.7.3)
+      guard (~> 2.1)
+      guard-compat (~> 1.1)
+      rspec (>= 2.99.0, < 4.0)
+    hashdiff (1.0.1)
+    hashie (5.0.0)
+    jwt (2.4.1)
+    listen (3.7.1)
+      rb-fsevent (~> 0.10, >= 0.10.3)
+      rb-inotify (~> 0.9, >= 0.9.10)
+    lumberjack (1.2.8)
+    method_source (1.0.0)
+    multi_xml (0.6.0)
+    nenv (0.3.0)
+    notiffany (0.1.3)
+      nenv (~> 0.1)
+      shellany (~> 0.0)
+    oauth2 (2.0.7)
+      faraday (>= 0.17.3, < 3.0)
+      jwt (>= 1.0, < 3.0)
+      multi_xml (~> 0.5)
+      rack (>= 1.2, < 3)
+      rash_alt (>= 0.4, < 1)
+      version_gem (~> 1.1)
+    omniauth (1.9.2)
+      hashie (>= 3.4.6)
+      rack (>= 1.6.2, < 3)
+    omniauth-oauth2 (1.7.3)
+      oauth2 (>= 1.4, < 3)
+      omniauth (>= 1.9, < 3)
+    pry (0.14.1)
+      coderay (~> 1.1)
+      method_source (~> 1.0)
+    public_suffix (5.0.0)
+    rack (2.2.4)
+    rack-test (2.0.2)
+      rack (>= 1.3)
+    rash_alt (0.4.12)
+      hashie (>= 3.4)
+    rb-fsevent (0.11.1)
+    rb-inotify (0.10.1)
+      ffi (~> 1.0)
+    rexml (3.2.5)
+    rspec (2.99.0)
+      rspec-core (~> 2.99.0)
+      rspec-expectations (~> 2.99.0)
+      rspec-mocks (~> 2.99.0)
+    rspec-core (2.99.2)
+    rspec-expectations (2.99.2)
+      diff-lcs (>= 1.1.3, < 2.0)
+    rspec-mocks (2.99.4)
+    ruby2_keywords (0.0.5)
+    shellany (0.0.1)
+    simplecov (0.21.2)
+      docile (~> 1.1)
+      simplecov-html (~> 0.11)
+      simplecov_json_formatter (~> 0.1)
+    simplecov-html (0.12.3)
+    simplecov_json_formatter (0.1.4)
+    thor (1.2.1)
+    version_gem (1.1.0)
+    webmock (3.18.1)
+      addressable (>= 2.8.0)
+      crack (>= 0.3.2)
+      hashdiff (>= 0.4.0, < 2.0.0)
+
+PLATFORMS
+  ruby
+
+DEPENDENCIES
+  growl
+  guard
+  guard-bundler
+  guard-rspec
+  omniauth-salesforce!
+  rack-test
+  rb-fsevent
+  rspec (~> 2.7)
+  simplecov
+  webmock
+
+BUNDLED WITH
+   2.3.20
diff --git a/vendor/gems/omniauth-salesforce/Guardfile b/vendor/gems/omniauth-salesforce/Guardfile
new file mode 100755
index 0000000000000..2aaba26cc430d
--- /dev/null
+++ b/vendor/gems/omniauth-salesforce/Guardfile
@@ -0,0 +1,10 @@
+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/vendor/gems/omniauth-salesforce/LICENSE.md b/vendor/gems/omniauth-salesforce/LICENSE.md
new file mode 100644
index 0000000000000..e662c7862164f
--- /dev/null
+++ b/vendor/gems/omniauth-salesforce/LICENSE.md
@@ -0,0 +1,5 @@
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
diff --git a/vendor/gems/omniauth-salesforce/README.md b/vendor/gems/omniauth-salesforce/README.md
new file mode 100755
index 0000000000000..df59e99bc55aa
--- /dev/null
+++ b/vendor/gems/omniauth-salesforce/README.md
@@ -0,0 +1,60 @@
+# omniauth-salesforce
+
+This is fork of [omniauth-salesforce](https://github.com/realdoug/omniauth-salesforce) to support:
+
+1. OmniAuth v1 and v2. OmniAuth v2 disables GET requests by default
+   and defaults to POST. GitLab already has patched v1 to use POST,
+   but other dependencies need to be updated:
+   https://gitlab.com/gitlab-org/gitlab/-/issues/30073.
+
+There is active discussion with the gem owner (via email) about adding some GitLab employees as gem
+authors so tha they can push changes. If that happens, the updated/canonical gem
+should be used in favor of this vendored fork.
+
+[OmniAuth](https://github.com/intridea/omniauth) Strategy for [salesforce.com](salesforce.com).
+
+Note: This is a fork of the [original](https://github.com/richardvanhook/omniauth-salesforce) project and is now the main repository for the omniauth-salesforce gem.
+
+## See it in action
+
+[http://omniauth-salesforce-example.herokuapp.com](http://omniauth-salesforce-example.herokuapp.com)
+
+[Source for above app](https://github.com/richardvanhook/omniauth-salesforce-example)
+
+## Basic Usage
+
+```ruby
+require "sinatra"
+require "omniauth"
+require "omniauth-salesforce"
+
+class MyApplication < Sinatra::Base
+  use Rack::Session
+  use OmniAuth::Builder do
+    provider :salesforce, ENV['SALESFORCE_KEY'], ENV['SALESFORCE_SECRET']
+  end
+end
+```
+
+## Including other sites
+
+```ruby
+use OmniAuth::Builder do
+    provider :salesforce, 
+             ENV['SALESFORCE_KEY'], 
+             ENV['SALESFORCE_SECRET']
+    provider OmniAuth::Strategies::SalesforceSandbox, 
+             ENV['SALESFORCE_SANDBOX_KEY'], 
+             ENV['SALESFORCE_SANDBOX_SECRET']
+    provider OmniAuth::Strategies::SalesforcePreRelease, 
+             ENV['SALESFORCE_PRERELEASE_KEY'], 
+             ENV['SALESFORCE_PRERELEASE_SECRET']
+    provider OmniAuth::Strategies::DatabaseDotCom, 
+             ENV['DATABASE_DOT_COM_KEY'], 
+             ENV['DATABASE_DOT_COM_SECRET']
+end
+```
+
+## Resources
+
+* [Article: Digging Deeper into OAuth 2.0 on Force.com](http://wiki.developerforce.com/index.php/Digging_Deeper_into_OAuth_2.0_on_Force.com)
diff --git a/vendor/gems/omniauth-salesforce/Rakefile b/vendor/gems/omniauth-salesforce/Rakefile
new file mode 100755
index 0000000000000..ca978a9cf0d6f
--- /dev/null
+++ b/vendor/gems/omniauth-salesforce/Rakefile
@@ -0,0 +1,12 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
+require 'rspec/core/rake_task'
+
+desc 'Default: run specs.'
+task :default => :spec
+
+desc "Run specs"
+RSpec::Core::RakeTask.new
+
+desc 'Run specs'
+task :default => :spec
diff --git a/vendor/gems/omniauth-salesforce/lib/omniauth-salesforce.rb b/vendor/gems/omniauth-salesforce/lib/omniauth-salesforce.rb
new file mode 100755
index 0000000000000..20a5937d762a9
--- /dev/null
+++ b/vendor/gems/omniauth-salesforce/lib/omniauth-salesforce.rb
@@ -0,0 +1,2 @@
+require "omniauth-salesforce/version"
+require 'omniauth/strategies/salesforce'
diff --git a/vendor/gems/omniauth-salesforce/lib/omniauth-salesforce/version.rb b/vendor/gems/omniauth-salesforce/lib/omniauth-salesforce/version.rb
new file mode 100755
index 0000000000000..51f0084840e44
--- /dev/null
+++ b/vendor/gems/omniauth-salesforce/lib/omniauth-salesforce/version.rb
@@ -0,0 +1,5 @@
+module OmniAuth
+  module Salesforce
+    VERSION = "1.0.5"
+  end
+end
diff --git a/vendor/gems/omniauth-salesforce/lib/omniauth/strategies/salesforce.rb b/vendor/gems/omniauth-salesforce/lib/omniauth/strategies/salesforce.rb
new file mode 100755
index 0000000000000..f2d811aeb9e73
--- /dev/null
+++ b/vendor/gems/omniauth-salesforce/lib/omniauth/strategies/salesforce.rb
@@ -0,0 +1,97 @@
+require 'omniauth-oauth2'
+require 'openssl'
+require 'base64'
+
+module OmniAuth
+  module Strategies
+    class Salesforce < OmniAuth::Strategies::OAuth2
+
+      MOBILE_USER_AGENTS =  'webos|ipod|iphone|ipad|android|blackberry|mobile'
+
+      option :client_options, {
+        :site          => 'https://login.salesforce.com',
+        :authorize_url => '/services/oauth2/authorize',
+        :token_url     => '/services/oauth2/token'
+      }
+      option :authorize_options, [
+        :scope,
+        :display,
+        :immediate,
+        :state,
+        :prompt
+      ]
+
+      def request_phase
+        req = Rack::Request.new(@env)
+        options.update(req.params)
+        ua = req.user_agent.to_s
+        if !options.has_key?(:display)
+          mobile_request = ua.downcase =~ Regexp.new(MOBILE_USER_AGENTS)
+          options[:display] = mobile_request ? 'touch' : 'page'
+        end
+        super
+      end
+
+      def auth_hash
+        signed_value = access_token.params['id'] + access_token.params['issued_at']
+        raw_expected_signature = OpenSSL::HMAC.digest('sha256', options.client_secret.to_s, signed_value)
+        expected_signature = Base64.strict_encode64 raw_expected_signature
+        signature = access_token.params['signature']
+        fail! "Salesforce user id did not match signature!" unless signature == expected_signature
+        super
+      end
+
+      uid { raw_info['id'] }
+
+      info do
+        {
+          'name'            => raw_info['display_name'],
+          'email'           => raw_info['email'],
+          'nickname'        => raw_info['nick_name'],
+          'first_name'      => raw_info['first_name'],
+          'last_name'       => raw_info['last_name'],
+          'location'        => '',
+          'description'     => '',
+          'image'           => raw_info['photos']['thumbnail'] + "?oauth_token=#{access_token.token}",
+          'phone'           => '',
+          'urls'            => raw_info['urls']
+        }
+      end
+
+      credentials do
+        hash = {'token' => access_token.token}
+        hash.merge!('instance_url' => access_token.params["instance_url"])
+        hash.merge!('refresh_token' => access_token.refresh_token) if access_token.refresh_token
+        hash
+      end
+
+      def raw_info
+        access_token.options[:mode] = :header
+        @raw_info ||= access_token.post(access_token['id']).parsed
+      end
+
+      extra do
+        raw_info.merge({
+          'instance_url' => access_token.params['instance_url'],
+          'pod' => access_token.params['instance_url'],
+          'signature' => access_token.params['signature'],
+          'issued_at' => access_token.params['issued_at']
+        })
+      end
+
+    end
+
+    class SalesforceSandbox < OmniAuth::Strategies::Salesforce
+      default_options[:client_options][:site] = 'https://test.salesforce.com'
+    end
+
+    class DatabaseDotCom < OmniAuth::Strategies::Salesforce
+      default_options[:client_options][:site] = 'https://login.database.com'
+    end
+
+    class SalesforcePreRelease < OmniAuth::Strategies::Salesforce
+      default_options[:client_options][:site] = 'https://prerellogin.pre.salesforce.com/'
+    end
+
+  end
+end
diff --git a/vendor/gems/omniauth-salesforce/omniauth-salesforce.gemspec b/vendor/gems/omniauth-salesforce/omniauth-salesforce.gemspec
new file mode 100755
index 0000000000000..0b9cfbd73ff42
--- /dev/null
+++ b/vendor/gems/omniauth-salesforce/omniauth-salesforce.gemspec
@@ -0,0 +1,24 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/omniauth-salesforce/version', __FILE__)
+
+Gem::Specification.new do |gem|
+  gem.authors       = ["Richard Vanhook"]
+  gem.email         = ["rvanhook@salesforce.com"]
+  gem.description   = %q{OmniAuth strategy for salesforce.com.}
+  gem.summary       = %q{OmniAuth strategy for salesforce.com.}
+  gem.homepage      = "https://github.com/realdoug/omniauth-salesforce"
+
+  gem.files         =  Dir.glob("lib/**/*.*")
+  gem.test_files    =  Dir.glob("spec/**/**/*.*")
+  gem.name          = "omniauth-salesforce"
+  gem.require_paths = ["lib"]
+  gem.version       = OmniAuth::Salesforce::VERSION
+  gem.license       = "MIT"
+
+  gem.add_dependency 'omniauth', '~> 1.0', '< 3'
+  gem.add_dependency 'omniauth-oauth2', '~> 1.0'
+  gem.add_development_dependency 'rspec', '~> 2.7'
+  gem.add_development_dependency 'rack-test'
+  gem.add_development_dependency 'simplecov'
+  gem.add_development_dependency 'webmock'
+end
diff --git a/vendor/gems/omniauth-salesforce/spec/omniauth/strategies/salesforce_spec.rb b/vendor/gems/omniauth-salesforce/spec/omniauth/strategies/salesforce_spec.rb
new file mode 100755
index 0000000000000..9b5afbdbe2576
--- /dev/null
+++ b/vendor/gems/omniauth-salesforce/spec/omniauth/strategies/salesforce_spec.rb
@@ -0,0 +1,219 @@
+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',
+            'refresh_token' => 'anything',
+						'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,
+            'refresh_token' => 'anything',
+						'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
+end
diff --git a/vendor/gems/omniauth-salesforce/spec/spec_helper.rb b/vendor/gems/omniauth-salesforce/spec/spec_helper.rb
new file mode 100755
index 0000000000000..0b00358fa0500
--- /dev/null
+++ b/vendor/gems/omniauth-salesforce/spec/spec_helper.rb
@@ -0,0 +1,16 @@
+$:.unshift File.expand_path('..', __FILE__)
+$:.unshift File.expand_path('../../lib', __FILE__)
+require 'simplecov'
+SimpleCov.start
+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
+end
+
-- 
GitLab