castle-rb 3.4.0 → 3.4.1
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 +36 -24
- data/lib/castle.rb +5 -3
- data/lib/castle/client.rb +21 -18
- data/lib/castle/commands/authenticate.rb +8 -16
- data/lib/castle/commands/identify.rb +9 -21
- data/lib/castle/commands/impersonate.rb +9 -23
- data/lib/castle/commands/review.rb +5 -4
- data/lib/castle/commands/track.rb +8 -16
- data/lib/castle/configuration.rb +1 -2
- 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/review.rb +1 -1
- data/lib/castle/utils/merger.rb +9 -9
- data/lib/castle/validators/not_supported.rb +16 -0
- data/lib/castle/validators/present.rb +16 -0
- data/lib/castle/version.rb +1 -1
- data/spec/lib/castle/client_spec.rb +3 -2
- data/spec/lib/castle/commands/authenticate_spec.rb +21 -21
- data/spec/lib/castle/commands/identify_spec.rb +17 -17
- data/spec/lib/castle/commands/impersonate_spec.rb +1 -1
- data/spec/lib/castle/commands/review_spec.rb +1 -1
- data/spec/lib/castle/commands/track_spec.rb +23 -23
- data/spec/lib/castle/configuration_spec.rb +13 -13
- data/spec/lib/castle/{default_context_spec.rb → context/default_spec.rb} +1 -1
- data/spec/lib/castle/{context_merger_spec.rb → context/merger_spec.rb} +4 -4
- data/spec/lib/castle/{context_sanitizer_spec.rb → context/sanitizer_spec.rb} +1 -1
- data/spec/lib/castle/extractors/client_id_spec.rb +1 -1
- data/spec/lib/castle/request_spec.rb +2 -2
- data/spec/lib/castle/response_spec.rb +4 -4
- data/spec/lib/castle/review_spec.rb +1 -1
- data/spec/lib/castle/utils_spec.rb +14 -14
- 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_spec.rb +3 -3
- metadata +19 -13
- data/lib/castle/context_merger.rb +0 -12
- data/lib/castle/context_sanitizer.rb +0 -20
- data/lib/castle/default_context.rb +0 -28
@@ -6,23 +6,23 @@ describe Castle::Configuration do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
describe 'host' do
|
9
|
-
context 'default' do
|
9
|
+
context 'with default' do
|
10
10
|
it { expect(config.host).to be_eql('api.castle.io') }
|
11
11
|
end
|
12
12
|
|
13
|
-
context 'setter' do
|
13
|
+
context 'with setter' do
|
14
14
|
before { config.host = 'api.castle.dev' }
|
15
15
|
|
16
16
|
it { expect(config.host).to be_eql('api.castle.dev') }
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
describe '
|
21
|
-
context 'default' do
|
20
|
+
describe 'post' do
|
21
|
+
context 'with default' do
|
22
22
|
it { expect(config.port).to be_eql(443) }
|
23
23
|
end
|
24
24
|
|
25
|
-
context 'setter' do
|
25
|
+
context 'with setter' do
|
26
26
|
before { config.port = 3001 }
|
27
27
|
|
28
28
|
it { expect(config.port).to be_eql(3001) }
|
@@ -30,7 +30,7 @@ describe Castle::Configuration do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
describe 'api_secret' do
|
33
|
-
context 'env' do
|
33
|
+
context 'with env' do
|
34
34
|
before do
|
35
35
|
allow(ENV).to receive(:fetch).with(
|
36
36
|
'CASTLE_API_SECRET', ''
|
@@ -42,7 +42,7 @@ describe Castle::Configuration do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
context 'setter' do
|
45
|
+
context 'with setter' do
|
46
46
|
let(:value) { 'new_secret' }
|
47
47
|
|
48
48
|
before do
|
@@ -63,7 +63,7 @@ describe Castle::Configuration do
|
|
63
63
|
expect(config.request_timeout).to be_eql(500)
|
64
64
|
end
|
65
65
|
|
66
|
-
context 'setter' do
|
66
|
+
context 'with setter' do
|
67
67
|
let(:value) { 50.0 }
|
68
68
|
|
69
69
|
before do
|
@@ -80,7 +80,7 @@ describe Castle::Configuration do
|
|
80
80
|
expect(config.whitelisted.size).to be_eql(13)
|
81
81
|
end
|
82
82
|
|
83
|
-
context 'setter' do
|
83
|
+
context 'with setter' do
|
84
84
|
before do
|
85
85
|
config.whitelisted = ['header']
|
86
86
|
end
|
@@ -89,7 +89,7 @@ describe Castle::Configuration do
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
context 'appending' do
|
92
|
+
context 'when appending' do
|
93
93
|
before do
|
94
94
|
config.whitelisted += ['header']
|
95
95
|
end
|
@@ -103,7 +103,7 @@ describe Castle::Configuration do
|
|
103
103
|
expect(config.blacklisted.size).to be_eql(1)
|
104
104
|
end
|
105
105
|
|
106
|
-
context 'setter' do
|
106
|
+
context 'with setter' do
|
107
107
|
before do
|
108
108
|
config.blacklisted = ['header']
|
109
109
|
end
|
@@ -112,7 +112,7 @@ describe Castle::Configuration do
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
context 'appending' do
|
115
|
+
context 'when appending' do
|
116
116
|
before do
|
117
117
|
config.blacklisted += ['header']
|
118
118
|
end
|
@@ -126,7 +126,7 @@ describe Castle::Configuration do
|
|
126
126
|
expect(config.failover_strategy).to be_eql(:allow)
|
127
127
|
end
|
128
128
|
|
129
|
-
context 'setter' do
|
129
|
+
context 'with setter' do
|
130
130
|
before do
|
131
131
|
config.failover_strategy = :deny
|
132
132
|
end
|
@@ -1,20 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe Castle::
|
3
|
+
describe Castle::Context::Merger do
|
4
4
|
let(:first) { { test: { test1: { c: '4' } } } }
|
5
5
|
|
6
|
-
|
6
|
+
describe '#call' do
|
7
7
|
subject { described_class.call(first, second) }
|
8
8
|
|
9
9
|
let(:result) { { test: { test1: { c: '4', d: '5' } } } }
|
10
10
|
|
11
|
-
context 'symbol keys' do
|
11
|
+
context 'with symbol keys' do
|
12
12
|
let(:second) { { test: { test1: { d: '5' } } } }
|
13
13
|
|
14
14
|
it { is_expected.to eq(result) }
|
15
15
|
end
|
16
16
|
|
17
|
-
context 'string keys' do
|
17
|
+
context 'with string keys' do
|
18
18
|
let(:second) { { 'test' => { 'test1' => { 'd' => '5' } } } }
|
19
19
|
|
20
20
|
it { is_expected.to eq(result) }
|
@@ -7,7 +7,7 @@ describe Castle::Request do
|
|
7
7
|
let(:api_secret) { Castle.config.api_secret }
|
8
8
|
|
9
9
|
describe 'build' do
|
10
|
-
context 'get' do
|
10
|
+
context 'when get' do
|
11
11
|
let(:path) { 'endpoint' }
|
12
12
|
let(:params) { { user_id: 1 } }
|
13
13
|
let(:request) { subject.build(path, params, :get) }
|
@@ -19,7 +19,7 @@ describe Castle::Request do
|
|
19
19
|
it { expect(request.to_hash['authorization'][0]).to match(/Basic \w/) }
|
20
20
|
end
|
21
21
|
|
22
|
-
context 'post' do
|
22
|
+
context 'when post' do
|
23
23
|
let(:path) { 'endpoint' }
|
24
24
|
let(:params) { { user_id: 1 } }
|
25
25
|
let(:request) { subject.build(path, params, :post) }
|
@@ -35,28 +35,28 @@ describe Castle::Response do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
describe 'parse' do
|
38
|
-
context '
|
38
|
+
context 'when success' do
|
39
39
|
let(:response) { OpenStruct.new(body: '{"user":1}', code: 200) }
|
40
40
|
|
41
41
|
it do
|
42
42
|
expect(castle_response.parse).to eql(user: 1)
|
43
43
|
end
|
44
44
|
end
|
45
|
-
context '
|
45
|
+
context 'when response empty' do
|
46
46
|
let(:response) { OpenStruct.new(body: '', code: 200) }
|
47
47
|
|
48
48
|
it do
|
49
49
|
expect(castle_response.parse).to eql({})
|
50
50
|
end
|
51
51
|
end
|
52
|
-
context '
|
52
|
+
context 'when response nil' do
|
53
53
|
let(:response) { OpenStruct.new(code: 200) }
|
54
54
|
|
55
55
|
it do
|
56
56
|
expect(castle_response.parse).to eql({})
|
57
57
|
end
|
58
58
|
end
|
59
|
-
context '
|
59
|
+
context 'when json is malformed' do
|
60
60
|
let(:response) { OpenStruct.new(body: '{a', code: 200) }
|
61
61
|
|
62
62
|
it do
|
@@ -8,80 +8,80 @@ describe Castle::Utils do
|
|
8
8
|
let(:symbol_array_of_hashes) { { a: [{ b: 2 }, { c: 3 }, 4] } }
|
9
9
|
let(:mixed_array_of_hashes) { { a: [{ b: 2 }, { 'c' => 3 }, 4] } }
|
10
10
|
|
11
|
-
|
11
|
+
describe '#deep_symbolize_keys' do
|
12
12
|
subject { described_class.deep_symbolize_keys(hash) }
|
13
13
|
|
14
|
-
context 'nested_symbols' do
|
14
|
+
context 'when nested_symbols' do
|
15
15
|
let(:hash) { nested_symbols }
|
16
16
|
|
17
17
|
it { is_expected.to eq(nested_symbols) }
|
18
18
|
end
|
19
19
|
|
20
|
-
context 'nested_strings' do
|
20
|
+
context 'when nested_strings' do
|
21
21
|
let(:hash) { nested_strings }
|
22
22
|
|
23
23
|
it { is_expected.to eq(nested_symbols) }
|
24
24
|
end
|
25
25
|
|
26
|
-
context 'nested_mixed' do
|
26
|
+
context 'when nested_mixed' do
|
27
27
|
let(:hash) { nested_mixed }
|
28
28
|
|
29
29
|
it { is_expected.to eq(nested_symbols) }
|
30
30
|
end
|
31
31
|
|
32
|
-
context 'string_array_of_hashes' do
|
32
|
+
context 'when string_array_of_hashes' do
|
33
33
|
let(:hash) { string_array_of_hashes }
|
34
34
|
|
35
35
|
it { is_expected.to eq(symbol_array_of_hashes) }
|
36
36
|
end
|
37
37
|
|
38
|
-
context 'symbol_array_of_hashes' do
|
38
|
+
context 'when symbol_array_of_hashes' do
|
39
39
|
let(:hash) { symbol_array_of_hashes }
|
40
40
|
|
41
41
|
it { is_expected.to eq(symbol_array_of_hashes) }
|
42
42
|
end
|
43
43
|
|
44
|
-
context 'mixed_array_of_hashes' do
|
44
|
+
context 'when mixed_array_of_hashes' do
|
45
45
|
let(:hash) { mixed_array_of_hashes }
|
46
46
|
|
47
47
|
it { is_expected.to eq(symbol_array_of_hashes) }
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
|
51
|
+
describe '#deep_symbolize_keys' do
|
52
52
|
subject { described_class.deep_symbolize_keys!(Castle::Utils::Cloner.call(hash)) }
|
53
53
|
|
54
|
-
context 'nested_symbols' do
|
54
|
+
context 'when nested_symbols' do
|
55
55
|
let(:hash) { nested_symbols }
|
56
56
|
|
57
57
|
it { is_expected.to eq(nested_symbols) }
|
58
58
|
end
|
59
59
|
|
60
|
-
context 'nested_strings' do
|
60
|
+
context 'when nested_strings' do
|
61
61
|
let(:hash) { nested_strings }
|
62
62
|
|
63
63
|
it { is_expected.to eq(nested_symbols) }
|
64
64
|
end
|
65
65
|
|
66
|
-
context 'nested_mixed' do
|
66
|
+
context 'when nested_mixed' do
|
67
67
|
let(:hash) { nested_mixed }
|
68
68
|
|
69
69
|
it { is_expected.to eq(nested_symbols) }
|
70
70
|
end
|
71
71
|
|
72
|
-
context 'string_array_of_hashes' do
|
72
|
+
context 'when string_array_of_hashes' do
|
73
73
|
let(:hash) { string_array_of_hashes }
|
74
74
|
|
75
75
|
it { is_expected.to eq(symbol_array_of_hashes) }
|
76
76
|
end
|
77
77
|
|
78
|
-
context 'symbol_array_of_hashes' do
|
78
|
+
context 'when symbol_array_of_hashes' do
|
79
79
|
let(:hash) { symbol_array_of_hashes }
|
80
80
|
|
81
81
|
it { is_expected.to eq(symbol_array_of_hashes) }
|
82
82
|
end
|
83
83
|
|
84
|
-
context 'mixed_array_of_hashes' do
|
84
|
+
context 'when mixed_array_of_hashes' do
|
85
85
|
let(:hash) { mixed_array_of_hashes }
|
86
86
|
|
87
87
|
it { is_expected.to eq(symbol_array_of_hashes) }
|
@@ -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
|
data/spec/lib/castle_spec.rb
CHANGED
@@ -24,7 +24,7 @@ describe Castle do
|
|
24
24
|
it { expect(castle.config.request_timeout).to be_eql(timeout) }
|
25
25
|
end
|
26
26
|
|
27
|
-
context '
|
27
|
+
context 'with block' do
|
28
28
|
before do
|
29
29
|
castle.configure do |config|
|
30
30
|
config.api_secret = value
|
@@ -35,13 +35,13 @@ describe Castle do
|
|
35
35
|
it_behaves_like 'config_setup'
|
36
36
|
end
|
37
37
|
|
38
|
-
context '
|
38
|
+
context 'with options' do
|
39
39
|
before { castle.configure(request_timeout: timeout, api_secret: value) }
|
40
40
|
|
41
41
|
it_behaves_like 'config_setup'
|
42
42
|
end
|
43
43
|
|
44
|
-
context '
|
44
|
+
context 'with block and options' do
|
45
45
|
before do
|
46
46
|
castle.configure(request_timeout: timeout) do |config|
|
47
47
|
config.api_secret = value
|
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: 3.4.
|
4
|
+
version: 3.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johan Brissmyr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Castle protects your users from account compromise
|
14
14
|
email: johan@castle.io
|
@@ -28,9 +28,9 @@ files:
|
|
28
28
|
- lib/castle/commands/review.rb
|
29
29
|
- lib/castle/commands/track.rb
|
30
30
|
- lib/castle/configuration.rb
|
31
|
-
- lib/castle/
|
32
|
-
- lib/castle/
|
33
|
-
- lib/castle/
|
31
|
+
- lib/castle/context/default.rb
|
32
|
+
- lib/castle/context/merger.rb
|
33
|
+
- lib/castle/context/sanitizer.rb
|
34
34
|
- lib/castle/errors.rb
|
35
35
|
- lib/castle/extractors/client_id.rb
|
36
36
|
- lib/castle/extractors/headers.rb
|
@@ -49,6 +49,8 @@ files:
|
|
49
49
|
- lib/castle/utils/cloner.rb
|
50
50
|
- lib/castle/utils/merger.rb
|
51
51
|
- lib/castle/utils/timestamp.rb
|
52
|
+
- lib/castle/validators/not_supported.rb
|
53
|
+
- lib/castle/validators/present.rb
|
52
54
|
- lib/castle/version.rb
|
53
55
|
- spec/lib/castle/api_spec.rb
|
54
56
|
- spec/lib/castle/client_spec.rb
|
@@ -59,9 +61,9 @@ files:
|
|
59
61
|
- spec/lib/castle/commands/review_spec.rb
|
60
62
|
- spec/lib/castle/commands/track_spec.rb
|
61
63
|
- spec/lib/castle/configuration_spec.rb
|
62
|
-
- spec/lib/castle/
|
63
|
-
- spec/lib/castle/
|
64
|
-
- spec/lib/castle/
|
64
|
+
- spec/lib/castle/context/default_spec.rb
|
65
|
+
- spec/lib/castle/context/merger_spec.rb
|
66
|
+
- spec/lib/castle/context/sanitizer_spec.rb
|
65
67
|
- spec/lib/castle/extractors/client_id_spec.rb
|
66
68
|
- spec/lib/castle/extractors/headers_spec.rb
|
67
69
|
- spec/lib/castle/extractors/ip_spec.rb
|
@@ -74,6 +76,8 @@ files:
|
|
74
76
|
- spec/lib/castle/utils/merger_spec.rb
|
75
77
|
- spec/lib/castle/utils/timestamp_spec.rb
|
76
78
|
- spec/lib/castle/utils_spec.rb
|
79
|
+
- spec/lib/castle/validators/not_supported_spec.rb
|
80
|
+
- spec/lib/castle/validators/present_spec.rb
|
77
81
|
- spec/lib/castle/version_spec.rb
|
78
82
|
- spec/lib/castle_spec.rb
|
79
83
|
- spec/spec_helper.rb
|
@@ -89,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
93
|
requirements:
|
90
94
|
- - ">="
|
91
95
|
- !ruby/object:Gem::Version
|
92
|
-
version:
|
96
|
+
version: 2.2.6
|
93
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
98
|
requirements:
|
95
99
|
- - ">="
|
@@ -97,20 +101,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
101
|
version: '0'
|
98
102
|
requirements: []
|
99
103
|
rubyforge_project:
|
100
|
-
rubygems_version: 2.7.
|
104
|
+
rubygems_version: 2.7.3
|
101
105
|
signing_key:
|
102
106
|
specification_version: 4
|
103
107
|
summary: Castle
|
104
108
|
test_files:
|
105
109
|
- spec/spec_helper.rb
|
106
110
|
- spec/lib/castle_spec.rb
|
107
|
-
- spec/lib/castle/context_sanitizer_spec.rb
|
108
111
|
- spec/lib/castle/review_spec.rb
|
109
112
|
- spec/lib/castle/client_spec.rb
|
113
|
+
- spec/lib/castle/context/default_spec.rb
|
114
|
+
- spec/lib/castle/context/merger_spec.rb
|
115
|
+
- spec/lib/castle/context/sanitizer_spec.rb
|
110
116
|
- spec/lib/castle/api_spec.rb
|
111
117
|
- spec/lib/castle/configuration_spec.rb
|
112
118
|
- spec/lib/castle/version_spec.rb
|
113
|
-
- spec/lib/castle/default_context_spec.rb
|
114
119
|
- spec/lib/castle/header_formatter_spec.rb
|
115
120
|
- spec/lib/castle/utils/cloner_spec.rb
|
116
121
|
- spec/lib/castle/utils/timestamp_spec.rb
|
@@ -123,7 +128,8 @@ test_files:
|
|
123
128
|
- spec/lib/castle/commands/track_spec.rb
|
124
129
|
- spec/lib/castle/commands/impersonate_spec.rb
|
125
130
|
- spec/lib/castle/commands/identify_spec.rb
|
126
|
-
- spec/lib/castle/
|
131
|
+
- spec/lib/castle/validators/not_supported_spec.rb
|
132
|
+
- spec/lib/castle/validators/present_spec.rb
|
127
133
|
- spec/lib/castle/extractors/ip_spec.rb
|
128
134
|
- spec/lib/castle/extractors/headers_spec.rb
|
129
135
|
- spec/lib/castle/extractors/client_id_spec.rb
|