Skip to content

Commit

Permalink
Merge pull request #40 from zaikio/ruby3-2
Browse files Browse the repository at this point in the history
Fix another issue in Ruby 3
  • Loading branch information
nickcampbell18 authored Jan 20, 2021
2 parents 9649780 + 05e1c71 commit 508ecf7
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Metrics/BlockLength:
- test/**/*.rb

Metrics/AbcSize:
Max: 16
Max: 22

Metrics/CyclomaticComplexity:
Max: 10
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions app/models/zaikio/access_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion lib/zaikio/oauth_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion lib/zaikio/oauth_client/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def initialize
end

def logger
@logger ||= Logger.new(STDOUT)
@logger ||= Logger.new($stdout)
end

def register_client(name)
Expand Down
2 changes: 1 addition & 1 deletion lib/zaikio/oauth_client/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Zaikio
module OAuthClient
VERSION = "0.4.3".freeze
VERSION = "0.4.4".freeze
end
end
4 changes: 2 additions & 2 deletions test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 36 additions & 0 deletions test/zaikio/oauth_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 508ecf7

Please sign in to comment.