@@ -4120,6 +4120,72 @@ test("BotImpl.onQuoteRequested() rejects unknown-audience quotes", async () => {
41204120 ) ;
41214121} ) ;
41224122
4123+ test ( "BotImpl.onQuoteRequested() checks direct quote recipients for unknown targets" , async ( ) => {
4124+ const repository = new MemoryRepository ( ) ;
4125+ const bot = new BotImpl < void > ( {
4126+ kv : new MemoryKvStore ( ) ,
4127+ repository,
4128+ username : "bot" ,
4129+ quotePolicy : "public" ,
4130+ } ) ;
4131+ const ctx = createMockInboxContext ( bot , "https://example.com" , "bot" ) ;
4132+ const session = new SessionImpl ( bot , ctx ) ;
4133+ const actor = new Person ( {
4134+ id : new URL ( "https://remote.example/users/alice" ) ,
4135+ preferredUsername : "alice" ,
4136+ } ) ;
4137+ const unrelatedActor = new Person ( {
4138+ id : new URL ( "https://remote.example/users/bob" ) ,
4139+ preferredUsername : "bob" ,
4140+ } ) ;
4141+ const targetId = new URL (
4142+ "https://example.com/ap/note/01950000-0000-7000-8000-000000000101" ,
4143+ ) ;
4144+ await repository . addMessage (
4145+ "bot" ,
4146+ "01950000-0000-7000-8000-000000000101" as Uuid ,
4147+ new Create ( {
4148+ id : new URL (
4149+ "https://example.com/ap/create/01950000-0000-7000-8000-000000000101" ,
4150+ ) ,
4151+ actor : session . actorId ,
4152+ object : new Note ( {
4153+ id : targetId ,
4154+ attribution : session . actorId ,
4155+ content : "A target with an unrecognized audience." ,
4156+ to : actor . id ,
4157+ } ) ,
4158+ } ) ,
4159+ ) ;
4160+ const quote = new Note ( {
4161+ id : new URL ( "https://remote.example/notes/direct-quote-outside-target" ) ,
4162+ attribution : actor . id ,
4163+ quoteUrl : targetId ,
4164+ content : "Quoted directly to someone else." ,
4165+ to : unrelatedActor . id ,
4166+ tags : [ new Mention ( { href : unrelatedActor . id } ) ] ,
4167+ } ) ;
4168+
4169+ await bot . onQuoteRequested (
4170+ ctx ,
4171+ new QuoteRequest ( {
4172+ id : new URL ( "https://remote.example/quote-requests/direct-outside" ) ,
4173+ actor,
4174+ object : targetId ,
4175+ instrument : quote ,
4176+ } ) ,
4177+ ) ;
4178+
4179+ assert . deepStrictEqual ( ctx . sentActivities . length , 1 ) ;
4180+ const { recipients, activity } = ctx . sentActivities [ 0 ] ;
4181+ assert . deepStrictEqual ( recipients , [ actor ] ) ;
4182+ assert . ok ( activity instanceof Reject ) ;
4183+ assert . deepStrictEqual (
4184+ await repository . findQuoteAuthorization ( "bot" , quote . id ! ) ,
4185+ undefined ,
4186+ ) ;
4187+ } ) ;
4188+
41234189test ( "AuthorizedMessage.unauthorizeQuote() checks the target message" , async ( ) => {
41244190 const repository = new MemoryRepository ( ) ;
41254191 const bot = new BotImpl < void > ( {
0 commit comments