Skip to content

Commit

Permalink
fix(spec): allow tests to return :body
Browse files Browse the repository at this point in the history
  • Loading branch information
ZachGrande committed Sep 24, 2024
1 parent 7499cde commit f9a8bdf
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion spec/omniauth/strategies/microsoft_graph_oauth2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,14 @@
end

describe 'build_access_token' do
let(:body) { StringIO.new(%({"code":"json_access_token"})) }

it 'should use a hybrid authorization request_uri if this is an AJAX request with a code parameter' do
allow(request).to receive(:scheme).and_return('https')
allow(request).to receive(:url).and_return('https://example.com')
allow(request).to receive(:xhr?).and_return(true)
allow(request).to receive(:params).and_return('code' => 'valid_code')
allow(request).to receive(:body).and_return(body)

client = double(:client)
auth_code = double(:auth_code)
Expand All @@ -337,6 +340,7 @@
allow(request).to receive(:url).and_return('https://example.com')
allow(request).to receive(:xhr?).and_return(true)
allow(request).to receive(:params).and_return('code' => 'valid_code', 'callback_url' => 'localhost')
allow(request).to receive(:body).and_return(body)

client = double(:client)
auth_code = double(:auth_code)
Expand All @@ -354,6 +358,7 @@
allow(request).to receive(:url).and_return('https://example.com')
allow(request).to receive(:xhr?).and_return(false)
allow(request).to receive(:params).and_return('code' => 'valid_code', 'callback_url' => 'callback_url')
allow(request).to receive(:body).and_return(body)

client = double(:client)
auth_code = double(:auth_code)
Expand All @@ -370,6 +375,7 @@
allow(request).to receive(:url).and_return('https://example.com')
allow(request).to receive(:xhr?).and_return(false)
allow(request).to receive(:params).and_return('access_token' => 'valid_access_token')
allow(request).to receive(:body).and_return(body)
expect(subject).to receive(:verify_token).with('valid_access_token').and_return true
expect(subject).to receive(:client).and_return(:client)

Expand All @@ -380,7 +386,6 @@
end

it 'reads the code from a json request body' do
body = StringIO.new(%({"code":"json_access_token"}))
client = double(:client)
auth_code = double(:auth_code)

Expand All @@ -403,6 +408,7 @@
allow(request).to receive(:xhr?).and_return(false)
allow(request).to receive(:params).and_return('code' => 'valid_code')
allow(request).to receive(:content_type).and_return('application/x-www-form-urlencoded')
allow(request).to receive(:body).and_return(body)

client = double(:client)
auth_code = double(:auth_code)
Expand Down

0 comments on commit f9a8bdf

Please sign in to comment.