diff --git a/.circleci/config.yml b/.circleci/config.yml index ea1b3d5..e6e38a4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -58,8 +58,6 @@ commands: - restore_cache: keys: - <>-{{ arch }}-{{ .Branch }}-{{ checksum "omniauth-bigcommerce.gemspec" }}-{{checksum "Gemfile"}} - - <>-{{ arch }}-{{ .Branch }} - - <> - run: name: "bundle install" command: | @@ -136,7 +134,6 @@ jobs: - bundle-install: <<: *gem_cache_key - rspec-unit - workflows: version: 2 ruby_2_7: diff --git a/.rubocop.yml b/.rubocop.yml index 5b4e1c0..ca45712 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,5 @@ AllCops: - TargetRubyVersion: 2.1 + TargetRubyVersion: 2.7.5 NewCops: enable SuggestExtensions: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a9e074..772b8d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ Changelog for the omniauth-bigcommerce gem. ### Pending release +- Add support for Ruby 3.0 and above +- Remove support for Ruby < 2.7.5 +- Upgrade `oauth2` gem >= 2.0 +- Upgrade `omniauth-oauth2` gem to >= 1.7 +- Add CircleCI support + ### 0.4.0 - Adds account_uuid to response payload diff --git a/README.md b/README.md index f958425..96bad9d 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ The following response format is provided back to you for this provider: raw_info: {}, scopes: 'requested_scopes store_v2_settings' context: 'store/xyz123', - account_uuid: 'fooBar' + account_uuid: '3D2D8C24-8378-4180-9550-69A95ABDFAAF' } } ``` diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..1628e46 --- /dev/null +++ b/bin/console @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require 'bundler/setup' +require 'omniauth-bigcommerce' + +# You can add fixtures and/or initialization code here to make experimenting +# with your gem easier. You can also use a different console, if you like. + +require 'irb' +IRB.start(__FILE__) diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..5407075 --- /dev/null +++ b/bin/setup @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' +set -vx + +bundle install +bundle exec rspec -p +bundle exec rubocop -P +bundle audit update +bundle audit diff --git a/lib/omniauth/bigcommerce/version.rb b/lib/omniauth/bigcommerce/version.rb index 5b2d0f1..2cfc29c 100644 --- a/lib/omniauth/bigcommerce/version.rb +++ b/lib/omniauth/bigcommerce/version.rb @@ -17,6 +17,6 @@ # module OmniAuth module BigCommerce - VERSION = '0.4.1.pre' + VERSION = '1.0.0.pre' end end diff --git a/lib/omniauth/strategies/bigcommerce.rb b/lib/omniauth/strategies/bigcommerce.rb index 15eef78..d9bcf40 100644 --- a/lib/omniauth/strategies/bigcommerce.rb +++ b/lib/omniauth/strategies/bigcommerce.rb @@ -30,8 +30,8 @@ class BigCommerce < OmniAuth::Strategies::OAuth2 option :token_options, %i[scope context account_uuid] option :client_options, site: ENV.fetch('BC_AUTH_SERVICE', 'https://login.bigcommerce.com'), - authorize_url: '/oauth2/authorize', - token_url: '/oauth2/token' + authorize_url: 'oauth2/authorize', + token_url: 'oauth2/token' uid { access_token.params['user']['id'] } @@ -64,7 +64,7 @@ def raw_info # Exclude query string in callback url. This used to be part of omniauth-oauth2, but was # removed in 1.4.0: https://github.com/intridea/omniauth-oauth2/pull/70 def callback_url - full_host + script_name + callback_path + full_host + callback_path end # Make sure to pass scope and context through to the authorize call diff --git a/omniauth-bigcommerce.gemspec b/omniauth-bigcommerce.gemspec index ea9b1e9..5fffd69 100644 --- a/omniauth-bigcommerce.gemspec +++ b/omniauth-bigcommerce.gemspec @@ -27,12 +27,12 @@ Gem::Specification.new do |gem| gem.files = Dir['README.md', 'lib/**/*', 'omniauth-bigcommerce.gemspec', 'Gemfile'] gem.name = 'omniauth-bigcommerce' gem.require_paths = ['lib'] - gem.required_ruby_version = '>= 2.1' + gem.required_ruby_version = '>= 2.7.5' gem.version = OmniAuth::BigCommerce::VERSION gem.license = 'MIT' - gem.add_dependency 'oauth2', '>= 1.4.4' + gem.add_dependency 'oauth2', '>= 2.0.0' gem.add_dependency 'omniauth' - gem.add_dependency 'omniauth-oauth2', '>= 1.5' + gem.add_dependency 'omniauth-oauth2', '>= 1.7' gem.metadata['rubygems_mfa_required'] = 'true' end diff --git a/spec/omniauth/strategies/bigcommerce_spec.rb b/spec/omniauth/strategies/bigcommerce_spec.rb index 8b8c420..ba935de 100644 --- a/spec/omniauth/strategies/bigcommerce_spec.rb +++ b/spec/omniauth/strategies/bigcommerce_spec.rb @@ -3,78 +3,79 @@ require 'spec_helper' RSpec.describe OmniAuth::Strategies::BigCommerce do + subject { described_class.new({}) } + let(:store_hash) { 'abcdefg' } let(:context) { "stores/#{store_hash}" } let(:scope) { 'store_v2_products' } let(:account_uuid) { 'foobar' } let(:request) do - double('Request', params: { 'context' => context, 'scope' => scope, 'account_uuid' => account_uuid }, cookies: {}, - env: {}) + instance_double(Rack::Request, params: { 'context' => context, 'scope' => scope, 'account_uuid' => account_uuid }, + cookies: {}, env: {}) end before do OmniAuth.config.test_mode = true - allow(subject).to receive(:request).and_return(request) - allow(subject).to receive(:script_name).and_return('') + allow(subject).to receive_messages(request: request, script_name: '') end + after { OmniAuth.config.test_mode = false } - subject { OmniAuth::Strategies::BigCommerce.new({}) } describe 'options' do - it 'should have correct name' do + it 'has correct name' do expect(subject.options.name).to eq('bigcommerce') end describe 'client options' do - it 'should have correct site' do + it 'has correct site' do # env variable set in spec_helper.rb # TODO: change this once we have bigcommerceapp.com url expect(subject.options.client_options.site).to eq('https://example.com') end - it 'should have correct authorize url' do - expect(subject.options.client_options.authorize_url).to eq('/oauth2/authorize') + it 'has correct authorize url' do + expect(subject.options.client_options.authorize_url).to eq('oauth2/authorize') end - it 'should have correct token url' do - expect(subject.options.client_options.token_url).to eq('/oauth2/token') + it 'has correct token url' do + expect(subject.options.client_options.token_url).to eq('oauth2/token') end end describe 'OAuth2 settings' do - it 'should ignore state' do - expect(subject.options.provider_ignores_state).to eq true + it 'ignores state' do + expect(subject.options.provider_ignores_state).to be true end end end describe 'callback url' do - it 'should have the correct path' do + it 'has the correct path' do expect(subject.callback_path).to eq('/auth/bigcommerce/callback') end context 'when callback url has a query string' do let(:host) { 'https://example.com' } let(:query_string) { 'foo=bar' } + before do - allow(subject).to receive(:full_host).and_return(host) - allow(subject).to receive(:query_string).and_return(query_string) + allow(subject).to receive_messages(full_host: host, script_name: '', query_string: query_string) end - it 'query string should not be included in the callback url' do + it 'query string is not included in the callback url' do expect(subject.callback_url).to eq("#{host}#{subject.callback_path}") - expect(subject.callback_url).to_not include(query_string) + expect(subject.callback_url).not_to include(query_string) end end end describe 'extra params for authorize and token exchange' do - it 'should set the context and scope parameters in the authorize request' do + it 'sets the context and scope parameters in the authorize request' do expect(subject.authorize_params['context']).to eq(context) expect(subject.authorize_params['scope']).to eq(scope) end - it 'should set the context and scope parameters in the token request' do + it 'sets the context and scope parameters in the token request' do expect(subject.token_params['context']).to eq(context) expect(subject.token_params['scope']).to eq(scope) expect(subject.token_params['account_uuid']).to eq(account_uuid)