1- use crate :: agent_control:: defaults:: get_custom_capabilities;
21use crate :: http:: client:: HttpClient ;
32use crate :: http:: config:: HttpConfig ;
43use crate :: http:: config:: ProxyConfig ;
54use crate :: opamp:: remote_config:: OpampRemoteConfig ;
6- use crate :: opamp:: remote_config:: signature:: SIGNATURE_CUSTOM_CAPABILITY ;
75use crate :: opamp:: remote_config:: validators:: RemoteConfigValidator ;
86use crate :: opamp:: remote_config:: validators:: signature:: public_key:: PublicKey ;
97use crate :: opamp:: remote_config:: validators:: signature:: public_key_fetcher:: PublicKeyFetcher ;
@@ -104,23 +102,14 @@ impl RemoteConfigValidator for SignatureValidator {
104102
105103 fn validate (
106104 & self ,
107- agent_identity : & AgentIdentity ,
105+ _ : & AgentIdentity ,
108106 opamp_remote_config : & OpampRemoteConfig ,
109107 ) -> Result < ( ) , Self :: Err > {
110108 // Noop validation
111109 let Some ( public_key_store) = & self . public_key_store else {
112110 return Ok ( ( ) ) ;
113111 } ;
114112
115- // custom capabilities are got from the agent-type (currently hard-coded)
116- // If the capability is not set, no validation is performed
117- if !get_custom_capabilities ( & agent_identity. agent_type_id ) . is_some_and ( |c| {
118- c. capabilities
119- . contains ( & SIGNATURE_CUSTOM_CAPABILITY . to_string ( ) )
120- } ) {
121- return Ok ( ( ) ) ;
122- }
123-
124113 let signature = opamp_remote_config
125114 . get_default_signature ( )
126115 . map_err ( |e| SignatureValidatorError :: VerifySignature ( e. to_string ( ) ) ) ?
@@ -170,10 +159,11 @@ pub mod tests {
170159 . unwrap ( ) ;
171160
172161 let config = "value" ;
173-
174162 let encoded_signature = pub_key_server. sign ( config. as_bytes ( ) ) ;
163+
164+ // agent remote config
175165 let remote_config = OpampRemoteConfig :: new (
176- AgentID :: AgentControl ,
166+ AgentIdentity :: default ( ) . id ,
177167 Hash :: from ( "test" ) ,
178168 ConfigState :: Applying ,
179169 ConfigurationMap :: new ( HashMap :: from ( [ (
@@ -189,6 +179,26 @@ pub mod tests {
189179
190180 signature_validator
191181 . validate ( & AgentIdentity :: default ( ) , & remote_config)
182+ . unwrap ( ) ;
183+
184+ // agent-control remote config
185+ let remote_config = OpampRemoteConfig :: new (
186+ AgentIdentity :: new_agent_control_identity ( ) . id ,
187+ Hash :: from ( "test" ) ,
188+ ConfigState :: Applying ,
189+ ConfigurationMap :: new ( HashMap :: from ( [ (
190+ DEFAULT_AGENT_CONFIG_IDENTIFIER . to_string ( ) ,
191+ config. to_string ( ) ,
192+ ) ] ) ) ,
193+ )
194+ . with_signature ( Signatures :: new_default (
195+ encoded_signature. as_str ( ) ,
196+ ED25519 ,
197+ pub_key_server. key_id . as_str ( ) ,
198+ ) ) ;
199+
200+ signature_validator
201+ . validate ( & AgentIdentity :: new_agent_control_identity ( ) , & remote_config)
192202 . unwrap ( )
193203 }
194204
@@ -302,7 +312,7 @@ pub mod tests {
302312 }
303313
304314 #[ test]
305- pub fn test_signature_is_missing_for_agent_control_agent ( ) {
315+ pub fn test_missing_signature_for_agent_control_agent ( ) {
306316 let pub_key_server = FakePubKeyServer :: new ( ) ;
307317
308318 let signature_validator = SignatureValidator :: new (
@@ -318,13 +328,12 @@ pub mod tests {
318328 AgentID :: AgentControl ,
319329 Hash :: from ( "test" ) ,
320330 ConfigState :: Applying ,
321- ConfigurationMap :: default ( ) ,
331+ ConfigurationMap :: new ( HashMap :: from ( [ ( "key" . to_string ( ) , "value" . to_string ( ) ) ] ) ) ,
322332 ) ;
323- // Signature custom capability is not set for agent-control agent, therefore signature is not checked
324- assert ! (
325- signature_validator
326- . validate( & AgentIdentity :: new_agent_control_identity( ) , & rc)
327- . is_ok( )
333+
334+ assert_matches ! (
335+ signature_validator. validate( & AgentIdentity :: new_agent_control_identity( ) , & rc) ,
336+ Err ( SignatureValidatorError :: VerifySignature ( _) )
328337 ) ;
329338 }
330339}
0 commit comments