@@ -406,18 +406,41 @@ describe('v1', { sequential: true }, () => {
406406
407407describe ( 'v1 - mod' , { sequential : true } , ( ) => {
408408 const addressUserA = getAtomOneAddress ( ) ;
409- const addressModerator = getAtomOneAddress ( ) ;
409+ let addressModerator = getAtomOneAddress ( ) ;
410410 const genericPostMessage
411411 = 'hello world, this is a really intereresting post $@!($)@!()@!$21,4214,12,42142,14,12,421,' ;
412412 const postHash = getRandomHash ( ) ;
413413 const secondPostHash = getRandomHash ( ) ;
414+ let bearerToken : string ;
414415
415416 it ( 'EMPTY ALL TABLES' , async ( ) => {
416417 for ( const tableName of tables ) {
417418 await getDatabase ( ) . execute ( sql `TRUNCATE TABLE ${ sql . raw ( tableName ) } ;` ) ;
418419 }
419420 } ) ;
420421
422+ it ( 'POST mod obtain bearer token' , async ( ) => {
423+ const walletA = await createWallet ( ) ;
424+ addressModerator = walletA . publicKey ;
425+ const body : typeof Posts . AuthCreateBody . static = {
426+ address : walletA . publicKey ,
427+ } ;
428+
429+ const response = ( await post ( `auth-create` , body , 'READ' ) ) as { status : 200 ; id : number ; message : string } ;
430+ assert . isOk ( response ?. status === 200 , 'response was not okay' ) ;
431+
432+ const signData = await signADR36Document ( walletA . mnemonic , response . message ) ;
433+ const verifyBody : typeof Posts . AuthBody . static = {
434+ id : response . id ,
435+ ...signData . signature ,
436+ } ;
437+
438+ const responseVerify = ( await post ( `auth` , verifyBody , 'READ' ) ) as { status : 200 ; bearer : string } ;
439+ assert . isOk ( responseVerify ?. status === 200 , 'response was not verified and confirmed okay' ) ;
440+ assert . isOk ( responseVerify . bearer . length >= 1 , 'bearer was not passed back' ) ;
441+ bearerToken = responseVerify . bearer ;
442+ } ) ;
443+
421444 it ( 'POST - /post' , async ( ) => {
422445 const body : typeof Posts . PostBody . static = {
423446 from : addressUserA ,
@@ -431,6 +454,18 @@ describe('v1 - mod', { sequential: true }, () => {
431454 assert . isOk ( response ?. status === 200 , 'response was not okay' ) ;
432455 } ) ;
433456
457+ it ( 'POST - /mod/post-remove without autorization' , async ( ) => {
458+ const body : typeof Posts . ModRemovePostBody . static = {
459+ hash : getRandomHash ( ) ,
460+ timestamp : '2025-04-16T19:46:42Z' ,
461+ post_hash : postHash ,
462+ reason : 'spam' ,
463+ } ;
464+
465+ const replyResponse = await post ( `mod/post-remove` , body ) ;
466+ assert . isOk ( replyResponse ?. status === 401 , `expected unauthorized, got ${ JSON . stringify ( replyResponse ) } ` ) ;
467+ } ) ;
468+
434469 it ( 'POST - /mod/post-remove moderator does not exists' , async ( ) => {
435470 const response = await get < { status : number ; rows : { hash : string ; author : string ; message : string } [ ] } > (
436471 `posts?address=${ addressUserA } ` ,
@@ -439,14 +474,13 @@ describe('v1 - mod', { sequential: true }, () => {
439474 assert . isOk ( Array . isArray ( response . rows ) && response . rows . length >= 1 , 'feed result was not an array type' ) ;
440475
441476 const body : typeof Posts . ModRemovePostBody . static = {
442- mod_address : addressModerator ,
443477 hash : getRandomHash ( ) ,
444478 timestamp : '2025-04-16T19:46:42Z' ,
445479 post_hash : response . rows [ 0 ] . hash ,
446480 reason : 'spam' ,
447481 } ;
448482
449- const replyResponse = await post ( `mod/post-remove` , body ) ;
483+ const replyResponse = await post ( `mod/post-remove` , body , 'WRITE' , bearerToken ) ;
450484 assert . isOk ( replyResponse ?. status === 404 , `expected moderator was not found` ) ;
451485
452486 const postsResponse = await get < {
@@ -481,14 +515,13 @@ describe('v1 - mod', { sequential: true }, () => {
481515 assert . isOk ( Array . isArray ( response . rows ) && response . rows . length >= 1 , 'feed result was not an array type' ) ;
482516
483517 const body : typeof Posts . ModRemovePostBody . static = {
484- mod_address : addressModerator ,
485518 hash : getRandomHash ( ) ,
486519 timestamp : '2025-04-16T19:46:42Z' ,
487520 post_hash : response . rows [ 0 ] . hash ,
488521 reason : 'spam' ,
489522 } ;
490523
491- const replyResponse = await post ( `mod/post-remove` , body ) ;
524+ const replyResponse = await post ( `mod/post-remove` , body , 'WRITE' , bearerToken ) ;
492525 assert . isOk ( replyResponse ?. status === 200 , `response was not okay, got ${ JSON . stringify ( replyResponse ) } ` ) ;
493526
494527 const postsResponse = await get < {
@@ -510,14 +543,13 @@ describe('v1 - mod', { sequential: true }, () => {
510543
511544 it ( 'POST - /mod/post-restore' , async ( ) => {
512545 const body : typeof Posts . ModRemovePostBody . static = {
513- mod_address : addressModerator ,
514546 hash : getRandomHash ( ) ,
515547 timestamp : '2025-04-16T19:46:42Z' ,
516548 post_hash : postHash ,
517549 reason : 'spam' ,
518550 } ;
519551
520- const replyResponse = await post ( `mod/post-restore` , body ) ;
552+ const replyResponse = await post ( `mod/post-restore` , body , 'WRITE' , bearerToken ) ;
521553 assert . isOk ( replyResponse ?. status === 200 , `response was not okay, got ${ JSON . stringify ( replyResponse ) } ` ) ;
522554
523555 const postsResponse = await get < {
@@ -546,12 +578,11 @@ describe('v1 - mod', { sequential: true }, () => {
546578 post_hash : postHash ,
547579 } ;
548580
549- const userRemoveResponse = await post ( `post-remove` , body ) ;
581+ const userRemoveResponse = await post ( `post-remove` , body , 'WRITE' , bearerToken ) ;
550582 assert . isOk ( userRemoveResponse ?. status === 200 , 'response was not okay' ) ;
551583
552584 // MOD tries to restore post
553585 const bodymod : typeof Posts . ModRemovePostBody . static = {
554- mod_address : addressModerator ,
555586 hash : getRandomHash ( ) ,
556587 timestamp : '2025-04-16T19:46:42Z' ,
557588 post_hash : postHash ,
@@ -578,14 +609,13 @@ describe('v1 - mod', { sequential: true }, () => {
578609 it ( 'POST - /mod/ban user banned deletes posts' , async ( ) => {
579610 // moderator bans user
580611 const body : typeof Posts . ModBanBody . static = {
581- mod_address : addressModerator ,
582612 hash : getRandomHash ( ) ,
583613 timestamp : '2025-04-16T19:46:42Z' ,
584614 user_address : addressUserA ,
585615 reason : 'user too political' ,
586616 } ;
587617
588- const userBanResponse = await post ( `mod/ban` , body ) ;
618+ const userBanResponse = await post ( `mod/ban` , body , 'WRITE' , bearerToken ) ;
589619 assert . isOk ( userBanResponse ?. status === 200 , `response was not okay ${ JSON . stringify ( userBanResponse ) } ` ) ;
590620
591621 // post from user should be all hidden
@@ -617,7 +647,7 @@ describe('v1 - mod', { sequential: true }, () => {
617647 timestamp : '2025-04-16T19:46:42Z' ,
618648 } ;
619649
620- const response = await post ( `post` , body ) ;
650+ const response = await post ( `post` , body , 'WRITE' , bearerToken ) ;
621651 assert . isOk ( response ?. status === 200 , 'response was not okay' ) ;
622652
623653 // Even new post should be hidden
@@ -642,14 +672,13 @@ describe('v1 - mod', { sequential: true }, () => {
642672
643673 it ( 'POST - unban restore all posts but user deleted ones' , async ( ) => {
644674 const body : typeof Posts . ModBanBody . static = {
645- mod_address : addressModerator ,
646675 hash : getRandomHash ( ) ,
647676 timestamp : '2025-04-16T19:46:42Z' ,
648677 user_address : addressUserA ,
649678 reason : 'user too political' ,
650679 } ;
651680
652- const userBanResponse = await post ( `mod/unban` , body ) ;
681+ const userBanResponse = await post ( `mod/unban` , body , 'WRITE' , bearerToken ) ;
653682 assert . isOk ( userBanResponse ?. status === 200 , `response was not okay ${ JSON . stringify ( userBanResponse ) } ` ) ;
654683
655684 // Totally user should have 2 post as one was deleted by itself (including the one posted while banned)
@@ -682,7 +711,7 @@ describe('v1 - mod', { sequential: true }, () => {
682711 timestamp : '2025-04-16T19:46:42Z' ,
683712 } ;
684713
685- const response = await post ( `post` , body ) ;
714+ const response = await post ( `post` , body , 'WRITE' , bearerToken ) ;
686715 assert . isOk ( response ?. status === 200 , 'response was not okay' ) ;
687716
688717 // Even new post should be hidden
0 commit comments