hoodoo 1.5.1 → 1.5.2
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 +8 -8
- data/lib/hoodoo/active/active_record/error_mapping.rb +2 -2
- data/lib/hoodoo/active/active_record/manually_dated.rb +3 -0
- data/lib/hoodoo/active/active_record/writer.rb +1 -1
- data/lib/hoodoo/client/endpoint/endpoint.rb +1 -1
- data/lib/hoodoo/client/endpoint/endpoints/auto_session.rb +19 -13
- data/lib/hoodoo/client/endpoint/endpoints/http_based.rb +1 -1
- data/lib/hoodoo/services/middleware/interaction.rb +1 -1
- data/lib/hoodoo/services/middleware/middleware.rb +2 -2
- data/lib/hoodoo/services/services/session.rb +1 -1
- data/lib/hoodoo/utilities/utilities.rb +1 -1
- data/lib/hoodoo/version.rb +1 -1
- data/spec/client/client_spec.rb +60 -7
- data/spec/services/middleware/middleware_exotic_communication_spec.rb +1 -1
- data/spec/services/middleware/middleware_multi_remote_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODRjNTI3Y2YyMGU1NThkYTVlNmI0YzZjMzJiNzE3MDg3NGU1Zjg4OQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTljMjA0NWU4ZTY0NjU4OGNiNTg5NDBiNzU5OWU4ZTA2MmYwNzJjNQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YWI1MDQwNzgzMjVmMTExM2JmM2QwYTI2YmI1OWU1ZjM2ZmE3ZWVkZWViMmE0
|
10
|
+
MzBiN2MxYThiYzNlYjcyY2ZlNmY0YmEzNzg4NjIwMDQyYWQ5ZmUwOWMzZWJj
|
11
|
+
YjkxMGNjNDA2MjdmM2FhODg0OWZkNzUwOGJkNmIyNTQ5YjQ0N2U=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzUzY2M0M2U4OWMyNWY1ZGQzYjU5YjAwM2EwZjY2OTU4ZDA0NTc1OThmZDI2
|
14
|
+
ODVhMTFjZDkwYTEwOTZhYzk1Zjk5MzAyMzRlY2FjOTlmZmI0NGIxZDAwN2E5
|
15
|
+
MmIwNDMwYTNiZDY5NTc5YjgzNzA1OTk4ZTQ2ZmZmMzNlZDJmMjA=
|
@@ -92,7 +92,7 @@ module Hoodoo
|
|
92
92
|
# model = SomeModel.new
|
93
93
|
# model.param_1 = 'something based on inbound creation data'
|
94
94
|
#
|
95
|
-
# unless model.persist_in( context )
|
95
|
+
# unless model.persist_in( context ).equal?( :success )
|
96
96
|
# context.response.add_errors( model.platform_errors )
|
97
97
|
# return
|
98
98
|
# end
|
@@ -323,7 +323,7 @@ module Hoodoo
|
|
323
323
|
reached_field = field
|
324
324
|
end
|
325
325
|
|
326
|
-
if reached_field
|
326
|
+
if reached_field == fields.last
|
327
327
|
attribute_name = leaf_field
|
328
328
|
target_instance = leaf_instance
|
329
329
|
end
|
@@ -611,6 +611,9 @@ module Hoodoo
|
|
611
611
|
# +assign_attributes+ method) in order to perform the
|
612
612
|
# update. If omitted, +context.request.body+ is used.
|
613
613
|
#
|
614
|
+
# If both +ident+ _and_ +attributes+ are supplied then the first
|
615
|
+
# parameter providing +context+ may be +nil+.
|
616
|
+
#
|
614
617
|
# +scope+:: ActiveRecord::Relation instance providing the scope
|
615
618
|
# to use for database locks and acquiring the record
|
616
619
|
# to update. Defaults to #acquisition_scope for the
|
@@ -94,7 +94,7 @@ module Hoodoo
|
|
94
94
|
#
|
95
95
|
# # ...maybe make other changes to model_instance, then...
|
96
96
|
#
|
97
|
-
# unless model_instance.persist_in( context )
|
97
|
+
# unless model_instance.persist_in( context ).equal?( :success )
|
98
98
|
#
|
99
99
|
# # Error condition. If you're using the error handler mixin
|
100
100
|
# # in Hoodoo::ActiveRecord::ErrorMapping, do this:
|
@@ -264,7 +264,7 @@ module Hoodoo
|
|
264
264
|
# Hoodoo::Services::Middleware::ALLOWED_ACTIONS.
|
265
265
|
#
|
266
266
|
def response_class_for( action )
|
267
|
-
return action
|
267
|
+
return action.equal?( :list ) ? Hoodoo::Client::AugmentedArray : Hoodoo::Client::AugmentedHash
|
268
268
|
end
|
269
269
|
|
270
270
|
# Utility method to aid subclass authors. Not usually overridden.
|
@@ -128,26 +128,31 @@ module Hoodoo
|
|
128
128
|
|
129
129
|
if @session_endpoint.session_id.nil?
|
130
130
|
session_creation_result = acquire_session_for( action )
|
131
|
-
return session_creation_result unless session_creation_result.
|
131
|
+
return session_creation_result unless session_creation_result.equal?( :success )
|
132
132
|
else
|
133
133
|
@wrapped_endpoint.session_id = @session_endpoint.session_id
|
134
134
|
end
|
135
135
|
|
136
|
-
result
|
136
|
+
result = @wrapped_endpoint.send( action, *args )
|
137
|
+
bad_session = result.platform_errors.has_errors? &&
|
138
|
+
result.platform_errors.errors.find do | error_hash |
|
139
|
+
error_hash[ 'code' ] == 'platform.invalid_session'
|
140
|
+
end
|
137
141
|
|
138
|
-
if
|
139
|
-
result.platform_errors.errors.size == 1 &&
|
140
|
-
result.platform_errors.errors[ 0 ][ 'code' ] == 'platform.invalid_session'
|
141
|
-
|
142
|
-
session_creation_result = acquire_session_for( action )
|
143
|
-
return session_creation_result unless session_creation_result.nil?
|
144
|
-
return @wrapped_endpoint.send( action, *args )
|
145
|
-
else
|
142
|
+
if bad_session == false
|
146
143
|
return result
|
144
|
+
else
|
145
|
+
session_creation_result = acquire_session_for( action )
|
146
|
+
|
147
|
+
if session_creation_result.equal?( :success )
|
148
|
+
return @wrapped_endpoint.send( action, *args )
|
149
|
+
else
|
150
|
+
return session_creation_result
|
151
|
+
end
|
147
152
|
end
|
148
153
|
end
|
149
154
|
|
150
|
-
# Acquire a
|
155
|
+
# Acquire a session using the configured session endpoint. If this
|
151
156
|
# fails, the failure result is returned. If it seems to succeed but
|
152
157
|
# a session ID cannot be found, an internal 'generic.malformed'
|
153
158
|
# result is generated and returned.
|
@@ -156,11 +161,12 @@ module Hoodoo
|
|
156
161
|
# action at hand - an augmented array for lists, else an augmented
|
157
162
|
# hash. It can be returned directly up to the calling layer.
|
158
163
|
#
|
159
|
-
# Returns +
|
164
|
+
# Returns +:success+ if all goes well; #session_id will be updated.
|
160
165
|
#
|
161
166
|
# +action+:: As given to #auto_retry.
|
162
167
|
#
|
163
168
|
def acquire_session_for( action )
|
169
|
+
|
164
170
|
session_creation_result = @session_endpoint.create(
|
165
171
|
'caller_id' => @caller_id,
|
166
172
|
'authentication_secret' => @caller_secret
|
@@ -184,7 +190,7 @@ module Hoodoo
|
|
184
190
|
return data
|
185
191
|
else
|
186
192
|
@wrapped_endpoint.session_id = @session_endpoint.session_id
|
187
|
-
return
|
193
|
+
return :success
|
188
194
|
end
|
189
195
|
end
|
190
196
|
|
@@ -292,7 +292,7 @@ module Hoodoo
|
|
292
292
|
when 200
|
293
293
|
data.platform_errors.add_error(
|
294
294
|
'platform.fault',
|
295
|
-
:message => 'Could not parse body data
|
295
|
+
:message => 'Could not parse retrieved body data despite receiving HTTP status code 200',
|
296
296
|
:reference => { :exception => RuntimeError.new( "#{ body }" ) }
|
297
297
|
)
|
298
298
|
when 204
|
@@ -72,7 +72,7 @@ module Hoodoo; module Services; class Middleware
|
|
72
72
|
# Returns +true+ if Hoodoo has previously called #using_test_session.
|
73
73
|
#
|
74
74
|
def using_test_session?
|
75
|
-
@using_test_session
|
75
|
+
@using_test_session == true
|
76
76
|
end
|
77
77
|
|
78
78
|
# Create a new Interaction instance, acquiring a new interaction
|
@@ -169,7 +169,7 @@ module Hoodoo; module Services
|
|
169
169
|
} ).to_h,
|
170
170
|
'scoping' => {
|
171
171
|
'authorised_http_headers' => Hoodoo::Client::Headers::HEADER_TO_PROPERTY.map() { | key, sub_hash |
|
172
|
-
sub_hash[ :header ] if sub_hash[ :secured ]
|
172
|
+
sub_hash[ :header ] if sub_hash[ :secured ] == true
|
173
173
|
}.compact
|
174
174
|
}
|
175
175
|
} )
|
@@ -2318,7 +2318,7 @@ module Hoodoo; module Services
|
|
2318
2318
|
extension = match_data[ 2 ]
|
2319
2319
|
|
2320
2320
|
elsif ( match_data[ 1 ] == '/' )
|
2321
|
-
remaining_path_components = match_data[ 2 ].split( '/' ).reject { | str | str
|
2321
|
+
remaining_path_components = match_data[ 2 ].split( '/' ).reject { | str | str == '' }
|
2322
2322
|
last_item = remaining_path_components.last
|
2323
2323
|
|
2324
2324
|
unless ( last_item.nil? )
|
@@ -179,7 +179,7 @@ module Hoodoo
|
|
179
179
|
self.caller_version,
|
180
180
|
mclient )
|
181
181
|
|
182
|
-
return result unless result
|
182
|
+
return result unless result.equal?( :ok )
|
183
183
|
|
184
184
|
# Must set this before saving, even though the delay between
|
185
185
|
# setting this value and Memcached actually saving the value
|
@@ -125,7 +125,7 @@ module Hoodoo
|
|
125
125
|
# http://stackoverflow.com/questions/9381553/ruby-merge-nested-hash
|
126
126
|
#
|
127
127
|
merger = proc { | key, v1, v2 |
|
128
|
-
Hash
|
128
|
+
v1.is_a?( Hash ) && v2.is_a?( Hash ) ? v1.merge( v2, &merger ) : v2.nil? ? v1 : v2
|
129
129
|
}
|
130
130
|
|
131
131
|
return target_hash.merge( inbound_hash, &merger )
|
data/lib/hoodoo/version.rb
CHANGED
data/spec/client/client_spec.rb
CHANGED
@@ -239,9 +239,9 @@ describe Hoodoo::Client do
|
|
239
239
|
# (or not) and a dated-at date/time (or not) given to the Endpoint.
|
240
240
|
#
|
241
241
|
def set_vars_for( opts )
|
242
|
-
@locale
|
243
|
-
@expected_locale
|
244
|
-
@client
|
242
|
+
@locale = rand( 2 ) == 0 ? nil : SecureRandom.urlsafe_base64(2)
|
243
|
+
@expected_locale = @locale.nil? ? 'en-nz' : @locale.downcase
|
244
|
+
@client = Hoodoo::Client.new( opts.merge( :locale => @locale ) )
|
245
245
|
|
246
246
|
endpoint_opts = {}
|
247
247
|
|
@@ -833,6 +833,10 @@ describe Hoodoo::Client do
|
|
833
833
|
##############################################################################
|
834
834
|
|
835
835
|
context 'with auto-session' do
|
836
|
+
before :each do
|
837
|
+
Hoodoo::Services::Middleware.set_test_session( nil )
|
838
|
+
end
|
839
|
+
|
836
840
|
shared_examples Hoodoo::Client do
|
837
841
|
it '(public actions allowed)' do
|
838
842
|
mock_ident = Hoodoo::UUID.generate()
|
@@ -910,6 +914,42 @@ describe Hoodoo::Client do
|
|
910
914
|
expect( result.platform_errors.has_errors? ).to eq( false )
|
911
915
|
end
|
912
916
|
|
917
|
+
it 'automatically retries with more than just "platform.invalid_session" present' do
|
918
|
+
|
919
|
+
# When we list first, Client has no session so will acquire one. The
|
920
|
+
# wrapping endpoint is asked to list, it pushes that through the
|
921
|
+
# session mechanism, gets the session and then calls the wrapped
|
922
|
+
# endpoint.
|
923
|
+
|
924
|
+
expect( @endpoint ).to receive( :acquire_session_for ).once.with( :list ).and_call_original
|
925
|
+
expect( @endpoint.instance_variable_get( '@wrapped_endpoint' ) ).to receive( :list ).once.and_call_original
|
926
|
+
|
927
|
+
result = @endpoint.list()
|
928
|
+
expect( result.platform_errors.has_errors? ).to eq( false )
|
929
|
+
|
930
|
+
# When we list the second time, the wrapping endpoint has a session
|
931
|
+
# but we fake a complex 'invalid session' response from the wrapped
|
932
|
+
# endpoint, as if the session had (say) expired at the server end,
|
933
|
+
# but other errors were being reported too.
|
934
|
+
|
935
|
+
expect( @endpoint.instance_variable_get( '@wrapped_endpoint' ) ).to receive( :list ).once do
|
936
|
+
array = Hoodoo::Client::AugmentedArray.new
|
937
|
+
array.platform_errors.add_error( 'platform.forbidden' )
|
938
|
+
array.platform_errors.add_error( 'platform.invalid_session' )
|
939
|
+
array.platform_errors.add_error( 'platform.method_not_allowed' )
|
940
|
+
array
|
941
|
+
end
|
942
|
+
|
943
|
+
# This means we expect another session acquisition attempt, which is
|
944
|
+
# allowed to succeed, then the wrapped endpoint should be called.
|
945
|
+
|
946
|
+
expect( @endpoint ).to receive( :acquire_session_for ).once.with( :list ).and_call_original
|
947
|
+
expect( @endpoint.instance_variable_get( '@wrapped_endpoint' ) ).to receive( :list ).once.and_call_original
|
948
|
+
|
949
|
+
result = @endpoint.list()
|
950
|
+
expect( result.platform_errors.has_errors? ).to eq( false )
|
951
|
+
end
|
952
|
+
|
913
953
|
it 'handles errors from the session resource' do
|
914
954
|
expect_any_instance_of( RSpecClientTestSessionImplementation ).to receive( :create ).and_raise( "boo!" )
|
915
955
|
|
@@ -928,6 +968,23 @@ describe Hoodoo::Client do
|
|
928
968
|
Hoodoo::Services::Middleware.set_test_session( nil )
|
929
969
|
|
930
970
|
result = @endpoint.list()
|
971
|
+
|
972
|
+
expect( result.platform_errors.has_errors? ).to eq( true )
|
973
|
+
expect( result.platform_errors.errors[ 0 ][ 'code' ] ).to eq( 'generic.malformed' )
|
974
|
+
end
|
975
|
+
|
976
|
+
it 'handles malformed sessions when retrying' do
|
977
|
+
result = @endpoint.list()
|
978
|
+
expect( result.platform_errors.has_errors? ).to eq( false )
|
979
|
+
|
980
|
+
Hoodoo::Services::Middleware.set_test_session( nil )
|
981
|
+
|
982
|
+
expect_any_instance_of( RSpecClientTestSessionImplementation ).to receive( :create ) { | ignored, context |
|
983
|
+
context.response.body = { 'not' => 'a session' }
|
984
|
+
}
|
985
|
+
|
986
|
+
result = @endpoint.list()
|
987
|
+
|
931
988
|
expect( result.platform_errors.has_errors? ).to eq( true )
|
932
989
|
expect( result.platform_errors.errors[ 0 ][ 'code' ] ).to eq( 'generic.malformed' )
|
933
990
|
end
|
@@ -954,10 +1011,6 @@ describe Hoodoo::Client do
|
|
954
1011
|
end
|
955
1012
|
end
|
956
1013
|
|
957
|
-
before :each do
|
958
|
-
Hoodoo::Services::Middleware.set_test_session( nil )
|
959
|
-
end
|
960
|
-
|
961
1014
|
context 'and by DRb' do
|
962
1015
|
before :each do
|
963
1016
|
set_vars_for(
|
@@ -456,7 +456,7 @@ describe Hoodoo::Services::Middleware do
|
|
456
456
|
expect( errors[ 'errors' ][ 0 ] ).to_not be_nil
|
457
457
|
|
458
458
|
expect( errors[ 'errors' ][ 0 ][ 'code' ] ).to eq( 'platform.fault' )
|
459
|
-
expect( errors[ 'errors' ][ 0 ][ 'message' ] ).to eq( 'Could not parse body data
|
459
|
+
expect( errors[ 'errors' ][ 0 ][ 'message' ] ).to eq( 'Could not parse retrieved body data despite receiving HTTP status code 200' )
|
460
460
|
expect( errors[ 'errors' ][ 0 ][ 'reference' ] ).to eq( "#{ bad_body_data }" )
|
461
461
|
end
|
462
462
|
end
|
@@ -1091,7 +1091,7 @@ describe Hoodoo::Services::Middleware do
|
|
1091
1091
|
|
1092
1092
|
result = JSON.parse(last_response.body)
|
1093
1093
|
expect(result['errors'][0]['code']).to eq('platform.fault')
|
1094
|
-
expect(result['errors'][0]['message']).to eq('Could not parse body data
|
1094
|
+
expect(result['errors'][0]['message']).to eq('Could not parse retrieved body data despite receiving HTTP status code 200')
|
1095
1095
|
end
|
1096
1096
|
|
1097
1097
|
context 'X-Assume-Identity-Of' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hoodoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Loyalty New Zealand
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kgio
|