et_fake_ccd 1.1.1 → 1.1.6

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
  SHA256:
3
- metadata.gz: c217e3105acba99e220c201ffbfb626150a7817b5033319f02aa6292e6901eb5
4
- data.tar.gz: f3a7ad0b2836fcab119dd1efe03652ab400315609908e01d19f47ced18954908
3
+ metadata.gz: 43e9e9254fb5ee9245e25079ab42e8b8dca4c35974c7dbe14582207dcc51b98d
4
+ data.tar.gz: 150d1449babea45b916cdce5e1faecaeebba183cf4c6f5f3e9c18e79a7f34b18
5
5
  SHA512:
6
- metadata.gz: f365970e29725d5c82a5d5af6bbf01c8e896b582453fe465a7ced6e2c365c0cd0909dcc3a8f7c2ea6fbaf3bb17b393ef7736228babd2306a25982d5c7a0c5005
7
- data.tar.gz: d1737766cbb6d8e9dc1468cff66bd7a95853755fea7b3492cd1f2ee96bc42b79484e119811a101e28c6b0ca015456272fca3e05e6e446b4223b5fdb203367c4a
6
+ metadata.gz: 6b474400fcfe6785c34cf458b6e762b6f7cd25e00287a1c616c2bd8fe39db24a9ed3b5016cdecb9666fc7e45404aa03146d5a1f502c352f65d3e2ae8796a0693
7
+ data.tar.gz: 066c6fd9b89e7f5c247bef0e3d936b7aad5d9d6e69f259c6967760f19900e8e6b9c72c6ce4f185166f68dc8ecc5be7c5222bcbb6ee2360e9443255fbd1351fa6
data/Gemfile.lock CHANGED
@@ -1,21 +1,21 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- et_fake_ccd (1.1.1)
4
+ et_fake_ccd (1.1.6)
5
5
  activemodel (>= 5.2.3)
6
6
  iodine (~> 0.7)
7
7
  json-schema (~> 2.5)
8
8
  roda (~> 3.21)
9
- rotp (~> 5.1)
9
+ rotp (~> 6.2)
10
10
  thor (~> 1.0)
11
11
  tilt (~> 2.0, >= 2.0.9)
12
12
 
13
13
  GEM
14
14
  remote: https://rubygems.org/
15
15
  specs:
16
- activemodel (6.1.0)
17
- activesupport (= 6.1.0)
18
- activesupport (6.1.0)
16
+ activemodel (6.1.3.1)
17
+ activesupport (= 6.1.3.1)
18
+ activesupport (6.1.3.1)
19
19
  concurrent-ruby (~> 1.0, >= 1.0.2)
20
20
  i18n (>= 1.6, < 2)
21
21
  minitest (>= 5.1)
@@ -23,21 +23,20 @@ GEM
23
23
  zeitwerk (~> 2.3)
24
24
  addressable (2.7.0)
25
25
  public_suffix (>= 2.0.2, < 5.0)
26
- concurrent-ruby (1.1.7)
26
+ concurrent-ruby (1.1.8)
27
27
  diff-lcs (1.3)
28
- i18n (1.8.7)
28
+ i18n (1.8.10)
29
29
  concurrent-ruby (~> 1.0)
30
- iodine (0.7.43)
30
+ iodine (0.7.44)
31
31
  json-schema (2.8.1)
32
32
  addressable (>= 2.4)
33
- minitest (5.14.2)
33
+ minitest (5.14.4)
34
34
  public_suffix (4.0.6)
35
35
  rack (2.2.3)
36
36
  rake (13.0.1)
37
- roda (3.39.0)
37
+ roda (3.43.1)
38
38
  rack
39
- rotp (5.1.0)
40
- addressable (~> 2.5)
39
+ rotp (6.2.0)
41
40
  rspec (3.9.0)
42
41
  rspec-core (~> 3.9.0)
43
42
  rspec-expectations (~> 3.9.0)
@@ -51,7 +50,7 @@ GEM
51
50
  diff-lcs (>= 1.2.0, < 2.0)
52
51
  rspec-support (~> 3.9.0)
53
52
  rspec-support (3.9.2)
54
- thor (1.0.1)
53
+ thor (1.1.0)
55
54
  tilt (2.0.10)
56
55
  tzinfo (2.0.4)
57
56
  concurrent-ruby (~> 1.0)
