@@ -461,3 +461,65 @@ impl<C: Callbacks> crate::Identity for IdentityPluginV1<C> {
461461 self . unwrap_stanzas ( stanzas. iter ( ) )
462462 }
463463}
464+
465+ #[ cfg( test) ]
466+ mod tests {
467+ use crate :: { Callbacks , DecryptError , EncryptError } ;
468+
469+ use super :: {
470+ Identity , IdentityPluginV1 , Recipient , RecipientPluginV1 , PLUGIN_IDENTITY_PREFIX ,
471+ PLUGIN_RECIPIENT_PREFIX ,
472+ } ;
473+
474+ const INVALID_PLUGIN_NAME : & str = "foobar/../../../../../../../usr/bin/echo" ;
475+
476+ struct NoCallbacks ;
477+ impl Callbacks for NoCallbacks {
478+ fn prompt ( & self , _: & str ) { }
479+ fn request_public_string ( & self , _: & str ) -> Option < String > {
480+ None
481+ }
482+ fn request_passphrase ( & self , _: & str ) -> Option < secrecy:: SecretString > {
483+ None
484+ }
485+ }
486+
487+ #[ test]
488+ fn recipient_rejects_invalid_chars ( ) {
489+ let invalid_recipient = bech32:: encode (
490+ & format ! ( "{}{}" , PLUGIN_RECIPIENT_PREFIX , INVALID_PLUGIN_NAME ) ,
491+ [ ] ,
492+ bech32:: Variant :: Bech32 ,
493+ )
494+ . unwrap ( ) ;
495+ assert ! ( invalid_recipient. parse:: <Recipient >( ) . is_err( ) ) ;
496+ }
497+
498+ #[ test]
499+ fn identity_rejects_invalid_chars ( ) {
500+ let invalid_identity = bech32:: encode (
501+ & format ! ( "{}{}-" , PLUGIN_IDENTITY_PREFIX , INVALID_PLUGIN_NAME ) ,
502+ [ ] ,
503+ bech32:: Variant :: Bech32 ,
504+ )
505+ . expect ( "HRP is valid" )
506+ . to_uppercase ( ) ;
507+ assert ! ( invalid_identity. parse:: <Identity >( ) . is_err( ) ) ;
508+ }
509+
510+ #[ test]
511+ fn recipient_plugin_v1_rejects_invalid_chars ( ) {
512+ assert ! ( matches!(
513+ RecipientPluginV1 :: new( INVALID_PLUGIN_NAME , & [ ] , & [ ] , NoCallbacks ) ,
514+ Err ( EncryptError :: MissingPlugin { binary_name } ) if binary_name == INVALID_PLUGIN_NAME ,
515+ ) ) ;
516+ }
517+
518+ #[ test]
519+ fn identity_plugin_v1_rejects_invalid_chars ( ) {
520+ assert ! ( matches!(
521+ IdentityPluginV1 :: new( INVALID_PLUGIN_NAME , & [ ] , NoCallbacks ) ,
522+ Err ( DecryptError :: MissingPlugin { binary_name } ) if binary_name == INVALID_PLUGIN_NAME ,
523+ ) ) ;
524+ }
525+ }
0 commit comments