Revert "Add ability to configure http client via callbacks"
This commit is contained in:
Родитель
be61469081
Коммит
b9056875d2
|
@ -1 +1 @@
|
|||
2.6.2
|
||||
2.3.1
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
language: ruby
|
||||
rvm:
|
||||
- 2.4
|
||||
- 2.5
|
||||
- 2.6
|
||||
- 2.3.5
|
||||
- 2.4.2
|
||||
bundler_args: --without production
|
||||
script:
|
||||
- bundle exec rspec spec
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class CreateTokens < ActiveRecord::Migration[5.2]
|
||||
class CreateTokens < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :tokens do |t|
|
||||
t.string :name
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class AddTokenIdToToken < ActiveRecord::Migration[5.2]
|
||||
class AddTokenIdToToken < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :tokens, :token_id, :string
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class AddProviderToTokens < ActiveRecord::Migration[5.2]
|
||||
class AddProviderToTokens < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :tokens, :provider, :string
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class SeparateTokens < ActiveRecord::Migration[5.2]
|
||||
class SeparateTokens < ActiveRecord::Migration
|
||||
def change
|
||||
rename_table :tokens, :recovery_tokens
|
||||
create_table :reference_tokens do |t|
|
||||
|
|
25
db/schema.rb
25
db/schema.rb
|
@ -10,24 +10,27 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2017_03_15_000657) do
|
||||
ActiveRecord::Schema.define(version: 20170315000657) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
create_table "recovery_tokens", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.text "token_blob"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "token_id"
|
||||
t.string "provider"
|
||||
t.string "name"
|
||||
t.text "token_blob"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "token_id"
|
||||
t.string "provider"
|
||||
end
|
||||
|
||||
create_table "reference_tokens", force: :cascade do |t|
|
||||
t.string "provider"
|
||||
t.string "token_id"
|
||||
t.string "provider"
|
||||
t.string "token_id"
|
||||
t.datetime "confirmed_at"
|
||||
t.datetime "recovered_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -64,7 +64,7 @@ module Darrrr
|
|||
#
|
||||
# provider_origin: the origin that contains the config data in a well-known
|
||||
# location.
|
||||
def recovery_provider(provider_origin, &block)
|
||||
def recovery_provider(provider_origin)
|
||||
unless self.recovery_providers
|
||||
raise "No recovery providers configured"
|
||||
end
|
||||
|
@ -72,11 +72,7 @@ module Darrrr
|
|||
if provider_origin == this_recovery_provider&.origin
|
||||
this_recovery_provider
|
||||
elsif self.recovery_providers.include?(provider_origin)
|
||||
RecoveryProvider.new(provider_origin).tap { |provider|
|
||||
if block_given?
|
||||
yield provider
|
||||
end
|
||||
}.load
|
||||
RecoveryProvider.new(provider_origin).load
|
||||
else
|
||||
raise UnknownProviderError, "Unknown recovery provider: #{provider_origin}"
|
||||
end
|
||||
|
@ -94,18 +90,14 @@ module Darrrr
|
|||
#
|
||||
# provider_origin: the origin that contains the config data in a well-known
|
||||
# location.
|
||||
def account_provider(provider_origin, &block)
|
||||
def account_provider(provider_origin)
|
||||
unless self.account_providers
|
||||
raise "No account providers configured"
|
||||
end
|
||||
if provider_origin == this_account_provider&.origin
|
||||
this_account_provider
|
||||
elsif self.account_providers.include?(provider_origin)
|
||||
AccountProvider.new(provider_origin).tap { |provider|
|
||||
if block_given?
|
||||
yield provider
|
||||
end
|
||||
}.load
|
||||
AccountProvider.new(provider_origin).load
|
||||
else
|
||||
raise UnknownProviderError, "Unknown account provider: #{provider_origin}"
|
||||
end
|
||||
|
|
|
@ -9,7 +9,6 @@ module Darrrr
|
|||
|
||||
def self.included(base)
|
||||
base.instance_eval do
|
||||
attr_accessor :faraday_config_callback
|
||||
# this represents the account/recovery provider on this web app
|
||||
class << self
|
||||
attr_accessor :this
|
||||
|
@ -77,11 +76,7 @@ module Darrrr
|
|||
|
||||
private def faraday
|
||||
Faraday.new do |f|
|
||||
if @faraday_config_callback
|
||||
@faraday_config_callback.call(f)
|
||||
else
|
||||
f.adapter(Faraday.default_adapter)
|
||||
end
|
||||
f.adapter(Faraday.default_adapter)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -27,39 +27,6 @@ module Darrrr
|
|||
end
|
||||
end
|
||||
|
||||
it "provides extra options for faraday" do
|
||||
account_provider.faraday_config_callback = lambda do |faraday|
|
||||
faraday.headers["Accept-Encoding"] = :foo
|
||||
faraday.adapter(:typhoeus)
|
||||
end
|
||||
|
||||
# assert extra header
|
||||
account_provider_faraday = account_provider.send(:faraday)
|
||||
expect(account_provider_faraday.headers).to include("Accept-Encoding" => :foo)
|
||||
|
||||
# assert handler is property set
|
||||
handler = JSON.parse(account_provider_faraday.to_json)["builder"]["handlers"]
|
||||
expect(handler).to_not be_nil
|
||||
handler_name = handler.first["name"]
|
||||
expect(handler_name).to_not be_nil
|
||||
expect(handler_name).to eq("Faraday::Adapter::Typhoeus")
|
||||
end
|
||||
|
||||
it "allows you to configure the recovery provider during retrieval" do
|
||||
account_provider = Darrrr.account_provider("https://example-provider.org") do |provider|
|
||||
provider.faraday_config_callback = lambda do |faraday|
|
||||
faraday.adapter(Faraday.default_adapter)
|
||||
faraday.headers["Accept-Encoding"] = "foo"
|
||||
end
|
||||
end
|
||||
|
||||
expect(account_provider).to be_kind_of(Darrrr::AccountProvider)
|
||||
|
||||
# assert extra header
|
||||
account_provider_faraday = account_provider.send(:faraday)
|
||||
expect(account_provider_faraday.headers).to include("Accept-Encoding" => "foo")
|
||||
end
|
||||
|
||||
it "tokens can be sealed and unsealed" do
|
||||
payload = Base64.strict_decode64(account_provider.send(:seal, token))
|
||||
unsealed_token = account_provider.unseal(payload)
|
||||
|
|
|
@ -44,24 +44,6 @@ module Darrrr
|
|||
}
|
||||
end
|
||||
|
||||
it "provides extra options for faraday" do
|
||||
recovery_provider.faraday_config_callback = lambda do |faraday|
|
||||
faraday.headers["Accept-Encoding"] = :foo
|
||||
faraday.adapter(:typhoeus)
|
||||
end
|
||||
|
||||
# assert extra header
|
||||
recovery_provider_faraday = recovery_provider.send(:faraday)
|
||||
expect(recovery_provider_faraday.headers).to include("Accept-Encoding" => :foo)
|
||||
|
||||
# assert handler is property set
|
||||
handler = JSON.parse(recovery_provider_faraday.to_json)["builder"]["handlers"]
|
||||
expect(handler).to_not be_nil
|
||||
handler_name = handler.first["name"]
|
||||
expect(handler_name).to_not be_nil
|
||||
expect(handler_name).to eq("Faraday::Adapter::Typhoeus")
|
||||
end
|
||||
|
||||
it "does not accept in incomplete config" do
|
||||
config.delete("issuer")
|
||||
expect {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require_relative "../spec_helper"
|
||||
|
||||
describe Darrrr, vcr: { :cassette_name => "delegated_account_recovery/recovery_provider", match_requests_on: [:method, :uri] } do
|
||||
describe Darrrr, vcr: { :cassette_name => "delegated_account_recovery/recovery_provider" } do
|
||||
context "#recovery_provider" do
|
||||
it "raises an error if you ask for an unregistered recovery provider" do
|
||||
expect {
|
||||
|
@ -13,21 +13,6 @@ describe Darrrr, vcr: { :cassette_name => "delegated_account_recovery/recovery_p
|
|||
it "returns a registered recovery provider" do
|
||||
expect(Darrrr.recovery_provider("https://example-provider.org")).to be_kind_of(Darrrr::RecoveryProvider)
|
||||
end
|
||||
|
||||
it "allows you to configure the recovery provider during retrieval" do
|
||||
recovery_provider = Darrrr.recovery_provider("https://example-provider.org") do |provider|
|
||||
provider.faraday_config_callback = lambda do |faraday|
|
||||
faraday.adapter(Faraday.default_adapter)
|
||||
faraday.headers["Accept-Encoding"] = "foo"
|
||||
end
|
||||
end
|
||||
|
||||
expect(recovery_provider).to be_kind_of(Darrrr::RecoveryProvider)
|
||||
|
||||
# assert extra header
|
||||
recovery_provider_faraday = recovery_provider.send(:faraday)
|
||||
expect(recovery_provider_faraday.headers).to include("Accept-Encoding" => "foo")
|
||||
end
|
||||
end
|
||||
|
||||
context "#register_recovery_provider" do
|
||||
|
|
Загрузка…
Ссылка в новой задаче