castle-rb 4.2.1 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/README.md +160 -45
 - data/lib/castle.rb +49 -28
 - data/lib/castle/api.rb +21 -14
 - data/lib/castle/api/approve_device.rb +20 -0
 - data/lib/castle/api/authenticate.rb +37 -0
 - data/lib/castle/api/end_impersonation.rb +24 -0
 - data/lib/castle/api/filter.rb +37 -0
 - data/lib/castle/api/get_device.rb +20 -0
 - data/lib/castle/api/get_devices_for_user.rb +20 -0
 - data/lib/castle/api/log.rb +37 -0
 - data/lib/castle/api/report_device.rb +20 -0
 - data/lib/castle/api/risk.rb +37 -0
 - data/lib/castle/api/start_impersonation.rb +24 -0
 - data/lib/castle/api/track.rb +21 -0
 - data/lib/castle/client.rb +78 -51
 - data/lib/castle/{extractors/client_id.rb → client_id/extract.rb} +2 -2
 - data/lib/castle/commands/approve_device.rb +17 -0
 - data/lib/castle/commands/authenticate.rb +13 -13
 - data/lib/castle/commands/end_impersonation.rb +25 -0
 - data/lib/castle/commands/filter.rb +23 -0
 - data/lib/castle/commands/get_device.rb +17 -0
 - data/lib/castle/commands/get_devices_for_user.rb +17 -0
 - data/lib/castle/commands/log.rb +23 -0
 - data/lib/castle/commands/report_device.rb +17 -0
 - data/lib/castle/commands/risk.rb +23 -0
 - data/lib/castle/commands/start_impersonation.rb +25 -0
 - data/lib/castle/commands/track.rb +12 -13
 - data/lib/castle/configuration.rb +57 -32
 - data/lib/castle/context/{default.rb → get_default.rb} +5 -6
 - data/lib/castle/context/{merger.rb → merge.rb} +3 -3
 - data/lib/castle/context/prepare.rb +18 -0
 - data/lib/castle/context/{sanitizer.rb → sanitize.rb} +1 -1
 - data/lib/castle/core/get_connection.rb +27 -0
 - data/lib/castle/{api/response.rb → core/process_response.rb} +8 -3
 - data/lib/castle/core/process_webhook.rb +25 -0
 - data/lib/castle/core/send_request.rb +42 -0
 - data/lib/castle/errors.rb +38 -12
 - data/lib/castle/failover/prepare_response.rb +18 -0
 - data/lib/castle/failover/strategy.rb +23 -0
 - data/lib/castle/headers/extract.rb +47 -0
 - data/lib/castle/headers/filter.rb +40 -0
 - data/lib/castle/headers/format.rb +24 -0
 - data/lib/castle/{extractors/ip.rb → ips/extract.rb} +31 -9
 - data/lib/castle/logger.rb +19 -0
 - data/lib/castle/payload/prepare.rb +26 -0
 - data/lib/castle/secure_mode.rb +7 -2
 - data/lib/castle/session.rb +18 -0
 - data/lib/castle/singleton_configuration.rb +9 -0
 - data/lib/castle/support/hanami.rb +2 -6
 - data/lib/castle/support/rails.rb +1 -3
 - data/lib/castle/utils/clean_invalid_chars.rb +22 -0
 - data/lib/castle/utils/clone.rb +15 -0
 - data/lib/castle/utils/deep_symbolize_keys.rb +45 -0
 - data/lib/castle/utils/get_timestamp.rb +15 -0
 - data/lib/castle/utils/{merger.rb → merge.rb} +3 -3
 - data/lib/castle/utils/secure_compare.rb +22 -0
 - data/lib/castle/validators/not_supported.rb +1 -0
 - data/lib/castle/validators/present.rb +1 -0
 - data/lib/castle/verdict.rb +15 -0
 - data/lib/castle/version.rb +1 -1
 - data/lib/castle/webhooks/verify.rb +45 -0
 - data/spec/integration/rails/rails_spec.rb +42 -14
 - data/spec/integration/rails/support/application.rb +3 -1
 - data/spec/integration/rails/support/home_controller.rb +50 -6
 - data/spec/lib/castle/api/approve_device_spec.rb +21 -0
 - data/spec/lib/castle/api/authenticate_spec.rb +136 -0
 - data/spec/lib/castle/api/end_impersonation_spec.rb +65 -0
 - data/spec/lib/castle/api/filter_spec.rb +5 -0
 - data/spec/lib/castle/api/get_device_spec.rb +19 -0
 - data/spec/lib/castle/api/get_devices_for_user_spec.rb +19 -0
 - data/spec/lib/castle/api/log_spec.rb +5 -0
 - data/spec/lib/castle/api/report_device_spec.rb +21 -0
 - data/spec/lib/castle/api/risk_spec.rb +5 -0
 - data/spec/lib/castle/api/start_impersonation_spec.rb +65 -0
 - data/spec/lib/castle/api/track_spec.rb +72 -0
 - data/spec/lib/castle/api_spec.rb +14 -15
 - data/spec/lib/castle/{extractors/client_id_spec.rb → client_id/extract_spec.rb} +6 -15
 - data/spec/lib/castle/client_spec.rb +108 -93
 - data/spec/lib/castle/commands/approve_device_spec.rb +24 -0
 - data/spec/lib/castle/commands/authenticate_spec.rb +15 -31
 - data/spec/lib/castle/commands/end_impersonation_spec.rb +79 -0
 - data/spec/lib/castle/commands/filter_spec.rb +99 -0
 - data/spec/lib/castle/commands/get_device_spec.rb +24 -0
 - data/spec/lib/castle/commands/{review_spec.rb → get_devices_for_user_spec.rb} +7 -7
 - data/spec/lib/castle/commands/log_spec.rb +100 -0
 - data/spec/lib/castle/commands/report_device_spec.rb +24 -0
 - data/spec/lib/castle/commands/risk_spec.rb +100 -0
 - data/spec/lib/castle/commands/start_impersonation_spec.rb +79 -0
 - data/spec/lib/castle/commands/track_spec.rb +14 -34
 - data/spec/lib/castle/configuration_spec.rb +8 -141
 - data/spec/lib/castle/context/{default_spec.rb → get_default_spec.rb} +9 -10
 - data/spec/lib/castle/context/{merger_spec.rb → merge_spec.rb} +1 -1
 - data/spec/lib/castle/context/prepare_spec.rb +43 -0
 - data/spec/lib/castle/context/{sanitizer_spec.rb → sanitize_spec.rb} +1 -1
 - data/spec/lib/castle/core/get_connection_spec.rb +43 -0
 - data/spec/lib/castle/{api/response_spec.rb → core/process_response_spec.rb} +49 -1
 - data/spec/lib/castle/core/process_webhook_spec.rb +46 -0
 - data/spec/lib/castle/core/send_request_spec.rb +77 -0
 - data/spec/lib/castle/failover/strategy_spec.rb +12 -0
 - data/spec/lib/castle/{extractors/headers_spec.rb → headers/extract_spec.rb} +18 -20
 - data/spec/lib/castle/headers/filter_spec.rb +39 -0
 - data/spec/lib/castle/headers/format_spec.rb +25 -0
 - data/spec/lib/castle/{extractors/ip_spec.rb → ips/extract_spec.rb} +27 -8
 - data/spec/lib/castle/logger_spec.rb +38 -0
 - data/spec/lib/castle/payload/prepare_spec.rb +55 -0
 - data/spec/lib/castle/session_spec.rb +65 -0
 - data/spec/lib/castle/singleton_configuration_spec.rb +14 -0
 - data/spec/lib/castle/utils/clean_invalid_chars_spec.rb +69 -0
 - data/spec/lib/castle/utils/{cloner_spec.rb → clone_spec.rb} +3 -3
 - data/spec/lib/castle/utils/deep_symbolize_keys_spec.rb +50 -0
 - data/spec/lib/castle/utils/{timestamp_spec.rb → get_timestamp_spec.rb} +1 -1
 - data/spec/lib/castle/utils/merge_spec.rb +15 -0
 - data/spec/lib/castle/validators/present_spec.rb +5 -6
 - data/spec/lib/castle/verdict_spec.rb +9 -0
 - data/spec/lib/castle/webhooks/verify_spec.rb +53 -0
 - data/spec/lib/castle_spec.rb +4 -10
 - data/spec/spec_helper.rb +3 -3
 - data/spec/support/shared_examples/action_request.rb +152 -0
 - data/spec/support/shared_examples/configuration.rb +101 -0
 - metadata +146 -64
 - data/lib/castle/api/request.rb +0 -42
 - data/lib/castle/api/session.rb +0 -39
 - data/lib/castle/commands/identify.rb +0 -23
 - data/lib/castle/commands/impersonate.rb +0 -26
 - data/lib/castle/commands/review.rb +0 -14
 - data/lib/castle/events.rb +0 -49
 - data/lib/castle/extractors/headers.rb +0 -45
 - data/lib/castle/failover_auth_response.rb +0 -21
 - data/lib/castle/headers_filter.rb +0 -35
 - data/lib/castle/headers_formatter.rb +0 -22
 - data/lib/castle/review.rb +0 -11
 - data/lib/castle/utils.rb +0 -55
 - data/lib/castle/utils/cloner.rb +0 -11
 - data/lib/castle/utils/timestamp.rb +0 -12
 - data/spec/lib/castle/api/request_spec.rb +0 -72
 - data/spec/lib/castle/commands/identify_spec.rb +0 -88
 - data/spec/lib/castle/commands/impersonate_spec.rb +0 -107
 - data/spec/lib/castle/events_spec.rb +0 -5
 - data/spec/lib/castle/headers_filter_spec.rb +0 -37
 - data/spec/lib/castle/headers_formatter_spec.rb +0 -25
 - data/spec/lib/castle/review_spec.rb +0 -19
 - data/spec/lib/castle/utils/merger_spec.rb +0 -13
 - data/spec/lib/castle/utils_spec.rb +0 -156
 
