@@ -37,8 +37,9 @@ pub(super) async fn handle_watch(
3737
3838 let suffix = format ! ( "{:08x}" , rand:: random:: <u32 >( ) ) ;
3939 let topic = if let Some ( ref t) = config. topic {
40- t . clone ( )
40+ crate :: helpers :: validate_resource_name ( t ) ? . to_string ( )
4141 } else {
42+ let project = crate :: helpers:: validate_resource_name ( & project) ?;
4243 let t = format ! ( "projects/{project}/topics/gws-gmail-watch-{suffix}" ) ;
4344 // Create Pub/Sub topic
4445 eprintln ! ( "Creating Pub/Sub topic: {t}" ) ;
@@ -97,6 +98,7 @@ pub(super) async fn handle_watch(
9798 t
9899 } ;
99100
101+ let project = crate :: helpers:: validate_resource_name ( & project) ?;
100102 let sub = format ! ( "projects/{project}/subscriptions/gws-gmail-watch-{suffix}" ) ;
101103
102104 // 3. Create Pub/Sub subscription
@@ -499,7 +501,7 @@ fn extract_message_ids_from_history(history_body: &Value) -> Vec<String> {
499501 result
500502}
501503
502- #[ derive( Clone ) ]
504+ #[ derive( Debug , Clone ) ]
503505struct WatchConfig {
504506 project : Option < String > ,
505507 subscription : Option < String > ,
@@ -630,7 +632,25 @@ mod tests {
630632 }
631633
632634 #[ test]
633- fn test_parse_watch_args ( ) {
635+ fn test_parse_watch_args_invalid_format ( ) {
636+ let matches = make_matches_watch ( & [ "test" , "--msg-format" , "invalid-format" ] ) ;
637+ let result = parse_watch_args ( & matches) ;
638+ assert ! ( result. is_err( ) ) ;
639+ let msg = result. unwrap_err ( ) . to_string ( ) ;
640+ assert ! ( msg. contains( "Invalid message format" ) ) ;
641+ }
642+
643+ #[ test]
644+ fn test_parse_watch_args_invalid_output_dir ( ) {
645+ let matches = make_matches_watch ( & [ "test" , "--output-dir" , "../../etc" ] ) ;
646+ let result = parse_watch_args ( & matches) ;
647+ assert ! ( result. is_err( ) ) ;
648+ let msg = result. unwrap_err ( ) . to_string ( ) ;
649+ assert ! ( msg. contains( "outside the current directory" ) ) ;
650+ }
651+
652+ #[ test]
653+ fn test_parse_watch_args_full ( ) {
634654 let matches = make_matches_watch ( & [
635655 "test" ,
636656 "--project" ,
0 commit comments