hoodoo 1.19.0 → 2.0.0

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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hoodoo/active/active_model/uuid_validator.rb +0 -1
  3. data/lib/hoodoo/active/active_record/dated.rb +2 -2
  4. data/lib/hoodoo/active/active_record/support.rb +2 -1
  5. data/lib/hoodoo/active/active_record/uuid.rb +2 -2
  6. data/lib/hoodoo/active/active_record/writer.rb +1 -1
  7. data/lib/hoodoo/generator.rb +52 -12
  8. data/lib/hoodoo/monkey/patch/datadog_traced_amqp.rb +11 -6
  9. data/lib/hoodoo/monkey/patch/newrelic_middleware_analytics.rb +17 -10
  10. data/lib/hoodoo/monkey/patch/newrelic_traced_amqp.rb +71 -33
  11. data/lib/hoodoo/services/discovery/discoverers/by_drb/by_drb.rb +13 -8
  12. data/lib/hoodoo/services/middleware/exception_reporting/reporters/airbrake_reporter.rb +8 -3
  13. data/lib/hoodoo/services/middleware/interaction.rb +1 -1
  14. data/lib/hoodoo/services/middleware/middleware.rb +52 -41
  15. data/lib/hoodoo/version.rb +2 -2
  16. data/spec/active/active_record/creator_spec.rb +1 -1
  17. data/spec/active/active_record/dated_spec.rb +7 -7
  18. data/spec/active/active_record/finder_spec.rb +953 -839
  19. data/spec/active/active_record/manually_dated_spec.rb +1 -1
  20. data/spec/active/active_record/search_helper_spec.rb +1 -1
  21. data/spec/active/active_record/secure_spec.rb +2 -2
  22. data/spec/active/active_record/support_spec.rb +3 -3
  23. data/spec/monkey/patch/datadog_traced_amqp_spec.rb +10 -2
  24. data/spec/monkey/patch/newrelic_traced_amqp_spec.rb +54 -21
  25. data/spec/new_relic/agent/logger.rb +24 -0
  26. data/spec/new_relic/agent/transaction.rb +32 -0
  27. data/spec/services/discovery/discoverers/by_drb/by_drb_spec.rb +48 -2
  28. data/spec/services/middleware/exception_reporting/reporters/airbrake_reporter_spec.rb +4 -4
  29. data/spec/services/middleware/middleware_multi_local_spec.rb +41 -13
  30. data/spec/services/middleware/middleware_multi_remote_spec.rb +93 -67
  31. data/spec/services/middleware/middleware_spec.rb +80 -7
  32. data/spec/services/services/interface_spec.rb +2 -2
  33. data/spec/transient_store/transient_store/mocks/redis_spec.rb +8 -6
  34. metadata +30 -26
@@ -18,7 +18,7 @@ describe Hoodoo::ActiveRecord::ManuallyDated do
18
18
  t.text :data
19
19
  t.text :unique
20
20
 
21
- t.timestamps
21
+ t.timestamps :null => true
22
22
  t.datetime :effective_start, :null => false
23
23
  t.datetime :effective_end, :null => false
24
24
  end
@@ -19,7 +19,7 @@ describe Hoodoo::ActiveRecord::Finder::SearchHelper do
19
19
  spec_helper_silence_stdout() do
20
20
  ActiveRecord::Migration.create_table( :r_spec_model_search_helper_tests ) do | t |
21
21
  t.text :field
22
- t.timestamps
22
+ t.timestamps :null => true
23
23
  end
24
24
  end
25
25
 
@@ -11,7 +11,7 @@ describe Hoodoo::ActiveRecord::Secure do
11
11
  t.text :distributor
12
12
  t.text :field
13
13
 
14
- t.timestamps
14
+ t.timestamps :null => true
15
15
  end
16
16
 
17
17
  ActiveRecord::Migration.create_table( :r_spec_model_secure_test_as, &migration )
@@ -332,7 +332,7 @@ describe Hoodoo::ActiveRecord::Secure do
332
332
  migration = Proc.new do | t |
333
333
  t.text :creating_caller_uuid
334
334
  t.text :programme_code
335
- t.timestamps
335
+ t.timestamps :null => true
336
336
  end
337
337
 
338
338
  ActiveRecord::Migration.create_table( :r_spec_model_secure_render_as, &migration )
@@ -203,7 +203,7 @@ describe Hoodoo::ActiveRecord::Support do
203
203
  manual_scope = RSpecFullScopeForTestSubclass.dated( @context ).to_sql()
204
204
 
205
205
  expect( manual_scope ).to include( "FROM #{ @thtname1 }" )
206
- expect( manual_scope ).to include( "\"effective_end\" > #{ RSpecFullScopeForTestSubclass.sanitize( @test_time_value ) }" )
206
+ expect( manual_scope ).to include( "\"effective_end\" > '#{ RSpecFullScopeForTestSubclass.connection.quoted_date( @test_time_value ) }'" )
207
207
  end
