Skip to content

Commit

Permalink
adding support for risk and filter failover
Browse files Browse the repository at this point in the history
the structure of authenticate differs from risk and filter

authenticate - { action: 'allow|deny|challenge' }
risk/filter - { policy: { action: 'allow|deny|challenge' } }
  • Loading branch information
James Stoup authored and bartes committed Jun 15, 2021
1 parent 29699bb commit f80d7ee
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## master

## 7.1.1

- [#246](https://github.com/castle/castle-ruby/pull/246)
* support failover for risk and filter

## 7.1.0 (2021-06-09)

- [#245](https://github.com/castle/castle-ruby/pull/245)
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
castle-rb (7.1.0)
castle-rb (7.1.1)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -104,4 +104,4 @@ DEPENDENCIES
webmock

BUNDLED WITH
2.1.4
2.2.19
12 changes: 11 additions & 1 deletion lib/castle/failover/prepare_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@ def initialize(user_id, reason:, strategy:)
end

def call
{ action: @strategy.to_s, user_id: @user_id, failover: true, failover_reason: @reason }
{
# v1/risk v1/filter structure
policy: {
action: @strategy.to_s,
},
# v1/authenticate structure
action: @strategy.to_s,
user_id: @user_id,
failover: true,
failover_reason: @reason
}
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/castle/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Castle
VERSION = '7.1.0'
VERSION = '7.1.1'
end
3 changes: 3 additions & 0 deletions spec/lib/castle/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
end

it { assert_not_requested :post, 'https://api.castle.io/v1/authenticate' }
it { expect(request_response[:policy][:action]).to be_eql(Castle::Verdict::ALLOW) }
it { expect(request_response[:action]).to be_eql(Castle::Verdict::ALLOW) }
it { expect(request_response[:user_id]).to be_eql('1234') }
it { expect(request_response[:failover]).to be true }
Expand All @@ -246,6 +247,7 @@

context 'with request error and not throw on eg deny strategy' do
it { assert_not_requested :post, 'https://:[email protected]/v1/authenticate' }
it { expect(request_response[:policy][:action]).to be_eql('allow') }
it { expect(request_response[:action]).to be_eql('allow') }
it { expect(request_response[:user_id]).to be_eql('1234') }
it { expect(request_response[:failover]).to be true }
Expand All @@ -266,6 +268,7 @@

describe 'not throw on eg deny strategy' do
it { assert_not_requested :post, 'https://:[email protected]/v1/authenticate' }
it { expect(request_response[:policy][:action]).to be_eql('allow') }
it { expect(request_response[:action]).to be_eql('allow') }
it { expect(request_response[:user_id]).to be_eql('1234') }
it { expect(request_response[:failover]).to be true }
Expand Down
3 changes: 3 additions & 0 deletions spec/support/shared_examples/action_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
end

it { assert_not_requested :post, "https://api.castle.io/v1/#{action}" }
it { expect(request_response[:policy][:action]).to be_eql(Castle::Verdict::ALLOW) }
it { expect(request_response[:action]).to be_eql(Castle::Verdict::ALLOW) }
it { expect(request_response[:user_id]).to be_eql('1234') }
it { expect(request_response[:failover]).to be true }
Expand All @@ -125,6 +126,7 @@

context 'with request error and not throw on eg deny strategy' do
it { assert_not_requested :post, "https:/:[email protected]/v1/#{action}" }
it { expect(request_response[:policy][:action]).to be_eql('allow') }
it { expect(request_response[:action]).to be_eql('allow') }
it { expect(request_response[:user_id]).to be_eql('1234') }
it { expect(request_response[:failover]).to be true }
Expand All @@ -143,6 +145,7 @@

describe 'not throw on eg deny strategy' do
it { assert_not_requested :post, "https:/:[email protected]/v1/#{action}" }
it { expect(request_response[:policy][:action]).to be_eql('allow') }
it { expect(request_response[:action]).to be_eql('allow') }
it { expect(request_response[:user_id]).to be_eql('1234') }
it { expect(request_response[:failover]).to be true }
Expand Down

0 comments on commit f80d7ee

Please sign in to comment.