| 
         @@ -0,0 +1,9 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe Castle::Verdict do
         
     | 
| 
      
 4 
     | 
    
         
            +
              subject(:verdict) { described_class }
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              it { expect(verdict::ALLOW).to be_eql('allow') }
         
     | 
| 
      
 7 
     | 
    
         
            +
              it { expect(verdict::DENY).to be_eql('deny') }
         
     | 
| 
      
 8 
     | 
    
         
            +
              it { expect(verdict::CHALLENGE).to be_eql('challenge') }
         
     | 
| 
      
 9 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,53 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe Castle::Webhooks::Verify do
         
     | 
| 
      
 4 
     | 
    
         
            +
              describe '#call' do
         
     | 
| 
      
 5 
     | 
    
         
            +
                subject(:call) { described_class.call(webhook) }
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                let(:env) { Rack::MockRequest.env_for('/', 'HTTP_X_CASTLE_SIGNATURE' => signature) }
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                let(:webhook) { Rack::Request.new(env) }
         
     | 
| 
      
 10 
     | 
    
         
            +
                let(:user_id) { '12345' }
         
     | 
| 
      
 11 
     | 
    
         
            +
                let(:webhook_body) do
         
     | 
| 
      
 12 
     | 
    
         
            +
                  {
         
     | 
| 
      
 13 
     | 
    
         
            +
                    api_version: 'v1',
         
     | 
| 
      
 14 
     | 
    
         
            +
                    app_id: '12345',
         
     | 
| 
      
 15 
     | 
    
         
            +
                    type: '$incident.confirmed',
         
     | 
| 
      
 16 
     | 
    
         
            +
                    created_at: '2020-12-18T12:55:21.779Z',
         
     | 
| 
      
 17 
     | 
    
         
            +
                    data: {
         
     | 
| 
      
 18 
     | 
    
         
            +
                      id: 'test',
         
     | 
| 
      
 19 
     | 
    
         
            +
                      device_token: 'token',
         
     | 
| 
      
 20 
     | 
    
         
            +
                      user_id: user_id,
         
     | 
| 
      
 21 
     | 
    
         
            +
                      trigger: '$login.succeeded',
         
     | 
| 
      
 22 
     | 
    
         
            +
                      context: {},
         
     | 
| 
      
 23 
     | 
    
         
            +
                      location: {},
         
     | 
| 
      
 24 
     | 
    
         
            +
                      user_agent: {}
         
     | 
| 
      
 25 
     | 
    
         
            +
                    },
         
     | 
| 
      
 26 
     | 
    
         
            +
                    user_traits: {},
         
     | 
| 
      
 27 
     | 
    
         
            +
                    properties: {},
         
     | 
| 
      
 28 
     | 
    
         
            +
                    policy: {}
         
     | 
| 
      
 29 
     | 
    
         
            +
                  }.to_json
         
     | 
| 
      
 30 
     | 
    
         
            +
                end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                context 'when success' do
         
     | 
| 
      
 33 
     | 
    
         
            +
                  let(:signature) { '3ptx3rUOBnGEqPjMrbcJn2UUfzwTKP54dFyP5uyPY+Y=' }
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                  before { allow(Castle::Core::ProcessWebhook).to receive(:call).and_return(webhook_body) }
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                  it { expect { call }.not_to raise_error }
         
     | 
| 
      
 38 
     | 
    
         
            +
                end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                context 'when signature is malformed' do
         
     | 
| 
      
 41 
     | 
    
         
            +
                  let(:signature) { '123' }
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                  before { allow(Castle::Core::ProcessWebhook).to receive(:call).and_return(webhook_body) }
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                  it do
         
     | 
| 
      
 46 
     | 
    
         
            +
                    expect { call }.to raise_error(
         
     | 
| 
      
 47 
     | 
    
         
            +
                      Castle::WebhookVerificationError,
         
     | 
| 
      
 48 
     | 
    
         
            +
                      'Signature not matching the expected signature'
         
     | 
| 
      
 49 
     | 
    
         
            +
                    )
         
     | 
| 
      
 50 
     | 
    
         
            +
                  end
         
     | 
| 
      
 51 
     | 
    
         
            +
                end
         
     | 
| 
      
 52 
     | 
    
         
            +
              end
         
     | 
| 
      
 53 
     | 
    
         
            +
            end
         
     | 
    
        data/spec/lib/castle_spec.rb
    CHANGED
    
    | 
         @@ -42,11 +42,7 @@ describe Castle do 
     | 
|
| 
       42 
42 
     | 
    
         
             
                end
         
     | 
| 
       43 
43 
     | 
    
         | 
| 
       44 
44 
     | 
    
         
             
                context 'with block and options' do
         
     | 
| 
       45 
     | 
    
         
            -
                  before  
     | 
| 
       46 
     | 
    
         
            -
                    castle.configure(request_timeout: timeout) do |config|
         
     | 
| 
       47 
     | 
    
         
            -
                      config.api_secret = value
         
     | 
| 
       48 
     | 
    
         
            -
                    end
         
     | 
| 
       49 
     | 
    
         
            -
                  end
         
     | 
| 
      
 45 
     | 
    
         
            +
                  before { castle.configure(request_timeout: timeout) { |config| config.api_secret = value } }
         
     | 
| 
       50 
46 
     | 
    
         | 
| 
       51 
47 
     | 
    
         
             
                  it_behaves_like 'config_setup'
         
     | 
| 
       52 
48 
     | 
    
         
             
                end
         
     | 
| 
         @@ -56,11 +52,9 @@ describe Castle do 
     | 
|
| 
       56 
52 
     | 
    
         
             
                let(:value) { 'new_secret' }
         
     | 
| 
       57 
53 
     | 
    
         | 
| 
       58 
54 
     | 
    
         
             
                it do
         
     | 
| 
       59 
     | 
    
         
            -
                  expect  
     | 
