diff --git a/.rubocop.yml b/.rubocop.yml index 6a4d533..07faa63 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -29,7 +29,7 @@ Metrics/BlockLength: - test/**/*.rb Metrics/AbcSize: - Max: 16 + Max: 22 Metrics/CyclomaticComplexity: Max: 10 diff --git a/CHANGELOG.md b/CHANGELOG.md index bbd5b1a..6612fc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## 0.4.4 - 2021-01-19 + +* Fix another compatibility issue with Ruby 3.0 + ## 0.4.3 - 2021-01-15 * Automatically publish to RubyGems diff --git a/Gemfile.lock b/Gemfile.lock index e6d461a..5f5b45d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - zaikio-oauth_client (0.4.1) + zaikio-oauth_client (0.4.4) oauth2 rails (>= 5.0.0) zaikio-jwt_auth (>= 0.2.1, < 0.5.0) diff --git a/app/models/zaikio/access_token.rb b/app/models/zaikio/access_token.rb index 3773ddf..fc2f912 100644 --- a/app/models/zaikio/access_token.rb +++ b/app/models/zaikio/access_token.rb @@ -38,13 +38,13 @@ def self.refresh_token_valid_for .where("refresh_token IS NOT NULL") .where.not(id: Zaikio::JWTAuth.revoked_token_ids) } - scope :by_bearer, lambda { |bearer_type: "Person", bearer_id:, scopes: []| + scope :by_bearer, lambda { |bearer_id:, scopes: [], bearer_type: "Person"| where(bearer_type: bearer_type, bearer_id: bearer_id) .where("scopes @> ARRAY[?]::varchar[]", scopes) } scope :usable, lambda { |options| by_bearer(**options).valid.or(by_bearer(**options).valid_refresh) - .order(expires_at: :desc) + .order(expires_at: :desc) } def expired? diff --git a/lib/zaikio/oauth_client.rb b/lib/zaikio/oauth_client.rb index 56273ff..e3ef4ab 100644 --- a/lib/zaikio/oauth_client.rb +++ b/lib/zaikio/oauth_client.rb @@ -45,7 +45,7 @@ def with_auth(options_or_access_token, &block) access_token = if options_or_access_token.is_a?(Zaikio::AccessToken) options_or_access_token else - get_access_token(options_or_access_token) + get_access_token(**options_or_access_token) end return unless block_given? diff --git a/lib/zaikio/oauth_client/configuration.rb b/lib/zaikio/oauth_client/configuration.rb index 2531501..1e83d25 100644 --- a/lib/zaikio/oauth_client/configuration.rb +++ b/lib/zaikio/oauth_client/configuration.rb @@ -25,7 +25,7 @@ def initialize end def logger - @logger ||= Logger.new(STDOUT) + @logger ||= Logger.new($stdout) end def register_client(name) diff --git a/lib/zaikio/oauth_client/version.rb b/lib/zaikio/oauth_client/version.rb index 90f9c16..4550a7b 100644 --- a/lib/zaikio/oauth_client/version.rb +++ b/lib/zaikio/oauth_client/version.rb @@ -1,5 +1,5 @@ module Zaikio module OAuthClient - VERSION = "0.4.3".freeze + VERSION = "0.4.4".freeze end end diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index be9c9ea..e8f4152 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb @@ -2,8 +2,8 @@ # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # -# This file is the source Rails uses to define your schema when running `rails -# db:schema:load`. When creating a new database, `rails db:schema:load` tends to +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to # be faster and is potentially less error prone than running all of your # migrations from scratch. Old migrations may fail to apply correctly if those # migrations use external dependencies or application code. diff --git a/test/test_helper.rb b/test/test_helper.rb index c71ecaf..d00b653 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -15,6 +15,6 @@ if ActiveSupport::TestCase.respond_to?(:fixture_path=) ActiveSupport::TestCase.fixture_path = File.expand_path("fixtures", __dir__) ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path - ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + "/files" + ActiveSupport::TestCase.file_fixture_path = File.join(ActiveSupport::TestCase.fixture_path, "files") ActiveSupport::TestCase.fixtures :all end diff --git a/test/zaikio/oauth_client_test.rb b/test/zaikio/oauth_client_test.rb index 99f6b57..6bf19da 100644 --- a/test/zaikio/oauth_client_test.rb +++ b/test/zaikio/oauth_client_test.rb @@ -322,4 +322,40 @@ def setup assert_equal "abc", MyLib.my_token end end + + test "use with auth helper to generate token" do + Zaikio::JWTAuth.stubs(:revoked_token_ids).returns([]) + stub_request(:post, "http://hub.zaikio.test/oauth/access_token") + .with( + basic_auth: %w[abc secret], + body: { + "grant_type" => "client_credentials", + "scope" => "Org/123.directory.organization.r" + }, + headers: { + "Accept" => "application/json" + } + ) + .to_return(status: 200, body: { + "access_token" => org_token, + "refresh_token" => "refresh_token", + "token_type" => "bearer", + "scope" => "directory.organization.r", + "audiences" => ["warehouse"], + "expires_in" => 600, + "bearer" => { + "id": "123", + "type": "Organization" + } + }.to_json, headers: { "Content-Type" => "application/json" }) + + obj = OpenStruct.new + obj.expects(:call) + + Zaikio::OAuthClient.with_auth(bearer_type: "Organization", + bearer_id: "123", + scopes: %w[directory.organization.r]) do + obj.call + end + end end