data/README.md CHANGED
@@ -97,7 +97,74 @@ So, here is a list of deliberate errors that Im sure will increase in size :-
97
97
  * Use the lead claimant title of "Mr" to only force the error on the first occurence
98
98
  * Use the lead claimant title of "Mrs" to force the error on every occurence
99
99
 
100
+ ### Improved Deliberate Error Control
100
101
 
102
+ The above deliberate error mechanism worked, it does not give quite enough control.
103
+
104
+ A new system has therefore been developed that you can use instead of it.
105
+
106
+ This uses special configuration settings in the 'External System' in the admin.
107
+
108
+ There are 2 key entries
109
+
110
+ 1. 'extra_headers'
111
+ 2. 'send_request_id'
112
+
113
+ #### extra_headers
114
+
115
+ 'extra_headers' should contain a JSON encoded value of a hash. Each entry in the hash is a header
116
+ to add to every request to this fake ccd server.
117
+
118
+ ##### force_failures header
119
+
120
+ The force_failures header should contain a hash which looks like this
121
+
122
+ ```json
123
+ {
124
+ "idam_stage": { ..spec.. },
125
+ "token_stage": { ..spec.. },
126
+ "data_stage": { ..spec.. }
127
+ }
128
+
129
+ ```
130
+
131
+ The 4 different stages give control of when the error will happen
132
+
133
+ The 'idam_stage' is the stage of the transaction when an IDAM token is requested.
134
+ However, this does not happen all of the time because IDAM tokens are cached, so
135
+ you will not necessarily see one request per transaction.
136
+
137
+ The 'token_stage' is used in most transactions such as case creation
138
+ where a 'token' is the starting stage - which then allows the case
139
+ to be created against this token.
140
+
141
+ The 'documents' stage is used in transactions that require documents uploading before the
142
+ case is created.
143
+
144
+ The 'data_stage' is used in most transactions and means the actual data
145
+ creation.
146
+
147
+ The '..spec..' is the same irrespective of which stage and is described below:
148
+
149
+ ```json
150
+ [a, b, c]
151
+ ```
152
+
153
+ a, b, c (you can specify as many as you want here, not just 3)
154
+ are http response codes for the 'nth' request. i.e. the first argument
155
+ is for the first request, the 2nd for the 2nd etc..
156
+ The special value of 0 means allow the normal response and do not force an
157
+ error - allowing for patterns such as error on the 1st, 2nd and 5th.
158
+
159
+ Any non zero value is the http status code to respond with.
160
+
161
+ #### send_request_id
162
+
163
+ 'send_request_id' should be set to 'true' to enable a request identifier to be sent with every
164
+ request to this fake ccd server. This identifier is unique to a particular export from the main system,
165
+ so it will persist even across retries of the same export.
166
+
167
+ This is then used to assist in special rules where errors are forced on the 'nth' request for example.
101
168
 
102
169
 
103
170
  ## Development
data/et_fake_ccd.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency 'roda', '~> 3.21'
27
27
  spec.add_dependency 'thor', '~> 1.0'
28
28
  spec.add_dependency 'activemodel', '>= 5.2.3'
29
- spec.add_dependency 'rotp', '~> 5.1'
29
+ spec.add_dependency 'rotp', '~> 6.2'
30
30
  spec.add_dependency 'tilt', '~> 2.0', '>= 2.0.9'
31
31
  spec.add_dependency 'iodine', '~> 0.7'
32
32
  spec.add_dependency 'json-schema', '~> 2.5'
@@ -3,7 +3,17 @@ module EtFakeCcd
3
3
  class EcmService
4
4
  OFFICE_CODE_LOOKUP = {
5
5
  'Manchester' => '24',
6
- 'Glasgow' => '41'
6
+ 'Glasgow' => '41',
7
+ 'Test1' => '60',
8
+ 'Test2' => '61',
9
+ 'Test3' => '62',
10
+ 'Test4' => '63',
11
+ 'Test5' => '64',
12
+ 'Test6' => '65',
13
+ 'Test7' => '66',
14
+ 'Test8' => '67',
15
+ 'Test9' => '68',
16
+ 'Test10' => '69'
7
17
  }
8
18
  Response = Struct.new(:case_reference_count, :start_reference, :multiple_reference)
9
19
  # @param [EtFakeCcd::Command::StartMultipleCommand] command