208
208
 
209
209
  it 'secure' do
@@ -239,7 +239,7 @@ describe Hoodoo::ActiveRecord::Support do
239
239
  manual_scope = RSpecFullScopeForTestBaseSubclassWithoutOverrides.dated( @context ).to_sql()
240
240
 
241
241
  expect( manual_scope ).to include( "FROM #{ @thtname2 }" )
242
- expect( manual_scope ).to include( "\"effective_end\" > #{ RSpecFullScopeForTestBaseSubclassWithoutOverrides.sanitize( @test_time_value ) }" )
242
+ expect( manual_scope ).to include( "\"effective_end\" > '#{ RSpecFullScopeForTestBaseSubclassWithoutOverrides.connection.quoted_date( @test_time_value ) }'" )
243
243
  end
244
244
 
245
245
  it 'secure' do
@@ -268,7 +268,7 @@ describe Hoodoo::ActiveRecord::Support do
268
268
  manual_scope = RSpecFullScopeForManuallyDated.manually_dated( @context ).to_sql()
269
269
 
270
270
  expect( manual_scope ).to include( 'FROM "r_spec_full_scope_for_manually_dateds"' )
271
- expect( manual_scope ).to include( "\"effective_end\" > #{ RSpecFullScopeForTestSubclass.sanitize( @test_time_value.to_time.round( Hoodoo::ActiveRecord::ManuallyDated::SECONDS_DECIMAL_PLACES ) ) }" )
271
+ expect( manual_scope ).to include( "\"effective_end\" > '#{ RSpecFullScopeForTestSubclass.connection.quoted_date( @test_time_value.to_time.round( Hoodoo::ActiveRecord::ManuallyDated::SECONDS_DECIMAL_PLACES ) ) }'" )
272
272
  end
273
273
 
274
274
  it 'secure' do
@@ -51,8 +51,16 @@ describe Hoodoo::Monkey::Patch::DatadogTracedAMQP, :order => :defined do
51
51
  end
52
52
  end
53
53
 
54
- it_behaves_like 'an AMQP-based middleware/client endpoint',
55
- {'X_DDTRACE_PARENT_TRACE_ID'=>'trace_id', 'X_DDTRACE_PARENT_SPAN_ID' => 'span_id'}
54
+ it_behaves_like(
55
+ 'an AMQP-based middleware/client endpoint',
56
+ {
57
+ 'X_DATADOG_TRACE_ID' => 'trace_id',
58
+ 'X_DATADOG_PARENT_ID' => 'span_id',
59
+
60
+ 'X_DDTRACE_PARENT_TRACE_ID' => 'trace_id',
61
+ 'X_DDTRACE_PARENT_SPAN_ID' => 'span_id',
62
+ }
63
+ )
56
64
 
57
65
  context 'afterwards' do
58
66
  it 'has non-zero NewRelic method call counts' do
@@ -18,14 +18,11 @@ describe Hoodoo::Monkey::Patch::NewRelicTracedAMQP, :order => :defined do
18
18
  @@newrelic_crossapp_count = 0
19
19
  @@newrelic_agent_disable_count = 0
20
20
 
21
- module NewRelic
22
- module Agent
23
- class CrossAppTracing
24
- end
25
- end
26
- end
27
-
28
21
  Hoodoo::Monkey.enable( extension_module: Hoodoo::Monkey::Patch::NewRelicTracedAMQP )
22
+
23
+ load 'new_relic/agent/logger.rb'
24
+ load 'new_relic/agent/method_tracer.rb'
25
+ load 'new_relic/agent/transaction.rb'
29
26
  end
30
27
 
31
28
  after :all do
@@ -51,19 +48,23 @@ describe Hoodoo::Monkey::Patch::NewRelicTracedAMQP, :order => :defined do
51
48
  result
52
49
  end
53
50
 
54
- allow( NewRelic::Agent::CrossAppTracing ).to receive( :tl_trace_http_request ) do | newrelic_request, &block |
51
+ # We should always start a new Segment...
52
+ #
53
+ allow( ::NewRelic::Agent::Transaction ).to receive( :start_external_request_segment ) do | type, uri, method |
55
54
  @@newrelic_crossapp_count += 1
56
55
 
57
- expect( newrelic_request ).to be_a( Hoodoo::Monkey::Patch::NewRelicTracedAMQP::AMQPNewRelicRequestWrapper )
58
- block.call()
56
+ expect( type ).to eq( 'AlchemyFlux' )
57
+ expect( uri ).to be_a( URI )
58
+ expect( method ).to be_a( String )
59
+
60
+ ::NewRelic::Agent::Transaction::Segment.new
59
61
  end
60
62
 
61
- allow( NewRelic::Agent ).to receive( :disable_all_tracing ) do | &block |
63
+ # ...and no matter what happens must always then call "finish" on
64
+ # that segment.
65
+ #
66
+ allow_any_instance_of( ::NewRelic::Agent::Transaction::Segment ).to receive( :finish ) do
62
67
  @@newrelic_agent_disable_count += 1
