castle-rb 7.2.0 → 8.1.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/lib/castle/api/authenticate.rb +3 -12
- data/lib/castle/api/end_impersonation.rb +1 -3
- data/lib/castle/api/filter.rb +2 -10
- data/lib/castle/api/list_items/archive.rb +23 -0
- data/lib/castle/api/list_items/count.rb +22 -0
- data/lib/castle/api/list_items/create.rb +22 -0
- data/lib/castle/api/list_items/get.rb +22 -0
- data/lib/castle/api/list_items/query.rb +22 -0
- data/lib/castle/api/list_items/unarchive.rb +22 -0
- data/lib/castle/api/list_items/update.rb +22 -0
- data/lib/castle/api/lists/create.rb +23 -0
- data/lib/castle/api/lists/delete.rb +22 -0
- data/lib/castle/api/lists/get.rb +22 -0
- data/lib/castle/api/lists/get_all.rb +22 -0
- data/lib/castle/api/lists/query.rb +22 -0
- data/lib/castle/api/lists/update.rb +22 -0
- data/lib/castle/api/log.rb +2 -10
- data/lib/castle/api/risk.rb +2 -10
- data/lib/castle/api/start_impersonation.rb +1 -3
- data/lib/castle/api/track.rb +1 -3
- data/lib/castle/client.rb +4 -5
- data/lib/castle/client_actions/list_items.rb +44 -0
- data/lib/castle/client_actions/lists.rb +39 -0
- data/lib/castle/commands/list_items/archive.rb +24 -0
- data/lib/castle/commands/list_items/count.rb +23 -0
- data/lib/castle/commands/list_items/create.rb +22 -0
- data/lib/castle/commands/list_items/get.rb +23 -0
- data/lib/castle/commands/list_items/query.rb +24 -0
- data/lib/castle/commands/list_items/unarchive.rb +23 -0
- data/lib/castle/commands/list_items/update.rb +22 -0
- data/lib/castle/commands/lists/create.rb +21 -0
- data/lib/castle/commands/lists/delete.rb +20 -0
- data/lib/castle/commands/lists/get.rb +20 -0
- data/lib/castle/commands/lists/get_all.rb +17 -0
- data/lib/castle/commands/lists/query.rb +21 -0
- data/lib/castle/commands/lists/update.rb +22 -0
- data/lib/castle/commands/log.rb +1 -5
- data/lib/castle/commands/risk.rb +1 -5
- data/lib/castle/configuration.rb +2 -5
- data/lib/castle/core/process_response.rb +4 -3
- data/lib/castle/core/send_request.rb +1 -3
- data/lib/castle/errors.rb +4 -0
- data/lib/castle/headers/extract.rb +1 -3
- data/lib/castle/headers/filter.rb +2 -3
- data/lib/castle/payload/prepare.rb +1 -2
- data/lib/castle/session.rb +1 -1
- data/lib/castle/version.rb +1 -1
- data/lib/castle.rb +29 -3
- data/spec/integration/rails/rails_spec.rb +9 -3
- data/spec/integration/rails/support/application.rb +2 -2
- data/spec/integration/rails/support/home_controller.rb +4 -30
- data/spec/lib/castle/api/approve_device_spec.rb +3 -7
- data/spec/lib/castle/api/authenticate_spec.rb +23 -26
- data/spec/lib/castle/api/end_impersonation_spec.rb +9 -15
- data/spec/lib/castle/api/filter_spec.rb +1 -1
- data/spec/lib/castle/api/get_device_spec.rb +2 -4
- data/spec/lib/castle/api/get_devices_for_user_spec.rb +2 -4
- data/spec/lib/castle/api/list_items/archive_spec.rb +18 -0
- data/spec/lib/castle/api/list_items/count_spec.rb +21 -0
- data/spec/lib/castle/api/list_items/create_spec.rb +22 -0
- data/spec/lib/castle/api/list_items/get_spec.rb +18 -0
- data/spec/lib/castle/api/list_items/query_spec.rb +21 -0
- data/spec/lib/castle/api/list_items/unarchive_spec.rb +18 -0
- data/spec/lib/castle/api/list_items/update_spec.rb +22 -0
- data/spec/lib/castle/api/lists/create_spec.rb +21 -0
- data/spec/lib/castle/api/lists/delete_spec.rb +17 -0
- data/spec/lib/castle/api/lists/get_all_spec.rb +17 -0
- data/spec/lib/castle/api/lists/get_spec.rb +17 -0
- data/spec/lib/castle/api/lists/query_spec.rb +21 -0
- data/spec/lib/castle/api/lists/update_spec.rb +21 -0
- data/spec/lib/castle/api/log_spec.rb +1 -1
- data/spec/lib/castle/api/report_device_spec.rb +3 -7
- data/spec/lib/castle/api/risk_spec.rb +1 -1
- data/spec/lib/castle/api/start_impersonation_spec.rb +9 -15
- data/spec/lib/castle/api/track_spec.rb +10 -17
- data/spec/lib/castle/api_spec.rb +1 -1
- data/spec/lib/castle/client_id/extract_spec.rb +3 -10
- data/spec/lib/castle/client_spec.rb +38 -79
- data/spec/lib/castle/command_spec.rb +4 -4
- data/spec/lib/castle/commands/approve_device_spec.rb +3 -3
- data/spec/lib/castle/commands/authenticate_spec.rb +18 -25
- data/spec/lib/castle/commands/end_impersonation_spec.rb +15 -22
- data/spec/lib/castle/commands/filter_spec.rb +16 -16
- data/spec/lib/castle/commands/get_device_spec.rb +3 -3
- data/spec/lib/castle/commands/get_devices_for_user_spec.rb +3 -3
- data/spec/lib/castle/commands/list_items/archive_spec.rb +21 -0
- data/spec/lib/castle/commands/list_items/count_spec.rb +21 -0
- data/spec/lib/castle/commands/list_items/create_spec.rb +22 -0
- data/spec/lib/castle/commands/list_items/get_spec.rb +21 -0
- data/spec/lib/castle/commands/list_items/query_spec.rb +27 -0
- data/spec/lib/castle/commands/list_items/unarchive_spec.rb +21 -0
- data/spec/lib/castle/commands/list_items/update_spec.rb +21 -0
- data/spec/lib/castle/commands/lists/create_spec.rb +33 -0
- data/spec/lib/castle/commands/lists/delete_spec.rb +21 -0
- data/spec/lib/castle/commands/lists/get_all_spec.rb +11 -0
- data/spec/lib/castle/commands/lists/get_spec.rb +21 -0
- data/spec/lib/castle/commands/lists/query_spec.rb +27 -0
- data/spec/lib/castle/commands/lists/update_spec.rb +29 -0
- data/spec/lib/castle/commands/log_spec.rb +16 -16
- data/spec/lib/castle/commands/report_device_spec.rb +3 -3
- data/spec/lib/castle/commands/risk_spec.rb +16 -16
- data/spec/lib/castle/commands/start_impersonation_spec.rb +15 -22
- data/spec/lib/castle/commands/track_spec.rb +20 -25
- data/spec/lib/castle/configuration_spec.rb +2 -2
- data/spec/lib/castle/context/get_default_spec.rb +10 -9
- data/spec/lib/castle/context/merge_spec.rb +1 -1
- data/spec/lib/castle/context/prepare_spec.rb +4 -5
- data/spec/lib/castle/context/sanitize_spec.rb +1 -1
- data/spec/lib/castle/core/get_connection_spec.rb +1 -1
- data/spec/lib/castle/core/process_response_spec.rb +4 -7
- data/spec/lib/castle/core/process_webhook_spec.rb +13 -7
- data/spec/lib/castle/core/send_request_spec.rb +8 -12
- data/spec/lib/castle/failover/strategy_spec.rb +6 -6
- data/spec/lib/castle/headers/extract_spec.rb +2 -2
- data/spec/lib/castle/headers/filter_spec.rb +7 -4
- data/spec/lib/castle/headers/format_spec.rb +6 -6
- data/spec/lib/castle/ips/extract_spec.rb +3 -7
- data/spec/lib/castle/logger_spec.rb +3 -2
- data/spec/lib/castle/payload/prepare_spec.rb +5 -8
- data/spec/lib/castle/secure_mode_spec.rb +2 -4
- data/spec/lib/castle/session_spec.rb +2 -6
- data/spec/lib/castle/singleton_configuration_spec.rb +2 -2
- data/spec/lib/castle/utils/clean_invalid_chars_spec.rb +1 -1
- data/spec/lib/castle/utils/clone_spec.rb +2 -2
- data/spec/lib/castle/utils/deep_symbolize_keys_spec.rb +1 -1
- data/spec/lib/castle/utils/get_timestamp_spec.rb +1 -1
- data/spec/lib/castle/utils/merge_spec.rb +3 -5
- data/spec/lib/castle/validators/not_supported_spec.rb +2 -7
- data/spec/lib/castle/validators/present_spec.rb +3 -10
- data/spec/lib/castle/verdict_spec.rb +4 -4
- data/spec/lib/castle/version_spec.rb +1 -1
- data/spec/lib/castle/webhooks/verify_spec.rb +13 -7
- data/spec/lib/castle_spec.rb +6 -8
- data/spec/spec_helper.rb +2 -0
- data/spec/support/shared_examples/action_request.rb +16 -34
- data/spec/support/shared_examples/configuration.rb +14 -16
- data/spec/support/shared_examples/list_items.rb +52 -0
- data/spec/support/shared_examples/lists.rb +45 -0
- metadata +132 -48
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Castle
|
4
|
+
module Commands
|
5
|
+
module ListItems
|
6
|
+
# Builds the command to query list items
|
7
|
+
class Query
|
8
|
+
class << self
|
9
|
+
# @param options [Hash]
|
10
|
+
# @return [Castle::Command]
|
11
|
+
def build(options = {})
|
12
|
+
Castle::Validators::Present.call(options, %i[list_id])
|
13
|
+
options[:filters]&.each { |f| Castle::Validators::Present.call(f, %i[field op value]) }
|
14
|
+
Castle::Validators::Present.call(options[:sort], %i[field order]) if options[:sort]
|
15
|
+
|
16
|
+
list_id = options.delete(:list_id)
|
17
|
+
|
18
|
+
Castle::Command.new("lists/#{list_id}/items/query", options, :post)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Castle
|
4
|
+
module Commands
|
5
|
+
module ListItems
|
6
|
+
# Builds the command to unarchive a list item
|
7
|
+
class Unarchive
|
8
|
+
class << self
|
9
|
+
# @param options [Hash]
|
10
|
+
# @return [Castle::Command]
|
11
|
+
def build(options = {})
|
12
|
+
Castle::Validators::Present.call(options, %i[list_id list_item_id])
|
13
|
+
|
14
|
+
list_id = options.delete(:list_id)
|
15
|
+
list_item_id = options.delete(:list_item_id)
|
16
|
+
|
17
|
+
Castle::Command.new("lists/#{list_id}/items/#{list_item_id}/unarchive", nil, :put)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Castle
|
4
|
+
module Commands
|
5
|
+
module ListItems
|
6
|
+
# Builds the command to update a list item
|
7
|
+
class Update
|
8
|
+
class << self
|
9
|
+
# @param options [Hash]
|
10
|
+
# @return [Castle::Command]
|
11
|
+
def build(options = {})
|
12
|
+
Castle::Validators::Present.call(options, %i[list_id list_item_id comment])
|
13
|
+
list_id = options.delete(:list_id)
|
14
|
+
list_item_id = options.delete(:list_item_id)
|
15
|
+
|
16
|
+
Castle::Command.new("lists/#{list_id}/items/#{list_item_id}", options, :put)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Castle
|
4
|
+
module Commands
|
5
|
+
# Commands for lists endpoints
|
6
|
+
module Lists
|
7
|
+
# Builds the command to create a list
|
8
|
+
class Create
|
9
|
+
class << self
|
10
|
+
# @param options [Hash]
|
11
|
+
# @return [Castle::Command]
|
12
|
+
def build(options = {})
|
13
|
+
Castle::Validators::Present.call(options, %i[name color primary_field])
|
14
|
+
|
15
|
+
Castle::Command.new('lists', options, :post)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Castle
|
4
|
+
module Commands
|
5
|
+
module Lists
|
6
|
+
# Builds the command to delete a list
|
7
|
+
class Delete
|
8
|
+
class << self
|
9
|
+
# @param options [Hash]
|
10
|
+
# @return [Castle::Command]
|
11
|
+
def build(options = {})
|
12
|
+
Castle::Validators::Present.call(options, %i[list_id])
|
13
|
+
|
14
|
+
Castle::Command.new("lists/#{options[:list_id]}", nil, :delete)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Castle
|
4
|
+
module Commands
|
5
|
+
module Lists
|
6
|
+
# Builds the command to get a list
|
7
|
+
class Get
|
8
|
+
class << self
|
9
|
+
# @param options [Hash]
|
10
|
+
# @return [Castle::Command]
|
11
|
+
def build(options = {})
|
12
|
+
Castle::Validators::Present.call(options, %i[list_id])
|
13
|
+
|
14
|
+
Castle::Command.new("lists/#{options[:list_id]}", nil, :get)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Castle
|
4
|
+
module Commands
|
5
|
+
module Lists
|
6
|
+
# Builds the command to get all lists
|
7
|
+
class GetAll
|
8
|
+
class << self
|
9
|
+
# @return [Castle::Command]
|
10
|
+
def build
|
11
|
+
Castle::Command.new('lists', nil, :get)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Castle
|
4
|
+
module Commands
|
5
|
+
module Lists
|
6
|
+
# Builds the command to query lists
|
7
|
+
class Query
|
8
|
+
class << self
|
9
|
+
# @param options [Hash]
|
10
|
+
# @return [Castle::Command]
|
11
|
+
def build(options = {})
|
12
|
+
options[:filters]&.each { |f| Castle::Validators::Present.call(f, %i[field op value]) }
|
13
|
+
Castle::Validators::Present.call(options[:sort], %i[field order]) if options[:sort]
|
14
|
+
|
15
|
+
Castle::Command.new('lists/query', options, :post)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Castle
|
4
|
+
module Commands
|
5
|
+
module Lists
|
6
|
+
# Builds the command to update a list
|
7
|
+
class Update
|
8
|
+
class << self
|
9
|
+
# @param options [Hash]
|
10
|
+
# @return [Castle::Command]
|
11
|
+
def build(options = {})
|
12
|
+
Castle::Validators::Present.call(options, %i[list_id])
|
13
|
+
|
14
|
+
list_id = options.delete(:list_id)
|
15
|
+
|
16
|
+
Castle::Command.new("lists/#{list_id}", options, :put)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/castle/commands/log.rb
CHANGED
@@ -10,11 +10,7 @@ module Castle
|
|
10
10
|
def build(options = {})
|
11
11
|
context = Castle::Context::Sanitize.call(options[:context])
|
12
12
|
|
13
|
-
Castle::Command.new(
|
14
|
-
'log',
|
15
|
-
options.merge(context: context, sent_at: Castle::Utils::GetTimestamp.call),
|
16
|
-
:post
|
17
|
-
)
|
13
|
+
Castle::Command.new('log', options.merge(context: context, sent_at: Castle::Utils::GetTimestamp.call), :post)
|
18
14
|
end
|
19
15
|
end
|
20
16
|
end
|
data/lib/castle/commands/risk.rb
CHANGED
@@ -10,11 +10,7 @@ module Castle
|
|
10
10
|
def build(options = {})
|
11
11
|
context = Castle::Context::Sanitize.call(options[:context])
|
12
12
|
|
13
|
-
Castle::Command.new(
|
14
|
-
'risk',
|
15
|
-
options.merge(context: context, sent_at: Castle::Utils::GetTimestamp.call),
|
16
|
-
:post
|
17
|
-
)
|
13
|
+
Castle::Command.new('risk', options.merge(context: context, sent_at: Castle::Utils::GetTimestamp.call), :post)
|
18
14
|
end
|
19
15
|
end
|
20
16
|
end
|
data/lib/castle/configuration.rb
CHANGED
@@ -104,9 +104,7 @@ module Castle
|
|
104
104
|
# sets trusted proxies
|
105
105
|
# @param value [Array<String,Regexp>]
|
106
106
|
def trusted_proxies=(value)
|
107
|
-
unless value.is_a?(Array)
|
108
|
-
raise Castle::ConfigurationError, 'trusted proxies must be an Array'
|
109
|
-
end
|
107
|
+
raise Castle::ConfigurationError, 'trusted proxies must be an Array' unless value.is_a?(Array)
|
110
108
|
|
111
109
|
@trusted_proxies = value
|
112
110
|
end
|
@@ -121,8 +119,7 @@ module Castle
|
|
121
119
|
end
|
122
120
|
|
123
121
|
def failover_strategy=(value)
|
124
|
-
@failover_strategy =
|
125
|
-
Castle::Failover::STRATEGIES.detect { |strategy| strategy == value.to_sym }
|
122
|
+
@failover_strategy = Castle::Failover::STRATEGIES.detect { |strategy| strategy == value.to_sym }
|
126
123
|
raise Castle::ConfigurationError, 'unrecognized failover strategy' if @failover_strategy.nil?
|
127
124
|
end
|
128
125
|
|
@@ -9,7 +9,8 @@ module Castle
|
|
9
9
|
401 => Castle::UnauthorizedError,
|
10
10
|
403 => Castle::ForbiddenError,
|
11
11
|
404 => Castle::NotFoundError,
|
12
|
-
419 => Castle::UserUnauthorizedError
|
12
|
+
419 => Castle::UserUnauthorizedError,
|
13
|
+
429 => Castle::RateLimitError
|
13
14
|
}.freeze
|
14
15
|
|
15
16
|
INVALID_REQUEST_TOKEN = 'invalid_request_token'
|
@@ -51,9 +52,9 @@ module Castle
|
|
51
52
|
if parsed_body.is_a?(Hash) && parsed_body.key?(:type)
|
52
53
|
if parsed_body[:type] == INVALID_REQUEST_TOKEN
|
53
54
|
raise Castle::InvalidRequestTokenError, parsed_body[:message]
|
54
|
-
else
|
55
|
-
raise Castle::InvalidParametersError, parsed_body[:message]
|
56
55
|
end
|
56
|
+
|
57
|
+
raise Castle::InvalidParametersError, parsed_body[:message]
|
57
58
|
end
|
58
59
|
rescue JSON::ParserError
|
59
60
|
end
|
@@ -15,9 +15,7 @@ module Castle
|
|
15
15
|
# @param http [Net::HTTP]
|
16
16
|
# @param config [Castle::Configuration, Castle::SingletonConfiguration, nil]
|
17
17
|
def call(command, headers, http = nil, config = nil)
|
18
|
-
(http || Castle::Core::GetConnection.call).request(
|
19
|
-
build(command, headers.merge(DEFAULT_HEADERS), config)
|
20
|
-
)
|
18
|
+
(http || Castle::Core::GetConnection.call).request(build(command, headers.merge(DEFAULT_HEADERS), config))
|
21
19
|
end
|
22
20
|
|
23
21
|
# @param command [String]
|
data/lib/castle/errors.rb
CHANGED
@@ -23,9 +23,7 @@ module Castle
|
|
23
23
|
# Serialize HTTP headers
|
24
24
|
# @return [Hash]
|
25
25
|
def call
|
26
|
-
@headers.each_with_object({})
|
27
|
-
acc[name] = header_value(name, value)
|
28
|
-
end
|
26
|
+
@headers.each_with_object({}) { |(name, value), acc| acc[name] = header_value(name, value) }
|
29
27
|
end
|
30
28
|
|
31
29
|
private
|
@@ -12,8 +12,7 @@ module Castle
|
|
12
12
|
HTTP(?:_|-).*|
|
13
13
|
CONTENT(?:_|-)LENGTH|
|
14
14
|
REMOTE(?:_|-)ADDR
|
15
|
-
$/xi
|
16
|
-
.freeze
|
15
|
+
$/xi.freeze
|
17
16
|
|
18
17
|
private_constant :VALUABLE_HEADERS
|
19
18
|
|
@@ -32,7 +31,7 @@ module Castle
|
|
32
31
|
next unless header_name.match(VALUABLE_HEADERS)
|
33
32
|
|
34
33
|
formatted_name = @header_format.call(header_name)
|
35
|
-
acc[formatted_name] = @request_env[header_name]
|
34
|
+
acc[formatted_name] = @request_env[header_name].to_s
|
36
35
|
end
|
37
36
|
end
|
38
37
|
end
|
@@ -12,8 +12,7 @@ module Castle
|
|
12
12
|
def call(payload_options, request, options = {})
|
13
13
|
context = Castle::Context::Prepare.call(request, payload_options.merge(options))
|
14
14
|
|
15
|
-
payload =
|
16
|
-
Castle::Utils::DeepSymbolizeKeys.call(payload_options || {}).merge(context: context)
|
15
|
+
payload = Castle::Utils::DeepSymbolizeKeys.call(payload_options || {}).merge(context: context)
|
17
16
|
payload[:timestamp] ||= Castle::Utils::GetTimestamp.call
|
18
17
|
|
19
18
|
warn '[DEPRECATION] use user_traits instead of traits key' if payload.key?(:traits)
|
data/lib/castle/session.rb
CHANGED
data/lib/castle/version.rb
CHANGED
data/lib/castle.rb
CHANGED
@@ -31,6 +31,19 @@
|
|
31
31
|
castle/commands/risk
|
32
32
|
castle/commands/start_impersonation
|
33
33
|
castle/commands/track
|
34
|
+
castle/commands/lists/get_all
|
35
|
+
castle/commands/lists/create
|
36
|
+
castle/commands/lists/delete
|
37
|
+
castle/commands/lists/get
|
38
|
+
castle/commands/lists/query
|
39
|
+
castle/commands/lists/update
|
40
|
+
castle/commands/list_items/archive
|
41
|
+
castle/commands/list_items/create
|
42
|
+
castle/commands/list_items/count
|
43
|
+
castle/commands/list_items/get
|
44
|
+
castle/commands/list_items/query
|
45
|
+
castle/commands/list_items/unarchive
|
46
|
+
castle/commands/list_items/update
|
34
47
|
castle/api/approve_device
|
35
48
|
castle/api/authenticate
|
36
49
|
castle/api/end_impersonation
|
@@ -42,12 +55,27 @@
|
|
42
55
|
castle/api/risk
|
43
56
|
castle/api/start_impersonation
|
44
57
|
castle/api/track
|
58
|
+
castle/api/lists/get_all
|
59
|
+
castle/api/lists/create
|
60
|
+
castle/api/lists/delete
|
61
|
+
castle/api/lists/get
|
62
|
+
castle/api/lists/query
|
63
|
+
castle/api/lists/update
|
64
|
+
castle/api/list_items/archive
|
65
|
+
castle/api/list_items/create
|
66
|
+
castle/api/list_items/count
|
67
|
+
castle/api/list_items/get
|
68
|
+
castle/api/list_items/query
|
69
|
+
castle/api/list_items/unarchive
|
70
|
+
castle/api/list_items/update
|
45
71
|
castle/payload/prepare
|
46
72
|
castle/configuration
|
47
73
|
castle/singleton_configuration
|
48
74
|
castle/logger
|
49
75
|
castle/failover/prepare_response
|
50
76
|
castle/failover/strategy
|
77
|
+
castle/client_actions/lists
|
78
|
+
castle/client_actions/list_items
|
51
79
|
castle/client
|
52
80
|
castle/headers/filter
|
53
81
|
castle/headers/format
|
@@ -67,9 +95,7 @@
|
|
67
95
|
module Castle
|
68
96
|
class << self
|
69
97
|
def configure(config_hash = nil)
|
70
|
-
(config_hash || {}).each
|
71
|
-
config.send("#{config_name}=", config_value)
|
72
|
-
end
|
98
|
+
(config_hash || {}).each { |config_name, config_value| config.send(:"#{config_name}=", config_value) }
|
73
99
|
|
74
100
|
yield(config) if block_given?
|
75
101
|
end
|
@@ -24,11 +24,12 @@ RSpec.describe HomeController, type: :request do
|
|
24
24
|
'Accept' =>
|
25
25
|
'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
|
26
26
|
'Authorization' => true,
|
27
|
-
'Content-Length' => '0',
|
28
27
|
'Cookie' => true,
|
28
|
+
'Content-Length' => '0',
|
29
29
|
'Host' => 'www.example.com',
|
30
30
|
'X-Forwarded-For' => '5.5.5.5, 1.2.3.4',
|
31
|
-
'Remote-Addr' => '127.0.0.1'
|
31
|
+
'Remote-Addr' => '127.0.0.1',
|
32
|
+
'Version' => 'HTTP/1.0'
|
32
33
|
},
|
33
34
|
'ip' => '1.2.3.4',
|
34
35
|
'library' => {
|
@@ -40,7 +41,12 @@ RSpec.describe HomeController, type: :request do
|
|
40
41
|
end
|
41
42
|
let(:now) { Time.now }
|
42
43
|
let(:headers) do
|
43
|
-
{
|
44
|
+
{
|
45
|
+
'HTTP_AUTHORIZATION' => 'Basic 123',
|
46
|
+
'HTTP_X_FORWARDED_FOR' => '5.5.5.5, 1.2.3.4',
|
47
|
+
'HTTP_VERSION' => 'HTTP/1.0',
|
48
|
+
'HTTP_CONTENT_LENGTH' => '0'
|
49
|
+
}
|
44
50
|
end
|
45
51
|
|
46
52
|
before do
|
@@ -3,8 +3,8 @@
|
|
3
3
|
require 'action_controller/railtie'
|
4
4
|
|
5
5
|
class TestApp < Rails::Application
|
6
|
-
|
7
|
-
|
6
|
+
credentials.secret_token = 'secret_token'
|
7
|
+
credentials.secret_key_base = 'secret_key_base'
|
8
8
|
|
9
9
|
config.logger = Logger.new($stdout)
|
10
10
|
Rails.logger = config.logger
|
@@ -4,16 +4,7 @@ class HomeController < ActionController::Base
|
|
4
4
|
# prepare context and calling track with client example
|
5
5
|
def index1
|
6
6
|
request_context = ::Castle::Context::Prepare.call(request)
|
7
|
-
payload = {
|
8
|
-
event: '$login.succeeded',
|
9
|
-
user_id: '123',
|
10
|
-
properties: {
|
11
|
-
key: 'value'
|
12
|
-
},
|
13
|
-
user_traits: {
|
14
|
-
key: 'value'
|
15
|
-
}
|
16
|
-
}
|
7
|
+
payload = { event: '$login.succeeded', user_id: '123', properties: { key: 'value' }, user_traits: { key: 'value' } }
|
17
8
|
client = ::Castle::Client.new(context: request_context)
|
18
9
|
client.track(payload)
|
19
10
|
|
@@ -24,16 +15,7 @@ class HomeController < ActionController::Base
|
|
24
15
|
def index2
|
25
16
|
payload =
|
26
17
|
::Castle::Payload::Prepare.call(
|
27
|
-
{
|
28
|
-
event: '$login.succeeded',
|
29
|
-
user_id: '123',
|
30
|
-
properties: {
|
31
|
-
key: 'value'
|
32
|
-
},
|
33
|
-
user_traits: {
|
34
|
-
key: 'value'
|
35
|
-
}
|
36
|
-
},
|
18
|
+
{ event: '$login.succeeded', user_id: '123', properties: { key: 'value' }, user_traits: { key: 'value' } },
|
37
19
|
request
|
38
20
|
)
|
39
21
|
client = ::Castle::Client.new
|
@@ -46,18 +28,10 @@ class HomeController < ActionController::Base
|
|
46
28
|
def index3
|
47
29
|
payload =
|
48
30
|
::Castle::Payload::Prepare.call(
|
49
|
-
{
|
50
|
-
event: '$login.succeeded',
|
51
|
-
user_id: '123',
|
52
|
-
properties: {
|
53
|
-
key: 'value'
|
54
|
-
},
|
55
|
-
user_traits: {
|
56
|
-
key: 'value'
|
57
|
-
}
|
58
|
-
},
|
31
|
+
{ event: '$login.succeeded', user_id: '123', properties: { key: 'value' }, user_traits: { key: 'value' } },
|
59
32
|
request
|
60
33
|
)
|
34
|
+
|
61
35
|
Castle::API::Track.call(payload)
|
62
36
|
|
63
37
|
render inline: 'hello'
|
@@ -1,10 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe Castle::API::ApproveDevice do
|
3
|
+
RSpec.describe Castle::API::ApproveDevice do
|
4
4
|
before do
|
5
|
-
stub_request(:any, /api.castle.io/)
|
6
|
-
.with(basic_auth: ['', 'secret'])
|
7
|
-
.to_return(status: 200, body: '{}', headers: {})
|
5
|
+
stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(status: 200, body: '{}', headers: {})
|
8
6
|
end
|
9
7
|
|
10
8
|
describe '.call' do
|
@@ -14,8 +12,6 @@ describe Castle::API::ApproveDevice do
|
|
14
12
|
|
15
13
|
before { retrieve }
|
16
14
|
|
17
|
-
it
|
18
|
-
assert_requested :put, "https://api.castle.io/v1/devices/#{device_token}/approve", times: 1
|
19
|
-
end
|
15
|
+
it { assert_requested :put, "https://api.castle.io/v1/devices/#{device_token}/approve", times: 1 }
|
20
16
|
end
|
21
17
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe Castle::API::Authenticate do
|
3
|
+
RSpec.describe Castle::API::Authenticate do
|
4
4
|
subject(:call_subject) { described_class.call(options) }
|
5
5
|
|
6
6
|
let(:ip) { '1.2.3.4' }
|
@@ -29,15 +29,16 @@ describe Castle::API::Authenticate do
|
|
29
29
|
after { Timecop.return }
|
30
30
|
|
31
31
|
describe '.call' do
|
32
|
-
let(:request_body)
|
33
|
-
{ event: '$login.succeeded', context: context, user_id: '1234', sent_at: time_auto }
|
34
|
-
end
|
32
|
+
let(:request_body) { { event: '$login.succeeded', context: context, user_id: '1234', sent_at: time_auto } }
|
35
33
|
|
36
34
|
context 'when used with symbol keys' do
|
37
35
|
before do
|
38
|
-
stub_request(:any, /api.castle.io/)
|
39
|
-
|
40
|
-
|
36
|
+
stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(
|
37
|
+
status: 200,
|
38
|
+
body: response_body,
|
39
|
+
headers: {
|
40
|
+
}
|
41
|
+
)
|
41
42
|
call_subject
|
42
43
|
end
|
43
44
|
|
@@ -50,17 +51,9 @@ describe Castle::API::Authenticate do
|
|
50
51
|
end
|
51
52
|
|
52
53
|
context 'when passed timestamp in options and no defined timestamp' do
|
53
|
-
let(:options)
|
54
|
-
{ event: '$login.succeeded', user_id: '1234', timestamp: time_user, context: context }
|
55
|
-
end
|
54
|
+
let(:options) { { event: '$login.succeeded', user_id: '1234', timestamp: time_user, context: context } }
|
56
55
|
let(:request_body) do
|
57
|
-
{
|
58
|
-
event: '$login.succeeded',
|
59
|
-
user_id: '1234',
|
60
|
-
context: context,
|
61
|
-
timestamp: time_user,
|
62
|
-
sent_at: time_auto
|
63
|
-
}
|
56
|
+
{ event: '$login.succeeded', user_id: '1234', context: context, timestamp: time_user, sent_at: time_auto }
|
64
57
|
end
|
65
58
|
|
66
59
|
it do
|
@@ -78,15 +71,16 @@ describe Castle::API::Authenticate do
|
|
78
71
|
|
79
72
|
context 'when denied without any risk policy' do
|
80
73
|
let(:response_body) { deny_response_without_rp.to_json }
|
81
|
-
let(:deny_response_without_rp)
|
82
|
-
{ action: 'deny', user_id: '12345', device_token: 'abcdefg1234' }
|
83
|
-
end
|
74
|
+
let(:deny_response_without_rp) { { action: 'deny', user_id: '12345', device_token: 'abcdefg1234' } }
|
84
75
|
let(:deny_without_rp_failover_result) { deny_response_without_rp.merge(failover_appendix) }
|
85
76
|
|
86
77
|
before do
|
87
|
-
stub_request(:any, /api.castle.io/)
|
88
|
-
|
89
|
-
|
78
|
+
stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(
|
79
|
+
status: 200,
|
80
|
+
body: deny_response_without_rp.to_json,
|
81
|
+
headers: {
|
82
|
+
}
|
83
|
+
)
|
90
84
|
call_subject
|
91
85
|
end
|
92
86
|
|
@@ -117,9 +111,12 @@ describe Castle::API::Authenticate do
|
|
117
111
|
let(:deny_with_rp_failover_result) { deny_response_with_rp.merge(failover_appendix) }
|
118
112
|
|
119
113
|
before do
|
120
|
-
stub_request(:any, /api.castle.io/)
|
121
|
-
|
122
|
-
|
114
|
+
stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(
|
115
|
+
status: 200,
|
116
|
+
body: deny_response_with_rp.to_json,
|
117
|
+
headers: {
|
118
|
+
}
|
119
|
+
)
|
123
120
|
call_subject
|
124
121
|
end
|
125
122
|
|