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
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe Castle::Client do
|
3
|
+
RSpec.describe Castle::Client do
|
4
4
|
let(:ip) { '1.2.3.4' }
|
5
5
|
let(:cookie_id) { 'abcd' }
|
6
6
|
let(:ua) { 'Chrome' }
|
@@ -9,20 +9,17 @@ describe Castle::Client do
|
|
9
9
|
'/',
|
10
10
|
'HTTP_USER_AGENT' => ua,
|
11
11
|
'HTTP_X_FORWARDED_FOR' => ip,
|
12
|
-
'HTTP_COOKIE' => "__cid=#{cookie_id};other=efgh"
|
12
|
+
'HTTP_COOKIE' => "__cid=#{cookie_id};other=efgh",
|
13
|
+
'HTTP_CONTENT_LENGTH' => '0'
|
13
14
|
)
|
14
15
|
end
|
15
16
|
let(:request) { Rack::Request.new(env) }
|
16
17
|
let(:client) { described_class.from_request(request) }
|
17
18
|
let(:request_to_context) { Castle::Context::Prepare.call(request) }
|
18
|
-
let(:client_with_user_timestamp)
|
19
|
-
described_class.new(context: request_to_context, timestamp: time_user)
|
20
|
-
end
|
19
|
+
let(:client_with_user_timestamp) { described_class.new(context: request_to_context, timestamp: time_user) }
|
21
20
|
let(:client_with_no_timestamp) { described_class.new(context: request_to_context) }
|
22
21
|
|
23
|
-
let(:headers)
|
24
|
-
{ 'Content-Length': '0', 'User-Agent': ua, 'X-Forwarded-For': ip.to_s, 'Cookie': true }
|
25
|
-
end
|
22
|
+
let(:headers) { { 'Content-Length': '0', 'User-Agent': ua, 'X-Forwarded-For': ip.to_s, Cookie: true } }
|
26
23
|
let(:context) do
|
27
24
|
{
|
28
25
|
client_id: 'abcd',
|
@@ -44,9 +41,12 @@ describe Castle::Client do
|
|
44
41
|
let(:response_code) { 200 }
|
45
42
|
|
46
43
|
let(:stub_response) do
|
47
|
-
stub_request(:any, /api.castle.io/)
|
48
|
-
|
49
|
-
|
44
|
+
stub_request(:any, /api.castle.io/).with(basic_auth: ['', 'secret']).to_return(
|
45
|
+
status: response_code,
|
46
|
+
body: response_body,
|
47
|
+
headers: {
|
48
|
+
}
|
49
|
+
)
|
50
50
|
end
|
51
51
|
|
52
52
|
before do
|
@@ -95,9 +95,7 @@ describe Castle::Client do
|
|
95
95
|
context 'when request is not successful' do
|
96
96
|
let(:response_body) { {}.to_json }
|
97
97
|
|
98
|
-
it
|
99
|
-
expect { client.end_impersonation(options) }.to raise_error(Castle::ImpersonationFailed)
|
100
|
-
end
|
98
|
+
it { expect { client.end_impersonation(options) }.to raise_error(Castle::ImpersonationFailed) }
|
101
99
|
end
|
102
100
|
end
|
103
101
|
|
@@ -130,9 +128,7 @@ describe Castle::Client do
|
|
130
128
|
context 'when request is not successful' do
|
131
129
|
let(:response_body) { {}.to_json }
|
132
130
|
|
133
|
-
it
|
134
|
-
expect { client.start_impersonation(options) }.to raise_error(Castle::ImpersonationFailed)
|
135
|
-
end
|
131
|
+
it { expect { client.start_impersonation(options) }.to raise_error(Castle::ImpersonationFailed) }
|
136
132
|
end
|
137
133
|
end
|
138
134
|
|
@@ -140,13 +136,7 @@ describe Castle::Client do
|
|
140
136
|
let(:options) { { event: '$login.succeeded', user_id: '1234' } }
|
141
137
|
let(:request_response) { client.authenticate(options) }
|
142
138
|
let(:request_body) do
|
143
|
-
{
|
144
|
-
event: '$login.succeeded',
|
145
|
-
user_id: '1234',
|
146
|
-
context: context,
|
147
|
-
timestamp: time_auto,
|
148
|
-
sent_at: time_auto
|
149
|
-
}
|
139
|
+
{ event: '$login.succeeded', user_id: '1234', context: context, timestamp: time_auto, sent_at: time_auto }
|
150
140
|
end
|
151
141
|
|
152
142
|
context 'when used with symbol keys' do
|
@@ -162,13 +152,7 @@ describe Castle::Client do
|
|
162
152
|
let(:client) { client_with_no_timestamp }
|
163
153
|
let(:options) { { event: '$login.succeeded', user_id: '1234', timestamp: time_user } }
|
164
154
|
let(:request_body) do
|
165
|
-
{
|
166
|
-
event: '$login.succeeded',
|
167
|
-
user_id: '1234',
|
168
|
-
context: context,
|
169
|
-
timestamp: time_user,
|
170
|
-
sent_at: time_auto
|
171
|
-
}
|
155
|
+
{ event: '$login.succeeded', user_id: '1234', context: context, timestamp: time_user, sent_at: time_auto }
|
172
156
|
end
|
173
157
|
|
174
158
|
it do
|
@@ -181,13 +165,7 @@ describe Castle::Client do
|
|
181
165
|
context 'with client initialized with timestamp' do
|
182
166
|
let(:client) { client_with_user_timestamp }
|
183
167
|
let(:request_body) do
|
184
|
-
{
|
185
|
-
event: '$login.succeeded',
|
186
|
-
user_id: '1234',
|
187
|
-
context: context,
|
188
|
-
timestamp: time_user,
|
189
|
-
sent_at: time_auto
|
190
|
-
}
|
168
|
+
{ event: '$login.succeeded', user_id: '1234', context: context, timestamp: time_user, sent_at: time_auto }
|
191
169
|
end
|
192
170
|
|
193
171
|
it do
|
@@ -230,19 +208,15 @@ describe Castle::Client do
|
|
230
208
|
end
|
231
209
|
|
232
210
|
it { assert_not_requested :post, 'https://api.castle.io/v1/authenticate' }
|
233
|
-
it { expect(request_response[:policy][:action]).to
|
234
|
-
it { expect(request_response[:action]).to
|
235
|
-
it { expect(request_response[:user_id]).to
|
211
|
+
it { expect(request_response[:policy][:action]).to eql(Castle::Verdict::ALLOW) }
|
212
|
+
it { expect(request_response[:action]).to eql(Castle::Verdict::ALLOW) }
|
213
|
+
it { expect(request_response[:user_id]).to eql('1234') }
|
236
214
|
it { expect(request_response[:failover]).to be true }
|
237
|
-
it { expect(request_response[:failover_reason]).to
|
215
|
+
it { expect(request_response[:failover_reason]).to eql('Castle is set to do not track.') }
|
238
216
|
end
|
239
217
|
|
240
218
|
context 'when request with fail' do
|
241
|
-
before
|
242
|
-
allow(Castle::API).to receive(:send_request).and_raise(
|
243
|
-
Castle::RequestError.new(Timeout::Error)
|
244
|
-
)
|
245
|
-
end
|
219
|
+
before { allow(Castle::API).to receive(:send_request).and_raise(Castle::RequestError.new(Timeout::Error)) }
|
246
220
|
|
247
221
|
context 'with request error and throw strategy' do
|
248
222
|
before { allow(Castle.config).to receive(:failover_strategy).and_return(:throw) }
|
@@ -252,18 +226,16 @@ describe Castle::Client do
|
|
252
226
|
|
253
227
|
context 'with request error and not throw on eg deny strategy' do
|
254
228
|
it { assert_not_requested :post, 'https://:secret@api.castle.io/v1/authenticate' }
|
255
|
-
it { expect(request_response[:policy][:action]).to
|
256
|
-
it { expect(request_response[:action]).to
|
257
|
-
it { expect(request_response[:user_id]).to
|
229
|
+
it { expect(request_response[:policy][:action]).to eql('allow') }
|
230
|
+
it { expect(request_response[:action]).to eql('allow') }
|
231
|
+
it { expect(request_response[:user_id]).to eql('1234') }
|
258
232
|
it { expect(request_response[:failover]).to be true }
|
259
|
-
it { expect(request_response[:failover_reason]).to
|
233
|
+
it { expect(request_response[:failover_reason]).to eql('Castle::RequestError') }
|
260
234
|
end
|
261
235
|
end
|
262
236
|
|
263
237
|
context 'when request is internal server error' do
|
264
|
-
before
|
265
|
-
allow(Castle::API).to receive(:send_request).and_raise(Castle::InternalServerError)
|
266
|
-
end
|
238
|
+
before { allow(Castle::API).to receive(:send_request).and_raise(Castle::InternalServerError) }
|
267
239
|
|
268
240
|
describe 'throw strategy' do
|
269
241
|
before { allow(Castle.config).to receive(:failover_strategy).and_return(:throw) }
|
@@ -273,24 +245,18 @@ describe Castle::Client do
|
|
273
245
|
|
274
246
|
describe 'not throw on eg deny strategy' do
|
275
247
|
it { assert_not_requested :post, 'https://:secret@api.castle.io/v1/authenticate' }
|
276
|
-
it { expect(request_response[:policy][:action]).to
|
277
|
-
it { expect(request_response[:action]).to
|
278
|
-
it { expect(request_response[:user_id]).to
|
248
|
+
it { expect(request_response[:policy][:action]).to eql('allow') }
|
249
|
+
it { expect(request_response[:action]).to eql('allow') }
|
250
|
+
it { expect(request_response[:user_id]).to eql('1234') }
|
279
251
|
it { expect(request_response[:failover]).to be true }
|
280
|
-
it { expect(request_response[:failover_reason]).to
|
252
|
+
it { expect(request_response[:failover_reason]).to eql('Castle::InternalServerError') }
|
281
253
|
end
|
282
254
|
end
|
283
255
|
end
|
284
256
|
|
285
257
|
describe 'track' do
|
286
258
|
let(:request_body) do
|
287
|
-
{
|
288
|
-
event: '$login.succeeded',
|
289
|
-
context: context,
|
290
|
-
user_id: '1234',
|
291
|
-
timestamp: time_auto,
|
292
|
-
sent_at: time_auto
|
293
|
-
}
|
259
|
+
{ event: '$login.succeeded', context: context, user_id: '1234', timestamp: time_auto, sent_at: time_auto }
|
294
260
|
end
|
295
261
|
|
296
262
|
before { client.track(options) }
|
@@ -308,13 +274,7 @@ describe Castle::Client do
|
|
308
274
|
let(:client) { client_with_no_timestamp }
|
309
275
|
let(:options) { { event: '$login.succeeded', user_id: '1234', timestamp: time_user } }
|
310
276
|
let(:request_body) do
|
311
|
-
{
|
312
|
-
event: '$login.succeeded',
|
313
|
-
user_id: '1234',
|
314
|
-
context: context,
|
315
|
-
timestamp: time_user,
|
316
|
-
sent_at: time_auto
|
317
|
-
}
|
277
|
+
{ event: '$login.succeeded', user_id: '1234', context: context, timestamp: time_user, sent_at: time_auto }
|
318
278
|
end
|
319
279
|
|
320
280
|
it do
|
@@ -327,13 +287,7 @@ describe Castle::Client do
|
|
327
287
|
context 'with client initialized with timestamp' do
|
328
288
|
let(:client) { client_with_user_timestamp }
|
329
289
|
let(:request_body) do
|
330
|
-
{
|
331
|
-
event: '$login.succeeded',
|
332
|
-
context: context,
|
333
|
-
user_id: '1234',
|
334
|
-
timestamp: time_user,
|
335
|
-
sent_at: time_auto
|
336
|
-
}
|
290
|
+
{ event: '$login.succeeded', context: context, user_id: '1234', timestamp: time_user, sent_at: time_auto }
|
337
291
|
end
|
338
292
|
|
339
293
|
it do
|
@@ -380,4 +334,9 @@ describe Castle::Client do
|
|
380
334
|
describe 'log' do
|
381
335
|
it_behaves_like 'action request', :log
|
382
336
|
end
|
337
|
+
|
338
|
+
describe 'client action mixins' do
|
339
|
+
it_behaves_like 'it has list actions'
|
340
|
+
it_behaves_like 'it has list item actions'
|
341
|
+
end
|
383
342
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe Castle::Command do
|
3
|
+
RSpec.describe Castle::Command do
|
4
4
|
subject(:command) { described_class.new('go', { id: '1' }, :post) }
|
5
5
|
|
6
|
-
it { expect(command.path).to
|
7
|
-
it { expect(command.data).to
|
8
|
-
it { expect(command.method).to
|
6
|
+
it { expect(command.path).to eql('go') }
|
7
|
+
it { expect(command.data).to eql(id: '1') }
|
8
|
+
it { expect(command.method).to be(:post) }
|
9
9
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe Castle::Commands::ApproveDevice do
|
3
|
+
RSpec.describe Castle::Commands::ApproveDevice do
|
4
4
|
subject(:instance) { described_class }
|
5
5
|
|
6
6
|
let(:context) { {} }
|
@@ -16,8 +16,8 @@ describe Castle::Commands::ApproveDevice do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
context 'with device_token' do
|
19
|
-
it { expect(command.method).to
|
20
|
-
it { expect(command.path).to
|
19
|
+
it { expect(command.method).to be(:put) }
|
20
|
+
it { expect(command.path).to eql("devices/#{device_token}/approve") }
|
21
21
|
it { expect(command.data).to be_nil }
|
22
22
|
end
|
23
23
|
end
|
@@ -1,12 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe Castle::Commands::Authenticate do
|
3
|
+
RSpec.describe Castle::Commands::Authenticate do
|
4
4
|
subject(:instance) { described_class }
|
5
5
|
|
6
6
|
let(:context) { { test: { test1: '1' } } }
|
7
|
-
let(:default_payload)
|
8
|
-
{ event: '$login.authenticate', user_id: '1234', sent_at: time_auto, context: context }
|
9
|
-
end
|
7
|
+
let(:default_payload) { { event: '$login.authenticate', user_id: '1234', sent_at: time_auto, context: context } }
|
10
8
|
|
11
9
|
let(:time_now) { Time.now }
|
12
10
|
let(:time_auto) { time_now.utc.iso8601(3) }
|
@@ -22,45 +20,45 @@ describe Castle::Commands::Authenticate do
|
|
22
20
|
let(:payload) { default_payload.merge(properties: { test: '1' }) }
|
23
21
|
let(:command_data) { default_payload.merge(properties: { test: '1' }, context: context) }
|
24
22
|
|
25
|
-
it { expect(command.method).to
|
26
|
-
it { expect(command.path).to
|
27
|
-
it { expect(command.data).to
|
23
|
+
it { expect(command.method).to be(:post) }
|
24
|
+
it { expect(command.path).to eql('authenticate') }
|
25
|
+
it { expect(command.data).to eql(command_data) }
|
28
26
|
end
|
29
27
|
|
30
28
|
context 'with user_traits' do
|
31
29
|
let(:payload) { default_payload.merge(user_traits: { test: '1' }) }
|
32
30
|
let(:command_data) { default_payload.merge(user_traits: { test: '1' }, context: context) }
|
33
31
|
|
34
|
-
it { expect(command.method).to
|
35
|
-
it { expect(command.path).to
|
36
|
-
it { expect(command.data).to
|
32
|
+
it { expect(command.method).to be(:post) }
|
33
|
+
it { expect(command.path).to eql('authenticate') }
|
34
|
+
it { expect(command.data).to eql(command_data) }
|
37
35
|
end
|
38
36
|
|
39
37
|
context 'when active true' do
|
40
38
|
let(:payload) { default_payload.merge(context: context.merge(active: true)) }
|
41
39
|
let(:command_data) { default_payload.merge(context: context.merge(active: true)) }
|
42
40
|
|
43
|
-
it { expect(command.method).to
|
44
|
-
it { expect(command.path).to
|
45
|
-
it { expect(command.data).to
|
41
|
+
it { expect(command.method).to be(:post) }
|
42
|
+
it { expect(command.path).to eql('authenticate') }
|
43
|
+
it { expect(command.data).to eql(command_data) }
|
46
44
|
end
|
47
45
|
|
48
46
|
context 'when active false' do
|
49
47
|
let(:payload) { default_payload.merge(context: context.merge(active: false)) }
|
50
48
|
let(:command_data) { default_payload.merge(context: context.merge(active: false)) }
|
51
49
|
|
52
|
-
it { expect(command.method).to
|
53
|
-
it { expect(command.path).to
|
54
|
-
it { expect(command.data).to
|
50
|
+
it { expect(command.method).to be(:post) }
|
51
|
+
it { expect(command.path).to eql('authenticate') }
|
52
|
+
it { expect(command.data).to eql(command_data) }
|
55
53
|
end
|
56
54
|
|
57
55
|
context 'when active string' do
|
58
56
|
let(:payload) { default_payload.merge(context: context.merge(active: 'string')) }
|
59
57
|
let(:command_data) { default_payload.merge(context: context) }
|
60
58
|
|
61
|
-
it { expect(command.method).to
|
62
|
-
it { expect(command.path).to
|
63
|
-
it { expect(command.data).to
|
59
|
+
it { expect(command.method).to be(:post) }
|
60
|
+
it { expect(command.path).to eql('authenticate') }
|
61
|
+
it { expect(command.data).to eql(command_data) }
|
64
62
|
end
|
65
63
|
end
|
66
64
|
|
@@ -70,12 +68,7 @@ describe Castle::Commands::Authenticate do
|
|
70
68
|
context 'with event not present' do
|
71
69
|
let(:payload) { {} }
|
72
70
|
|
73
|
-
it
|
74
|
-
expect { validate! }.to raise_error(
|
75
|
-
Castle::InvalidParametersError,
|
76
|
-
'event is missing or empty'
|
77
|
-
)
|
78
|
-
end
|
71
|
+
it { expect { validate! }.to raise_error(Castle::InvalidParametersError, 'event is missing or empty') }
|
79
72
|
end
|
80
73
|
|
81
74
|
context 'with user_id not present' do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe Castle::Commands::EndImpersonation do
|
3
|
+
RSpec.describe Castle::Commands::EndImpersonation do
|
4
4
|
subject(:instance) { described_class }
|
5
5
|
|
6
6
|
let(:context) { { user_agent: 'test', ip: '127.0.0.1', client_id: 'test' } }
|
@@ -19,40 +19,38 @@ describe Castle::Commands::EndImpersonation do
|
|
19
19
|
|
20
20
|
context 'with impersonator' do
|
21
21
|
let(:payload) { default_payload.merge(properties: { impersonator: impersonator }) }
|
22
|
-
let(:command_data)
|
23
|
-
default_payload.merge(properties: { impersonator: impersonator }, context: context)
|
24
|
-
end
|
22
|
+
let(:command_data) { default_payload.merge(properties: { impersonator: impersonator }, context: context) }
|
25
23
|
|
26
|
-
it { expect(command.method).to
|
27
|
-
it { expect(command.path).to
|
28
|
-
it { expect(command.data).to
|
24
|
+
it { expect(command.method).to be(:delete) }
|
25
|
+
it { expect(command.path).to eql('impersonate') }
|
26
|
+
it { expect(command.data).to eql(command_data) }
|
29
27
|
end
|
30
28
|
|
31
29
|
context 'when active true' do
|
32
30
|
let(:payload) { default_payload.merge(context: context.merge(active: true)) }
|
33
31
|
let(:command_data) { default_payload.merge(context: context.merge(active: true)) }
|
34
32
|
|
35
|
-
it { expect(command.method).to
|
36
|
-
it { expect(command.path).to
|
37
|
-
it { expect(command.data).to
|
33
|
+
it { expect(command.method).to be(:delete) }
|
34
|
+
it { expect(command.path).to eql('impersonate') }
|
35
|
+
it { expect(command.data).to eql(command_data) }
|
38
36
|
end
|
39
37
|
|
40
38
|
context 'when active false' do
|
41
39
|
let(:payload) { default_payload.merge(context: context.merge(active: false)) }
|
42
40
|
let(:command_data) { default_payload.merge(context: context.merge(active: false)) }
|
43
41
|
|
44
|
-
it { expect(command.method).to
|
45
|
-
it { expect(command.path).to
|
46
|
-
it { expect(command.data).to
|
42
|
+
it { expect(command.method).to be(:delete) }
|
43
|
+
it { expect(command.path).to eql('impersonate') }
|
44
|
+
it { expect(command.data).to eql(command_data) }
|
47
45
|
end
|
48
46
|
|
49
47
|
context 'when active string' do
|
50
48
|
let(:payload) { default_payload.merge(context: context.merge(active: 'string')) }
|
51
49
|
let(:command_data) { default_payload.merge(context: context) }
|
52
50
|
|
53
|
-
it { expect(command.method).to
|
54
|
-
it { expect(command.path).to
|
55
|
-
it { expect(command.data).to
|
51
|
+
it { expect(command.method).to be(:delete) }
|
52
|
+
it { expect(command.path).to eql('impersonate') }
|
53
|
+
it { expect(command.data).to eql(command_data) }
|
56
54
|
end
|
57
55
|
end
|
58
56
|
|
@@ -62,12 +60,7 @@ describe Castle::Commands::EndImpersonation do
|
|
62
60
|
context 'when user_id not present' do
|
63
61
|
let(:payload) { {} }
|
64
62
|
|
65
|
-
it
|
66
|
-
expect { validate! }.to raise_error(
|
67
|
-
Castle::InvalidParametersError,
|
68
|
-
'user_id is missing or empty'
|
69
|
-
)
|
70
|
-
end
|
63
|
+
it { expect { validate! }.to raise_error(Castle::InvalidParametersError, 'user_id is missing or empty') }
|
71
64
|
end
|
72
65
|
|
73
66
|
context 'when user_id present' do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe Castle::Commands::Filter do
|
3
|
+
RSpec.describe Castle::Commands::Filter do
|
4
4
|
subject(:instance) { described_class }
|
5
5
|
|
6
6
|
let(:context) { { test: { test1: '1' } } }
|
@@ -28,45 +28,45 @@ describe Castle::Commands::Filter do
|
|
28
28
|
let(:payload) { default_payload.merge(properties: { test: '1' }) }
|
29
29
|
let(:command_data) { default_payload.merge(properties: { test: '1' }, context: context) }
|
30
30
|
|
31
|
-
it { expect(command.method).to
|
32
|
-
it { expect(command.path).to
|
33
|
-
it { expect(command.data).to
|
31
|
+
it { expect(command.method).to be(:post) }
|
32
|
+
it { expect(command.path).to eql('filter') }
|
33
|
+
it { expect(command.data).to eql(command_data) }
|
34
34
|
end
|
35
35
|
|
36
36
|
context 'with user_traits' do
|
37
37
|
let(:payload) { default_payload.merge(user_traits: { test: '1' }) }
|
38
38
|
let(:command_data) { default_payload.merge(user_traits: { test: '1' }, context: context) }
|
39
39
|
|
40
|
-
it { expect(command.method).to
|
41
|
-
it { expect(command.path).to
|
42
|
-
it { expect(command.data).to
|
40
|
+
it { expect(command.method).to be(:post) }
|
41
|
+
it { expect(command.path).to eql('filter') }
|
42
|
+
it { expect(command.data).to eql(command_data) }
|
43
43
|
end
|
44
44
|
|
45
45
|
context 'when active true' do
|
46
46
|
let(:payload) { default_payload.merge(context: context.merge(active: true)) }
|
47
47
|
let(:command_data) { default_payload.merge(context: context.merge(active: true)) }
|
48
48
|
|
49
|
-
it { expect(command.method).to
|
50
|
-
it { expect(command.path).to
|
51
|
-
it { expect(command.data).to
|
49
|
+
it { expect(command.method).to be(:post) }
|
50
|
+
it { expect(command.path).to eql('filter') }
|
51
|
+
it { expect(command.data).to eql(command_data) }
|
52
52
|
end
|
53
53
|
|
54
54
|
context 'when active false' do
|
55
55
|
let(:payload) { default_payload.merge(context: context.merge(active: false)) }
|
56
56
|
let(:command_data) { default_payload.merge(context: context.merge(active: false)) }
|
57
57
|
|
58
|
-
it { expect(command.method).to
|
59
|
-
it { expect(command.path).to
|
60
|
-
it { expect(command.data).to
|
58
|
+
it { expect(command.method).to be(:post) }
|
59
|
+
it { expect(command.path).to eql('filter') }
|
60
|
+
it { expect(command.data).to eql(command_data) }
|
61
61
|
end
|
62
62
|
|
63
63
|
context 'when active string' do
|
64
64
|
let(:payload) { default_payload.merge(context: context.merge(active: 'string')) }
|
65
65
|
let(:command_data) { default_payload.merge(context: context) }
|
66
66
|
|
67
|
-
it { expect(command.method).to
|
68
|
-
it { expect(command.path).to
|
69
|
-
it { expect(command.data).to
|
67
|
+
it { expect(command.method).to be(:post) }
|
68
|
+
it { expect(command.path).to eql('filter') }
|
69
|
+
it { expect(command.data).to eql(command_data) }
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe Castle::Commands::GetDevice do
|
3
|
+
RSpec.describe Castle::Commands::GetDevice do
|
4
4
|
subject(:instance) { described_class }
|
5
5
|
|
6
6
|
let(:context) { {} }
|
@@ -16,8 +16,8 @@ describe Castle::Commands::GetDevice do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
context 'with device_token' do
|
19
|
-
it { expect(command.method).to
|
20
|
-
it { expect(command.path).to
|
19
|
+
it { expect(command.method).to be(:get) }
|
20
|
+
it { expect(command.path).to eql("devices/#{device_token}") }
|
21
21
|
it { expect(command.data).to be_nil }
|
22
22
|
end
|
23
23
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe Castle::Commands::GetDevicesForUser do
|
3
|
+
RSpec.describe Castle::Commands::GetDevicesForUser do
|
4
4
|
subject(:instance) { described_class }
|
5
5
|
|
6
6
|
let(:context) { {} }
|
@@ -16,8 +16,8 @@ describe Castle::Commands::GetDevicesForUser do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
context 'with user_id' do
|
19
|
-
it { expect(command.method).to
|
20
|
-
it { expect(command.path).to
|
19
|
+
it { expect(command.method).to be(:get) }
|
20
|
+
it { expect(command.path).to eql("users/#{user_id}/devices") }
|
21
21
|
it { expect(command.data).to be_nil }
|
22
22
|
end
|
23
23
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::ListItems::Archive do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build(options) }
|
6
|
+
|
7
|
+
context 'with valid options' do
|
8
|
+
let(:options) { { list_id: 'list_id', list_item_id: 'list_item_id'} }
|
9
|
+
|
10
|
+
it { expect(command.method).to be(:delete) }
|
11
|
+
it { expect(command.path).to eql('lists/list_id/items/list_item_id/archive') }
|
12
|
+
it { expect(command.data).to be_nil }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with invalid options' do
|
16
|
+
let(:options) { { list_id: 'list_id' } }
|
17
|
+
|
18
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::ListItems::Count do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build(options) }
|
6
|
+
|
7
|
+
context 'with valid options' do
|
8
|
+
let(:options) { { list_id: 'list_id', filters: [{ field: 'primary_value', op: '$eq', value: 'test'}]} }
|
9
|
+
|
10
|
+
it { expect(command.method).to be(:post) }
|
11
|
+
it { expect(command.path).to eql('lists/list_id/items/count') }
|
12
|
+
it { expect(command.data).to eql(options.except(:list_id)) }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with invalid filters' do
|
16
|
+
let(:options) { { list_id: 'list_id', filters: [{ field: 'primary_field', op: '$eq' }]} }
|
17
|
+
|
18
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::ListItems::Create do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build(options) }
|
6
|
+
|
7
|
+
context 'with valid options' do
|
8
|
+
let(:author) { { type: '$other', identifier: 'some value' } }
|
9
|
+
let(:options) { { list_id: 'list_id', author: author, primary_value: 'some value' } }
|
10
|
+
|
11
|
+
it { expect(command.method).to be(:post) }
|
12
|
+
it { expect(command.path).to eql('lists/list_id/items') }
|
13
|
+
it { expect(command.data).to eql(options.except(:list_id)) }
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'with invalid options' do
|
17
|
+
let(:options) { { list_id: 'list_id' } }
|
18
|
+
|
19
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::ListItems::Get do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build(options) }
|
6
|
+
|
7
|
+
context 'with valid options' do
|
8
|
+
let(:options) { { list_id: 'list_id', list_item_id: 'list_item_id'} }
|
9
|
+
|
10
|
+
it { expect(command.method).to be(:get) }
|
11
|
+
it { expect(command.path).to eql('lists/list_id/items/list_item_id') }
|
12
|
+
it { expect(command.data).to be_nil }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with invalid options' do
|
16
|
+
let(:options) { { list_id: 'list_id' } }
|
17
|
+
|
18
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Castle::Commands::ListItems::Query do
|
4
|
+
describe '.build' do
|
5
|
+
subject(:command) { described_class.build(options) }
|
6
|
+
|
7
|
+
context 'with valid options' do
|
8
|
+
let(:options) { { list_id: 'list_id', filters: [{ field: 'primary_value', op: '$eq', value: 'test'}]} }
|
9
|
+
|
10
|
+
it { expect(command.method).to be(:post) }
|
11
|
+
it { expect(command.path).to eql('lists/list_id/items/query') }
|
12
|
+
it { expect(command.data).to eql(options.except(:list_id)) }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'with invalid filters' do
|
16
|
+
let(:options) { { list_id: 'list_id', filters: [{ field: 'primary_field', op: '$eq' }]} }
|
17
|
+
|
18
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with no list_id' do
|
22
|
+
let(:options) { { filters: [{ field: 'primary_field', op: '$eq', value: 'test' }]} }
|
23
|
+
|
24
|
+
it { expect { command }.to raise_error(Castle::InvalidParametersError) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|