63
-
64
- result = block.call()
65
- expect( result ).to be_a( Hoodoo::Monkey::Patch::NewRelicTracedAMQP::AMQPNewRelicResponseWrapper )
66
- result
67
68
  end
68
69
  end
69
70
 
@@ -78,7 +79,7 @@ describe Hoodoo::Monkey::Patch::NewRelicTracedAMQP, :order => :defined do
78
79
  end
79
80
  end
80
81
 
81
- describe Hoodoo::Monkey::Patch::NewRelicTracedAMQP::AMQPNewRelicRequestWrapper do
82
+ describe Hoodoo::Monkey::Patch::NewRelicTracedAMQP::AlchemyFluxHTTPRequestWrapper do
82
83
  before :each do
83
84
  @full_uri = 'https://test.com:8080/1/Person/1234?_embed=Birthday'
84
85
  @http_message = {
@@ -98,7 +99,7 @@ describe Hoodoo::Monkey::Patch::NewRelicTracedAMQP::AMQPNewRelicRequestWrapper d
98
99
  end
99
100
 
100
101
  it 'reports the correct "type" value' do
101
- expect( @wrapper.type ).to eq( 'Hoodoo::Monkey::Patch::NewRelicTracedAMQP::AMQPNewRelicRequestWrapper' )
102
+ expect( @wrapper.type ).to eq( 'AlchemyFlux' )
102
103
  end
103
104
 
104
105
  it 'reports the correct "host" value' do
@@ -110,7 +111,35 @@ describe Hoodoo::Monkey::Patch::NewRelicTracedAMQP::AMQPNewRelicRequestWrapper d
110
111
  end
111
112
 
112
113
  it 'reports the correct "uri" value' do
113
- expect( @wrapper.uri ).to eq( @full_uri )
114
+ expect( @wrapper.uri ).to eq( URI.parse( @full_uri ) )
115
+ end
116
+
117
+ # The next three tests are for "#host_from_header" with behaviour simply
118
+ # copied from other NewRelic examples. NewRelic source code has very few
119
+ # comments explaining anything it does, so whether or not the combination
120
+ # of upper and lower case "host"/"Host" checks is actually important
121
+ # remains a mystery.
122
+ #
123
+ it 'reports the host from a "Host/host" header, lower case first' do
124
+ @http_message[ 'headers' ][ 'host' ] = 'foo'
125
+ @http_message[ 'headers' ][ 'Host' ] = 'Bar'
126
+
127
+ alt_wrapper = described_class.new( @http_message, @full_uri )
128
+ expect( alt_wrapper.host_from_header ).to eq( 'foo' )
129
+ end
130
+
131
+ it 'reports the host from a "Host/host" header, upper case last' do
132
+ @http_message[ 'headers' ][ 'Host' ] = 'Bar'
133
+
134
+ alt_wrapper = described_class.new( @http_message, @full_uri )
135
+ expect( alt_wrapper.host_from_header ).to eq( 'Bar' )
136
+ end
137
+
138
+ it 'survives missing headers when trying to report the host from a "Host/host" header' do
139
+ @http_message.delete( 'headers' )
140
+
141
+ alt_wrapper = described_class.new( @http_message, @full_uri )
142
+ expect( alt_wrapper.host_from_header ).to eq( nil )
114
143
  end
115
144
 
116
145
  it 'can read headers' do
@@ -123,7 +152,7 @@ describe Hoodoo::Monkey::Patch::NewRelicTracedAMQP::AMQPNewRelicRequestWrapper d
123
152
  end
124
153
  end
125
154
 
126
- describe Hoodoo::Monkey::Patch::NewRelicTracedAMQP::AMQPNewRelicResponseWrapper do
155
+ describe Hoodoo::Monkey::Patch::NewRelicTracedAMQP::AlchemyFluxHTTPResponseWrapper do
127
156
 
128
157
  before :all do
129
158
  module NewRelic
@@ -137,7 +166,7 @@ describe Hoodoo::Monkey::Patch::NewRelicTracedAMQP::AMQPNewRelicResponseWrapper
137
166
 
138
167
  before :each do
139
168
  @http_response = {
140
- 'headers' => { NewRelic::Agent::CrossAppTracing::NR_APPDATA_HEADER => '4321' },
169
+ 'headers' => { ::NewRelic::Agent::CrossAppTracing::NR_APPDATA_HEADER => '4321' },
141
170
  'CONTENT_TYPE' => 'application/json; charset=utf-8',
142
171
  'HTTP_X_FOO' => '46'
143
172
  }
@@ -150,11 +179,15 @@ describe Hoodoo::Monkey::Patch::NewRelicTracedAMQP::AMQPNewRelicResponseWrapper
150
179
  end
151
180
 
152
181
  it 'accesses the NewRelic NR_APPDATA_HEADER correctly' do
153
- expect( @wrapper[ NewRelic::Agent::CrossAppTracing::NR_APPDATA_HEADER ] ).to eq( @http_response[ 'headers' ][ NewRelic::Agent::CrossAppTracing::NR_APPDATA_HEADER ] )
182
+ expect( @wrapper[ ::NewRelic::Agent::CrossAppTracing::NR_APPDATA_HEADER ] ).to eq( @http_response[ 'headers' ][ ::NewRelic::Agent::CrossAppTracing::NR_APPDATA_HEADER ] )
154
183
  end
155
184
 
156
185
  it 'accesses other headers correctly' do
157
186
  expect( @wrapper[ 'CONTENT_TYPE' ] ).to eq( @http_response[ 'CONTENT_TYPE' ] )
158
187
  expect( @wrapper[ 'HTTP_X_FOO' ] ).to eq( @http_response[ 'HTTP_X_FOO' ] )
159
188
  end
189
+
190
+ it 'can report headers as a Hash' do
191
+ expect( @wrapper.to_hash ).to eq( @http_response[ 'headers' ] )
192
+ end
160
193
  end
@@ -0,0 +1,24 @@
1
+ ########################################################################
2
+ # File:: logger.rb
3
+ # (C):: Loyalty New Zealand 2017
4
+ #
5
+ # Purpose:: Override NewRelic 'new_relic/agent/logger'. See the
6
+ # top level 'spec/newrelic_rpm.rb' file for details.
7
+ # ----------------------------------------------------------------------
8
+ # 04-Aug-2017 (ADH): Created.
9
+ ########################################################################
10
+
11
+ require 'logger'
12
+
13
+ # Note that all of this will be defined when the test suite is starting up, but
14
+ # during test runs, local redefinitions of NewRelic and *undefinitions* of that
15
+ # constant will occur. The code only exists so that other "require"s will work
16
+ # and thus provide coverage, mainly inside "newrelic_middleware_analytics.rb".
17
+ #
18
+ module NewRelic
19
+ module Agent
20
+ def self.logger
21
+ Logger.new( File::NULL )
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,32 @@
1
+ ########################################################################
2
+ # File:: transaction.rb
3
+ # (C):: Loyalty New Zealand 2017
4
+ #
5
+ # Purpose:: Override NewRelic 'new_relic/agent/transaction'. See the
6
+ # top level 'spec/newrelic_rpm.rb' file for details.
7
+ # ----------------------------------------------------------------------
8
+ # 07-Aug-2017 (ADH): Created.
9
+ ########################################################################
10
+
11
+ # Note that all of this will be defined when the test suite is starting up, but
12
+ # during test runs, local redefinitions of NewRelic and *undefinitions* of that
13
+ # constant will occur. The code only exists so that other "require"s will work
14
+ # and thus provide coverage, mainly inside "newrelic_middleware_analytics.rb".
15
+ #
16
+ module NewRelic
17
+ module Agent
18
+ class Transaction
19
+
20
+ class Segment
21
+ def add_request_headers( request ); end
22
+ def read_response_headers( request ); end
23
+ def finish(); end
24
+ end
25
+
26
+ def self.start_external_request_segment( type, uri, method )
27
+ return Segment.new
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -39,7 +39,7 @@ describe Hoodoo::Services::Discovery::ByDRb do
39
39
  port = Hoodoo::Utilities.spare_port().to_s
40
40
 
41
41
  discoverer = Hoodoo::Services::Discovery::ByDRb.new( :drb_port => port )
42
- discoverer.announce( :Foo, 1, :host => '127.0.0.1', :port => '9292' )
42
+ discoverer.announce( :Foo, 1, :host => '127.0.0.1', :port => '9292', :path => '/1/Resource' )
43
43
 
44
44
  shut_down_drb_service_on( port )
45
45
  }.to_not raise_error
