Skip to content

Commit

Permalink
Add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
kwent committed Jan 4, 2024
1 parent 34cc847 commit e9f6a5d
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in omniauth-service-now.gemspec
gemspec

group :development, :test do
gem 'guard'
gem 'guard-rspec'
gem 'guard-bundler'
gem 'rb-fsevent'
gem 'growl'
gem 'rake'
end
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env rake
require "bundler/gem_tasks"
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new

desc 'Run specs'
task :default => :spec
4 changes: 2 additions & 2 deletions lib/omniauth/strategies/dropbox_oauth2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class DropboxOauth2 < OmniAuth::Strategies::OAuth2
option :name, "dropbox_oauth2"
option :client_options, {
:site => 'https://api.dropbox.com',
:authorize_url => 'https://www.dropbox.com/oauth2/authorize',
:authorize_url => 'https://api.dropbox.com/oauth2/authorize',
:token_url => 'https://api.dropbox.com/oauth2/token'
}

Expand Down Expand Up @@ -44,7 +44,7 @@ def callback_url
if @authorization_code_from_signed_request
''
else
options[:callback_url] || super
options.redirect_url || (full_host + callback_path)
end
end
end
Expand Down
80 changes: 80 additions & 0 deletions spec/omniauth/strategies/dropbox_oauth2_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
require 'spec_helper'

describe OmniAuth::Strategies::DropboxOauth2 do
let(:access_token) { instance_double('AccessToken', :options => {}, :[] => 'user') }
let(:parsed_response) { instance_double('ParsedResponse') }
let(:response) { instance_double('Response', :parsed => parsed_response) }

let(:enterprise_site) { 'https://some.other.site.com' }
let(:enterprise_authorize_url) { 'https://some.other.site.com/login/oauth/authorize' }
let(:enterprise_token_url) { 'https://some.other.site.com/login/oauth/token' }
let(:enterprise) do
OmniAuth::Strategies::DropboxOauth2.new('DROPBOX_CLIENT_ID', 'DROPBOX_CLIENT_SECRET',
{
:client_options => {
:site => enterprise_site,
:authorize_url => enterprise_authorize_url,
:token_url => enterprise_token_url
}
}
)
end

subject do
OmniAuth::Strategies::DropboxOauth2.new({})
end

before(:each) do
allow(subject).to receive(:access_token).and_return(access_token)
end

context 'client options' do
it 'should have correct site' do
expect(subject.options.client_options.site).to eq('https://api.dropbox.com')
end

it 'should have correct authorize url' do
expect(subject.options.client_options.authorize_url).to eq('https://api.dropbox.com/oauth2/authorize')
end

it 'should have correct token url' do
expect(subject.options.client_options.token_url).to eq('https://api.dropbox.com/oauth2/token')
end

describe 'should be overrideable' do
it 'for site' do
expect(enterprise.options.client_options.site).to eq(enterprise_site)
end

it 'for authorize url' do
expect(enterprise.options.client_options.authorize_url).to eq(enterprise_authorize_url)
end

it 'for token url' do
expect(enterprise.options.client_options.token_url).to eq(enterprise_token_url)
end
end
end

describe '#callback_url' do
let(:base_url) { 'https://example.com' }

context 'no script name present' do
it 'has the correct default callback path' do
allow(subject).to receive(:full_host) { base_url }
allow(subject).to receive(:script_name) { '' }
allow(subject).to receive(:query_string) { '' }
expect(subject.callback_url).to eq(base_url + '/auth/dropbox_oauth2/callback')
end
end

context 'script name' do
it 'should set the callback path with script_name' do
allow(subject).to receive(:full_host) { base_url }
allow(subject).to receive(:script_name) { '/v1' }
allow(subject).to receive(:query_string) { '' }
expect(subject.callback_url).to eq(base_url + '/v1/auth/dropbox_oauth2/callback')
end
end
end
end
16 changes: 16 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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-dropbox-oauth2'

RSpec.configure do |config|
config.include WebMock::API
config.include Rack::Test::Methods
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
end

0 comments on commit e9f6a5d

Please sign in to comment.