1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
require 'spec_helper.rb'
describe Rack::OAuth2::Server::Token::AuthorizationCode do
let(:request) { Rack::MockRequest.new app }
let(:app) do
Rack::OAuth2::Server::Token.new do |request, response|
response.access_token = Rack::OAuth2::AccessToken::Bearer.new(access_token: 'access_token')
end
end
let(:params) do
{
grant_type: 'authorization_code',
client_id: 'client_id',
code: 'authorization_code',
redirect_uri: 'http://client.example.com/callback'
}
end
let(:response) { request.post('/', params: params) }
subject { response }
its(:status) { should == 200 }
its(:content_type) { should == 'application/json' }
its(:body) { should include '"access_token":"access_token"' }
its(:body) { should include '"token_type":"bearer"' }
it 'should prevent to be cached' do
response.headers['Cache-Control'].should == 'no-store'
response.headers['Pragma'].should == 'no-cache'
end
[:code].each do |required|
context "when #{required} is missing" do
before do
params.delete_if do |key, value|
key == required
end
end
its(:status) { should == 400 }
its(:content_type) { should == 'application/json' }
its(:body) { should include '"error":"invalid_request"' }
end
end
end
|