et_fake_ccd 1.1.3 → 1.1.9

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: 715abb41a7a8c8b03d511144100c3c850bdf0c28ac692ff4035fe4f1e98fbd20
4
- data.tar.gz: 610bfb8032916563890b8078e433ad7db24b7d42ba623d2e01579432f9fe489d
3
+ metadata.gz: 1bf967c29880b1ad1e3994fbdc45b4b33e785ac3c0e89b87cbac456421e9acd8
4
+ data.tar.gz: 6fe8f3072516fdd21832687ce98ddc542e795914b5ffc1b5edad6c1e37dd87c8
5
5
  SHA512:
6
- metadata.gz: 5b0c423548802001cad2d385821ad76aae05a760e00152fac1fb7fc5864246401ac98bd70267c93cf9e744831ca6abf96dcb3056f99cf0e157ae3504908732fb
7
- data.tar.gz: 29bdc2795a91160e1bdd654d5b10a83074f568a10d0a63e69e8509c318fd1fe4d527607b806918b68019c6ec7a407b49a07b2eac3c66deaa1c0b60cf6af2a41e
6
+ metadata.gz: cf544a8326303e22e002b38b91291f42e1aaef310ed8e5d6040cbf910a047c66f83c5f0bc5a2be707eb28c00cd35a943a73124c36214176e4fd0ecaa15ab1ca6
7
+ data.tar.gz: 862e06a37b7ad391f2af5effd8653650db6cf80ce594a7376b29b6f58ea9ae529560325fd4b0123412eb53f7cdfc19831c54129962962dd31d124ad9252dc967
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- et_fake_ccd (1.1.3)
4
+ et_fake_ccd (1.1.9)
5
5
  activemodel (>= 5.2.3)
6
6
  iodine (~> 0.7)
7
7
  json-schema (~> 2.5)
@@ -13,9 +13,9 @@ PATH
13
13
  GEM
14
14
  remote: https://rubygems.org/
15
15
  specs:
16
- activemodel (6.1.1)
17
- activesupport (= 6.1.1)
18
- activesupport (6.1.1)
16
+ activemodel (6.1.3.2)
17
+ activesupport (= 6.1.3.2)
18
+ activesupport (6.1.3.2)
19
19
  concurrent-ruby (~> 1.0, >= 1.0.2)
20
20
  i18n (>= 1.6, < 2)
21
21
  minitest (>= 5.1)
@@ -23,18 +23,18 @@ 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.3)
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.40.0)
37
+ roda (3.44.0)
38
38
  rack
39
39
  rotp (6.2.0)
40
40
  rspec (3.9.0)
@@ -50,7 +50,7 @@ GEM
50
50
  diff-lcs (>= 1.2.0, < 2.0)
51
51
  rspec-support (~> 3.9.0)
52
52
  rspec-support (3.9.2)
53
- thor (1.0.1)
53
+ thor (1.1.0)
54
54
  tilt (2.0.10)
55
55
  tzinfo (2.0.4)
56
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
@@ -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,121 @@
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)
68
+ end
69
+ end
70
+ r.is "caseworkers", String, "jurisdictions", String, "case-types", String, "cases", String do |uid, jid, ctid, case_id|
71
+ r.get do
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
+ case_response(case_id, uid, jid, ctid)
57
78
  end
58
-
59
79
  end
80
+
60
81
  end
61
82
  r.is "caseworkers", String, "jurisdictions", String, "case-types", String, "cases" do |uid, jid, ctid|
62
83
  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)
84
+ with_forced_error_handling(r, stage: :data) 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
88
+ end
89
+ json = JSON.parse(r.body.read)
90
+ next if force_deliberate_error(json, r)
69
91
 
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)
92
+ command = case json.dig('event', 'id')
93
+ when 'initiateCase' then ::EtFakeCcd::Command::CreateCaseCommand.from_json json
94
+ when 'createMultiple' then ::EtFakeCcd::Command::CreateMultipleCaseCommand.from_json json
95
+ else
96
+ r.halt 400, unknown_event_error_for(r)
97
+ end
98
+ if command.valid?
99
+ id = ::EtFakeCcd::DataStoreService.store_case_data(command.data, jid: jid, ctid: ctid)
100
+ case_created_response(id, uid, jid, ctid)
101
+ else
102
+ r.halt 422, render_error_for(command, r)
103
+ end
81
104
  end
82
105
  end
83
106
 
84
107
  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
108
+ with_forced_error_handling(r, stage: :data) do
109
+ if !EtFakeCcd::AuthService.validate_service_token(r.headers['ServiceAuthorization'].gsub(/\ABearer /, '')) || !EtFakeCcd::AuthService.validate_user_token(r.headers['Authorization'].gsub(/\ABearer /, ''))
110
+ r.halt 403, forbidden_error_for(r)
111
+ break
112
+ end
113
+ filters = r.params.dup
114
+ page = (filters.delete('page') || "1").to_i
115
+ sort_direction = filters.delete('sortDirection') || 'asc'
116
+ list = DataStoreService.list(jid: jid, ctid: ctid, filters: filters, page: page, sort_direction: sort_direction, page_size: 25)
117
+ cases_response(list, uid, jid, ctid)
88
118
  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
119
  end
95
120
  end
96
121
  end
@@ -242,6 +267,11 @@ module EtFakeCcd
242
267
  JSON.generate(j)
243
268
  end
244
269
 
270
+ def case_response(id, uid, jid, ctid)
271
+ j = case_hash(ctid, id, jid)
272
+ JSON.generate(j)
273
+ end
274
+
245
275
  def case_hash(ctid, id, jid)
246
276
  {
247
277
  "id": id,
@@ -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.3"
2
+ VERSION = "1.1.9"
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.3
4
+ version: 1.1.9
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-18 00:00:00.000000000 Z
11
+ date: 2021-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: roda
@@ -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