| 
       60 
     | 
    
         
            -
                     
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
                    end
         
     | 
| 
       63 
     | 
    
         
            -
                  end.to raise_error(Castle::ConfigurationError)
         
     | 
| 
      
 55 
     | 
    
         
            +
                  expect { castle.configure { |config| config.wrong_config = value } }.to raise_error(
         
     | 
| 
      
 56 
     | 
    
         
            +
                    Castle::ConfigurationError
         
     | 
| 
      
 57 
     | 
    
         
            +
                  )
         
     | 
| 
       64 
58 
     | 
    
         
             
                end
         
     | 
| 
       65 
59 
     | 
    
         
             
              end
         
     | 
| 
       66 
60 
     | 
    
         
             
            end
         
     | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | 
         @@ -14,11 +14,11 @@ require 'castle' 
     | 
|
| 
       14 
14 
     | 
    
         | 
| 
       15 
15 
     | 
    
         
             
            WebMock.disable_net_connect!(allow_localhost: true)
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
      
 17 
     | 
    
         
            +
            Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
       17 
19 
     | 
    
         
             
            RSpec.configure do |config|
         
     | 
| 
       18 
20 
     | 
    
         
             
              config.before do
         
     | 
| 
       19 
21 
     | 
    
         
             
                Castle.config.reset
         
     | 
| 
       20 
     | 
    
         
            -
                Castle.configure  
     | 
| 
       21 
     | 
    
         
            -
                  cfg.api_secret = 'secret'
         
     | 
| 
       22 
     | 
    
         
            -
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
                Castle.configure { |cfg| cfg.api_secret = 'secret' }
         
     | 
| 
       23 
23 
     | 
    
         
             
              end
         
     | 
| 
       24 
24 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,152 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            RSpec.shared_examples_for 'action request' do |action|
         
     | 
| 
      
 4 
     | 
    
         
            +
              subject(:request_response) { client.send(action.to_sym, options) }
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              let(:options) do
         
     | 
| 
      
 7 
     | 
    
         
            +
                {
         
     | 
| 
      
 8 
     | 
    
         
            +
                  request_token: request_token,
         
     | 
| 
      
 9 
     | 
    
         
            +
                  event: event,
         
     | 
| 
      
 10 
     | 
    
         
            +
                  status: status,
         
     | 
| 
      
 11 
     | 
    
         
            +
                  user: user,
         
     | 
| 
      
 12 
     | 
    
         
            +
                  context: context,
         
     | 
| 
      
 13 
     | 
    
         
            +
                  properties: properties
         
     | 
| 
      
 14 
     | 
    
         
            +
                }
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
              let(:request_token) { '7e51335b-f4bc-4bc7-875d-b713fb61eb23-bf021a3022a1a302' }
         
     | 
| 
      
 17 
     | 
    
         
            +
              let(:event) { '$login' }
         
     | 
| 
      
 18 
     | 
    
         
            +
              let(:status) { '$succeeded' }
         
     | 
| 
      
 19 
     | 
    
         
            +
              let(:user) { { id: '1234', email: 'foobar@mail.com' } }
         
     | 
| 
      
 20 
     | 
    
         
            +
              let(:properties) { {} }
         
     | 
| 
      
 21 
     | 
    
         
            +
              let(:request_body) do
         
     | 
| 
      
 22 
     | 
    
         
            +
                {
         
     | 
| 
      
 23 
     | 
    
         
            +
                  request_token: request_token,
         
     | 
| 
      
 24 
     | 
    
         
            +
                  event: event,
         
     | 
| 
      
 25 
     | 
    
         
            +
                  status: status,
         
     | 
| 
      
 26 
     | 
    
         
            +
                  user: user,
         
     | 
| 
      
 27 
     | 
    
         
            +
                  context: context,
         
     | 
| 
      
 28 
     | 
    
         
            +
                  properties: properties,
         
     | 
| 
      
 29 
     | 
    
         
            +
                  timestamp: time_auto,
         
     | 
| 
      
 30 
     | 
    
         
            +
                  sent_at: time_auto
         
     | 
| 
      
 31 
     | 
    
         
            +
                }
         
     | 
| 
      
 32 
     | 
    
         
            +
              end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
              context 'when used with symbol keys' do
         
     | 
| 
      
 35 
     | 
    
         
            +
                it do
         
     | 
| 
      
 36 
     | 
    
         
            +
                  request_response
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                  assert_requested :post, "https://api.castle.io/v1/#{action}", times: 1 do |req|
         
     | 
| 
      
 39 
     | 
    
         
            +
                    JSON.parse(req.body) == JSON.parse(request_body.to_json)
         
     | 
| 
      
 40 
     | 
    
         
            +
                  end
         
     | 
| 
      
 41 
     | 
    
         
            +
                end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                context 'when passed timestamp in options and no defined timestamp' do
         
     | 
| 
      
 44 
     | 
    
         
            +
                  let(:client) { client_with_no_timestamp }
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                  before do
         
     | 
| 
      
 47 
     | 
    
         
            +
                    options[:timestamp] = time_user
         
     | 
| 
      
 48 
     | 
    
         
            +
                    request_body[:timestamp] = time_user
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                    request_response
         
     | 
| 
      
 51 
     | 
    
         
            +
                  end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                  it do
         
     | 
| 
      
 54 
     | 
    
         
            +
                    assert_requested :post, "https://api.castle.io/v1/#{action}", times: 1 do |req|
         
     | 
| 
      
 55 
     | 
    
         
            +
                      JSON.parse(req.body) == JSON.parse(request_body.to_json)
         
     | 
| 
      
 56 
     | 
    
         
            +
                    end
         
     | 
| 
      
 57 
     | 
    
         
            +
                  end
         
     | 
| 
      
 58 
     | 
    
         
            +
                end
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                context 'with client initialized with timestamp' do
         
     | 
| 
      
 61 
     | 
    
         
            +
                  let(:client) { client_with_user_timestamp }
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                  before do
         
     | 
| 
      
 64 
     | 
    
         
            +
                    request_body[:timestamp] = time_user
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                    request_response
         
     | 
| 
      
 67 
     | 
    
         
            +
                  end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                  it do
         
     | 
| 
      
 70 
     | 
    
         
            +
                    assert_requested :post, "https://api.castle.io/v1/#{action}", times: 1 do |req|
         
     | 
| 
      
 71 
     | 
    
         
            +
                      JSON.parse(req.body) == JSON.parse(request_body.to_json)
         
     | 
| 
      
 72 
     | 
    
         
            +
                    end
         
     | 
| 
      
 73 
     | 
    
         
            +
                  end
         
     | 
| 
      
 74 
     | 
    
         
            +
                end
         
     | 
| 
      
 75 
     | 
    
         
            +
              end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
              context 'when used with string keys' do
         
     | 
| 
      
 78 
     | 
    
         
            +
                before { request_response }
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                it do
         
     | 
| 
      
 81 
     | 
    
         
            +
                  assert_requested :post, "https://api.castle.io/v1/#{action}", times: 1 do |req|
         
     | 
| 
      
 82 
     | 
    
         
            +
                    JSON.parse(req.body) == JSON.parse(request_body.to_json)
         
     | 
| 
      
 83 
     | 
    
         
            +
                  end
         
     | 
| 
      
 84 
     | 
    
         
            +
                end
         
     | 
| 
      
 85 
     | 
    
         
            +
              end
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
              context 'when tracking enabled' do
         
     | 
| 
      
 88 
     | 
    
         
            +
                before { request_response }
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
                it do
         
     | 
| 
      
 91 
     | 
    
         
            +
                  assert_requested :post, "https://api.castle.io/v1/#{action}", times: 1 do |req|
         
     | 
| 
      
 92 
     | 
    
         
            +
                    JSON.parse(req.body) == JSON.parse(request_body.to_json)
         
     | 
| 
      
 93 
     | 
    
         
            +
                  end
         
     | 