@@ -0,0 +1,20 @@
1
+ require 'et_fake_ccd/request_store_service'
2
+ module EtFakeCcd
3
+ module ForcedErrorHandling
4
+ extend ActiveSupport::Concern
5
+
6
+ def with_forced_error_handling(r, stage:)
7
+ request_id = r.headers['request_id']
8
+ RequestStoreService.store "#{stage}-#{request_id}" unless request_id.nil?
9
+ count = request_id.nil? ? 1 : RequestStoreService.count("#{stage}-#{request_id}")
10
+ specs = JSON.parse(r.headers['force_failures'] || '{}')
11
+ spec = specs.fetch("#{stage}_stage", [])
12
+ response_code = spec[count - 1].to_i
13
+ if response_code.zero?
14
+ yield
15
+ else
16
+ r.halt response_code
17
+ end
18
+ end
19
+ end
20
+ end
@@ -2,19 +2,23 @@ require 'roda'
2
2
  require 'json'
3
3
  require 'et_fake_ccd/commands'
4
4
  require 'et_fake_ccd/auth_service'
5
+ require 'et_fake_ccd/forced_error_handling'
5
6
  module EtFakeCcd
6
7
  module Service
7
8
  class AuthApp < Roda
9
+ include EtFakeCcd::ForcedErrorHandling
8
10
  plugin :request_headers
9
11
  plugin :halt
10
12
  route do |r|
11
13
  r.is "lease" do
12
- r.post do
13
- command = ::EtFakeCcd::Command::LeaseCommand.from_json JSON.parse(r.body.read)
14
- if command.valid?
15
- ::EtFakeCcd::AuthService.generate_service_token
16
- else
17
- r.halt 403, render_error_for(command)
14
+ with_forced_error_handling(r, stage: :token) do
15
+ r.post do
16
+ command = ::EtFakeCcd::Command::LeaseCommand.from_json JSON.parse(r.body.read)
17
+ if command.valid?
18
+ ::EtFakeCcd::AuthService.generate_service_token
19
+ else
20
+ r.halt 403, render_error_for(command)
21
+ end
18
22
  end
19
23
  end
20
24
  end
@@ -2,24 +2,30 @@ require 'roda'
2
2
  require 'json'
3
3
  require 'et_fake_ccd/commands'
4
4
  require 'et_fake_ccd/auth_service'
5
+ require 'et_fake_ccd/forced_error_handling'
5
6
  module EtFakeCcd
6
7
  module Service
7
8
  class AuthenticationWebApp < Roda
9
+ include EtFakeCcd::ForcedErrorHandling
8
10
  plugin :request_headers
9
11
  plugin :halt
10
12
  plugin :render
11
13
  route do |r|
12
14
  r.is "login" do
13
15
  r.get do
14
- file = File.absolute_path(File.join('..', 'views', 'login.html.erb'), __dir__)
15
- render(path: file, locals: { oauth2_redirect_url: config.oauth2_redirect_url, oauth2_client_id: config.oauth2_client_id })
16
+ with_forced_error_handling(r, stage: :token) do
17
+ file = File.absolute_path(File.join('..', 'views', 'login.html.erb'), __dir__)
18
+ render(path: file, locals: { oauth2_redirect_url: config.oauth2_redirect_url, oauth2_client_id: config.oauth2_client_id })
19
+ end
16
20
  end
17
21
  r.post do
18
- command = ::EtFakeCcd::Command::LoginUserCommand.from_json(r.params)
19
- if command.valid?
20
- r.redirect "/case-management-web/oauth2redirect?code=pfSHb6v4dEDEfqqP"
21
- else
22
- r.halt 401, "Access Denied"
22
+ with_forced_error_handling(r, stage: :token) do
23
+ command = ::EtFakeCcd::Command::LoginUserCommand.from_json(r.params)
24
+ if command.valid?
25
+ r.redirect "/case-management-web/oauth2redirect?code=pfSHb6v4dEDEfqqP"
26
+ else
27
+ r.halt 401, "Access Denied"
28
+ end
23
29
  end
24
30
  end
25
31
  end
@@ -1,96 +1,109 @@
1
1
  require 'roda'
2
2
  require 'json'
3
3
  require 'et_fake_ccd/commands'
4
+ require 'et_fake_ccd/forced_error_handling'
4
5
  require 'et_fake_ccd/auth_service'
5
6
  require 'et_fake_ccd/data_store_service'
6
7
  require 'et_fake_ccd/request_store_service'
7
8
  module EtFakeCcd
8
9
  module Service
