castle-rb 3.6.2
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 +7 -0
- data/README.md +157 -0
- data/lib/castle-rb.rb +3 -0
- data/lib/castle.rb +62 -0
- data/lib/castle/api.rb +40 -0
- data/lib/castle/api/request.rb +37 -0
- data/lib/castle/api/request/build.rb +27 -0
- data/lib/castle/api/response.rb +40 -0
- data/lib/castle/client.rb +106 -0
- data/lib/castle/command.rb +5 -0
- data/lib/castle/commands/authenticate.rb +23 -0
- data/lib/castle/commands/identify.rb +23 -0
- data/lib/castle/commands/impersonate.rb +26 -0
- data/lib/castle/commands/review.rb +14 -0
- data/lib/castle/commands/track.rb +23 -0
- data/lib/castle/configuration.rb +80 -0
- data/lib/castle/context/default.rb +40 -0
- data/lib/castle/context/merger.rb +14 -0
- data/lib/castle/context/sanitizer.rb +23 -0
- data/lib/castle/errors.rb +41 -0
- data/lib/castle/extractors/client_id.rb +17 -0
- data/lib/castle/extractors/headers.rb +51 -0
- data/lib/castle/extractors/ip.rb +18 -0
- data/lib/castle/failover_auth_response.rb +21 -0
- data/lib/castle/header_formatter.rb +9 -0
- data/lib/castle/review.rb +11 -0
- data/lib/castle/secure_mode.rb +11 -0
- data/lib/castle/support/hanami.rb +19 -0
- data/lib/castle/support/padrino.rb +19 -0
- data/lib/castle/support/rails.rb +13 -0
- data/lib/castle/support/sinatra.rb +19 -0
- data/lib/castle/utils.rb +55 -0
- data/lib/castle/utils/cloner.rb +11 -0
- data/lib/castle/utils/merger.rb +23 -0
- data/lib/castle/utils/timestamp.rb +12 -0
- data/lib/castle/validators/not_supported.rb +16 -0
- data/lib/castle/validators/present.rb +16 -0
- data/lib/castle/version.rb +5 -0
- data/spec/lib/castle/api/request/build_spec.rb +44 -0
- data/spec/lib/castle/api/request_spec.rb +59 -0
- data/spec/lib/castle/api/response_spec.rb +58 -0
- data/spec/lib/castle/api_spec.rb +37 -0
- data/spec/lib/castle/client_spec.rb +358 -0
- data/spec/lib/castle/command_spec.rb +9 -0
- data/spec/lib/castle/commands/authenticate_spec.rb +108 -0
- data/spec/lib/castle/commands/identify_spec.rb +87 -0
- data/spec/lib/castle/commands/impersonate_spec.rb +106 -0
- data/spec/lib/castle/commands/review_spec.rb +24 -0
- data/spec/lib/castle/commands/track_spec.rb +113 -0
- data/spec/lib/castle/configuration_spec.rb +130 -0
- data/spec/lib/castle/context/default_spec.rb +41 -0
- data/spec/lib/castle/context/merger_spec.rb +23 -0
- data/spec/lib/castle/context/sanitizer_spec.rb +27 -0
- data/spec/lib/castle/extractors/client_id_spec.rb +62 -0
- data/spec/lib/castle/extractors/headers_spec.rb +89 -0
- data/spec/lib/castle/extractors/ip_spec.rb +27 -0
- data/spec/lib/castle/header_formatter_spec.rb +25 -0
- data/spec/lib/castle/review_spec.rb +19 -0
- data/spec/lib/castle/secure_mode_spec.rb +9 -0
- data/spec/lib/castle/utils/cloner_spec.rb +18 -0
- data/spec/lib/castle/utils/merger_spec.rb +13 -0
- data/spec/lib/castle/utils/timestamp_spec.rb +17 -0
- data/spec/lib/castle/utils_spec.rb +156 -0
- data/spec/lib/castle/validators/not_supported_spec.rb +26 -0
- data/spec/lib/castle/validators/present_spec.rb +33 -0
- data/spec/lib/castle/version_spec.rb +5 -0
- data/spec/lib/castle_spec.rb +66 -0
- data/spec/spec_helper.rb +25 -0
- metadata +139 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe Castle::Validators::NotSupported do
|
4
|
+
describe '#call' do
|
5
|
+
subject(:call) { described_class.call({ first: 1 }, keys) }
|
6
|
+
|
7
|
+
context 'when keys is present' do
|
8
|
+
let(:keys) { %i[first second] }
|
9
|
+
|
10
|
+
it do
|
11
|
+
expect do
|
12
|
+
call
|
13
|
+
end.to raise_error(
|
14
|
+
Castle::InvalidParametersError,
|
15
|
+
'first is/are not supported'
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when key is not present' do
|
21
|
+
let(:keys) { %i[second third] }
|
22
|
+
|
23
|
+
it { expect { call }.not_to raise_error }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe Castle::Validators::Present do
|
4
|
+
describe '#call' do
|
5
|
+
subject(:call) { described_class.call({ first: 1, second: '2', invalid: '' }, keys) }
|
6
|
+
|
7
|
+
context 'when keys is not present' do
|
8
|
+
let(:keys) { %i[second third] }
|
9
|
+
|
10
|
+
it do
|
11
|
+
expect do
|
12
|
+
call
|
13
|
+
end.to raise_error(Castle::InvalidParametersError, 'third is missing or empty')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when keys is empty' do
|
18
|
+
let(:keys) { %i[second invalid] }
|
19
|
+
|
20
|
+
it do
|
21
|
+
expect do
|
22
|
+
call
|
23
|
+
end.to raise_error(Castle::InvalidParametersError, 'invalid is missing or empty')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when key is present' do
|
28
|
+
let(:keys) { %i[first second] }
|
29
|
+
|
30
|
+
it { expect { call }.not_to raise_error }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe Castle do
|
4
|
+
subject(:castle) { described_class }
|
5
|
+
|
6
|
+
describe 'config' do
|
7
|
+
it { expect(castle.config).to be_kind_of(Castle::Configuration) }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'api_secret setter' do
|
11
|
+
let(:value) { 'new_secret' }
|
12
|
+
|
13
|
+
before { castle.api_secret = value }
|
14
|
+
|
15
|
+
it { expect(castle.config.api_secret).to be_eql(value) }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'configure' do
|
19
|
+
let(:value) { 'new_secret' }
|
20
|
+
let(:timeout) { 60 }
|
21
|
+
|
22
|
+
shared_examples 'config_setup' do
|
23
|
+
it { expect(castle.config.api_secret).to be_eql(value) }
|
24
|
+
it { expect(castle.config.request_timeout).to be_eql(timeout) }
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'with block' do
|
28
|
+
before do
|
29
|
+
castle.configure do |config|
|
30
|
+
config.api_secret = value
|
31
|
+
config.request_timeout = timeout
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it_behaves_like 'config_setup'
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'with options' do
|
39
|
+
before { castle.configure(request_timeout: timeout, api_secret: value) }
|
40
|
+
|
41
|
+
it_behaves_like 'config_setup'
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'with block and options' do
|
45
|
+
before do
|
46
|
+
castle.configure(request_timeout: timeout) do |config|
|
47
|
+
config.api_secret = value
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it_behaves_like 'config_setup'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe 'configure wrongly' do
|
56
|
+
let(:value) { 'new_secret' }
|
57
|
+
|
58
|
+
it do
|
59
|
+
expect do
|
60
|
+
castle.configure do |config|
|
61
|
+
config.wrong_config = value
|
62
|
+
end
|
63
|
+
end.to raise_error(Castle::ConfigurationError)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'rack'
|
6
|
+
require 'webmock/rspec'
|
7
|
+
require 'byebug'
|
8
|
+
require 'timecop'
|
9
|
+
|
10
|
+
require 'coveralls'
|
11
|
+
Coveralls.wear!
|
12
|
+
|
13
|
+
require 'castle'
|
14
|
+
|
15
|
+
WebMock.disable_net_connect!(allow_localhost: true)
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
config.before do
|
19
|
+
Castle.instance_variable_set(:@configuration, Castle::Configuration.new)
|
20
|
+
|
21
|
+
Castle.configure do |cfg|
|
22
|
+
cfg.api_secret = 'secret'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: castle-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.6.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Johan Brissmyr
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-24 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Castle protects your users from account compromise
|
14
|
+
email: johan@castle.io
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- README.md
|
20
|
+
- lib/castle-rb.rb
|
21
|
+
- lib/castle.rb
|
22
|
+
- lib/castle/api.rb
|
23
|
+
- lib/castle/api/request.rb
|
24
|
+
- lib/castle/api/request/build.rb
|
25
|
+
- lib/castle/api/response.rb
|
26
|
+
- lib/castle/client.rb
|
27
|
+
- lib/castle/command.rb
|
28
|
+
- lib/castle/commands/authenticate.rb
|
29
|
+
- lib/castle/commands/identify.rb
|
30
|
+
- lib/castle/commands/impersonate.rb
|
31
|
+
- lib/castle/commands/review.rb
|
32
|
+
- lib/castle/commands/track.rb
|
33
|
+
- lib/castle/configuration.rb
|
34
|
+
- lib/castle/context/default.rb
|
35
|
+
- lib/castle/context/merger.rb
|
36
|
+
- lib/castle/context/sanitizer.rb
|
37
|
+
- lib/castle/errors.rb
|
38
|
+
- lib/castle/extractors/client_id.rb
|
39
|
+
- lib/castle/extractors/headers.rb
|
40
|
+
- lib/castle/extractors/ip.rb
|
41
|
+
- lib/castle/failover_auth_response.rb
|
42
|
+
- lib/castle/header_formatter.rb
|
43
|
+
- lib/castle/review.rb
|
44
|
+
- lib/castle/secure_mode.rb
|
45
|
+
- lib/castle/support/hanami.rb
|
46
|
+
- lib/castle/support/padrino.rb
|
47
|
+
- lib/castle/support/rails.rb
|
48
|
+
- lib/castle/support/sinatra.rb
|
49
|
+
- lib/castle/utils.rb
|
50
|
+
- lib/castle/utils/cloner.rb
|
51
|
+
- lib/castle/utils/merger.rb
|
52
|
+
- lib/castle/utils/timestamp.rb
|
53
|
+
- lib/castle/validators/not_supported.rb
|
54
|
+
- lib/castle/validators/present.rb
|
55
|
+
- lib/castle/version.rb
|
56
|
+
- spec/lib/castle/api/request/build_spec.rb
|
57
|
+
- spec/lib/castle/api/request_spec.rb
|
58
|
+
- spec/lib/castle/api/response_spec.rb
|
59
|
+
- spec/lib/castle/api_spec.rb
|
60
|
+
- spec/lib/castle/client_spec.rb
|
61
|
+
- spec/lib/castle/command_spec.rb
|
62
|
+
- spec/lib/castle/commands/authenticate_spec.rb
|
63
|
+
- spec/lib/castle/commands/identify_spec.rb
|
64
|
+
- spec/lib/castle/commands/impersonate_spec.rb
|
65
|
+
- spec/lib/castle/commands/review_spec.rb
|
66
|
+
- spec/lib/castle/commands/track_spec.rb
|
67
|
+
- spec/lib/castle/configuration_spec.rb
|
68
|
+
- spec/lib/castle/context/default_spec.rb
|
69
|
+
- spec/lib/castle/context/merger_spec.rb
|
70
|
+
- spec/lib/castle/context/sanitizer_spec.rb
|
71
|
+
- spec/lib/castle/extractors/client_id_spec.rb
|
72
|
+
- spec/lib/castle/extractors/headers_spec.rb
|
73
|
+
- spec/lib/castle/extractors/ip_spec.rb
|
74
|
+
- spec/lib/castle/header_formatter_spec.rb
|
75
|
+
- spec/lib/castle/review_spec.rb
|
76
|
+
- spec/lib/castle/secure_mode_spec.rb
|
77
|
+
- spec/lib/castle/utils/cloner_spec.rb
|
78
|
+
- spec/lib/castle/utils/merger_spec.rb
|
79
|
+
- spec/lib/castle/utils/timestamp_spec.rb
|
80
|
+
- spec/lib/castle/utils_spec.rb
|
81
|
+
- spec/lib/castle/validators/not_supported_spec.rb
|
82
|
+
- spec/lib/castle/validators/present_spec.rb
|
83
|
+
- spec/lib/castle/version_spec.rb
|
84
|
+
- spec/lib/castle_spec.rb
|
85
|
+
- spec/spec_helper.rb
|
86
|
+
homepage: https://castle.io
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '2.4'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubygems_version: 3.0.6
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Castle
|
109
|
+
test_files:
|
110
|
+
- spec/spec_helper.rb
|
111
|
+
- spec/lib/castle_spec.rb
|
112
|
+
- spec/lib/castle/review_spec.rb
|
113
|
+
- spec/lib/castle/client_spec.rb
|
114
|
+
- spec/lib/castle/context/default_spec.rb
|
115
|
+
- spec/lib/castle/context/merger_spec.rb
|
116
|
+
- spec/lib/castle/context/sanitizer_spec.rb
|
117
|
+
- spec/lib/castle/api_spec.rb
|
118
|
+
- spec/lib/castle/configuration_spec.rb
|
119
|
+
- spec/lib/castle/version_spec.rb
|
120
|
+
- spec/lib/castle/header_formatter_spec.rb
|
121
|
+
- spec/lib/castle/utils/cloner_spec.rb
|
122
|
+
- spec/lib/castle/utils/timestamp_spec.rb
|
123
|
+
- spec/lib/castle/utils/merger_spec.rb
|
124
|
+
- spec/lib/castle/command_spec.rb
|
125
|
+
- spec/lib/castle/api/request_spec.rb
|
126
|
+
- spec/lib/castle/api/response_spec.rb
|
127
|
+
- spec/lib/castle/api/request/build_spec.rb
|
128
|
+
- spec/lib/castle/commands/review_spec.rb
|
129
|
+
- spec/lib/castle/commands/authenticate_spec.rb
|
130
|
+
- spec/lib/castle/commands/track_spec.rb
|
131
|
+
- spec/lib/castle/commands/impersonate_spec.rb
|
132
|
+
- spec/lib/castle/commands/identify_spec.rb
|
133
|
+
- spec/lib/castle/validators/not_supported_spec.rb
|
134
|
+
- spec/lib/castle/validators/present_spec.rb
|
135
|
+
- spec/lib/castle/extractors/ip_spec.rb
|
136
|
+
- spec/lib/castle/extractors/headers_spec.rb
|
137
|
+
- spec/lib/castle/extractors/client_id_spec.rb
|
138
|
+
- spec/lib/castle/utils_spec.rb
|
139
|
+
- spec/lib/castle/secure_mode_spec.rb
|