From c24aab6a464c38f5fbaa7a2528d0e17b0c579b74 Mon Sep 17 00:00:00 2001 From: Zack Olson Date: Thu, 16 Nov 2017 13:39:55 -0500 Subject: [PATCH 1/3] bump rake version for core rails upgrade compatibility --- oauth2.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oauth2.gemspec b/oauth2.gemspec index f57cf9ba..8f9c8cb3 100644 --- a/oauth2.gemspec +++ b/oauth2.gemspec @@ -5,7 +5,7 @@ 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 'rack', '~> 2.0' gem.add_dependency 'jwt', '~> 0.1.4' gem.add_development_dependency 'addressable' gem.add_development_dependency 'multi_xml' From 20ac98a35c7235c8a4734dab50710015f4262f88 Mon Sep 17 00:00:00 2001 From: Zack Olson Date: Thu, 16 Nov 2017 16:29:54 -0500 Subject: [PATCH 2/3] fix all tests, rake passing --- spec/oauth2/access_token_spec.rb | 19 +++++----------- spec/oauth2/client_spec.rb | 37 ++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/spec/oauth2/access_token_spec.rb b/spec/oauth2/access_token_spec.rb index 637dc9a9..789c7bd7 100644 --- a/spec/oauth2/access_token_spec.rb +++ b/spec/oauth2/access_token_spec.rb @@ -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) @@ -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 @@ -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 diff --git a/spec/oauth2/client_spec.rb b/spec/oauth2/client_spec.rb index e9a9ea07..4d1d778c 100644 --- a/spec/oauth2/client_spec.rb +++ b/spec/oauth2/client_spec.rb @@ -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 @@ -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 @@ -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 @@ -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 From e5105c7184fe2848ca82695b5baaf4cf4745d3d8 Mon Sep 17 00:00:00 2001 From: Zack Olson Date: Thu, 16 Nov 2017 16:31:28 -0500 Subject: [PATCH 3/3] bump jwt version and rebundle, rake passing --- oauth2.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oauth2.gemspec b/oauth2.gemspec index 8f9c8cb3..a625338a 100644 --- a/oauth2.gemspec +++ b/oauth2.gemspec @@ -6,7 +6,7 @@ Gem::Specification.new do |gem| gem.add_dependency 'httpauth', '~> 0.1' gem.add_dependency 'multi_json', '~> 1.0' gem.add_dependency 'rack', '~> 2.0' - gem.add_dependency 'jwt', '~> 0.1.4' + gem.add_dependency 'jwt', '~> 1.5.6' gem.add_development_dependency 'addressable' gem.add_development_dependency 'multi_xml' gem.add_development_dependency 'rake'