9
10
  class DataStoreApp < Roda
11
+ include ForcedErrorHandling
10
12
  plugin :request_headers
11
13
  plugin :halt
12
14
  route do |r|
13
15
  r.is "caseworkers", String, "jurisdictions", String, "case-types", String, "event-triggers", "initiateCase", "token" do |uid, jid, ctid|
14
16
  r.get do
15
- if EtFakeCcd::AuthService.validate_service_token(r.headers['ServiceAuthorization'].gsub(/\ABearer /, '')) && EtFakeCcd::AuthService.validate_user_token(r.headers['Authorization'].gsub(/\ABearer /, ''))
16
- initiate_case(uid, jid, ctid)
17
- else
18
- r.halt 403, forbidden_error_for(r)
17
+ with_forced_error_handling(r, stage: :token) do
18
+ if EtFakeCcd::AuthService.validate_service_token(r.headers['ServiceAuthorization'].gsub(/\ABearer /, '')) && EtFakeCcd::AuthService.validate_user_token(r.headers['Authorization'].gsub(/\ABearer /, ''))
19
+ initiate_case(uid, jid, ctid)
20
+ else
21
+ r.halt 403, forbidden_error_for(r)
22
+ end
19
23
  end
20
24
  end
21
25
  end
22
26
  r.is "caseworkers", String, "jurisdictions", String, "case-types", String, "event-triggers", "createMultiple", "token" do |uid, jid, ctid|
23
27
  r.get do
24
- if EtFakeCcd::AuthService.validate_service_token(r.headers['ServiceAuthorization'].gsub(/\ABearer /, '')) && EtFakeCcd::AuthService.validate_user_token(r.headers['Authorization'].gsub(/\ABearer /, ''))
25
- initiate_bulk_case(uid, jid, ctid)
26
- else
27
- r.halt 403, forbidden_error_for(r)
28
+ with_forced_error_handling(r, stage: :token) do
29
+ if EtFakeCcd::AuthService.validate_service_token(r.headers['ServiceAuthorization'].gsub(/\ABearer /, '')) && EtFakeCcd::AuthService.validate_user_token(r.headers['Authorization'].gsub(/\ABearer /, ''))
30
+ initiate_bulk_case(uid, jid, ctid)
31
+ else
32
+ r.halt 403, forbidden_error_for(r)
33
+ end
28
34
  end
29
35
  end
30
36
  end
31
37
  r.is "caseworkers", String, "jurisdictions", String, "case-types", String, "cases", String, "event-triggers", "uploadDocument", "token" do |uid, jid, ctid, cid|
32
38
  r.get do
33
- if EtFakeCcd::AuthService.validate_service_token(r.headers['ServiceAuthorization'].gsub(/\ABearer /, '')) && EtFakeCcd::AuthService.validate_user_token(r.headers['Authorization'].gsub(/\ABearer /, ''))
34
- initiate_upload_document(uid, jid, ctid, cid)
35
- else
36
- r.halt 403, forbidden_error_for(r)
39
+ with_forced_error_handling(r, stage: :documents) do
40
+ if EtFakeCcd::AuthService.validate_service_token(r.headers['ServiceAuthorization'].gsub(/\ABearer /, '')) && EtFakeCcd::AuthService.validate_user_token(r.headers['Authorization'].gsub(/\ABearer /, ''))
41
+ initiate_upload_document(uid, jid, ctid, cid)
42
+ else
43
+ r.halt 403, forbidden_error_for(r)
44
+ end
37
45
  end
38
46
  end
39
47
  end
40
48
  r.is "caseworkers", String, "jurisdictions", String, "case-types", String, "cases", String, "events" do |uid, jid, ctid, cid|
41
49
  r.post do
42
- if !EtFakeCcd::AuthService.validate_service_token(r.headers['ServiceAuthorization'].gsub(/\ABearer /, '')) || !EtFakeCcd::AuthService.validate_user_token(r.headers['Authorization'].gsub(/\ABearer /, ''))
43
- r.halt 403, forbidden_error_for(r)
44
- break
50
+ with_forced_error_handling(r, stage: :documents) do
51
+ if !EtFakeCcd::AuthService.validate_service_token(r.headers['ServiceAuthorization'].gsub(/\ABearer /, '')) || !EtFakeCcd::AuthService.validate_user_token(r.headers['Authorization'].gsub(/\ABearer /, ''))
52
+ r.halt 403, forbidden_error_for(r)
53
+ break
54
+ end
55
+ json = JSON.parse(r.body.read)
56
+ command = case json.dig('event', 'id')
57
+ when 'uploadDocument' then ::EtFakeCcd::Command::UploadDocumentsToCaseCommand.from_json json
58
+ else
59
+ r.halt 400, unknown_event_error_for(r)
60
+ end
61
+ if command.valid?
62
+ ::EtFakeCcd::DataStoreService.update_case_data(json, jid: jid, ctid: ctid, cid: cid)
63
+ case_updated_response(cid, uid, jid, ctid)
64
+ else
65
+ r.halt 422, render_error_for(command, r)
66
+ end
45
67
  end