| 
      
 94 
     | 
    
         
            +
                end
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
                it { expect(request_response[:failover]).to be false }
         
     | 
| 
      
 97 
     | 
    
         
            +
                it { expect(request_response[:failover_reason]).to be_nil }
         
     | 
| 
      
 98 
     | 
    
         
            +
              end
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
              context 'when tracking disabled' do
         
     | 
| 
      
 101 
     | 
    
         
            +
                before do
         
     | 
| 
      
 102 
     | 
    
         
            +
                  client.disable_tracking
         
     | 
| 
      
 103 
     | 
    
         
            +
                  request_response
         
     | 
| 
      
 104 
     | 
    
         
            +
                end
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
                it { assert_not_requested :post, "https://api.castle.io/v1/#{action}" }
         
     | 
| 
      
 107 
     | 
    
         
            +
                it { expect(request_response[:action]).to be_eql(Castle::Verdict::ALLOW) }
         
     | 
| 
      
 108 
     | 
    
         
            +
                it { expect(request_response[:user_id]).to be_eql('1234') }
         
     | 
| 
      
 109 
     | 
    
         
            +
                it { expect(request_response[:failover]).to be true }
         
     | 
| 
      
 110 
     | 
    
         
            +
                it { expect(request_response[:failover_reason]).to be_eql('Castle is set to do not track.') }
         
     | 
| 
      
 111 
     | 
    
         
            +
              end
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
              context 'when request with fail' do
         
     | 
| 
      
 114 
     | 
    
         
            +
                before do
         
     | 
| 
      
 115 
     | 
    
         
            +
                  allow(Castle::API).to receive(:send_request).and_raise(
         
     | 
| 
      
 116 
     | 
    
         
            +
                    Castle::RequestError.new(Timeout::Error)
         
     | 
| 
      
 117 
     | 
    
         
            +
                  )
         
     | 
| 
      
 118 
     | 
    
         
            +
                end
         
     | 
| 
      
 119 
     | 
    
         
            +
             
     | 
| 
      
 120 
     | 
    
         
            +
                context 'with request error and throw strategy' do
         
     | 
| 
      
 121 
     | 
    
         
            +
                  before { allow(Castle.config).to receive(:failover_strategy).and_return(:throw) }
         
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
      
 123 
     | 
    
         
            +
                  it { expect { request_response }.to raise_error(Castle::RequestError) }
         
     | 
| 
      
 124 
     | 
    
         
            +
                end
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
                context 'with request error and not throw on eg deny strategy' do
         
     | 
| 
      
 127 
     | 
    
         
            +
                  it { assert_not_requested :post, "https:/:secret@api.castle.io/v1/#{action}" }
         
     | 
| 
      
 128 
     | 
    
         
            +
                  it { expect(request_response[:action]).to be_eql('allow') }
         
     | 
| 
      
 129 
     | 
    
         
            +
                  it { expect(request_response[:user_id]).to be_eql('1234') }
         
     | 
| 
      
 130 
     | 
    
         
            +
                  it { expect(request_response[:failover]).to be true }
         
     | 
| 
      
 131 
     | 
    
         
            +
                  it { expect(request_response[:failover_reason]).to be_eql('Castle::RequestError') }
         
     | 
| 
      
 132 
     | 
    
         
            +
                end
         
     | 
| 
      
 133 
     | 
    
         
            +
              end
         
     | 
| 
      
 134 
     | 
    
         
            +
             
     | 
| 
      
 135 
     | 
    
         
            +
              context 'when request is internal server error' do
         
     | 
| 
      
 136 
     | 
    
         
            +
                before { allow(Castle::API).to receive(:send_request).and_raise(Castle::InternalServerError) }
         
     | 
| 
      
 137 
     | 
    
         
            +
             
     | 
| 
      
 138 
     | 
    
         
            +
                describe 'throw strategy' do
         
     | 
| 
      
 139 
     | 
    
         
            +
                  before { allow(Castle.config).to receive(:failover_strategy).and_return(:throw) }
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
                  it { expect { request_response }.to raise_error(Castle::InternalServerError) }
         
     | 
| 
      
 142 
     | 
    
         
            +
                end
         
     | 
| 
      
 143 
     | 
    
         
            +
             
     | 
| 
      
 144 
     | 
    
         
            +
                describe 'not throw on eg deny strategy' do
         
     | 
| 
      
 145 
     | 
    
         
            +
                  it { assert_not_requested :post, "https:/:secret@api.castle.io/v1/#{action}" }
         
     | 
| 
      
 146 
     | 
    
         
            +
                  it { expect(request_response[:action]).to be_eql('allow') }
         
     | 
| 
      
 147 
     | 
    
         
            +
                  it { expect(request_response[:user_id]).to be_eql('1234') }
         
     | 
| 
      
 148 
     | 
    
         
            +
                  it { expect(request_response[:failover]).to be true }
         
     | 
| 
      
 149 
     | 
    
         
            +
                  it { expect(request_response[:failover_reason]).to be_eql('Castle::InternalServerError') }
         
     | 
| 
      
 150 
     | 
    
         
            +
                end
         
     | 
| 
      
 151 
     | 
    
         
            +
              end
         
     | 
| 
      
 152 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,101 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            shared_examples 'configuration_host' do
         
     | 
| 
      
 4 
     | 
    
         
            +
              describe 'host' do
         
     | 
| 
      
 5 
     | 
    
         
            +
                context 'with default' do
         
     | 
| 
      
 6 
     | 
    
         
            +
                  it { expect(config.base_url.host).to be_eql('api.castle.io') }
         
     | 
| 
      
 7 
     | 
    
         
            +
                end
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                context 'with setter' do
         
     | 
| 
      
 10 
     | 
    
         
            +
                  before { config.base_url = 'http://api.castle.dev/v2' }
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                  it { expect(config.base_url.host).to be_eql('api.castle.dev') }
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
            end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            shared_examples 'configuration_request_timeout' do
         
     | 
| 
      
 18 
     | 
    
         
            +
              describe 'request_timeout' do
         
     | 
| 
      
 19 
     | 
    
         
            +
                it { expect(config.request_timeout).to be_eql(1000) }
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                context 'with setter' do
         
     | 
| 
      
 22 
     | 
    
         
            +
                  let(:value) { 50.0 }
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                  before { config.request_timeout = value }
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                  it { expect(config.request_timeout).to be_eql(value) }
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
            end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            shared_examples 'configuration_allowlisted' do
         
     | 
| 
      
 32 
     | 
    
         
            +
              describe 'allowlisted' do
         
     | 
| 
      
 33 
     | 
    
         
            +
                it { expect(config.allowlisted.size).to be_eql(0) }
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                context 'with setter' do
         
     | 
| 
      
 36 
     | 
    
         
            +
                  before { config.allowlisted = ['header'] }
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                  it { expect(config.allowlisted).to be_eql(['Header']) }
         
     | 
| 
      
 39 
     | 
    
         
            +
                end
         
     | 
| 
      
 40 
     | 
    
         
            +
              end
         
     | 
| 
      
 41 
     | 
    
         
            +
            end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
            shared_examples 'configuration_denylisted' do
         
     | 
| 
      
 44 
     | 
    
         
            +
              describe 'denylisted' do
         
     | 
| 
      
 45 
     | 
    
         
            +
                it { expect(config.denylisted.size).to be_eql(0) }
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                context 'with setter' do
         
     | 
| 
      
 48 
     | 
    
         
            +
                  before { config.denylisted = ['header'] }
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                  it { expect(config.denylisted).to be_eql(['Header']) }
         
     | 
| 
      
 51 
     | 
    
         
            +
                end
         
     | 
| 
      
 52 
     | 
    
         
            +
              end
         
     | 
| 
      
 53 
     | 
    
         
            +
            end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
            shared_examples 'configuration_failover_strategy' do
         
     | 
| 
      
 56 
     | 
    
         
            +
              describe 'failover_strategy' do
         
     | 
