@@ -131,12 +131,13 @@ impl ServiceConfiguration {
131131
132132 pub fn get_action_configuration (
133133 & self ,
134+ token : & String ,
134135 action_identifier : & String ,
135136 ) -> Vec < ModuleConfigurations > {
136137 match self
137138 . actions
138139 . iter ( )
139- . find ( |x| & x. service_name == action_identifier)
140+ . find ( |x| & x. token == token && & x . service_name == action_identifier)
140141 {
141142 Some ( a) => a. config . clone ( ) ,
142143 None => vec ! [ ] ,
@@ -187,6 +188,7 @@ impl ServiceConfiguration {
187188mod tests {
188189 use super :: {
189190 RuntimeServiceConfiguration , SerializableActionServiceConfiguration ,
191+ SerializableModuleConfiguration , SerializableModuleProjectConfiguration ,
190192 SerializableServiceConfiguration , ServiceConfiguration ,
191193 } ;
192194
@@ -253,6 +255,7 @@ mod tests {
253255 & String :: from( "action-identifier" )
254256 ) ) ;
255257 assert ! ( !config. has_action( & String :: from( "action-token" ) , & String :: from( "action-other" ) ) ) ;
258+ assert ! ( !config. has_action( & String :: from( "example" ) , & String :: from( "example" ) ) ) ;
256259 }
257260
258261 #[ test]
@@ -274,4 +277,57 @@ mod tests {
274277 ) ) ;
275278 assert ! ( !config. has_service( & String :: from( "action-token" ) , & String :: from( "taurus-x" ) ) ) ;
276279 }
280+
281+ #[ test]
282+ fn get_action_configuration_requires_matching_token_and_identifier ( ) {
283+ let config: ServiceConfiguration = SerializableServiceConfiguration {
284+ actions : vec ! [
285+ SerializableActionServiceConfiguration {
286+ token: String :: from( "old-token" ) ,
287+ identifier: String :: from( "shared-action" ) ,
288+ configs: vec![ SerializableModuleProjectConfiguration {
289+ project_id: 1 ,
290+ configs: vec![ SerializableModuleConfiguration {
291+ identifier: String :: from( "endpoint" ) ,
292+ value: serde_json:: json!( "old.example" ) ,
293+ } ] ,
294+ } ] ,
295+ } ,
296+ SerializableActionServiceConfiguration {
297+ token: String :: from( "new-token" ) ,
298+ identifier: String :: from( "shared-action" ) ,
299+ configs: vec![ SerializableModuleProjectConfiguration {
300+ project_id: 2 ,
301+ configs: vec![ SerializableModuleConfiguration {
302+ identifier: String :: from( "endpoint" ) ,
303+ value: serde_json:: json!( "new.example" ) ,
304+ } ] ,
305+ } ] ,
306+ } ,
307+ ] ,
308+ runtimes : vec ! [ ] ,
309+ }
310+ . into ( ) ;
311+
312+ let configs = config
313+ . get_action_configuration ( & String :: from ( "new-token" ) , & String :: from ( "shared-action" ) ) ;
314+
315+ assert_eq ! ( configs. len( ) , 1 ) ;
316+ assert_eq ! ( configs[ 0 ] . module_identifier, "shared-action" ) ;
317+ assert_eq ! ( configs[ 0 ] . module_configurations[ 0 ] . project_id, 2 ) ;
318+ }
319+
320+ #[ test]
321+ fn get_action_configuration_returns_empty_for_identifier_with_wrong_token ( ) {
322+ let config = fixture ( ) ;
323+
324+ assert ! (
325+ config
326+ . get_action_configuration(
327+ & String :: from( "wrong-token" ) ,
328+ & String :: from( "action-identifier" )
329+ )
330+ . is_empty( )
331+ ) ;
332+ }
277333}
0 commit comments