Skip to content

Commit

Permalink
Add specs for callback_url + fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kwent committed Jan 4, 2024
1 parent 6e635c4 commit 65d801f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/omniauth/strategies/pagerduty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def me
end

def callback_url
full_host + script_name + callback_path
options.redirect_url || (full_host + callback_path)
end
end
end
Expand Down
21 changes: 17 additions & 4 deletions spec/omniauth/strategies/pagerduty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,24 @@
end

describe '#callback_url' do
it 'is a combination of host, script name, and callback path' do
allow(subject).to receive(:full_host).and_return('https://example.com')
allow(subject).to receive(:script_name).and_return('/sub_uri')
let(:base_url) { 'https://example.com' }

expect(subject.callback_url).to eq('https://example.com/sub_uri/auth/pagerduty/callback')
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/pagerduty/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/pagerduty/callback')
end
end
end
end

0 comments on commit 65d801f

Please sign in to comment.