| 
      
 57 
     | 
    
         
            +
                it { expect(config.failover_strategy).to be_eql(Castle::Failover::Strategy::ALLOW) }
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                context 'with setter' do
         
     | 
| 
      
 60 
     | 
    
         
            +
                  before { config.failover_strategy = Castle::Failover::Strategy::DENY }
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                  it { expect(config.failover_strategy).to be_eql(Castle::Failover::Strategy::DENY) }
         
     | 
| 
      
 63 
     | 
    
         
            +
                end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                context 'when broken' do
         
     | 
| 
      
 66 
     | 
    
         
            +
                  it do
         
     | 
| 
      
 67 
     | 
    
         
            +
                    expect { config.failover_strategy = :unicorn }.to raise_error(Castle::ConfigurationError)
         
     | 
| 
      
 68 
     | 
    
         
            +
                  end
         
     | 
| 
      
 69 
     | 
    
         
            +
                end
         
     | 
| 
      
 70 
     | 
    
         
            +
              end
         
     | 
| 
      
 71 
     | 
    
         
            +
            end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
            shared_examples 'configuration_api_secret' do
         
     | 
| 
      
 74 
     | 
    
         
            +
              describe 'api_secret' do
         
     | 
| 
      
 75 
     | 
    
         
            +
                context 'with env' do
         
     | 
| 
      
 76 
     | 
    
         
            +
                  let(:secret_key_env) { 'secret_key_env' }
         
     | 
| 
      
 77 
     | 
    
         
            +
                  let(:secret_key) { 'secret_key' }
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
                  before do
         
     | 
| 
      
 80 
     | 
    
         
            +
                    allow(ENV).to receive(:fetch).with('CASTLE_API_SECRET', '').and_return(secret_key_env)
         
     | 
| 
      
 81 
     | 
    
         
            +
                    config.reset
         
     | 
| 
      
 82 
     | 
    
         
            +
                  end
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
                  it { expect(config.api_secret).to be_eql(secret_key_env) }
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
                  context 'when key is overwritten' do
         
     | 
| 
      
 87 
     | 
    
         
            +
                    before { config.api_secret = secret_key }
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
                    it { expect(config.api_secret).to be_eql(secret_key) }
         
     | 
| 
      
 90 
     | 
    
         
            +
                  end
         
     | 
| 
      
 91 
     | 
    
         
            +
                end
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
                context 'with setter' do
         
     | 
| 
      
 94 
     | 
    
         
            +
                  let(:value) { 'new_secret' }
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
                  before { config.api_secret = value }
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
                  it { expect(config.api_secret).to be_eql(value) }
         
     | 
| 
      
 99 
     | 
    
         
            +
                end
         
     | 
| 
      
 100 
     | 
    
         
            +
              end
         
     | 
| 
      
 101 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: castle-rb
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version:  
     | 
| 
      
 4 
     | 
    
         
            +
              version: 7.0.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Johan Brissmyr
         
     | 
| 
       8 
     | 
    
         
            -
            autorequire: 
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2021-06-03 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: appraisal
         
     | 
| 
         @@ -34,81 +34,135 @@ files: 
     | 
|
| 
       34 
34 
     | 
    
         
             
            - lib/castle-rb.rb
         
     | 
| 
       35 
35 
     | 
    
         
             
            - lib/castle.rb
         
     | 
| 
       36 
36 
     | 
    
         
             
            - lib/castle/api.rb
         
     | 
| 
       37 
     | 
    
         
            -
            - lib/castle/api/ 
     | 
| 
       38 
     | 
    
         
            -
            - lib/castle/api/ 
     | 
| 
       39 
     | 
    
         
            -
            - lib/castle/api/ 
     | 
| 
      
 37 
     | 
    
         
            +
            - lib/castle/api/approve_device.rb
         
     | 
| 
      
 38 
     | 
    
         
            +
            - lib/castle/api/authenticate.rb
         
     | 
| 
      
 39 
     | 
    
         
            +
            - lib/castle/api/end_impersonation.rb
         
     | 
| 
      
 40 
     | 
    
         
            +
            - lib/castle/api/filter.rb
         
     | 
| 
      
 41 
     | 
    
         
            +
            - lib/castle/api/get_device.rb
         
     | 
| 
      
 42 
     | 
    
         
            +
            - lib/castle/api/get_devices_for_user.rb
         
     | 
| 
      
 43 
     | 
    
         
            +
            - lib/castle/api/log.rb
         
     | 
| 
      
 44 
     | 
    
         
            +
            - lib/castle/api/report_device.rb
         
     | 
| 
      
 45 
     | 
    
         
            +
            - lib/castle/api/risk.rb
         
     | 
| 
      
 46 
     | 
    
         
            +
            - lib/castle/api/start_impersonation.rb
         
     | 
| 
      
 47 
     | 
    
         
            +
            - lib/castle/api/track.rb
         
     | 
| 
       40 
48 
     | 
    
         
             
            - lib/castle/client.rb
         
     | 
| 
      
 49 
     | 
    
         
            +
            - lib/castle/client_id/extract.rb
         
     | 
| 
       41 
50 
     | 
    
         
             
            - lib/castle/command.rb
         
     | 
| 
      
 51 
     | 
    
         
            +
            - lib/castle/commands/approve_device.rb
         
     | 
| 
       42 
52 
     | 
    
         
             
            - lib/castle/commands/authenticate.rb
         
     | 
| 
       43 
     | 
    
         
            -
            - lib/castle/commands/ 
     | 
| 
       44 
     | 
    
         
            -
            - lib/castle/commands/ 
     | 
| 
       45 
     | 
    
         
            -
            - lib/castle/commands/ 
     | 
| 
      
 53 
     | 
    
         
            +
            - lib/castle/commands/end_impersonation.rb
         
     | 
| 
      
 54 
     | 
    
         
            +
            - lib/castle/commands/filter.rb
         
     | 
| 
      
 55 
     | 
    
         
            +
            - lib/castle/commands/get_device.rb
         
     | 
| 
      
 56 
     | 
    
         
            +
            - lib/castle/commands/get_devices_for_user.rb
         
     | 
| 
      
 57 
     | 
    
         
            +
            - lib/castle/commands/log.rb
         
     | 
| 
      
 58 
     | 
    
         
            +
            - lib/castle/commands/report_device.rb
         
     | 
| 
      
 59 
     | 
    
         
            +
            - lib/castle/commands/risk.rb
         
     | 
| 
      
 60 
     | 
    
         
            +
            - lib/castle/commands/start_impersonation.rb
         
     | 
| 
       46 
61 
     | 
    
         
             
            - lib/castle/commands/track.rb
         
     | 
| 
       47 
62 
     | 
    
         
             
            - lib/castle/configuration.rb
         
     | 
| 
       48 
     | 
    
         
            -
            - lib/castle/context/ 
     | 
| 
       49 
     | 
    
         
            -
            - lib/castle/context/ 
     | 
| 
       50 
     | 
    
         
            -
            - lib/castle/context/ 
     | 
| 
      
 63 
     | 
    
         
            +
            - lib/castle/context/get_default.rb
         
     | 
| 
      
 64 
     | 
    
         
            +
            - lib/castle/context/merge.rb
         
     | 
| 
      
 65 
     | 
    
         
            +
            - lib/castle/context/prepare.rb
         
     | 
| 
      
 66 
     | 
    
         
            +
            - lib/castle/context/sanitize.rb
         
     | 
| 
      
 67 
     | 
    
         
            +
            - lib/castle/core/get_connection.rb
         
     | 
| 
      
 68 
     | 
    
         
            +
            - lib/castle/core/process_response.rb
         
     | 
| 
      
 69 
     | 
    
         
            +
            - lib/castle/core/process_webhook.rb
         
     | 
| 
      
 70 
     | 
    
         
            +
            - lib/castle/core/send_request.rb
         
     | 
| 
       51 
71 
     | 
    
         
             
            - lib/castle/errors.rb
         
     | 