@@ -53,7 +53,7 @@ describe Hoodoo::Services::Discovery::ByDRb do
53
53
  port = Hoodoo::Utilities.spare_port().to_s
54
54
 
55
55
  discoverer = Hoodoo::Services::Discovery::ByDRb.new( :drb_port => port )
56
- discoverer.announce( :Foo, 1, :host => '127.0.0.1', :port => '9292' )
56
+ discoverer.announce( :Foo, 1, :host => '127.0.0.1', :port => '9292', :path => '/1/Resource' )
57
57
 
58
58
  discoverer = Hoodoo::Services::Discovery::ByDRb.new(
59
59
  :drb_uri => Hoodoo::Services::Discovery::ByDRb::DRbServer.uri( port )
@@ -65,6 +65,52 @@ describe Hoodoo::Services::Discovery::ByDRb do
65
65
  }.to_not raise_error
66
66
  end
67
67
 
68
+ it 'allows nil host/port/path but cannot announce remotely, only locally' do
69
+ port = Hoodoo::Utilities.spare_port().to_s
70
+ array = [
71
+ { },
72
+
73
+ { :host => '127.0.0.1' },
74
+ { :port => '9292' },
75
+ { :path => '/1/Resource' },
76
+
77
+ { :host => '127.0.0.1', :port => '9292' },
78
+ { :port => '9292', :path => '/1/Resource' },
79
+ { :host => '127.0.0.1', :path => '/1/Resource' },
80
+ ]
81
+
82
+ array.each do | options |
83
+
84
+ # Announce and enquire with various incomplete options in one
85
+ # discoverer; as if this were the declaring service.
86
+ #
87
+ discoverer = Hoodoo::Services::Discovery::ByDRb.new( :drb_port => port )
88
+ discoverer.announce( :Foo, 1, options )
89
+ expect( discoverer.is_local?( :Foo, 1 ) ).to eq( true )
90
+
91
+ # This is important as it has a side effect of starting the DRb
92
+ # server which may not even be running yet since there have been
93
+ # no remote announcements. That'd cause the tests below here to
94
+ # fail since the discoverer is configured there to assume a
95
+ # running DRb process.
96
+ #
97
+ expect( discoverer.send( :discover_remote, :Foo, 1 ) ).to be_nil
98
+
99
+ # Now enquire in a new discoverer, which can only get its data
100
+ # from the DRb service, as if this were a second service.
101
+ #
102
+ discoverer = Hoodoo::Services::Discovery::ByDRb.new(
103
+ :drb_uri => Hoodoo::Services::Discovery::ByDRb::DRbServer.uri( port )
104
+ )
105
+
106
+ expect( discoverer.is_local?( :Foo, 1 ) ).to eq( false )
107
+ expect( discoverer.discover( :Foo, 1 ) ).to be_nil
108
+
109
+ end
110
+
111
+ shut_down_drb_service_on( port )
112
+ end
113
+
68
114
  it 'complains if it cannot contact an existing DRb server' do
