razorrisk-razor-connectivity 0.14.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,125 @@
1
+ #! /usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ # ##########################################################################
5
+ #
6
+ # Copyright (c) 2018 Razor Risk Technologies Pty Limited. All rights reserved.
7
+ #
8
+ # ##########################################################################
9
+
10
+
11
+ # ##########################################################
12
+ # load path
13
+
14
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 4), 'lib')
15
+
16
+
17
+ # ##########################################################
18
+ # diagnostics
19
+
20
+ unless $DEBUG
21
+
22
+ require 'pantheios/globals'
23
+ require 'pantheios/services/null_log_service'
24
+
25
+ ::Pantheios::Globals.INITIAL_SERVICE_CLASSES = [ ::Pantheios::Services::NullLogService ]
26
+ end
27
+
28
+
29
+ # ##########################################################
30
+ # code coverage
31
+
32
+ require 'simplecov'
33
+
34
+
35
+ # ##########################################################
36
+ # requires
37
+
38
+ require 'razor_risk/razor/connectivity/razor_3/message_map'
39
+
40
+ require 'nokogiri'
41
+ require 'pantheios'
42
+ require 'xqsr3/extensions/test/unit'
43
+
44
+ require 'test/unit'
45
+ require 'time'
46
+
47
+
48
+ # ##########################################################
49
+ # tests
50
+
51
+ class Test_MessageMap < Test::Unit::TestCase
52
+
53
+ include ::Pantheios
54
+
55
+ include ::RazorRisk::Razor::Connectivity::Razor3
56
+
57
+ def severity_logged? sev; false; end
58
+
59
+
60
+ def test_type_exists_and_is_a_class
61
+
62
+ assert defined? ::RazorRisk
63
+ assert defined? ::RazorRisk::Razor
64
+ assert defined? ::RazorRisk::Razor::Connectivity
65
+ assert defined? ::RazorRisk::Razor::Connectivity::Razor3
66
+ assert defined? ::RazorRisk::Razor::Connectivity::Razor3::MessageMap
67
+ assert MessageMap.is_a? ::Class
68
+ end
69
+
70
+ def test_DefaultInstance
71
+
72
+ di = MessageMap::DefaultInstance
73
+
74
+ assert_kind_of MessageMap, di
75
+
76
+ assert_equal 'CreditRiskServer', di.lookup_server('statusEnquiry')
77
+ assert_equal 'CreditRiskServer', di.lookup_server('statusenquiry')
78
+ assert_equal 'CreditRiskServer', di.lookup_server('STATUSENQUIRY')
79
+ assert_equal 'CreditRiskServer', di.lookup_server(' STATUSENQUIRY ')
80
+
81
+ assert_raise(::ArgumentError) { di.lookup_server(nil) }
82
+ assert_raise(::ArgumentError) { di.lookup_server('') }
83
+
84
+ assert_equal 'CreditRiskServer', di.lookup_server('selectTrades')
85
+
86
+ assert_equal 'PortfolioExposureServer', di.lookup_server('selectNettingAgreements')
87
+ assert_equal 'PortfolioExposureServer', di.lookup_server('selectNettingAgreements')
88
+ assert_equal 'PortfolioExposureServer', di.lookup_server('deletePortfolio')
89
+ assert_equal 'PortfolioExposureServer', di.lookup_server('insertPortfolios')
90
+ assert_equal 'PortfolioExposureServer', di.lookup_server('selectPortfolios')
91
+ assert_equal 'PortfolioExposureServer', di.lookup_server('lookupRiskPointRecord')
92
+ assert_equal 'PortfolioExposureServer', di.lookup_server('selectRiskPointTree')
93
+
94
+ assert_nil di.lookup_server('some-unknown-message')
95
+ end
96
+
97
+ def test_custom_specification
98
+
99
+ mappings = {
100
+
101
+ 'crs-msg-1' => 'CreditRiskServer',
102
+ 'crs-msg-2' => 'CreditRiskServer',
103
+
104
+ 'pes-msg-1' => 'PortfolioExposureServer',
105
+ 'pes-msg-2' => 'PortfolioExposureServer',
106
+ }
107
+
108
+ di = MessageMap.new mappings
109
+
110
+ assert_raise(::ArgumentError) { di.lookup_server(nil) }
111
+ assert_raise(::ArgumentError) { di.lookup_server('') }
112
+
113
+ assert_equal 'CreditRiskServer', di.lookup_server('crs-msg-1')
114
+ assert_equal 'CreditRiskServer', di.lookup_server('CRS-MSG-2')
115
+
116
+ assert_equal 'PortfolioExposureServer', di.lookup_server('PES-msg-1')
117
+ assert_equal 'PortfolioExposureServer', di.lookup_server('pes-MSG-2')
118
+
119
+ assert_nil di.lookup_server('selectTrades')
120
+ end
121
+ end
122
+
123
+ # ############################## end of file ############################# #
124
+
125
+
@@ -0,0 +1,244 @@
1
+ #! /usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ # ##########################################################################
5
+ #
6
+ # Copyright (c) 2017 Razor Risk Technologies Pty Limited. All rights reserved.
7
+ #
8
+ # ##########################################################################
9
+
10
+
11
+ # ##########################################################
12
+ # load path
13
+
14
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 4), 'lib')
15
+
16
+
17
+ # ##########################################################
18
+ # diagnostics
19
+
20
+ unless $DEBUG
21
+
22
+ require 'pantheios/globals'
23
+ require 'pantheios/services/null_log_service'
24
+
25
+ ::Pantheios::Globals.INITIAL_SERVICE_CLASSES = [ ::Pantheios::Services::NullLogService ]
26
+ end
27
+
28
+
29
+ # ##########################################################
30
+ # code coverage
31
+
32
+ require 'simplecov'
33
+
34
+
35
+ # ##########################################################
36
+ # requires
37
+
38
+ require 'razor_risk/razor/connectivity/razor_3/razor_requester'
39
+ require 'razor_risk/core/diagnostics/exceptions/rrcs_base_exception'
40
+
41
+ require 'nokogiri'
42
+ require 'xqsr3/extensions/test/unit'
43
+
44
+ require 'test/unit'
45
+ require 'time'
46
+
47
+
48
+ # ##########################################################
49
+ # constants
50
+
51
+ ProjectRoot = File.join(File.dirname(__FILE__), *(['..']*4))
52
+ RazorRequestStub = File.join(ProjectRoot, 'test', 'bin', 'razor_requester.rb')
53
+
54
+
55
+ # ##########################################################
56
+ # tests
57
+
58
+ class Test_RazorRequester_types_exist < Test::Unit::TestCase
59
+
60
+ def test_has_RazorRisk_module
61
+
62
+ assert Object.const_defined? :RazorRisk
63
+ end
64
+
65
+ def test_has_RazorRisk_Razor_module
66
+
67
+ assert RazorRisk.const_defined? :Razor
68
+ end
69
+
70
+ def test_has_RazorRisk_Razor_Connectivity_module
71
+
72
+ assert RazorRisk::Razor.const_defined? :Connectivity
73
+ end
74
+
75
+ def test_has_RazorRisk_Razor_Connectivity_Razor3_module
76
+
77
+ assert RazorRisk::Razor::Connectivity.const_defined? :Razor3
78
+ end
79
+
80
+ def test_has_RazorRequester_class
81
+
82
+ assert RazorRisk::Razor::Connectivity::Razor3.const_defined? :RazorRequester
83
+ end
84
+
85
+ def test_RazorRequester_is_a_class
86
+
87
+ assert_kind_of ::Class, ::RazorRisk::Razor::Connectivity::Razor3::RazorRequester
88
+ end
89
+
90
+ def test_RazorRequester_Executable_is_a_class
91
+
92
+ assert ::RazorRisk::Razor::Connectivity::Razor3::RazorRequester.const_defined? :Executable
93
+ end
94
+ end
95
+
96
+
97
+ class Test_RazorRequester_exceptions < Test::Unit::TestCase
98
+
99
+ include ::RazorRisk::Razor::Connectivity::Razor3
100
+
101
+ def test_RazorRequester_RazorRequestFailedException_type_exists
102
+
103
+ assert RazorRequester.const_defined? :RequestFailedException
104
+ end
105
+
106
+ def test_RazorRequester_RazorRequestFailedException_type_is_a_class
107
+
108
+ assert_kind_of ::Class, RazorRequester::RequestFailedException
109
+ end
110
+
111
+ def test_RazorRequester_RazorRequestFailedException_type_is_derived_from_RRCSBaseException
112
+
113
+ assert_subclass_of ::Exception, RazorRequester::RequestFailedException
114
+ assert_subclass_of ::RazorRisk::Core::Diagnostics::Exceptions::RRCSBaseException, RazorRequester::RequestFailedException
115
+ assert_subclass_of ::Exception, RazorRequester::RequestFailedException
116
+ end
117
+ end
118
+
119
+
120
+ class Test_RazorRequester_construction < Test::Unit::TestCase
121
+
122
+ include ::RazorRisk::Razor::Connectivity::Razor3
123
+
124
+ class AbortException < StandardError; end
125
+
126
+ class AborterClass
127
+
128
+ def initialize cls
129
+
130
+ @cls = cls
131
+ end
132
+
133
+ def abort message
134
+
135
+ raise @cls, message
136
+ end
137
+ end
138
+
139
+ Aborter = AborterClass.new AbortException
140
+
141
+ def test_construct_failures
142
+
143
+ assert_raise_with_message(::ArgumentError, /config not specified/i) do
144
+ RazorRequester.new nil
145
+ end
146
+ assert_raise_with_message(::ArgumentError, /either :razor_environment or :razor_alias.*specified/i) do
147
+ RazorRequester.new $0, {}
148
+ end
149
+ assert_raise_with_message(::ArgumentError, /:executable.*required/i) do
150
+ RazorRequester.new $0, {razor_environment: 'abc'}
151
+ end
152
+ end
153
+
154
+ def test_send_request_with_invalid_options
155
+
156
+ rr = RazorRequester.new $0, {executable: $0, razor_alias: 'abc'}
157
+
158
+ assert_raise_with_message(::ArgumentError, /:razor_alias.*may not be combined/i) do
159
+ rr.send_request 'abc', razor_environment: 'abc', single_sign_on: true
160
+ end
161
+ assert_raise_with_message(::ArgumentError, /:razor_alias.*may not be combined/i) do
162
+ rr.send_request 'abc', razor_space: 'abc', single_sign_on: true
163
+ end
164
+ end
165
+
166
+ def test_send_request_fails_without_credentials
167
+
168
+ rr = RazorRequester.new $0, {executable: $0, razor_environment: 'env'}
169
+
170
+ assert_raise_with_message(::ArgumentError, /some form of credentials must be provided/i) do
171
+ rr.send_request 'abc', razor_environment: 'abc'
172
+ end
173
+ end
174
+
175
+ def test_send_request_ignores_empty_strings
176
+
177
+ rr = RazorRequester.new $0, {executable: $0, razor_environment: 'env'}
178
+
179
+ assert_raise_with_message(::ArgumentError, /some form of credentials must be provided/i) do
180
+ rr.send_request 'abc', username: 'abc', password: ''
181
+ end
182
+ end
183
+ end
184
+
185
+
186
+
187
+ class Test_RazorRequester < Test::Unit::TestCase
188
+
189
+ include ::RazorRisk::Razor::Connectivity::Razor3
190
+
191
+ # FIXME: This does not ensure SQL safety.
192
+ class Test_StopgapSqlValidator < Test_RazorRequester
193
+
194
+ def test_validator_requires_string_argument
195
+
196
+ assert_raise_with_message(::TypeError, /'str'/) do
197
+ RazorRequester.stopgap_sql_string_validator_fix_me(123) {}
198
+ end
199
+ end
200
+
201
+ def test_validator_requires_a_block
202
+
203
+ assert_raise_with_message ArgumentError, /No block was given/ do
204
+ RazorRequester.stopgap_sql_string_validator_fix_me 'abc'
205
+ end
206
+ end
207
+
208
+ def test_validator_only_calls_block_for_invalid_string
209
+
210
+ RazorRequester.stopgap_sql_string_validator_fix_me 'abc' do
211
+ flunk 'Block should not execute for valid string'
212
+ end
213
+
214
+ assert_raise_with_message ArgumentError, /The block executed/ do
215
+ RazorRequester.stopgap_sql_string_validator_fix_me '!.?' do
216
+ raise ArgumentError.new 'The block executed'
217
+ end
218
+ end
219
+ end
220
+
221
+ def test_validator_as_instance_method
222
+
223
+ rr = RazorRequester.new(
224
+ $0,
225
+ executable: $0,
226
+ razor_environment: 'env',
227
+ )
228
+
229
+ rr.stopgap_sql_string_validator_fix_me 'abc' do
230
+ flunk 'Block should not execute for valid string'
231
+ end
232
+
233
+ assert_raise_with_message ArgumentError, /The block executed/ do
234
+ rr.stopgap_sql_string_validator_fix_me '!.?' do
235
+ raise ArgumentError.new 'The block executed'
236
+ end
237
+ end
238
+ end
239
+ end
240
+ end
241
+
242
+ # ############################## end of file ############################# #
243
+
244
+
@@ -0,0 +1,176 @@
1
+ #! /usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ # ##########################################################################
5
+ #
6
+ # Copyright (c) 2017 Razor Risk Technologies Pty Limited. All rights reserved.
7
+ #
8
+ # ##########################################################################
9
+
10
+
11
+ # ##########################################################
12
+ # load path
13
+
14
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 4), 'lib')
15
+
16
+
17
+ # ##########################################################
18
+ # diagnostics
19
+
20
+ unless $DEBUG
21
+
22
+ require 'pantheios/globals'
23
+ require 'pantheios/services/null_log_service'
24
+
25
+ ::Pantheios::Globals.INITIAL_SERVICE_CLASSES = [ ::Pantheios::Services::NullLogService ]
26
+ end
27
+
28
+
29
+ # ##########################################################
30
+ # code coverage
31
+
32
+ require 'simplecov'
33
+
34
+
35
+ # ##########################################################
36
+ # requires
37
+
38
+ require 'razor_risk/razor/connectivity/razor_3/razor_requester'
39
+
40
+ require 'nokogiri'
41
+ require 'xqsr3/extensions/test/unit'
42
+
43
+ require 'test/unit'
44
+ require 'time'
45
+
46
+
47
+ # ##########################################################
48
+ # tests
49
+
50
+ class Test_RazorRisk_Executable_type_exists < Test::Unit::TestCase
51
+
52
+ def test_has_RazorRisk_module
53
+
54
+ assert Object.const_defined? :RazorRisk
55
+ end
56
+
57
+ def test_has_RazorRisk_Razor_module
58
+
59
+ assert RazorRisk.const_defined? :Razor
60
+ end
61
+
62
+ def test_has_RazorRisk_Razor_Connectivity_module
63
+
64
+ assert RazorRisk::Razor.const_defined? :Connectivity
65
+ end
66
+
67
+ def test_has_RazorRisk_Razor_Connectivity_Razor3_module
68
+
69
+ assert RazorRisk::Razor::Connectivity.const_defined? :Razor3
70
+ end
71
+
72
+ def test_has_RazorRequester_class
73
+
74
+ assert RazorRisk::Razor::Connectivity::Razor3.const_defined? :RazorRequester
75
+ end
76
+
77
+ def test_RazorRequester_is_a_class
78
+
79
+ assert_kind_of ::Class, ::RazorRisk::Razor::Connectivity::Razor3::RazorRequester
80
+ end
81
+
82
+ def test_RazorRequester_Executable_is_a_class
83
+
84
+ assert ::RazorRisk::Razor::Connectivity::Razor3::RazorRequester.const_defined? :Executable
85
+ end
86
+ end
87
+
88
+ class Test_RazorRisk_Executable_functionality < Test::Unit::TestCase
89
+
90
+ include ::RazorRisk::Razor::Connectivity::Razor3
91
+
92
+ def test_construction_failures
93
+
94
+ assert_raise_with_message(::ArgumentError, /the given executable.*resolves to nothing/) { RazorRequester::Executable.new '' }
95
+ assert_raise_with_message(::ArgumentError, /the given executable.*resolves to nothing/) { RazorRequester::Executable.new '|' }
96
+ assert_raise_with_message(::ArgumentError, /the given executable.*resolves to nothing/) { RazorRequester::Executable.new ' |' }
97
+ end
98
+
99
+ def test_simple_construction
100
+
101
+ ex = RazorRequester::Executable.new $0
102
+
103
+ path0 = File.realpath($0)
104
+
105
+ assert_not_nil ex
106
+ assert_equal path0, ex.program_path.path
107
+ assert_kind_of ::Array, ex.program_arguments
108
+ assert_equal [], ex.program_arguments
109
+
110
+ assert_equal(
111
+ %Q<#{path0} /config clarite_config.xml /request "my request.xml" /env RZR_ENV-01>,
112
+ ex.form_command(
113
+ 'clarite_config.xml',
114
+ 'my request.xml',
115
+ razor_environment: 'RZR_ENV-01'
116
+ )
117
+ )
118
+ assert_equal(
119
+ %Q<#{path0} /config clarite_config.xml /request "my request.xml" /impersonate some-user /env RZR_ENV-01>,
120
+ ex.form_command(
121
+ 'clarite_config.xml',
122
+ 'my request.xml',
123
+ razor_environment: 'RZR_ENV-01',
124
+ impersonatee: 'some-user'
125
+ )
126
+ )
127
+ assert_equal(
128
+ %Q<#{path0} /config clarite_config.xml /request "my request.xml" /space RZR_ENV-02 /env RZR_ENV-01>,
129
+ ex.form_command(
130
+ 'clarite_config.xml',
131
+ 'my request.xml',
132
+ razor_environment: 'RZR_ENV-01',
133
+ razor_space: 'RZR_ENV-02',
134
+ )
135
+ )
136
+ assert_equal(
137
+ %Q<#{path0} /config clarite_config.xml /request "my request.xml" /alias RZR_ENV-01>,
138
+ ex.form_command(
139
+ 'clarite_config.xml',
140
+ 'my request.xml',
141
+ razor_alias: 'RZR_ENV-01',
142
+ )
143
+ )
144
+ assert_equal(
145
+ %Q<#{path0} /config clarite_config.xml /request "my request.xml" /usr "some user" /pwd "&* fgh" /domain "some domain" /impersonate some-user /env RZR_ENV-01 /session>,
146
+ ex.form_command(
147
+ 'clarite_config.xml',
148
+ 'my request.xml',
149
+ razor_environment: 'RZR_ENV-01',
150
+ impersonatee: 'some-user',
151
+ domain: 'some domain',
152
+ username: 'some user',
153
+ password: "&* fgh",
154
+ session: true
155
+ )
156
+ )
157
+ end
158
+
159
+ def test_constructed_from_complex_arguments
160
+
161
+ ex = RazorRequester::Executable.new "#$0|| |abc|--def=x y z||"
162
+
163
+ path0 = File.realpath($0)
164
+
165
+ assert_not_nil ex
166
+ assert_equal path0, ex.program_path.path
167
+ assert_kind_of ::Array, ex.program_arguments
168
+ assert_equal [ 'abc', '--def=x y z' ], ex.program_arguments
169
+
170
+ assert_equal %Q<#{path0} abc "--def=x y z">, ex.form_command(nil, nil)
171
+ end
172
+ end
173
+
174
+ # ############################## end of file ############################# #
175
+
176
+