razorrisk-cassini-common 0.26.24
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 +7 -0
- data/CHANGELOG.md +22 -0
- data/LICENSE +5 -0
- data/README.md +2 -0
- data/Rakefile +102 -0
- data/lib/razor_risk/cassini/applications/microservice.rb +318 -0
- data/lib/razor_risk/cassini/applications/rest_framework/route_verb_dispatcher.rb +120 -0
- data/lib/razor_risk/cassini/applications/rest_framework/verb_handler.rb +117 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/utilities/collection_get_helper.rb +86 -0
- data/lib/razor_risk/cassini/applications/securable_microservice.rb +164 -0
- data/lib/razor_risk/cassini/applications/secured_microservice.rb +63 -0
- data/lib/razor_risk/cassini/applications/unsecured_microservice.rb +77 -0
- data/lib/razor_risk/cassini/authorisation/header_helpers.rb +271 -0
- data/lib/razor_risk/cassini/authorisation/security_model_helpers.rb +93 -0
- data/lib/razor_risk/cassini/authorisation.rb +27 -0
- data/lib/razor_risk/cassini/cli.rb +19 -0
- data/lib/razor_risk/cassini/common/version.rb +44 -0
- data/lib/razor_risk/cassini/common.rb +32 -0
- data/lib/razor_risk/cassini/constants.rb +68 -0
- data/lib/razor_risk/cassini/diagnostics/util_functions.rb +248 -0
- data/lib/razor_risk/cassini/diagnostics/zeroth_include.rb +35 -0
- data/lib/razor_risk/cassini/extensions/libclimate/common_options.rb +267 -0
- data/lib/razor_risk/cassini/extensions/libclimate.rb +26 -0
- data/lib/razor_risk/cassini/header_functions.rb +59 -0
- data/lib/razor_risk/cassini/main.rb +238 -0
- data/lib/razor_risk/cassini/mixin/razor_response_validator.rb +176 -0
- data/lib/razor_risk/cassini/testing/suppress_pantheios_logging.rb +31 -0
- data/lib/razor_risk/cassini/util/conversion_util.rb +176 -0
- data/lib/razor_risk/cassini/util/program_execution_util.rb +379 -0
- data/lib/razor_risk/cassini/util/secrets_util.rb +229 -0
- data/lib/razor_risk/cassini/util/version_util.rb +88 -0
- data/lib/razor_risk/sinatra/helpers/check_auth_helper.rb +209 -0
- data/lib/razor_risk/sinatra/helpers/validate_accept_helper.rb +69 -0
- data/lib/razor_risk/sinatra/helpers/validate_content_type_helper.rb +74 -0
- data/lib/razor_risk/sinatra/helpers/validate_query_parameters_helper.rb +198 -0
- data/test/scratch/cassini/util/convert_XML.rb +54 -0
- data/test/unit/applications/route_verb_adaptors/utilities/tc_collection_get_helper.rb +236 -0
- data/test/unit/applications/tc_verb_handler.rb +130 -0
- data/test/unit/mixin/tc_razor_response_validator.rb +328 -0
- data/test/unit/sinatra/helpers/tc_validate_query_parameters_helper.rb +134 -0
- data/test/unit/tc_authorisation_util.rb +265 -0
- data/test/unit/tc_load_secrets.rb +95 -0
- data/test/unit/util/tc_conversion_util.rb +393 -0
- data/test/unit/util/tc_program_execution_util.rb +462 -0
- metadata +380 -0
@@ -0,0 +1,462 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), *(['..'] * 3), 'lib')
|
4
|
+
|
5
|
+
require 'simplecov'
|
6
|
+
|
7
|
+
require 'razor_risk/cassini/testing/suppress_pantheios_logging' unless $DEBUG
|
8
|
+
|
9
|
+
require 'razor_risk/cassini/util/program_execution_util'
|
10
|
+
|
11
|
+
require 'xqsr3/extensions/test/unit'
|
12
|
+
|
13
|
+
require 'test/unit'
|
14
|
+
|
15
|
+
require 'recls'
|
16
|
+
|
17
|
+
require 'uri'
|
18
|
+
|
19
|
+
class Test_program_execution_util < Test::Unit::TestCase
|
20
|
+
|
21
|
+
class Test_make_microservice_command < Test::Unit::TestCase
|
22
|
+
|
23
|
+
include ::RazorRisk::Cassini::Util::ProgramExecutionUtil
|
24
|
+
|
25
|
+
RUBY_COMMAND = 'ruby' + (Recls::Ximpl::OS::OS_IS_WINDOWS ? '.exe' : '')
|
26
|
+
|
27
|
+
def test_make_microservice_command
|
28
|
+
|
29
|
+
assert_equal \
|
30
|
+
[
|
31
|
+
[
|
32
|
+
RUBY_COMMAND,
|
33
|
+
'/usr/local/cassini/tools/services/razor-request/ws.rb',
|
34
|
+
'-x "razor requester.sh"',
|
35
|
+
'-e rz01',
|
36
|
+
'-a b',
|
37
|
+
'-p 4567',
|
38
|
+
'-o "clarite config.xml"',
|
39
|
+
'--program-name=razor-request',
|
40
|
+
] * ' ',
|
41
|
+
URI.parse('http://localhost:4567/')
|
42
|
+
],
|
43
|
+
make_microservice_command(
|
44
|
+
'razor-request',
|
45
|
+
:basic,
|
46
|
+
'razor requester.sh',
|
47
|
+
'/usr/local/cassini',
|
48
|
+
'clarite config.xml',
|
49
|
+
nil,
|
50
|
+
4567,
|
51
|
+
nil,
|
52
|
+
razor_environment: 'rz01',
|
53
|
+
)
|
54
|
+
|
55
|
+
assert_equal \
|
56
|
+
[
|
57
|
+
[
|
58
|
+
RUBY_COMMAND,
|
59
|
+
'-d',
|
60
|
+
'/usr/local/cassini/tools/services/razor-request/ws.rb',
|
61
|
+
'-x "razor requester.sh"',
|
62
|
+
'-e rz01',
|
63
|
+
'-a b',
|
64
|
+
'-p 4567',
|
65
|
+
'-o "clarite config.xml"',
|
66
|
+
'--program-name=razor-request',
|
67
|
+
] * ' ',
|
68
|
+
URI.parse('http://localhost:4567/')
|
69
|
+
],
|
70
|
+
make_microservice_command(
|
71
|
+
'razor-request',
|
72
|
+
:basic,
|
73
|
+
'razor requester.sh',
|
74
|
+
'/usr/local/cassini',
|
75
|
+
'clarite config.xml',
|
76
|
+
nil,
|
77
|
+
4567,
|
78
|
+
nil,
|
79
|
+
razor_environment: 'rz01',
|
80
|
+
debug: true,
|
81
|
+
)
|
82
|
+
|
83
|
+
assert_equal \
|
84
|
+
[
|
85
|
+
[
|
86
|
+
RUBY_COMMAND,
|
87
|
+
'/usr/local/cassini/tools/services/razor-request/ws.rb',
|
88
|
+
'-x "razor requester.sh"',
|
89
|
+
'-e rz01',
|
90
|
+
'-a b',
|
91
|
+
'-p 4567',
|
92
|
+
'-o "clarite config.xml"',
|
93
|
+
'--program-name=razor-request',
|
94
|
+
] * ' ',
|
95
|
+
URI.parse('https://localhost:4567/')
|
96
|
+
],
|
97
|
+
make_microservice_command(
|
98
|
+
'razor-request',
|
99
|
+
:basic,
|
100
|
+
'razor requester.sh',
|
101
|
+
'/usr/local/cassini',
|
102
|
+
'clarite config.xml',
|
103
|
+
nil,
|
104
|
+
4567,
|
105
|
+
nil,
|
106
|
+
uri_scheme: :https,
|
107
|
+
razor_environment: 'rz01',
|
108
|
+
)
|
109
|
+
|
110
|
+
assert_equal(
|
111
|
+
[
|
112
|
+
[
|
113
|
+
RUBY_COMMAND,
|
114
|
+
'/usr/local/cassini/tools/services/razor-request/ws.rb',
|
115
|
+
'-x "razor requester.sh"',
|
116
|
+
'-e rz01',
|
117
|
+
'--razor-space rz02',
|
118
|
+
'-a b',
|
119
|
+
'-p 4567',
|
120
|
+
'-o "clarite config.xml"',
|
121
|
+
'--program-name=razor-request',
|
122
|
+
] * ' ',
|
123
|
+
URI.parse('http://localhost:4567/')
|
124
|
+
],
|
125
|
+
make_microservice_command(
|
126
|
+
'razor-request',
|
127
|
+
:basic,
|
128
|
+
'razor requester.sh',
|
129
|
+
'/usr/local/cassini',
|
130
|
+
'clarite config.xml',
|
131
|
+
nil,
|
132
|
+
4567,
|
133
|
+
nil,
|
134
|
+
razor_environment: 'rz01',
|
135
|
+
razor_space: 'rz02',
|
136
|
+
)
|
137
|
+
)
|
138
|
+
|
139
|
+
assert_equal(
|
140
|
+
[
|
141
|
+
[
|
142
|
+
RUBY_COMMAND,
|
143
|
+
'/usr/local/cassini/tools/services/razor-request/ws.rb',
|
144
|
+
'-x "razor requester.sh"',
|
145
|
+
'--razor-alias rz01',
|
146
|
+
'-a b',
|
147
|
+
'-p 4567',
|
148
|
+
'-o "clarite config.xml"',
|
149
|
+
'--program-name=razor-request',
|
150
|
+
] * ' ',
|
151
|
+
URI.parse('http://localhost:4567/')
|
152
|
+
],
|
153
|
+
make_microservice_command(
|
154
|
+
'razor-request',
|
155
|
+
:basic,
|
156
|
+
'razor requester.sh',
|
157
|
+
'/usr/local/cassini',
|
158
|
+
'clarite config.xml',
|
159
|
+
nil,
|
160
|
+
4567,
|
161
|
+
nil,
|
162
|
+
razor_alias: 'rz01',
|
163
|
+
)
|
164
|
+
)
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_make_microservice_command_logging
|
168
|
+
|
169
|
+
microservice_name = 'razor-request'
|
170
|
+
security_model = :basic
|
171
|
+
razor_executable = 'razor requester.sh'
|
172
|
+
cassini_root_directory = '/usr/local/cassini'
|
173
|
+
clarite_config_path = 'clarite config.xml'
|
174
|
+
host = 'localhost'
|
175
|
+
port = 4567
|
176
|
+
url_path = 'test'
|
177
|
+
log_dir = 'dir'
|
178
|
+
|
179
|
+
args = [
|
180
|
+
microservice_name,
|
181
|
+
security_model,
|
182
|
+
razor_executable,
|
183
|
+
cassini_root_directory,
|
184
|
+
clarite_config_path,
|
185
|
+
host,
|
186
|
+
port,
|
187
|
+
url_path,
|
188
|
+
]
|
189
|
+
opts = {
|
190
|
+
log_directory: log_dir
|
191
|
+
}
|
192
|
+
cmd = [
|
193
|
+
RUBY_COMMAND,
|
194
|
+
"#{cassini_root_directory}/tools/services/#{microservice_name}/ws.rb",
|
195
|
+
"-x \"#{razor_executable}\"",
|
196
|
+
"-a #{security_model[0]}",
|
197
|
+
"-h #{host}",
|
198
|
+
"-p #{port}",
|
199
|
+
"-o \"#{clarite_config_path}\"",
|
200
|
+
"--log-directory=#{log_dir}",
|
201
|
+
"--program-name=#{microservice_name}",
|
202
|
+
] * ' '
|
203
|
+
uri = URI.parse("http://#{host}:#{port}/#{url_path}")
|
204
|
+
|
205
|
+
|
206
|
+
act_cmd, act_uri = make_microservice_command(
|
207
|
+
*args,
|
208
|
+
**opts,
|
209
|
+
)
|
210
|
+
assert_equal cmd, act_cmd
|
211
|
+
assert_equal uri, act_uri
|
212
|
+
end
|
213
|
+
|
214
|
+
def test_make_microservice_command_web_server
|
215
|
+
|
216
|
+
microservice_name = 'razor-request'
|
217
|
+
security_model = :basic
|
218
|
+
razor_executable = 'razor requester.sh'
|
219
|
+
cassini_root_directory = '/usr/local/cassini'
|
220
|
+
clarite_config_path = 'clarite config.xml'
|
221
|
+
host = 'localhost'
|
222
|
+
port = 4567
|
223
|
+
url_path = 'test'
|
224
|
+
web_server = 'webrick'
|
225
|
+
|
226
|
+
args = [
|
227
|
+
microservice_name,
|
228
|
+
security_model,
|
229
|
+
razor_executable,
|
230
|
+
cassini_root_directory,
|
231
|
+
clarite_config_path,
|
232
|
+
host,
|
233
|
+
port,
|
234
|
+
url_path,
|
235
|
+
]
|
236
|
+
opts = {
|
237
|
+
web_server: web_server
|
238
|
+
}
|
239
|
+
cmd = [
|
240
|
+
RUBY_COMMAND,
|
241
|
+
"#{cassini_root_directory}/tools/services/#{microservice_name}/ws.rb",
|
242
|
+
"-x \"#{razor_executable}\"",
|
243
|
+
"-a #{security_model[0]}",
|
244
|
+
"-h #{host}",
|
245
|
+
"-p #{port}",
|
246
|
+
"-o \"#{clarite_config_path}\"",
|
247
|
+
"-w #{web_server}",
|
248
|
+
"--program-name=#{microservice_name}",
|
249
|
+
] * ' '
|
250
|
+
uri = URI.parse("http://#{host}:#{port}/#{url_path}")
|
251
|
+
|
252
|
+
|
253
|
+
act_cmd, act_uri = make_microservice_command(
|
254
|
+
*args,
|
255
|
+
**opts,
|
256
|
+
)
|
257
|
+
assert_equal cmd, act_cmd
|
258
|
+
assert_equal uri, act_uri
|
259
|
+
end
|
260
|
+
|
261
|
+
def test_make_microservice_command_auth_test_mode
|
262
|
+
|
263
|
+
microservice_name = 'razor-request'
|
264
|
+
security_model = :basic
|
265
|
+
razor_executable = 'razor requester.sh'
|
266
|
+
cassini_root_directory = '/usr/local/cassini'
|
267
|
+
clarite_config_path = 'clarite config.xml'
|
268
|
+
host = 'localhost'
|
269
|
+
port = 4567
|
270
|
+
url_path = 'test'
|
271
|
+
auth_test_mode = true
|
272
|
+
|
273
|
+
args = [
|
274
|
+
microservice_name,
|
275
|
+
security_model,
|
276
|
+
razor_executable,
|
277
|
+
cassini_root_directory,
|
278
|
+
clarite_config_path,
|
279
|
+
host,
|
280
|
+
port,
|
281
|
+
url_path,
|
282
|
+
]
|
283
|
+
opts = {
|
284
|
+
auth_test_mode: auth_test_mode
|
285
|
+
}
|
286
|
+
cmd = [
|
287
|
+
RUBY_COMMAND,
|
288
|
+
"#{cassini_root_directory}/tools/services/#{microservice_name}/ws.rb",
|
289
|
+
"-x \"#{razor_executable}\"",
|
290
|
+
"-a #{security_model[0]}",
|
291
|
+
"-h #{host}",
|
292
|
+
"-p #{port}",
|
293
|
+
"-o \"#{clarite_config_path}\"",
|
294
|
+
'--authorization-test-mode',
|
295
|
+
"--program-name=#{microservice_name}",
|
296
|
+
] * ' '
|
297
|
+
uri = URI.parse("http://#{host}:#{port}/#{url_path}")
|
298
|
+
|
299
|
+
|
300
|
+
act_cmd, act_uri = make_microservice_command(
|
301
|
+
*args,
|
302
|
+
**opts,
|
303
|
+
)
|
304
|
+
assert_equal cmd, act_cmd
|
305
|
+
assert_equal uri, act_uri
|
306
|
+
end
|
307
|
+
|
308
|
+
end
|
309
|
+
|
310
|
+
class Test_make_secretserver_command < Test::Unit::TestCase
|
311
|
+
|
312
|
+
include ::RazorRisk::Cassini::Util::ProgramExecutionUtil
|
313
|
+
|
314
|
+
RUBY_COMMAND = 'ruby' + (Recls::Ximpl::OS::OS_IS_WINDOWS ? '.exe' : '')
|
315
|
+
|
316
|
+
def test_make_secretserver
|
317
|
+
|
318
|
+
cassini_root_directory = '/usr/local/cassini'
|
319
|
+
host = 'localhost'
|
320
|
+
port = 4567
|
321
|
+
secrets_path = '/secret'
|
322
|
+
|
323
|
+
args = [
|
324
|
+
cassini_root_directory,
|
325
|
+
secrets_path,
|
326
|
+
host,
|
327
|
+
port,
|
328
|
+
]
|
329
|
+
opts = {
|
330
|
+
}
|
331
|
+
cmd = [
|
332
|
+
RUBY_COMMAND,
|
333
|
+
"#{cassini_root_directory}/tools/utilities/secret-server/ws.rb",
|
334
|
+
"-h #{host}",
|
335
|
+
"-p #{port}",
|
336
|
+
"#{secrets_path}",
|
337
|
+
"--program-name=secret-server",
|
338
|
+
] * ' '
|
339
|
+
uri = URI.parse("http://#{host}:#{port}")
|
340
|
+
|
341
|
+
|
342
|
+
act_cmd, act_uri = make_secretserver_command(
|
343
|
+
*args,
|
344
|
+
**opts,
|
345
|
+
)
|
346
|
+
assert_equal cmd, act_cmd
|
347
|
+
assert_equal uri, act_uri
|
348
|
+
end
|
349
|
+
|
350
|
+
def test_make_secretserver_program_name
|
351
|
+
|
352
|
+
cassini_root_directory = '/usr/local/cassini'
|
353
|
+
host = 'localhost'
|
354
|
+
port = 4567
|
355
|
+
secrets_path = '/secret'
|
356
|
+
program_name = 'secret-name'
|
357
|
+
|
358
|
+
args = [
|
359
|
+
cassini_root_directory,
|
360
|
+
secrets_path,
|
361
|
+
host,
|
362
|
+
port,
|
363
|
+
]
|
364
|
+
opts = {
|
365
|
+
program_name: program_name,
|
366
|
+
}
|
367
|
+
cmd = [
|
368
|
+
RUBY_COMMAND,
|
369
|
+
"#{cassini_root_directory}/tools/utilities/secret-server/ws.rb",
|
370
|
+
"-h #{host}",
|
371
|
+
"-p #{port}",
|
372
|
+
"#{secrets_path}",
|
373
|
+
"--program-name=#{program_name}",
|
374
|
+
] * ' '
|
375
|
+
uri = URI.parse("http://#{host}:#{port}")
|
376
|
+
|
377
|
+
|
378
|
+
act_cmd, act_uri = make_secretserver_command(
|
379
|
+
*args,
|
380
|
+
**opts,
|
381
|
+
)
|
382
|
+
assert_equal cmd, act_cmd
|
383
|
+
assert_equal uri, act_uri
|
384
|
+
end
|
385
|
+
|
386
|
+
def test_make_secretserver_command_logging
|
387
|
+
|
388
|
+
cassini_root_directory = '/usr/local/cassini'
|
389
|
+
host = 'localhost'
|
390
|
+
port = 4567
|
391
|
+
log_dir = 'dir'
|
392
|
+
|
393
|
+
secrets_path = '/secret'
|
394
|
+
|
395
|
+
args = [
|
396
|
+
cassini_root_directory,
|
397
|
+
secrets_path,
|
398
|
+
host,
|
399
|
+
port,
|
400
|
+
]
|
401
|
+
opts = {
|
402
|
+
log_directory: log_dir,
|
403
|
+
}
|
404
|
+
cmd = [
|
405
|
+
RUBY_COMMAND,
|
406
|
+
"#{cassini_root_directory}/tools/utilities/secret-server/ws.rb",
|
407
|
+
"-h #{host}",
|
408
|
+
"-p #{port}",
|
409
|
+
"#{secrets_path}",
|
410
|
+
"--log-directory=#{log_dir}",
|
411
|
+
"--program-name=secret-server",
|
412
|
+
] * ' '
|
413
|
+
uri = URI.parse("http://#{host}:#{port}")
|
414
|
+
|
415
|
+
|
416
|
+
act_cmd, act_uri = make_secretserver_command(
|
417
|
+
*args,
|
418
|
+
**opts,
|
419
|
+
)
|
420
|
+
assert_equal cmd, act_cmd
|
421
|
+
assert_equal uri, act_uri
|
422
|
+
end
|
423
|
+
|
424
|
+
def test_make_secretserver_command_web_server
|
425
|
+
|
426
|
+
cassini_root_directory = '/usr/local/cassini'
|
427
|
+
host = 'localhost'
|
428
|
+
port = 4567
|
429
|
+
secrets_path = '/secret'
|
430
|
+
web_server = 'webrick'
|
431
|
+
|
432
|
+
args = [
|
433
|
+
cassini_root_directory,
|
434
|
+
secrets_path,
|
435
|
+
host,
|
436
|
+
port,
|
437
|
+
]
|
438
|
+
opts = {
|
439
|
+
web_server: web_server,
|
440
|
+
}
|
441
|
+
cmd = [
|
442
|
+
RUBY_COMMAND,
|
443
|
+
"#{cassini_root_directory}/tools/utilities/secret-server/ws.rb",
|
444
|
+
"-h #{host}",
|
445
|
+
"-p #{port}",
|
446
|
+
"-w #{web_server}",
|
447
|
+
"#{secrets_path}",
|
448
|
+
"--program-name=secret-server",
|
449
|
+
] * ' '
|
450
|
+
uri = URI.parse("http://#{host}:#{port}")
|
451
|
+
|
452
|
+
|
453
|
+
act_cmd, act_uri = make_secretserver_command(
|
454
|
+
*args,
|
455
|
+
**opts,
|
456
|
+
)
|
457
|
+
assert_equal cmd, act_cmd
|
458
|
+
assert_equal uri, act_uri
|
459
|
+
end
|
460
|
+
end
|
461
|
+
end
|
462
|
+
|