46
- json = JSON.parse(r.body.read)
47
- command = case json.dig('event', 'id')
48
- when 'uploadDocument' then ::EtFakeCcd::Command::UploadDocumentsToCaseCommand.from_json json
49
- else
50
- r.halt 400, unknown_event_error_for(r)
51
- end
52
- if command.valid?
53
- ::EtFakeCcd::DataStoreService.update_case_data(json, jid: jid, ctid: ctid, cid: cid)
54
- case_updated_response(cid, uid, jid, ctid)
55
- else
56
- r.halt 422, render_error_for(command, r)
57
- end
58
-
59
68
  end
60
69
  end
61
70
  r.is "caseworkers", String, "jurisdictions", String, "case-types", String, "cases" do |uid, jid, ctid|
62
71
  r.post do
63
- if !EtFakeCcd::AuthService.validate_service_token(r.headers['ServiceAuthorization'].gsub(/\ABearer /, '')) || !EtFakeCcd::AuthService.validate_user_token(r.headers['Authorization'].gsub(/\ABearer /, ''))
64
- r.halt 403, forbidden_error_for(r)
65
- break
66
- end
67
- json = JSON.parse(r.body.read)
68
- next if force_deliberate_error(json, r)
72
+ with_forced_error_handling(r, stage: :data) do
73
+ if !EtFakeCcd::AuthService.validate_service_token(r.headers['ServiceAuthorization'].gsub(/\ABearer /, '')) || !EtFakeCcd::AuthService.validate_user_token(r.headers['Authorization'].gsub(/\ABearer /, ''))
74
+ r.halt 403, forbidden_error_for(r)
75
+ break
76
+ end
77
+ json = JSON.parse(r.body.read)
78
+ next if force_deliberate_error(json, r)
69
79
 
70
- command = case json.dig('event', 'id')
71
- when 'initiateCase' then ::EtFakeCcd::Command::CreateCaseCommand.from_json json
72
- when 'createMultiple' then ::EtFakeCcd::Command::CreateMultipleCaseCommand.from_json json
73
- else
74
- r.halt 400, unknown_event_error_for(r)
75
- end
76
- if command.valid?
77
- id = ::EtFakeCcd::DataStoreService.store_case_data(command.data, jid: jid, ctid: ctid)
78
- case_created_response(id, uid, jid, ctid)
79
- else
80
- r.halt 422, render_error_for(command, r)
80
+ command = case json.dig('event', 'id')
81
+ when 'initiateCase' then ::EtFakeCcd::Command::CreateCaseCommand.from_json json
82
+ when 'createMultiple' then ::EtFakeCcd::Command::CreateMultipleCaseCommand.from_json json
83
+ else
84
+ r.halt 400, unknown_event_error_for(r)
85
+ end
86
+ if command.valid?
87
+ id = ::EtFakeCcd::DataStoreService.store_case_data(command.data, jid: jid, ctid: ctid)
88
+ case_created_response(id, uid, jid, ctid)
89
+ else
90
+ r.halt 422, render_error_for(command, r)
91
+ end
81
92
  end
82
93
  end
83
94
 
84
95
  r.get do
85
- if !EtFakeCcd::AuthService.validate_service_token(r.headers['ServiceAuthorization'].gsub(/\ABearer /, '')) || !EtFakeCcd::AuthService.validate_user_token(r.headers['Authorization'].gsub(/\ABearer /, ''))
86
- r.halt 403, forbidden_error_for(r)
87
- break
96
+ with_forced_error_handling(r, stage: :data) do
97
+ if !EtFakeCcd::AuthService.validate_service_token(r.headers['ServiceAuthorization'].gsub(/\ABearer /, '')) || !EtFakeCcd::AuthService.validate_user_token(r.headers['Authorization'].gsub(/\ABearer /, ''))
98
+ r.halt 403, forbidden_error_for(r)
99
+ break
100
+ end
101
+ filters = r.params.dup
102
+ page = (filters.delete('page') || "1").to_i
103
+ sort_direction = filters.delete('sortDirection') || 'asc'
104
+ list = DataStoreService.list(jid: jid, ctid: ctid, filters: filters, page: page, sort_direction: sort_direction, page_size: 25)
105
+ cases_response(list, uid, jid, ctid)
88
106
  end