69
115
  port = Hoodoo::Utilities.spare_port().to_s
70
116
  uri = Hoodoo::Services::Discovery::ByDRb::DRbServer.uri( port )
@@ -19,7 +19,7 @@ describe Hoodoo::Services::Middleware::ExceptionReporting::AirbrakeReporter do
19
19
  it 'calls Airbrake correctly without an "env"' do
20
20
  ex = RuntimeError.new( 'A' )
21
21
 
22
- expect( Airbrake ).to receive( :notify_or_ignore ).once do | e, opts |
22
+ expect( Airbrake ).to receive( :notify_sync ).once do | e, opts |
23
23
  expect( e ).to be_a( Exception )
24
24
  expect( opts ).to be_a( Hash )
25
25
  expect( opts ).to have_key( :backtrace )
@@ -33,7 +33,7 @@ describe Hoodoo::Services::Middleware::ExceptionReporting::AirbrakeReporter do
33
33
  ex = RuntimeError.new( 'A' )
34
34
  mock_env = { 'rack' => 'request' }
35
35
 
36
- expect( Airbrake ).to receive( :notify_or_ignore ).once do | e, opts |
36
+ expect( Airbrake ).to receive( :notify_sync ).once do | e, opts |
37
37
  expect( e ).to be_a( Exception )
38
38
 
39
39
  expect( opts ).to be_a( Hash )
@@ -59,7 +59,7 @@ describe Hoodoo::Services::Middleware::ExceptionReporting::AirbrakeReporter do
59
59
 
60
60
  expect( described_class.instance ).to receive( :user_data_for ).once.and_return( mock_user_data )
61
61
 
62
- expect( Airbrake ).to receive( :notify_or_ignore ).once do | e, opts |
62
+ expect( Airbrake ).to receive( :notify_sync ).once do | e, opts |
63
63
  expect( e ).to be_a( Exception )
64
64
 
65
65
  expect( opts ).to be_a( Hash )
@@ -84,7 +84,7 @@ describe Hoodoo::Services::Middleware::ExceptionReporting::AirbrakeReporter do
84
84
 
85
85
  expect( described_class.instance ).to receive( :user_data_for ).once.and_return( nil )
86
86
 
87
- expect( Airbrake ).to receive( :notify_or_ignore ).once do | e, opts |
87
+ expect( Airbrake ).to receive( :notify_sync ).once do | e, opts |
88
88
  expect( e ).to be_a( Exception )
89
89
 
90
90
  expect( opts ).to be_a( Hash )
@@ -6,7 +6,8 @@ require 'spec_helper'
6
6
 
7
7
  # Used for X-Assume-Identity-Of testing to avoid magic value copy-and-paste.
8
8
  #
9
- VALID_ASSUMED_IDENTITY_HASH ||= { 'caller_id' => 'custom_caller_id' }
9
+ MMLS_CUSTOM_CALLER_ID = 'custom_caller_id'
10
+ MMLS_VALID_ASSUMED_IDENTITY_HASH = { 'caller_id' => MMLS_CUSTOM_CALLER_ID }
10
11
 
