Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rack dependency update #1

Open
wants to merge 3 commits into
base: core-0-8-stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions oauth2.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Gem::Specification.new do |gem|
gem.add_dependency 'faraday', '~> 0.8'
gem.add_dependency 'httpauth', '~> 0.1'
gem.add_dependency 'multi_json', '~> 1.0'
gem.add_dependency 'rack', '~> 1.2'
gem.add_dependency 'jwt', '~> 0.1.4'
gem.add_dependency 'rack', '~> 2.0'
gem.add_dependency 'jwt', '~> 1.5.6'
gem.add_development_dependency 'addressable'
gem.add_development_dependency 'multi_xml'
gem.add_development_dependency 'rake'
Expand Down
19 changes: 5 additions & 14 deletions spec/oauth2/access_token_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def assert_initialized_token(target)
target.options[:header_format].should == 'Bearer %'
target.options[:mode].should == :body
end

it "initializes with a string expires_at" do
hash = {:access_token => token, :expires_at => '1361396829', 'foo' => 'bar'}
target = AccessToken.from_hash(client, hash)
Expand All @@ -70,36 +70,27 @@ def assert_initialized_token(target)

describe '#request' do
context ':mode => :header' do
before :all do
subject.options[:mode] = :header
end

VERBS.each do |verb|
it "sends the token in the Authorization header for a #{verb.to_s.upcase} request" do
subject.options[:mode] = :header
subject.post('/token/header').body.should include(token)
end
end
end

context ':mode => :query' do
before :all do
subject.options[:mode] = :query
end

VERBS.each do |verb|
it "sends the token in the Authorization header for a #{verb.to_s.upcase} request" do
subject.options[:mode] = :query
subject.post('/token/query').body.should == token
end
end
end

context ':mode => :body' do
before :all do
subject.options[:mode] = :body
end

VERBS.each do |verb|
it "sends the token in the Authorization header for a #{verb.to_s.upcase} request" do
subject.options[:mode] = :body
subject.post('/token/body').body.split('=').last.should == token
end
end
Expand Down Expand Up @@ -132,7 +123,7 @@ def assert_initialized_token(target)
it 'should be true if expires_at is in the past' do
access = AccessToken.new(client, token, :refresh_token => 'abaca', :expires_in => 600)
@now = Time.now + 10800
Time.stub!(:now).and_return(@now)
Time.stub(:now).and_return(@now)
access.should be_expired
end

Expand Down
37 changes: 21 additions & 16 deletions spec/oauth2/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
end

it 'should leave Faraday::Connection#ssl unset' do
subject.connection.ssl.should == {}
subject.connection.ssl.to_hash.should == {}
end

it "should be able to pass a block to configure the connection" do
Expand All @@ -53,14 +53,14 @@
end

it "defaults raise_errors to true" do
subject.options[:raise_errors].should be_true
subject.options[:raise_errors].should be_truthy
end

it "allows true/false for raise_errors option" do
client = OAuth2::Client.new('abc', 'def', :site => 'https://api.example.com', :raise_errors => false)
client.options[:raise_errors].should be_false
client.options[:raise_errors].should be_falsey
client = OAuth2::Client.new('abc', 'def', :site => 'https://api.example.com', :raise_errors => true)
client.options[:raise_errors].should be_true
client.options[:raise_errors].should be_truthy
end

it "allows get/post for access_token_method option" do
Expand Down Expand Up @@ -136,29 +136,34 @@
response.error.should_not be_nil
end

%w(/unauthorized /conflict /error).each do |error_path|
it "raises OAuth2::Error on error response to path #{error_path}" do
lambda {subject.request(:get, error_path)}.should raise_error(OAuth2::Error)
it "raises OAuth2::Conflict error in response to a conflict" do
begin
subject.request(:get, '/conflict')
true.should be_falsey, "expected an OAuth2::Conflict error to be raised"
rescue OAuth2::Conflict => ex
ex.response.should_not be_nil
ex.to_s.should match(/Received HTTP 409/)
end
end

it 'parses OAuth2 standard error response' do
begin
subject.request(:get, '/unauthorized')
rescue Exception => e
e.code.should == error_value
e.description.should == error_description_value
e.to_s.should match(/#{error_value}/)
e.to_s.should match(/#{error_description_value}/)
# test that the above raised an error as expected
true.should be_falsey, "expected an OAuth2::AccessDenied error to be raised"
rescue OAuth2::AccessDenied => ex
ex.response.should_not be_nil
ex.to_s.should match(/Received HTTP 401/)
end
end

it "provides the response in the Exception" do
begin
subject.request(:get, '/error')
rescue Exception => e
e.response.should_not be_nil
e.to_s.should match(/unknown error/)
true.should be_falsey, "expected an OAuth2::HTTPError error to be raised"
rescue OAuth2::HTTPError => ex
ex.response.should_not be_nil
ex.to_s.should match(/Received HTTP 500/)
end
end
end
Expand All @@ -181,7 +186,7 @@
end

it 'should pass the SSL options along to Faraday::Connection#ssl' do
subject.connection.ssl.should == {:ca_file => 'foo.pem'}
subject.connection.ssl.to_hash.should == {:ca_file => 'foo.pem'}
end
end
end