89
- filters = r.params.dup
90
- page = (filters.delete('page') || "1").to_i
91
- sort_direction = filters.delete('sortDirection') || 'asc'
92
- list = DataStoreService.list(jid: jid, ctid: ctid, filters: filters, page: page, sort_direction: sort_direction, page_size: 25)
93
- cases_response(list, uid, jid, ctid)
94
107
  end
95
108
  end
96
109
  end
@@ -4,36 +4,42 @@ require 'et_fake_ccd/commands'
4
4
  require 'et_fake_ccd/auth_service'
5
5
  require 'et_fake_ccd/document_store_service'
6
6
  require 'active_support/core_ext/hash'
7
+ require 'et_fake_ccd/forced_error_handling'
7
8
  module EtFakeCcd
8
9
  module Service
9
10
  class DocumentStoreApp < Roda
11
+ include EtFakeCcd::ForcedErrorHandling
10
12
  plugin :request_headers
11
13
  plugin :halt
12
14
  plugin :sinatra_helpers
13
15
  route do |r|
14
16
  r.is "documents" do
15
17
  r.post do
16
- unless EtFakeCcd::AuthService.validate_service_token(r.headers['ServiceAuthorization'].gsub(/\ABearer /, '')) && EtFakeCcd::AuthService.validate_user_token(r.headers['Authorization'].gsub(/\ABearer /, ''))
17
- r.halt 403, forbidden_error_for(r)
18
- break
19
- end
20
- command = ::EtFakeCcd::Command::UploadDocumentCommand.from_json(r.params.deep_stringify_keys)
21
- unless command.valid?
22
- r.halt 422, render_error_for(command, r)
23
- break
24
- end
18
+ with_forced_error_handling(r, stage: :documents) do
19
+ unless EtFakeCcd::AuthService.validate_service_token(r.headers['ServiceAuthorization'].gsub(/\ABearer /, '')) && EtFakeCcd::AuthService.validate_user_token(r.headers['Authorization'].gsub(/\ABearer /, ''))
20
+ r.halt 403, forbidden_error_for(r)
21
+ break
22
+ end
23
+ command = ::EtFakeCcd::Command::UploadDocumentCommand.from_json(r.params.deep_stringify_keys)
24
+ unless command.valid?
25
+ r.halt 422, render_error_for(command, r)
26
+ break
27
+ end
25
28
 
26
- upload_document(r)
29
+ upload_document(r)
30
+ end
27
31
  end
28
32
  end
29
33
  r.is "documents", String, "binary" do |uuid|
30
- r.get do
31
- file = ::EtFakeCcd::DocumentStoreService.find_file_by_id(uuid)
32
- unless file
33
- r.halt 404, not_found_error_for(r)
34
- break
34
+ with_forced_error_handling(r, stage: :documents) do
35
+ r.get do
36
+ file = ::EtFakeCcd::DocumentStoreService.find_file_by_id(uuid)
37
+ unless file
38
+ r.halt 404, not_found_error_for(r)
39
+ break
40
+ end
41
+ send_file file.path
35
42
  end
36
- send_file file.path
37
43
  end
38
44
  end
39
45
  end
@@ -3,25 +3,29 @@ require 'json'
3
3
  require 'et_fake_ccd/commands'
4
4
  require 'et_fake_ccd/auth_service'
5
5
  require 'et_fake_ccd/ecm_service'
6
+ require 'et_fake_ccd/forced_error_handling'
6
7
  module EtFakeCcd
7
8
  module Service
8
9
  class EcmApp < Roda
10
+ include EtFakeCcd::ForcedErrorHandling
9
11
  plugin :request_headers
10
12
  plugin :halt
11
13
  route do |r|
12
14
  r.is "generateCaseRefNumbers" do
13
15
  r.post do