11
12
  # This gets inter-resource called from ...BImplementation. It expects search
12
13
  # data containing an 'offset' key and string/integer value. If > 0, an error
@@ -40,7 +41,10 @@ class RSpecTestInterResourceCallsAImplementation < Hoodoo::Services::Implementat
40
41
  :reference => { :another => 'no other ident', :field_name => 'no ident' }
41
42
  )
42
43
  elsif context.request.ident == 'hello_return_identity' || context.request.ident == 'hello_set_good_inter_resource_identity'
43
- context.response.set_resource( { 'identity' => context.session.identity.to_h } )
44
+ context.response.body = {
45
+ 'identity' => context.session.identity.to_h,
46
+ 'fingerprint' => context.session.caller_fingerprint
47
+ }
44
48
  else
45
49
  context.response.set_resource( { 'inner' => 'shown' } )
46
50
  end
@@ -167,10 +171,10 @@ class RSpecTestInterResourceCallsBImplementation < Hoodoo::Services::Implementat
167
171
 
168
172
  if ( context.request.ident == 'set_bad_inter_resource_identity' )
169
173
  resource.assume_identity_of = {
170
- VALID_ASSUMED_IDENTITY_HASH.keys.first => Hoodoo::UUID.generate
174
+ MMLS_VALID_ASSUMED_IDENTITY_HASH.keys.first => Hoodoo::UUID.generate
171
175
  }
172
176
  elsif ( context.request.ident == 'set_good_inter_resource_identity' )
173
- resource.assume_identity_of = VALID_ASSUMED_IDENTITY_HASH
177
+ resource.assume_identity_of = MMLS_VALID_ASSUMED_IDENTITY_HASH
174
178
  end
175
179
 
