cellect-server 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87c22c0c9de05b34f0da9f19778ffc5cb89faf2f
4
- data.tar.gz: 6018574d21d7b9c74a67419bfff573153bdfcf9c
3
+ metadata.gz: ad603f50ab4f1cb53a8d2f67792f1acae0484d14
4
+ data.tar.gz: 8c9c4df72fbddd0e1ae3f357f14dc6c3bac2c384
5
5
  SHA512:
6
- metadata.gz: 47f439777229098490e256db315e66e9bb20f285262f2a1bf72cbeca3ecac88c2c7055e9bf3b05a2a6aef685084e0d7c860f745301e0372d957361afb2cd01da
7
- data.tar.gz: b73b3f427c2329dd3ef7b7e2d0697cabf09fc07624f2d33f2d994f74cff8578b7ccc9ba9b9daacaa2e7e7d6e8b002a7f1b739c788a2bea2bc6e901c12564b75b
6
+ metadata.gz: 49c3dbb9447b9f12920b49c8af8350e536b7318c2225228a8b1f64b8dc5e33fe6a2515d8dc8d0a2b2c63a39b2f16af844d2e1b94d5935c9c8abd978339a94dcd
7
+ data.tar.gz: 1e772e5a66f80a5557be992a73460e46b132c6bbe2ccca8786988f56db0467bb531f288bad6d1dfdde97b501c9d3d1a980236db78f406c927e607810c7ef9555
@@ -10,6 +10,28 @@ module Cellect
10
10
  error! 'Not Found', 404
11
11
  end
12
12
 
13
+ def bad_request
14
+ error! 'Bad Request', 400
15
+ end
16
+
17
+ def validate_param(hash, key, expect: nil)
18
+ hash[key] && hash[key].is_a?(expect)
19
+ end
20
+
21
+ def valid_subject_id_update?
22
+ validate_param update_params, :subject_id, expect: Fixnum
23
+ end
24
+
25
+ def valid_group_id_update?
26
+ return true unless workflow.grouped?
27
+ validate_param update_params, :group_id, expect: Fixnum
28
+ end
29
+
30
+ def valid_priority_update?
31
+ return true unless workflow.prioritized?
32
+ validate_param update_params, :priority, expect: Numeric
33
+ end
34
+
13
35
  def selector_params
14
36
  {
15
37
  limit: param_to_int(:limit, default: 5),
@@ -23,6 +23,9 @@ module Cellect
23
23
  # priority: float, required if prioritized
24
24
  put :add do
25
25
  return four_oh_four unless workflow
26
+ return bad_request unless valid_subject_id_update?
27
+ return bad_request unless valid_group_id_update?
28
+ return bad_request unless valid_priority_update?
26
29
  workflow.add(update_params)
27
30
  nil
28
31
  end
@@ -35,6 +38,8 @@ module Cellect
35
38
  # group_id: integer, required if grouped
36
39
  put :remove do
37
40
  return four_oh_four unless workflow
41
+ return bad_request unless valid_subject_id_update?
42
+ return bad_request unless valid_group_id_update?
38
43
  workflow.remove(update_params)
39
44
  nil
40
45
  end
@@ -11,6 +11,7 @@ module Cellect
11
11
  # subject_id: integer, required
12
12
  put :add_seen do
13
13
  return four_oh_four unless workflow
14
+ return bad_request unless valid_subject_id_update?
14
15
  user_id = param_to_int :user_id
15
16
  subject_id = param_to_int :subject_id
16
17
 
@@ -1,3 +1,3 @@
1
1
  module Cellect
2
- VERSION = '1.3.2'
2
+ VERSION = '1.3.3'
3
3
  end
@@ -19,6 +19,12 @@ module Cellect::Server
19
19
  put "/workflows/#{ workflow_type }/users/123/add_seen", subject_id: 123
20
20
  expect(last_response.status).to eq 200
21
21
  end
22
+
23
+ it 'should handle invalid params' do
24
+ put "/workflows/#{ workflow_type }/users/123/add_seen", subject_id: '%(*ERRRR)'
25
+ expect(last_response.status).to eql 400
26
+ expect(last_response.body).to match /Bad Request/
27
+ end
22
28
  end
23
29
  end
24
30
  end
@@ -33,6 +33,38 @@ module Cellect::Server
33
33
  put "/workflows/#{ workflow_type }/add", opts
34
34
  expect(last_response.status).to eq 200
35
35
  end
36
+
37
+ it 'should handle invalid subject_ids' do
38
+ bad_opts = opts.merge subject_id: '%(*ERRRR)'
39
+ put "/workflows/#{ workflow_type }/add", bad_opts
40
+ expect(last_response.status).to eql 400
41
+ expect(last_response.body).to match /Bad Request/
42
+ end
43
+
44
+ it 'should handle invalid group_ids' do
45
+ if workflow.grouped?
46
+ bad_opts = opts.merge group_id: '%(*ERRRR)'
47
+ put "/workflows/#{ workflow_type }/add", bad_opts
48
+ expect(last_response.status).to eql 400
49
+ expect(last_response.body).to match /Bad Request/
50
+ else
51
+ put "/workflows/#{ workflow_type }/add", opts
52
+ expect(last_response).to be_ok
53
+ end
54
+ end
55
+
56
+ it 'should handle invalid priorities' do
57
+ bad_opts = opts.merge priority: '%(*ERRRR)'
58
+
59
+ if workflow.prioritized?
60
+ put "/workflows/#{ workflow_type }/add", bad_opts
61
+ expect(last_response.status).to eql 400
62
+ expect(last_response.body).to match /Bad Request/
63
+ else
64
+ put "/workflows/#{ workflow_type }/add", bad_opts
65
+ expect(last_response).to be_ok
66
+ end
67
+ end
36
68
  end
37
69
  end
38
70
  end
@@ -28,6 +28,25 @@ module Cellect::Server
28
28
  put "/workflows/#{ workflow_type }/remove", opts
29
29
  expect(last_response.status).to eq 200
30
30
  end
31
+
32
+ it 'should handle invalid subject_ids' do
33
+ bad_opts = opts.merge subject_id: '%(*ERRRR)'
34
+ put "/workflows/#{ workflow_type }/remove", bad_opts
35
+ expect(last_response.status).to eql 400
36
+ expect(last_response.body).to match /Bad Request/
37
+ end
38
+
39
+ it 'should handle invalid group_ids' do
40
+ if workflow.grouped?
41
+ bad_opts = opts.merge group_id: '%(*ERRRR)'
42
+ put "/workflows/#{ workflow_type }/remove", bad_opts
43
+ expect(last_response.status).to eql 400
44
+ expect(last_response.body).to match /Bad Request/
45
+ else
46
+ put "/workflows/#{ workflow_type }/remove", opts
47
+ expect(last_response).to be_ok
48
+ end
49
+ end
31
50
  end
32
51
  end
33
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cellect-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Parrish