| 
       52 
     | 
    
         
            -
            - lib/castle/ 
     | 
| 
       53 
     | 
    
         
            -
            - lib/castle/ 
     | 
| 
       54 
     | 
    
         
            -
            - lib/castle/ 
     | 
| 
       55 
     | 
    
         
            -
            - lib/castle/ 
     | 
| 
       56 
     | 
    
         
            -
            - lib/castle/ 
     | 
| 
       57 
     | 
    
         
            -
            - lib/castle/ 
     | 
| 
       58 
     | 
    
         
            -
            - lib/castle/ 
     | 
| 
       59 
     | 
    
         
            -
            - lib/castle/ 
     | 
| 
      
 72 
     | 
    
         
            +
            - lib/castle/failover/prepare_response.rb
         
     | 
| 
      
 73 
     | 
    
         
            +
            - lib/castle/failover/strategy.rb
         
     | 
| 
      
 74 
     | 
    
         
            +
            - lib/castle/headers/extract.rb
         
     | 
| 
      
 75 
     | 
    
         
            +
            - lib/castle/headers/filter.rb
         
     | 
| 
      
 76 
     | 
    
         
            +
            - lib/castle/headers/format.rb
         
     | 
| 
      
 77 
     | 
    
         
            +
            - lib/castle/ips/extract.rb
         
     | 
| 
      
 78 
     | 
    
         
            +
            - lib/castle/logger.rb
         
     | 
| 
      
 79 
     | 
    
         
            +
            - lib/castle/payload/prepare.rb
         
     | 
| 
       60 
80 
     | 
    
         
             
            - lib/castle/secure_mode.rb
         
     | 
| 
      
 81 
     | 
    
         
            +
            - lib/castle/session.rb
         
     | 
| 
      
 82 
     | 
    
         
            +
            - lib/castle/singleton_configuration.rb
         
     | 
| 
       61 
83 
     | 
    
         
             
            - lib/castle/support/hanami.rb
         
     | 
| 
       62 
84 
     | 
    
         
             
            - lib/castle/support/padrino.rb
         
     | 
| 
       63 
85 
     | 
    
         
             
            - lib/castle/support/rails.rb
         
     | 
| 
       64 
86 
     | 
    
         
             
            - lib/castle/support/sinatra.rb
         
     | 
| 
       65 
     | 
    
         
            -
            - lib/castle/utils.rb
         
     | 
| 
       66 
     | 
    
         
            -
            - lib/castle/utils/ 
     | 
| 
       67 
     | 
    
         
            -
            - lib/castle/utils/ 
     | 
| 
       68 
     | 
    
         
            -
            - lib/castle/utils/ 
     | 
| 
      
 87 
     | 
    
         
            +
            - lib/castle/utils/clean_invalid_chars.rb
         
     | 
| 
      
 88 
     | 
    
         
            +
            - lib/castle/utils/clone.rb
         
     | 
| 
      
 89 
     | 
    
         
            +
            - lib/castle/utils/deep_symbolize_keys.rb
         
     | 
| 
      
 90 
     | 
    
         
            +
            - lib/castle/utils/get_timestamp.rb
         
     | 
| 
      
 91 
     | 
    
         
            +
            - lib/castle/utils/merge.rb
         
     | 
| 
      
 92 
     | 
    
         
            +
            - lib/castle/utils/secure_compare.rb
         
     | 
| 
       69 
93 
     | 
    
         
             
            - lib/castle/validators/not_supported.rb
         
     | 
| 
       70 
94 
     | 
    
         
             
            - lib/castle/validators/present.rb
         
     | 
| 
      
 95 
     | 
    
         
            +
            - lib/castle/verdict.rb
         
     | 
| 
       71 
96 
     | 
    
         
             
            - lib/castle/version.rb
         
     | 
| 
      
 97 
     | 
    
         
            +
            - lib/castle/webhooks/verify.rb
         
     | 
| 
       72 
98 
     | 
    
         
             
            - spec/integration/rails/rails_spec.rb
         
     | 
| 
       73 
99 
     | 
    
         
             
            - spec/integration/rails/support/all.rb
         
     | 
| 
       74 
100 
     | 
    
         
             
            - spec/integration/rails/support/application.rb
         
     | 
| 
       75 
101 
     | 
    
         
             
            - spec/integration/rails/support/home_controller.rb
         
     | 
| 
       76 
     | 
    
         
            -
            - spec/lib/castle/api/ 
     | 
| 
       77 
     | 
    
         
            -
            - spec/lib/castle/api/ 
     | 
| 
      
 102 
     | 
    
         
            +
            - spec/lib/castle/api/approve_device_spec.rb
         
     | 
| 
      
 103 
     | 
    
         
            +
            - spec/lib/castle/api/authenticate_spec.rb
         
     | 
| 
      
 104 
     | 
    
         
            +
            - spec/lib/castle/api/end_impersonation_spec.rb
         
     | 
| 
      
 105 
     | 
    
         
            +
            - spec/lib/castle/api/filter_spec.rb
         
     | 
| 
      
 106 
     | 
    
         
            +
            - spec/lib/castle/api/get_device_spec.rb
         
     | 
| 
      
 107 
     | 
    
         
            +
            - spec/lib/castle/api/get_devices_for_user_spec.rb
         
     | 
| 
      
 108 
     | 
    
         
            +
            - spec/lib/castle/api/log_spec.rb
         
     | 
| 
      
 109 
     | 
    
         
            +
            - spec/lib/castle/api/report_device_spec.rb
         
     | 
| 
      
 110 
     | 
    
         
            +
            - spec/lib/castle/api/risk_spec.rb
         
     | 
| 
      
 111 
     | 
    
         
            +
            - spec/lib/castle/api/start_impersonation_spec.rb
         
     | 
| 
      
 112 
     | 
    
         
            +
            - spec/lib/castle/api/track_spec.rb
         
     | 
| 
       78 
113 
     | 
    
         
             
            - spec/lib/castle/api_spec.rb
         
     | 
| 
      
 114 
     | 
    
         
            +
            - spec/lib/castle/client_id/extract_spec.rb
         
     | 
| 
       79 
115 
     | 
    
         
             
            - spec/lib/castle/client_spec.rb
         
     | 
| 
       80 
116 
     | 
    
         
             
            - spec/lib/castle/command_spec.rb
         
     | 
| 
      
 117 
     | 
    
         
            +
            - spec/lib/castle/commands/approve_device_spec.rb
         
     | 
| 
       81 
118 
     | 
    
         
             
            - spec/lib/castle/commands/authenticate_spec.rb
         
     | 
| 
       82 
     | 
    
         
            -
            - spec/lib/castle/commands/ 
     | 
| 
       83 
     | 
    
         
            -
            - spec/lib/castle/commands/ 
     | 
| 
       84 
     | 
    
         
            -
            - spec/lib/castle/commands/ 
     | 
| 
      
 119 
     | 
    
         
            +
            - spec/lib/castle/commands/end_impersonation_spec.rb
         
     | 
| 
      
 120 
     | 
    
         
            +
            - spec/lib/castle/commands/filter_spec.rb
         
     | 
| 
      
 121 
     | 
    
         
            +
            - spec/lib/castle/commands/get_device_spec.rb
         
     | 
| 
      
 122 
     | 
    
         
            +
            - spec/lib/castle/commands/get_devices_for_user_spec.rb
         
     | 
| 
      
 123 
     | 
    
         
            +
            - spec/lib/castle/commands/log_spec.rb
         
     | 
| 
      
 124 
     | 
    
         
            +
            - spec/lib/castle/commands/report_device_spec.rb
         
     | 
| 
      
 125 
     | 
    
         
            +
            - spec/lib/castle/commands/risk_spec.rb
         
     | 
| 
      
 126 
     | 
    
         
            +
            - spec/lib/castle/commands/start_impersonation_spec.rb
         
     | 
| 
       85 
127 
     | 
    
         
             
            - spec/lib/castle/commands/track_spec.rb
         
     | 