176
180
  result = resource.show(
@@ -318,13 +322,18 @@ end
318
322
  describe Hoodoo::Services::Middleware::InterResourceLocal do
319
323
 
320
324
  before :each do
321
- @test_uuid = Hoodoo::UUID.generate()
322
325
  @old_test_session = Hoodoo::Services::Middleware.test_session()
326
+
323
327
  @test_session = @old_test_session.dup
328
+ @test_session.caller_fingerprint = @caller_fingerprint = Hoodoo::UUID.generate()
329
+
324
330
  permissions = Hoodoo::Services::Permissions.new # (this is "default-else-deny")
325
331
  permissions.set_default_fallback( Hoodoo::Services::Permissions::ALLOW )
326
332
  @test_session.permissions = permissions
333
+
334
+ @test_session.scoping = @test_session.scoping.dup
327
335
  @test_session.scoping.authorised_http_headers = [] # (no secured headers allowed to start with)
336
+
328
337
  Hoodoo::Services::Middleware.set_test_session( @test_session )
329
338
  end
330
339
 
@@ -395,6 +404,7 @@ describe Hoodoo::Services::Middleware::InterResourceLocal do
395
404
  expect(context.request.dated_from).to eq(nil) # Not used => expect 'nil'
396
405
  expect(context.request.deja_vu).to eq(nil) # Not used => expect 'nil'
397
406
  expect(context.request.resource_uuid).to eq(nil) # Not used => expect 'nil'
407
+ expect(context.session.caller_fingerprint).to eq(@caller_fingerprint)
398
408
  end
399
409
  # -> A
400
410
  expect_any_instance_of(RSpecTestInterResourceCallsAImplementation).to receive(:list).once.and_call_original
@@ -412,6 +422,7 @@ describe Hoodoo::Services::Middleware::InterResourceLocal do
412
422
  expect(context.request.dated_from).to eq(nil) # Not used => expect 'nil'
413
423
  expect(context.request.deja_vu).to eq(nil) # Not used => expect 'nil'
414
424
  expect(context.request.resource_uuid).to eq(nil) # Not used => expect 'nil'
425
+ expect(context.session.caller_fingerprint).to eq(@caller_fingerprint)
415
426
  end
416
427
  # <- B
417
428
  expect_any_instance_of(RSpecTestInterResourceCallsBImplementation).to receive(:expectable_result_hook).once do | ignored_rspec_mock_instance, result |
@@ -548,6 +559,7 @@ describe Hoodoo::Services::Middleware::InterResourceLocal do
548
559
  expect(context.request.dated_from).to eq(nil) # Not used => expect 'nil'
549
560
  expect(context.request.deja_vu).to eq(nil) # Not used => expect 'nil'
550
561
  expect(context.request.resource_uuid).to eq(nil) # Not used => expect 'nil'
562
+ expect(context.session.caller_fingerprint).to eq(@caller_fingerprint)
551
563
  end
552
564
  # -> A
553
565
  expect_any_instance_of(RSpecTestInterResourceCallsAImplementation).to receive(:show).once.and_call_original
@@ -565,6 +577,7 @@ describe Hoodoo::Services::Middleware::InterResourceLocal do
565
577
  expect(context.request.dated_from).to eq(nil) # Not used => expect 'nil'
566
578
  expect(context.request.deja_vu).to eq(nil) # Not used => expect 'nil'
567
579
  expect(context.request.resource_uuid).to eq(nil) # Not used => expect 'nil'
580
+ expect(context.session.caller_fingerprint).to eq(@caller_fingerprint)
568
581
  end
569
582
  # <- B
570
583
  expect_any_instance_of(RSpecTestInterResourceCallsBImplementation).to receive(:expectable_result_hook).once do | ignored_rspec_mock_instance, result |
@@ -631,6 +644,7 @@ describe Hoodoo::Services::Middleware::InterResourceLocal do
631
644
  expect(context.request.dated_from).to eq(dated_from) # Is used
632
645
  expect(context.request.deja_vu).to eq(deja_vu) # Is used
633
646
  expect(context.request.resource_uuid).to eq(resource_uuid) # Is used
647
+ expect(context.session.caller_fingerprint).to eq(@caller_fingerprint)
634
648
  end
635
649
  # -> A
636
650
  expect_any_instance_of(RSpecTestInterResourceCallsAImplementation).to receive(:create).once.and_call_original
@@ -645,6 +659,7 @@ describe Hoodoo::Services::Middleware::InterResourceLocal do
645
659
  expect(context.request.dated_from).to eq(dated_from) # Is passed through inter-resource calls
646
660
  expect(context.request.deja_vu).to eq(nil) # Is not passed through inter-resource calls
647
661
  expect(context.request.resource_uuid).to eq(nil) # Is not passed through inter-resource calls
662
+ expect(context.session.caller_fingerprint).to eq(@caller_fingerprint)
648
663
  end
649
664
  # <- B
650
665
  expect_any_instance_of(RSpecTestInterResourceCallsBImplementation).to receive(:expectable_result_hook).once do | ignored_rspec_mock_instance, result |
@@ -877,6 +892,7 @@ describe Hoodoo::Services::Middleware::InterResourceLocal do
877
892
  expect(context.request.dated_from).to eq(nil) # Not used => expect 'nil'
878
893
  expect(context.request.deja_vu).to eq(nil) # Not used => expect 'nil'
879
894
  expect(context.request.resource_uuid).to eq(nil) # Not used => expect 'nil'
895
+ expect(context.session.caller_fingerprint).to eq(@caller_fingerprint)
880
896
  end
881
897
  # -> A
882
898
  expect_any_instance_of(RSpecTestInterResourceCallsAImplementation).to receive(:update).once.and_call_original
@@ -891,6 +907,7 @@ describe Hoodoo::Services::Middleware::InterResourceLocal do
891
907
  expect(context.request.dated_from).to eq(nil) # Not used => expect 'nil'
892
908
  expect(context.request.deja_vu).to eq(nil) # Not used => expect 'nil'
893
909
  expect(context.request.resource_uuid).to eq(nil) # Not used => expect 'nil'
910
+ expect(context.session.caller_fingerprint).to eq(@caller_fingerprint)
894
911
  end
895
912
  # <- B
896
913
  expect_any_instance_of(RSpecTestInterResourceCallsBImplementation).to receive(:expectable_result_hook).once do | ignored_rspec_mock_instance, result |
@@ -955,6 +972,7 @@ describe Hoodoo::Services::Middleware::InterResourceLocal do
955
972
  expect(context.request.dated_from).to eq(nil) # Not used => expect 'nil'
956
973
  expect(context.request.deja_vu).to eq(deja_vu) # Is used
957
974
  expect(context.request.resource_uuid).to eq(nil) # Not used => expect 'nil'
975
+ expect(context.session.caller_fingerprint).to eq(@caller_fingerprint)
958
976
  end
959
977
  # -> A
960
978
  expect_any_instance_of(RSpecTestInterResourceCallsAImplementation).to receive(:delete).once.and_call_original
@@ -969,6 +987,7 @@ describe Hoodoo::Services::Middleware::InterResourceLocal do
969
987
  expect(context.request.dated_from).to eq(nil) # Not used => expect 'nil'
970
988
  expect(context.request.deja_vu).to eq(nil) # Is not passed through inter-resource calls
971
989
  expect(context.request.resource_uuid).to eq(nil) # Not used => expect 'nil'
990
+ expect(context.session.caller_fingerprint).to eq(@caller_fingerprint)
972
991
  end
973
992
  # <- B
974
993
  expect_any_instance_of(RSpecTestInterResourceCallsBImplementation).to receive(:expectable_result_hook).once do | ignored_rspec_mock_instance, result |
@@ -1064,6 +1083,7 @@ describe Hoodoo::Services::Middleware::InterResourceLocal do
1064
1083
  expect(context.request.uri_path_extension).to eq('')
1065
1084
  expect(context.request.list.offset).to eq(0)
1066
1085
  expect(context.request.list.limit).to eq(50)
1086
+ expect(context.session.caller_fingerprint).to eq(@caller_fingerprint)
1067
1087
  end
1068
1088
  # <- B
1069
1089
  expect_any_instance_of(RSpecTestInterResourceCallsBImplementation).to receive(:expectable_result_hook).once.and_call_original
@@ -1090,8 +1110,8 @@ describe Hoodoo::Services::Middleware::InterResourceLocal do
1090
1110
 
1091
1111
  test_session.scoping.authorised_http_headers = [ 'X-Assume-Identity-Of' ]
1092
1112
  test_session.scoping.authorised_identities = {
1093
- VALID_ASSUMED_IDENTITY_HASH.keys.first =>
1094
- [ VALID_ASSUMED_IDENTITY_HASH.values.first ]
1113
+ MMLS_VALID_ASSUMED_IDENTITY_HASH.keys.first =>
1114
+ [ MMLS_VALID_ASSUMED_IDENTITY_HASH.values.first ]
1095
1115
  }
1096
1116
 
1097
1117
  Hoodoo::Services::Middleware.set_test_session( test_session )
@@ -1108,12 +1128,16 @@ describe Hoodoo::Services::Middleware::InterResourceLocal do
1108
1128
  nil,
1109
1129
  {
1110
1130
  'CONTENT_TYPE' => 'application/json; charset=utf-8',
1111
- 'HTTP_X_ASSUME_IDENTITY_OF' => URI.encode_www_form( VALID_ASSUMED_IDENTITY_HASH )
1131
+ 'HTTP_X_ASSUME_IDENTITY_OF' => URI.encode_www_form( MMLS_VALID_ASSUMED_IDENTITY_HASH )
1112
1132
  }
1113
1133
  )