14
- unless EtFakeCcd::AuthService.validate_service_token(r.headers['ServiceAuthorization'].gsub(/\ABearer /, '')) && EtFakeCcd::AuthService.validate_user_token(r.headers['Authorization'].gsub(/\ABearer /, ''))
15
- r.halt 403, forbidden_error_for(r)
16
- break
17
- end
18
- json = JSON.parse(r.body.read)
19
- command = ::EtFakeCcd::Command::StartMultipleCommand.from_json json
20
- if command.valid?
21
- response = ::EtFakeCcd::EcmService.start_multiple(command)
22
- start_multiple_response(response)
23
- else
24
- r.halt 422, render_error_for(command, r)
16
+ with_forced_error_handling(r, stage: :data) do
17
+ unless EtFakeCcd::AuthService.validate_service_token(r.headers['ServiceAuthorization'].gsub(/\ABearer /, '')) && EtFakeCcd::AuthService.validate_user_token(r.headers['Authorization'].gsub(/\ABearer /, ''))
18
+ r.halt 403, forbidden_error_for(r)
19
+ break
20
+ end
21
+ json = JSON.parse(r.body.read)
22
+ command = ::EtFakeCcd::Command::StartMultipleCommand.from_json json
23
+ if command.valid?
24
+ response = ::EtFakeCcd::EcmService.start_multiple(command)
25
+ start_multiple_response(response)
26
+ else
27
+ r.halt 422, render_error_for(command, r)
28
+ end
25
29
  end
26
30
  end
27
31
  end
@@ -61,6 +65,11 @@ module EtFakeCcd
61
65
 
62
66
  JSON.generate(j)
63
67
  end
68
+
69
+ def forbidden_error_for(r)
70
+ j = {"timestamp":"2019-07-01T07:46:35.405+0000","status":403,"error":"Forbidden","message":"Access Denied","path": r.path}
71
+ JSON.generate(j)
72
+ end
64
73
  end
65
74
  end
66
75
  end
@@ -2,25 +2,31 @@ require 'roda'
2
2
  require 'json'
3
3
  require 'et_fake_ccd/commands'
4
4
  require 'et_fake_ccd/auth_service'
5
+ require 'et_fake_ccd/forced_error_handling'
5
6
  module EtFakeCcd
6
7
  module Service
7
8
  class SidamApp < Roda
9
+ include EtFakeCcd::ForcedErrorHandling
8
10
  plugin :request_headers
9
11
  plugin :halt
10
12
  route do |r|
11
13
  r.is "loginUser" do
12
14
  r.post do
13
- command = ::EtFakeCcd::Command::LoginUserCommand.from_json(r.params)
14
- if command.valid?
15
- logged_in_result
16
- else
17
- r.halt 401, render_error_for(command)
15
+ with_forced_error_handling(r, stage: :token) do
16
+ command = ::EtFakeCcd::Command::LoginUserCommand.from_json(r.params)
17
+ if command.valid?
18
+ logged_in_result
19
+ else
20
+ r.halt 401, render_error_for(command)
21
+ end
18
22
  end
19
23
  end
20
24
  end
21
25
  r.is "details" do
22
26
  r.get do
23
- details_result
27
+ with_forced_error_handling(r, stage: :token) do
28
+ details_result
29
+ end
24
30
  end
25
31
  end
26
32
  end
@@ -1,3 +1,3 @@
1
1
  module EtFakeCcd
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: et_fake_ccd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary Taylor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-05 00:00:00.000000000 Z
11
+ date: 2021-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: roda
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '5.1'
61
+ version: '6.2'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '5.1'
68
+ version: '6.2'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: tilt
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -192,6 +192,7 @@ files:
192
192
  - lib/et_fake_ccd/data_store_service.rb
193
193
  - lib/et_fake_ccd/document_store_service.rb
194
194
  - lib/et_fake_ccd/ecm_service.rb
195
+ - lib/et_fake_ccd/forced_error_handling.rb
195
196
  - lib/et_fake_ccd/iodine.rb
196
197
  - lib/et_fake_ccd/request_store_service.rb
197
198
  - lib/et_fake_ccd/root_app.rb
@@ -225,8 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
226
  - !ruby/object:Gem::Version
226
227
  version: '0'
227
228
  requirements: []
228
- rubyforge_project:
229
- rubygems_version: 2.7.6
229
+ rubygems_version: 3.1.4
230
230
  signing_key:
231
231
  specification_version: 4
232
232
  summary: Fake CCD server for employment tribunals