| 
       86 
128 
     | 
    
         
             
            - spec/lib/castle/configuration_spec.rb
         
     | 
| 
       87 
     | 
    
         
            -
            - spec/lib/castle/context/ 
     | 
| 
       88 
     | 
    
         
            -
            - spec/lib/castle/context/ 
     | 
| 
       89 
     | 
    
         
            -
            - spec/lib/castle/context/ 
     | 
| 
       90 
     | 
    
         
            -
            - spec/lib/castle/ 
     | 
| 
       91 
     | 
    
         
            -
            - spec/lib/castle/ 
     | 
| 
       92 
     | 
    
         
            -
            - spec/lib/castle/ 
     | 
| 
       93 
     | 
    
         
            -
            - spec/lib/castle/ 
     | 
| 
       94 
     | 
    
         
            -
            - spec/lib/castle/ 
     | 
| 
       95 
     | 
    
         
            -
            - spec/lib/castle/ 
     | 
| 
       96 
     | 
    
         
            -
            - spec/lib/castle/ 
     | 
| 
      
 129 
     | 
    
         
            +
            - spec/lib/castle/context/get_default_spec.rb
         
     | 
| 
      
 130 
     | 
    
         
            +
            - spec/lib/castle/context/merge_spec.rb
         
     | 
| 
      
 131 
     | 
    
         
            +
            - spec/lib/castle/context/prepare_spec.rb
         
     | 
| 
      
 132 
     | 
    
         
            +
            - spec/lib/castle/context/sanitize_spec.rb
         
     | 
| 
      
 133 
     | 
    
         
            +
            - spec/lib/castle/core/get_connection_spec.rb
         
     | 
| 
      
 134 
     | 
    
         
            +
            - spec/lib/castle/core/process_response_spec.rb
         
     | 
| 
      
 135 
     | 
    
         
            +
            - spec/lib/castle/core/process_webhook_spec.rb
         
     | 
| 
      
 136 
     | 
    
         
            +
            - spec/lib/castle/core/send_request_spec.rb
         
     | 
| 
      
 137 
     | 
    
         
            +
            - spec/lib/castle/failover/strategy_spec.rb
         
     | 
| 
      
 138 
     | 
    
         
            +
            - spec/lib/castle/headers/extract_spec.rb
         
     | 
| 
      
 139 
     | 
    
         
            +
            - spec/lib/castle/headers/filter_spec.rb
         
     | 
| 
      
 140 
     | 
    
         
            +
            - spec/lib/castle/headers/format_spec.rb
         
     | 
| 
      
 141 
     | 
    
         
            +
            - spec/lib/castle/ips/extract_spec.rb
         
     | 
| 
      
 142 
     | 
    
         
            +
            - spec/lib/castle/logger_spec.rb
         
     | 
| 
      
 143 
     | 
    
         
            +
            - spec/lib/castle/payload/prepare_spec.rb
         
     | 
| 
       97 
144 
     | 
    
         
             
            - spec/lib/castle/secure_mode_spec.rb
         
     | 
| 
       98 
     | 
    
         
            -
            - spec/lib/castle/ 
     | 
| 
       99 
     | 
    
         
            -
            - spec/lib/castle/ 
     | 
| 
       100 
     | 
    
         
            -
            - spec/lib/castle/utils/ 
     | 
| 
       101 
     | 
    
         
            -
            - spec/lib/castle/ 
     | 
| 
      
 145 
     | 
    
         
            +
            - spec/lib/castle/session_spec.rb
         
     | 
| 
      
 146 
     | 
    
         
            +
            - spec/lib/castle/singleton_configuration_spec.rb
         
     | 
| 
      
 147 
     | 
    
         
            +
            - spec/lib/castle/utils/clean_invalid_chars_spec.rb
         
     | 
| 
      
 148 
     | 
    
         
            +
            - spec/lib/castle/utils/clone_spec.rb
         
     | 
| 
      
 149 
     | 
    
         
            +
            - spec/lib/castle/utils/deep_symbolize_keys_spec.rb
         
     | 
| 
      
 150 
     | 
    
         
            +
            - spec/lib/castle/utils/get_timestamp_spec.rb
         
     | 
| 
      
 151 
     | 
    
         
            +
            - spec/lib/castle/utils/merge_spec.rb
         
     | 
| 
       102 
152 
     | 
    
         
             
            - spec/lib/castle/validators/not_supported_spec.rb
         
     | 
| 
       103 
153 
     | 
    
         
             
            - spec/lib/castle/validators/present_spec.rb
         
     | 
| 
      
 154 
     | 
    
         
            +
            - spec/lib/castle/verdict_spec.rb
         
     | 
| 
       104 
155 
     | 
    
         
             
            - spec/lib/castle/version_spec.rb
         
     | 
| 
      
 156 
     | 
    
         
            +
            - spec/lib/castle/webhooks/verify_spec.rb
         
     | 
| 
       105 
157 
     | 
    
         
             
            - spec/lib/castle_spec.rb
         
     | 
| 
       106 
158 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
      
 159 
     | 
    
         
            +
            - spec/support/shared_examples/action_request.rb
         
     | 
| 
      
 160 
     | 
    
         
            +
            - spec/support/shared_examples/configuration.rb
         
     | 
| 
       107 
161 
     | 
    
         
             
            homepage: https://castle.io
         
     | 
| 
       108 
162 
     | 
    
         
             
            licenses:
         
     | 
| 
       109 
163 
     | 
    
         
             
            - MIT
         
     | 
| 
       110 
164 
     | 
    
         
             
            metadata: {}
         
     | 
| 
       111 
     | 
    
         
            -
            post_install_message: 
     | 
| 
      
 165 
     | 
    
         
            +
            post_install_message:
         
     | 
| 
       112 
166 
     | 
    
         
             
            rdoc_options: []
         
     | 
| 
       113 
167 
     | 
    
         
             
            require_paths:
         
     | 
| 
       114 
168 
     | 
    
         
             
            - lib
         
     | 
| 
         @@ -124,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       124 
178 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       125 
179 
     | 
    
         
             
            requirements: []
         
     | 
| 
       126 
180 
     | 
    
         
             
            rubygems_version: 3.0.6
         
     | 
| 
       127 
     | 
    
         
            -
            signing_key: 
     | 
| 
      
 181 
     | 
    
         
            +
            signing_key:
         
     | 
| 
       128 
182 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       129 
183 
     | 
    
         
             
            summary: Castle
         
     | 
| 
       130 
184 
     | 
    
         
             
            test_files:
         
     | 
| 
         @@ -133,33 +187,61 @@ test_files: 
     | 
|
| 
       133 
187 
     | 
    
         
             
            - spec/integration/rails/support/all.rb
         
     | 
| 
       134 
188 
     | 
    
         
             
            - spec/integration/rails/support/home_controller.rb
         
     | 
| 
       135 
189 
     | 
    
         
             
            - spec/integration/rails/rails_spec.rb
         
     | 
| 
      
 190 
     | 
    
         
            +
            - spec/support/shared_examples/action_request.rb
         
     | 
| 
      
 191 
     | 
    
         
            +
            - spec/support/shared_examples/configuration.rb
         
     | 
| 
       136 
192 
     | 
    
         
             
            - spec/lib/castle_spec.rb
         
     | 
| 
       137 
     | 
    
         
            -
            - spec/lib/castle/ 
     | 
| 
       138 
     | 
    
         
            -
            - spec/lib/castle/ 
     | 
| 
      
 193 
     | 
    
         
            +
            - spec/lib/castle/session_spec.rb
         
     | 
| 
      
 194 
     | 
    
         
            +
            - spec/lib/castle/verdict_spec.rb
         
     | 
| 
       139 
195 
     | 
    
         
             
            - spec/lib/castle/client_spec.rb
         
     | 
| 
       140 
     | 
    
         
            -
            - spec/lib/castle/context/ 
     | 
