2023-05-22 23:38:11 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								'use strict' ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 16:13:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  assert  =  require ( 'assert' ) ;  
						 
					
						
							
								
									
										
										
										
											2023-05-22 23:38:11 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								const  nconf  =  require ( 'nconf' ) ;  
						 
					
						
							
								
									
										
										
										
											2024-04-26 11:30:08 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  path  =  require ( 'path' ) ;  
						 
					
						
							
								
									
										
										
										
											2023-05-22 23:38:11 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const  db  =  require ( './mocks/databasemock' ) ;  
						 
					
						
							
								
									
										
										
										
											2023-05-23 16:13:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  slugify  =  require ( '../src/slugify' ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const  utils  =  require ( '../src/utils' ) ;  
						 
					
						
							
								
									
										
										
										
											2023-12-21 14:38:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  request  =  require ( '../src/request' ) ;  
						 
					
						
							
								
									
										
										
										
											2023-05-23 16:13:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-04-26 11:30:08 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  file  =  require ( '../src/file' ) ;  
						 
					
						
							
								
									
										
										
										
											2024-02-26 14:22:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  install  =  require ( '../src/install' ) ;  
						 
					
						
							
								
									
										
										
										
											2023-05-24 14:00:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  meta  =  require ( '../src/meta' ) ;  
						 
					
						
							
								
									
										
										
										
											2023-05-23 16:13:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  user  =  require ( '../src/user' ) ;  
						 
					
						
							
								
									
										
										
										
											2024-01-26 21:39:20 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  categories  =  require ( '../src/categories' ) ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								const  topics  =  require ( '../src/topics' ) ;  
						 
					
						
							
								
									
										
										
										
											2024-05-07 12:15:51 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  posts  =  require ( '../src/posts' ) ;  
						 
					
						
							
								
									
										
										
										
											2023-06-21 15:45:29 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  activitypub  =  require ( '../src/activitypub' ) ;  
						 
					
						
							
								
									
										
										
										
											2023-05-22 23:38:11 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								describe ( 'ActivityPub integration' ,  ( )  =>  {  
						 
					
						
							
								
									
										
										
										
											2024-02-26 14:22:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									before ( async  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-16 10:57:34 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										meta . config . activitypubEnabled  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-26 14:22:35 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										await  install . giveWorldPrivileges ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-24 14:00:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									after ( ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-16 10:57:34 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										delete  meta . config . activitypubEnabled ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-24 14:00:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-12-13 13:38:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									describe ( 'Helpers' ,  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-11 14:35:04 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										describe ( '.query()' ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										describe ( '.generateKeys()' ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-21 13:43:56 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										describe ( '.resolveId()' ,  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-21 10:58:20 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											let  url ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											let  resolved ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											before ( ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												url  =  'https://example.org/topic/foobar' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												resolved  =  'https://example.org/tid/1234' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												activitypub . _cache . set ( ` 0; ${ url } ` ,  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													id :  resolved , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											it ( 'should return the resolved id when queried' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												const  id  =  await  activitypub . resolveId ( 0 ,  url ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . strictEqual ( id ,  resolved ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											it ( 'should return null when the query fails' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												const  id  =  await  activitypub . resolveId ( 0 ,  'https://example.org/sdlknsdfnsd' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . strictEqual ( id ,  null ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											it ( 'should return null when the resolved host does not match the queried host' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												const  url  =  'https://example.com/topic/foobar' ;  // .com attempting to overwrite .org data
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												const  resolved  =  'https://example.org/tid/1234' ;  // .org
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												activitypub . _cache . set ( ` 0; ${ url } ` ,  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													id :  resolved , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												const  id  =  await  activitypub . resolveId ( 0 ,  url ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . strictEqual ( id ,  null ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-05 16:57:17 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										describe ( '.resolveLocalId()' ,  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-11 14:35:04 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											let  uid ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											let  slug ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											beforeEach ( async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												slug  =  slugify ( utils . generateUUID ( ) . slice ( 0 ,  8 ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												uid  =  await  user . create ( {  username :  slug  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-21 10:26:26 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											it ( 'should return null when an invalid input is passed in' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												const  {  type ,  id  }  =  await  activitypub . helpers . resolveLocalId ( 'ncl28h3qwhoiclwnevoinw3u' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . strictEqual ( type ,  null ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . strictEqual ( id ,  null ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-11 14:35:04 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											it ( 'should return null when valid input is passed but does not resolve' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-25 12:00:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												const  {  type ,  id  }  =  await  activitypub . helpers . resolveLocalId ( ` acct%3afoobar@ ${ nconf . get ( 'url_parsed' ) . host } ` ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-21 10:26:26 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												assert . strictEqual ( type ,  'user' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-05 16:57:17 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												assert . strictEqual ( id ,  null ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-11 14:35:04 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											it ( 'should resolve to a local uid when given a webfinger-style string' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-25 12:00:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												const  {  id  }  =  await  activitypub . helpers . resolveLocalId ( ` acct%3a ${ slug } @ ${ nconf . get ( 'url_parsed' ) . host } ` ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-05 16:57:17 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												assert . strictEqual ( id ,  uid ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-11 14:35:04 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											it ( 'should resolve even without the "acct:" prefix' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-05 16:57:17 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												const  {  id  }  =  await  activitypub . helpers . resolveLocalId ( ` ${ slug } @ ${ nconf . get ( 'url_parsed' ) . host } ` ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . strictEqual ( id ,  uid ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-11 14:35:04 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											it ( 'should resolve when passed a full URL' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-05 16:57:17 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												const  {  id  }  =  await  activitypub . helpers . resolveLocalId ( ` ${ nconf . get ( 'url' ) } /user/ ${ slug } ` ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . strictEqual ( id ,  uid ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-11 14:35:04 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-29 16:16:07 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-25 13:18:45 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										describe ( '.generateTitle' ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											describe ( 'test strings' ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												const  cases  =  new  Map ( [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// first paragraph element
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													[ '<p>test title</p><span>abc</span>' ,  'test title' ] , 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-29 16:16:07 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-25 13:18:45 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													// other tags like h1 or span
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													[ '<h1>Lorem ipsum dolor sit amet</h1><p>consectetur adipiscing elit. Integer tincidunt metus scelerisque, dignissim risus a, fermentum leo. Pellentesque eleifend ullamcorper risus tempus vestibulum. Proin mollis ipsum et magna lobortis, at pretium enim pharetra. Ut vel ex metus. Mauris faucibus lectus et nulla iaculis, et pellentesque elit pellentesque. Aliquam rhoncus nec nulla eu lacinia. Maecenas cursus iaculis ligula, eu pharetra ex suscipit sit amet.</p>' ,  'Lorem ipsum dolor sit amet' ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													[ '<span>Lorem ipsum dolor sit amet</span><p>consectetur adipiscing elit. Integer tincidunt metus scelerisque, dignissim risus a, fermentum leo. Pellentesque eleifend ullamcorper risus tempus vestibulum. Proin mollis ipsum et magna lobortis, at pretium enim pharetra. Ut vel ex metus. Mauris faucibus lectus et nulla iaculis, et pellentesque elit pellentesque. Aliquam rhoncus nec nulla eu lacinia. Maecenas cursus iaculis ligula, eu pharetra ex suscipit sit amet.</p>' ,  'Lorem ipsum dolor sit amet' ] , 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-18 14:41:22 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-25 13:18:45 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													// first line's text otherwise
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													[ 'Lorem ipsum dolor sit amet\n\nconsectetur adipiscing elit. Integer tincidunt metus scelerisque, dignissim risus a, fermentum leo. Pellentesque eleifend ullamcorper risus tempus vestibulum. Proin mollis ipsum et magna lobortis, at pretium enim pharetra. Ut vel ex metus. Mauris faucibus lectus et nulla iaculis, et pellentesque elit pellentesque. Aliquam rhoncus nec nulla eu lacinia. Maecenas cursus iaculis ligula, eu pharetra ex suscipit sit amet.' ,  'Lorem ipsum dolor sit amet' ] , 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-18 14:41:22 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-25 13:18:45 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													// first sentence of matched line/element
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													[ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam a ex pellentesque, fringilla lorem non, blandit est. Nulla facilisi. Curabitur cursus neque vel enim semper, id lacinia elit facilisis. Vestibulum turpis orci, efficitur ut semper eu, faucibus eu turpis. Praesent eu odio non libero gravida tempor. Ut porta pellentesque orci. In porta nunc eget tincidunt interdum. Curabitur vel dui nec libero tempus porttitor. Phasellus tincidunt, diam id viverra suscipit, est diam maximus purus, in vestibulum dui ligula vel libero. Sed tempus finibus ante, sit amet consequat magna facilisis eget. Proin ullamcorper, velit sit amet feugiat varius, massa sem aliquam dui, non aliquam augue velit vel est. Phasellus eu sapien in purus feugiat scelerisque congue id velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.' ,  'Lorem ipsum dolor sit amet, consectetur adipiscing elit.' ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// other sentence ending symbols
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													[ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit? Etiam a ex pellentesque, fringilla lorem non, blandit est. Nulla facilisi. Curabitur cursus neque vel enim semper, id lacinia elit facilisis. Vestibulum turpis orci, efficitur ut semper eu, faucibus eu turpis. Praesent eu odio non libero gravida tempor. Ut porta pellentesque orci. In porta nunc eget tincidunt interdum. Curabitur vel dui nec libero tempus porttitor. Phasellus tincidunt, diam id viverra suscipit, est diam maximus purus, in vestibulum dui ligula vel libero. Sed tempus finibus ante, sit amet consequat magna facilisis eget. Proin ullamcorper, velit sit amet feugiat varius, massa sem aliquam dui, non aliquam augue velit vel est. Phasellus eu sapien in purus feugiat scelerisque congue id velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.' ,  'Lorem ipsum dolor sit amet, consectetur adipiscing elit?' ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// Content after line breaks can be discarded
 
							 
						 
					
						
							
								
									
										
										
										
											2024-11-14 15:07:42 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													[ '<p>Intro text<br /><a href="https://example.org/">example.org/</span></a></p><p>more text</p>' ,  'Intro text' ] , 
							 
						 
					
						
							
								
									
										
										
										
											2024-10-25 13:18:45 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-31 11:35:28 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													// HTML without outer wrapping element
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													[ 'Lorem ipsum dolor <span>sit amet</span>' ,  'Lorem ipsum dolor sit amet' ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// Two sentences with punctuation
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													[ 'Lorem ipsum. Dolor sit amet.' ,  'Lorem ipsum.' ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-10-25 13:18:45 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													// Additional tests?
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// ['', ''],
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												cases . forEach ( ( value ,  key )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													it ( 'should convert as expected' ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														const  title  =  activitypub . helpers . generateTitle ( key ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														assert . strictEqual ( title ,  value ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-29 16:16:07 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											it ( 'should trim down the title if it is too long per settings' ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												const  value  =  meta . config . maximumTitleLength ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												meta . config . maximumTitleLength  =  10 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												const  source  =  '@@@@@@@@@@@@@@@@@@@@' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												const  title  =  activitypub . helpers . generateTitle ( source ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . strictEqual ( title ,  '@@@@@@@...' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												meta . config . maximumTitleLength  =  value ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-11 14:35:04 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 16:13:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									describe ( 'ActivityPub screener middleware' ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										let  uid ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										beforeEach ( async  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-05 14:12:23 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											uid  =  await  user . create ( {  username :  slugify ( utils . generateUUID ( ) . slice ( 0 ,  8 ) )  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 16:13:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-05-24 14:00:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										it ( 'should return regular user profile html if federation is disabled' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-16 10:57:34 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											delete  meta . config . activitypubEnabled ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-24 14:00:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-05 14:12:23 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											const  {  response ,  body  }  =  await  request . get ( ` ${ nconf . get ( 'url' ) } /uid/ ${ uid } ` ,  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-24 14:00:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												headers :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													Accept :  'text/html' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert ( response ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert . strictEqual ( response . statusCode ,  200 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-21 14:38:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											assert ( body . startsWith ( '<!DOCTYPE html>' ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-24 14:00:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-06-16 10:57:34 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											meta . config . activitypubEnabled  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-24 14:00:41 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 16:13:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										it ( 'should return regular user profile html if Accept header is not ActivityPub-related' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-05 14:12:23 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											const  {  response ,  body  }  =  await  request . get ( ` ${ nconf . get ( 'url' ) } /uid/ ${ uid } ` ,  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 16:13:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												headers :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													Accept :  'text/html' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert ( response ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert . strictEqual ( response . statusCode ,  200 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-21 14:38:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											assert ( body . startsWith ( '<!DOCTYPE html>' ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 16:13:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										it ( 'should return the ActivityPub Actor JSON-LD payload if the correct Accept header is provided' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-05 14:12:23 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											const  {  response ,  body  }  =  await  request . get ( ` ${ nconf . get ( 'url' ) } /uid/ ${ uid } ` ,  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-22 23:38:11 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												headers :  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 16:13:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													Accept :  'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' , 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-22 23:38:11 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 16:13:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert ( response ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert . strictEqual ( response . statusCode ,  200 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-21 14:38:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											assert ( body . hasOwnProperty ( '@context' ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert ( body [ '@context' ] . includes ( 'https://www.w3.org/ns/activitystreams' ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 16:13:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 16:18:49 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									describe ( 'User Actor endpoint' ,  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 16:13:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										let  uid ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										let  slug ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										beforeEach ( async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											slug  =  slugify ( utils . generateUUID ( ) . slice ( 0 ,  8 ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											uid  =  await  user . create ( {  username :  slug  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										it ( 'should return a valid ActivityPub Actor JSON-LD payload' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-05 14:12:23 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											const  {  response ,  body  }  =  await  request . get ( ` ${ nconf . get ( 'url' ) } /uid/ ${ uid } ` ,  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 16:13:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												headers :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													Accept :  'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert ( response ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert . strictEqual ( response . statusCode ,  200 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-21 14:38:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											assert ( body . hasOwnProperty ( '@context' ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert ( body [ '@context' ] . includes ( 'https://www.w3.org/ns/activitystreams' ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 16:13:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											[ 'id' ,  'url' ,  'followers' ,  'following' ,  'inbox' ,  'outbox' ] . forEach ( ( prop )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-21 14:38:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												assert ( body . hasOwnProperty ( prop ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert ( body [ prop ] ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 16:13:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-05 14:12:23 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											assert . strictEqual ( body . id ,  ` ${ nconf . get ( 'url' ) } /uid/ ${ uid } ` ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-21 14:38:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											assert . strictEqual ( body . type ,  'Person' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 16:13:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										it ( 'should contain a `publicKey` property with a public key' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-05 14:12:23 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											const  {  response ,  body  }  =  await  request . get ( ` ${ nconf . get ( 'url' ) } /uid/ ${ uid } ` ,  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 16:13:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												headers :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													Accept :  'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' , 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-22 23:38:11 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-23 16:13:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-12-21 14:38:16 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											assert ( body . hasOwnProperty ( 'publicKey' ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert ( [ 'id' ,  'owner' ,  'publicKeyPem' ] . every ( prop  =>  body . publicKey . hasOwnProperty ( prop ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-22 23:38:11 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-21 15:45:29 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 16:18:49 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									describe ( 'Instance Actor endpoint' ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										let  response ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										let  body ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										before ( async  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-24 14:09:40 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											( {  response ,  body  }  =  await  request . get ( ` ${ nconf . get ( 'url' ) } /actor ` ,  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 16:18:49 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												headers :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													Accept :  'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										it ( 'should respond properly' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert ( response ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert . strictEqual ( response . statusCode ,  200 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										it ( 'should return a valid ActivityPub Actor JSON-LD payload' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert ( body . hasOwnProperty ( '@context' ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert ( body [ '@context' ] . includes ( 'https://www.w3.org/ns/activitystreams' ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-23 11:22:18 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											[ 'id' ,  'url' ,  'inbox' ,  'outbox' ,  'name' ,  'preferredUsername' ] . forEach ( ( prop )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 16:18:49 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												assert ( body . hasOwnProperty ( prop ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert ( body [ prop ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert . strictEqual ( body . id ,  body . url ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert . strictEqual ( body . type ,  'Application' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-23 11:22:18 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											assert . strictEqual ( body . name ,  meta . config . site _title  ||  'NodeBB' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert . strictEqual ( body . preferredUsername ,  nconf . get ( 'url_parsed' ) . hostname ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 16:18:49 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										it ( 'should contain a `publicKey` property with a public key' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert ( body . hasOwnProperty ( 'publicKey' ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert ( [ 'id' ,  'owner' ,  'publicKeyPem' ] . every ( prop  =>  body . publicKey . hasOwnProperty ( prop ) ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-23 11:22:18 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										it ( 'should also have a valid WebFinger response tied to `preferredUsername`' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-25 12:00:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											const  {  response ,  body :  body2  }  =  await  request . get ( ` ${ nconf . get ( 'url' ) } /.well-known/webfinger?resource=acct%3a ${ body . preferredUsername } @ ${ nconf . get ( 'url_parsed' ) . host } ` ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-23 11:22:18 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert . strictEqual ( response . statusCode ,  200 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert ( body2  &&  body2 . aliases  &&  body2 . links ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											assert ( body2 . aliases . includes ( nconf . get ( 'url' ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-25 11:01:22 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											assert ( body2 . links . some ( item  =>  item . rel  ===  'self'  &&  item . type  ===  'application/activity+json'  &&  item . href  ===  ` ${ nconf . get ( 'url' ) } /actor ` ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-23 11:22:18 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-22 16:18:49 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-05 14:12:23 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									describe ( 'Receipt of ActivityPub events to inboxes (federating IN)' ,  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-26 21:39:20 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										describe ( 'Create' ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											describe ( 'Note' ,  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-21 10:26:26 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												const  slug  =  utils . generateUUID ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												const  id  =  ` https://example.org/status/ ${ slug } ` ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												const  remoteNote  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													'@context' :  'https://www.w3.org/ns/activitystreams' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													id , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													url :  id , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													type :  'Note' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													to :  [ 'https://www.w3.org/ns/activitystreams#Public' ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													cc :  [ 'https://example.org/user/foobar/followers' ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													inReplyTo :  null , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													attributedTo :  'https://example.org/user/foobar' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													name :  'Foo Bar' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													content :  '<b>Baz quux</b>' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													published :  new  Date ( ) . toISOString ( ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													source :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														content :  '**Baz quux**' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														mediaType :  'text/markdown' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-12 12:03:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												const  remoteUser  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													'@context' :  'https://www.w3.org/ns/activitystreams' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													id :  'https://example.org/user/foobar' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													url :  'https://example.org/user/foobar' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													type :  'Person' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													name :  'Foo Bar' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													preferredUsername :  'foobar' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													publicKey :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														id :  'https://example.org/user/foobar#key' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														owner :  'https://example.org/user/foobar' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														publicKeyPem :  'publickey' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-21 10:26:26 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-26 21:39:20 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												let  topic ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												before ( async  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-21 10:26:26 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													const  controllers  =  require ( '../src/controllers' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													activitypub . _cache . set ( ` 0; ${ id } ` ,  remoteNote ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-12 12:03:16 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													activitypub . _cache . set ( ` 0;https://example.org/user/foobar ` ,  remoteUser ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-03 13:49:27 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													await  db . sortedSetAdd ( ` followersRemote: ${ remoteUser . id } ` ,  Date . now ( ) ,  1 ) ;  // fake a follow
 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-21 10:26:26 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													await  controllers . activitypub . postInbox ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														body :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															type :  'Create' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															actor :  'https://example.org/user/foobar' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															object :  remoteNote , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} ,  {  sendStatus :  ( )  =>  { }  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-26 21:39:20 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												it ( 'should create a new topic if Note is at root-level or its parent has not been seen before' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-21 10:26:26 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													const  saved  =  await  db . getObject ( ` post: ${ id } ` ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-26 21:39:20 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													assert ( saved ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													assert ( saved . tid ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-21 10:26:26 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													topic  =  await  topics . getTopicData ( saved . tid ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													assert ( topic ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													assert . strictEqual ( saved . uid ,  'https://example.org/user/foobar' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													assert . strictEqual ( saved . content ,  '<b>Baz quux</b>' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-26 21:39:20 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												it ( 'should properly save the topic title in the topic hash' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-21 10:26:26 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													assert . strictEqual ( topic . title ,  'Foo Bar' ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-26 21:39:20 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												it ( 'should properly save the mainPid in the topic hash' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-21 10:26:26 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													assert . strictEqual ( topic . mainPid ,  id ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-26 21:39:20 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-26 22:35:02 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												// todo: test topic replies, too
 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-26 21:39:20 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-05 14:12:23 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-05-14 12:06:59 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									describe ( 'Serving of local assets to remote clients (mocking)' ,  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-09 15:48:58 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										describe ( 'Note' ,  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-07 11:56:58 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											let  cid ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											let  uid ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-05 14:12:23 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											before ( async  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-07 11:56:58 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												( {  cid  }  =  await  categories . create ( {  name :  utils . generateUUID ( ) . slice ( 0 ,  8 )  } ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												const  slug  =  slugify ( utils . generateUUID ( ) . slice ( 0 ,  8 ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												uid  =  await  user . create ( {  username :  slug  } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-05 14:12:23 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-05-07 11:56:58 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											describe ( 'Existing and resolvable' ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												let  body ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												let  response ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												let  postData ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												before ( async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													( {  postData  }  =  await  topics . post ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														uid , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														cid , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														title :  'Lorem "Lipsum" Ipsum' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														content :  'Lorem ipsum dolor sit amet' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													( {  body ,  response  }  =  await  request . get ( ` ${ nconf . get ( 'url' ) } /post/ ${ postData . pid } ` ,  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														headers :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															Accept :  'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-05 14:12:23 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-05-07 11:56:58 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												it ( 'should return a 404 on a non-existant post' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													const  {  response  }  =  await  request . get ( ` ${ nconf . get ( 'url' ) } /post/ ${ parseInt ( postData . pid ,  10 )  +  1 } ` ,  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														headers :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															Accept :  'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-05 14:12:23 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-05-07 11:56:58 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													assert . strictEqual ( response . statusCode ,  404 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-05 14:12:23 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-05-07 11:56:58 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												it ( 'should return a 200 response on an existing post' ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													assert . strictEqual ( response . statusCode ,  200 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												it ( 'should return the expected Content-Type header' ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													assert . strictEqual ( response . headers [ 'content-type' ] ,  'application/activity+json; charset=utf-8' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												it ( 'Topic title (`name`) should not be escaped' ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													assert . strictEqual ( body . name ,  'Lorem "Lipsum" Ipsum' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-05 14:12:23 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-26 11:30:08 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-05-07 11:56:58 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											describe ( 'Soft deleted' ,  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-07 12:15:51 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												let  body ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												let  response ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												let  postData ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												before ( async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													( {  postData  }  =  await  topics . post ( { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														uid , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														cid , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														title :  utils . generateUUID ( ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														content :  utils . generateUUID ( ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													await  posts . delete ( postData . pid ,  uid ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													( {  body ,  response  }  =  await  request . get ( ` ${ nconf . get ( 'url' ) } /post/ ${ postData . pid } ` ,  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														headers :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															Accept :  'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-05-07 11:56:58 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-05-07 12:15:51 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												it ( 'should return a 200 response on an existing post' ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													assert . strictEqual ( response . statusCode ,  200 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												it ( 'should return a Tombstone object' ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													assert . strictEqual ( body . type ,  'Tombstone' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												it ( 'should still retain the existing id and former type' ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													assert . strictEqual ( body . id ,  ` ${ nconf . get ( 'url' ) } /post/ ${ postData . pid } ` ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													assert . strictEqual ( body . formerType ,  'Note' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												it ( 'should still contain contextual information (context, audience, attributedTo)' ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													assert ( [ 'context' ,  'audience' ,  'attributedTo' ] . every ( prop  =>  body . hasOwnProperty ( prop )  &&  body [ prop ] ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-26 11:30:08 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-05 14:12:23 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-03 13:49:27 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									describe ( 'Actor asserton' ,  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-05 11:37:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										describe ( 'happy path' ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											let  uid ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											let  actorUri ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-03 13:49:27 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-04-05 11:37:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											before ( async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												uid  =  utils . generateUUID ( ) . slice ( 0 ,  8 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												actorUri  =  ` https://example.org/user/ ${ uid } ` ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												activitypub . _cache . set ( ` 0; ${ actorUri } ` ,  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													'@context' :  'https://www.w3.org/ns/activitystreams' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													id :  actorUri , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													url :  actorUri , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													type :  'Person' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													name :  'example' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													preferredUsername :  'example' , 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-30 16:59:24 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													inbox :  ` https://example.org/user/ ${ uid } /inbox ` , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													outbox :  ` https://example.org/user/ ${ uid } /outbox ` , 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-05 11:37:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													publicKey :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														id :  ` ${ actorUri } #key ` , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														owner :  actorUri , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														publicKeyPem :  'somekey' , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-03 13:49:27 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-04-05 11:37:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											it ( 'should return true if successfully asserted' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												const  result  =  await  activitypub . actors . assert ( [ actorUri ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert ( result ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											it ( 'should contain a representation of that remote user in the database' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												const  exists  =  await  db . exists ( ` userRemote: ${ actorUri } ` ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert ( exists ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-03 13:49:27 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-04-05 11:37:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												const  userData  =  await  user . getUserData ( actorUri ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert ( userData ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . strictEqual ( userData . uid ,  actorUri ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-03 13:49:27 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-04-05 11:37:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											it ( 'should save the actor\'s publicly accessible URL in the hash as well' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												const  url  =  await  user . getUserField ( actorUri ,  'url' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . strictEqual ( url ,  actorUri ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-03 13:49:27 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-04-05 11:37:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										describe ( 'edge case: loopback handles and uris' ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											let  uid ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											const  userslug  =  utils . generateUUID ( ) . slice ( 0 ,  8 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											before ( async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												uid  =  await  user . create ( {  username :  userslug  } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											it ( 'should return true but not actually assert the handle into the database' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												const  handle  =  ` ${ userslug } @ ${ nconf . get ( 'url_parsed' ) . host } ` ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												const  result  =  await  activitypub . actors . assert ( [ handle ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert ( result ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												const  handleExists  =  await  db . isObjectField ( 'handle:uid' ,  handle ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . strictEqual ( handleExists ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												const  userRemoteHashExists  =  await  db . exists ( ` userRemote: ${ nconf . get ( 'url' ) } /uid/ ${ uid } ` ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . strictEqual ( userRemoteHashExists ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											it ( 'should return true but not actually assert the uri into the database' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												const  uri  =  ` ${ nconf . get ( 'url' ) } /uid/ ${ uid } ` ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												const  result  =  await  activitypub . actors . assert ( [ uri ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert ( result ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												const  userRemoteHashExists  =  await  db . exists ( ` userRemote: ${ uri } ` ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												assert . strictEqual ( userRemoteHashExists ,  false ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-03 13:49:27 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-26 11:30:08 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-05-14 12:13:23 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									describe ( 'ActivityPub' ,  async  ( )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-26 11:30:08 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										let  files ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										before ( async  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											files  =  await  file . walk ( path . resolve ( _ _dirname ,  './activitypub' ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										it ( 'subfolder tests' ,  ( )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											files . forEach ( ( filePath )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												require ( filePath ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-22 23:38:11 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								} ) ;