1114
1134
 
1115
1135
  result = JSON.parse( last_response.body )
1116
- expect( result[ 'result' ][ 'identity' ] ).to eq( VALID_ASSUMED_IDENTITY_HASH )
1136
+
1137
+ expect( result[ 'result' ] ).to eq( {
1138
+ 'identity' => MMLS_VALID_ASSUMED_IDENTITY_HASH,
1139
+ 'fingerprint' => @caller_fingerprint
1140
+ } )
1117
1141
  end
1118
1142
 
1119
1143
  it 'cannot set an illegal identity in the inter-resource call' do
@@ -1122,7 +1146,7 @@ describe Hoodoo::Services::Middleware::InterResourceLocal do
1122
1146
  nil,
1123
1147
  {
1124
1148
  'CONTENT_TYPE' => 'application/json; charset=utf-8',
1125
- 'HTTP_X_ASSUME_IDENTITY_OF' => URI.encode_www_form( VALID_ASSUMED_IDENTITY_HASH )
1149
+ 'HTTP_X_ASSUME_IDENTITY_OF' => URI.encode_www_form( MMLS_VALID_ASSUMED_IDENTITY_HASH )
1126
1150
  }
1127
1151
  )
1128
1152
 
@@ -1133,7 +1157,7 @@ describe Hoodoo::Services::Middleware::InterResourceLocal do
1133
1157
  end
1134
1158
 
1135
1159
  context 'in inter-resource call only' do
1136
- identity_hash = { 'caller_id' => 'custom_caller_id' }
1160
+ identity_hash = { 'caller_id' => MMLS_CUSTOM_CALLER_ID }
1137
1161
 
1138
1162
  it 'can still set identity for the downstream resource' do
1139
1163
  get(
@@ -1143,7 +1167,11 @@ describe Hoodoo::Services::Middleware::InterResourceLocal do
1143
1167
  )
1144
1168
 
1145
1169
  result = JSON.parse( last_response.body )
1146
- expect( result[ 'result' ][ 'identity' ] ).to eq( VALID_ASSUMED_IDENTITY_HASH )
1170
+
1171
+ expect( result[ 'result' ] ).to eq( {
1172
+ 'identity' => MMLS_VALID_ASSUMED_IDENTITY_HASH,
1173
+ 'fingerprint' => @caller_fingerprint
1174
+ } )
1147
1175
  end
1148
1176
 
1149
1177
  it 'cannot set an illegal identity for the downstream resource' do
@@ -1169,7 +1197,7 @@ describe Hoodoo::Services::Middleware::InterResourceLocal do
1169
1197
  test_session.scoping = test_session.scoping.dup
1170
1198
 
1171
1199
  test_session.scoping.authorised_http_headers = [] # NO ALLOWED HEADERS
1172
- test_session.scoping.authorised_identities = { 'caller_id' => [ 'custom_caller_id' ] }
1200
+ test_session.scoping.authorised_identities = { 'caller_id' => [ MMLS_CUSTOM_CALLER_ID ] }
1173
1201
 
1174
1202
  Hoodoo::Services::Middleware.set_test_session( test_session )
1175
1203
  end