| 
       141 
     | 
    
         
            -
            - spec/lib/castle/context/ 
     | 
| 
       142 
     | 
    
         
            -
            - spec/lib/castle/context/ 
     | 
| 
      
 196 
     | 
    
         
            +
            - spec/lib/castle/context/get_default_spec.rb
         
     | 
| 
      
 197 
     | 
    
         
            +
            - spec/lib/castle/context/prepare_spec.rb
         
     | 
| 
      
 198 
     | 
    
         
            +
            - spec/lib/castle/context/sanitize_spec.rb
         
     | 
| 
      
 199 
     | 
    
         
            +
            - spec/lib/castle/context/merge_spec.rb
         
     | 
| 
      
 200 
     | 
    
         
            +
            - spec/lib/castle/core/get_connection_spec.rb
         
     | 
| 
      
 201 
     | 
    
         
            +
            - spec/lib/castle/core/process_webhook_spec.rb
         
     | 
| 
      
 202 
     | 
    
         
            +
            - spec/lib/castle/core/send_request_spec.rb
         
     | 
| 
      
 203 
     | 
    
         
            +
            - spec/lib/castle/core/process_response_spec.rb
         
     | 
| 
      
 204 
     | 
    
         
            +
            - spec/lib/castle/ips/extract_spec.rb
         
     | 
| 
       143 
205 
     | 
    
         
             
            - spec/lib/castle/api_spec.rb
         
     | 
| 
      
 206 
     | 
    
         
            +
            - spec/lib/castle/logger_spec.rb
         
     | 
| 
      
 207 
     | 
    
         
            +
            - spec/lib/castle/client_id/extract_spec.rb
         
     | 
| 
       144 
208 
     | 
    
         
             
            - spec/lib/castle/configuration_spec.rb
         
     | 
| 
       145 
209 
     | 
    
         
             
            - spec/lib/castle/version_spec.rb
         
     | 
| 
       146 
     | 
    
         
            -
            - spec/lib/castle/ 
     | 
| 
       147 
     | 
    
         
            -
            - spec/lib/castle/utils/ 
     | 
| 
       148 
     | 
    
         
            -
            - spec/lib/castle/utils/ 
     | 
| 
      
 210 
     | 
    
         
            +
            - spec/lib/castle/payload/prepare_spec.rb
         
     | 
| 
      
 211 
     | 
    
         
            +
            - spec/lib/castle/utils/clean_invalid_chars_spec.rb
         
     | 
| 
      
 212 
     | 
    
         
            +
            - spec/lib/castle/utils/deep_symbolize_keys_spec.rb
         
     | 
| 
      
 213 
     | 
    
         
            +
            - spec/lib/castle/utils/get_timestamp_spec.rb
         
     | 
| 
      
 214 
     | 
    
         
            +
            - spec/lib/castle/utils/clone_spec.rb
         
     | 
| 
      
 215 
     | 
    
         
            +
            - spec/lib/castle/utils/merge_spec.rb
         
     | 
| 
       149 
216 
     | 
    
         
             
            - spec/lib/castle/command_spec.rb
         
     | 
| 
       150 
     | 
    
         
            -
            - spec/lib/castle/ 
     | 
| 
       151 
     | 
    
         
            -
            - spec/lib/castle/ 
     | 
| 
       152 
     | 
    
         
            -
            - spec/lib/castle/ 
     | 
| 
       153 
     | 
    
         
            -
            - spec/lib/castle/ 
     | 
| 
      
 217 
     | 
    
         
            +
            - spec/lib/castle/headers/format_spec.rb
         
     | 
| 
      
 218 
     | 
    
         
            +
            - spec/lib/castle/headers/extract_spec.rb
         
     | 
| 
      
 219 
     | 
    
         
            +
            - spec/lib/castle/headers/filter_spec.rb
         
     | 
| 
      
 220 
     | 
    
         
            +
            - spec/lib/castle/api/report_device_spec.rb
         
     | 
| 
      
 221 
     | 
    
         
            +
            - spec/lib/castle/api/authenticate_spec.rb
         
     | 
| 
      
 222 
     | 
    
         
            +
            - spec/lib/castle/api/track_spec.rb
         
     | 
| 
      
 223 
     | 
    
         
            +
            - spec/lib/castle/api/get_device_spec.rb
         
     | 
| 
      
 224 
     | 
    
         
            +
            - spec/lib/castle/api/risk_spec.rb
         
     | 
| 
      
 225 
     | 
    
         
            +
            - spec/lib/castle/api/start_impersonation_spec.rb
         
     | 
| 
      
 226 
     | 
    
         
            +
            - spec/lib/castle/api/log_spec.rb
         
     | 
| 
      
 227 
     | 
    
         
            +
            - spec/lib/castle/api/approve_device_spec.rb
         
     | 
| 
      
 228 
     | 
    
         
            +
            - spec/lib/castle/api/get_devices_for_user_spec.rb
         
     | 
| 
      
 229 
     | 
    
         
            +
            - spec/lib/castle/api/end_impersonation_spec.rb
         
     | 
| 
      
 230 
     | 
    
         
            +
            - spec/lib/castle/api/filter_spec.rb
         
     | 
| 
      
 231 
     | 
    
         
            +
            - spec/lib/castle/commands/report_device_spec.rb
         
     | 
| 
       154 
232 
     | 
    
         
             
            - spec/lib/castle/commands/authenticate_spec.rb
         
     | 
| 
       155 
233 
     | 
    
         
             
            - spec/lib/castle/commands/track_spec.rb
         
     | 
| 
       156 
     | 
    
         
            -
            - spec/lib/castle/commands/ 
     | 
| 
       157 
     | 
    
         
            -
            - spec/lib/castle/commands/ 
     | 
| 
      
 234 
     | 
    
         
            +
            - spec/lib/castle/commands/get_device_spec.rb
         
     | 
| 
      
 235 
     | 
    
         
            +
            - spec/lib/castle/commands/risk_spec.rb
         
     | 
| 
      
 236 
     | 
    
         
            +
            - spec/lib/castle/commands/start_impersonation_spec.rb
         
     | 
| 
      
 237 
     | 
    
         
            +
            - spec/lib/castle/commands/log_spec.rb
         
     | 
| 
      
 238 
     | 
    
         
            +
            - spec/lib/castle/commands/approve_device_spec.rb
         
     | 
| 
      
 239 
     | 
    
         
            +
            - spec/lib/castle/commands/get_devices_for_user_spec.rb
         
     | 
| 
      
 240 
     | 
    
         
            +
            - spec/lib/castle/commands/end_impersonation_spec.rb
         
     | 
| 
      
 241 
     | 
    
         
            +
            - spec/lib/castle/commands/filter_spec.rb
         
     | 
| 
       158 
242 
     | 
    
         
             
            - spec/lib/castle/validators/not_supported_spec.rb
         
     | 
| 
       159 
243 
     | 
    
         
             
            - spec/lib/castle/validators/present_spec.rb
         
     | 
| 
       160 
     | 
    
         
            -
            - spec/lib/castle/ 
     | 
| 
       161 
     | 
    
         
            -
            - spec/lib/castle/ 
     | 
| 
       162 
     | 
    
         
            -
            - spec/lib/castle/extractors/client_id_spec.rb
         
     | 
| 
       163 
     | 
    
         
            -
            - spec/lib/castle/utils_spec.rb
         
     | 
| 
      
 244 
     | 
    
         
            +
            - spec/lib/castle/webhooks/verify_spec.rb
         
     | 
| 
      
 245 
     | 
    
         
            +
            - spec/lib/castle/failover/strategy_spec.rb
         
     | 
| 
       164 
246 
     | 
    
         
             
            - spec/lib/castle/secure_mode_spec.rb
         
     | 
| 
       165 
     | 
    
         
            -
            - spec/lib/castle/ 
     | 
| 
      
 247 
     | 
    
         
            +
            - spec/lib/castle/singleton_configuration_spec.rb
         
     |