@@ -411,13 +411,35 @@ describe('v1 - mod', { sequential: true }, () => {
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+ const body : typeof Posts . AuthCreateBody . static = {
425+ address : walletA . publicKey ,
426+ } ;
427+
428+ const response = ( await post ( `auth-create` , body , 'READ' ) ) as { status : 200 ; id : number ; message : string } ;
429+ assert . isOk ( response ?. status === 200 , 'response was not okay' ) ;
430+
431+ const signData = await signADR36Document ( walletA . mnemonic , response . message ) ;
432+ const verifyBody : typeof Posts . AuthBody . static = {
433+ id : response . id ,
434+ ...signData . signature ,
435+ } ;
436+
437+ const responseVerify = ( await post ( `auth` , verifyBody , 'READ' ) ) as { status : 200 ; bearer : string } ;
438+ assert . isOk ( responseVerify ?. status === 200 , 'response was not verified and confirmed okay' ) ;
439+ assert . isOk ( responseVerify . bearer . length >= 1 , 'bearer was not passed back' ) ;
440+ bearerToken = responseVerify . bearer ;
441+ } ) ;
442+
421443 it ( 'POST - /post' , async ( ) => {
422444 const body : typeof Posts . PostBody . static = {
423445 from : addressUserA ,
@@ -431,6 +453,19 @@ describe('v1 - mod', { sequential: true }, () => {
431453 assert . isOk ( response ?. status === 200 , 'response was not okay' ) ;
432454 } ) ;
433455
456+ it ( 'POST - /mod/post-remove without autorization' , async ( ) => {
457+ const body : typeof Posts . ModRemovePostBody . static = {
458+ mod_address : addressModerator ,
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 } ` ,
@@ -446,7 +481,7 @@ describe('v1 - mod', { sequential: true }, () => {
446481 reason : 'spam' ,
447482 } ;
448483
449- const replyResponse = await post ( `mod/post-remove` , body ) ;
484+ const replyResponse = await post ( `mod/post-remove` , body , 'WRITE' , bearerToken ) ;
450485 assert . isOk ( replyResponse ?. status === 404 , `expected moderator was not found` ) ;
451486
452487 const postsResponse = await get < {
@@ -488,7 +523,7 @@ describe('v1 - mod', { sequential: true }, () => {
488523 reason : 'spam' ,
489524 } ;
490525
491- const replyResponse = await post ( `mod/post-remove` , body ) ;
526+ const replyResponse = await post ( `mod/post-remove` , body , 'WRITE' , bearerToken ) ;
492527 assert . isOk ( replyResponse ?. status === 200 , `response was not okay, got ${ JSON . stringify ( replyResponse ) } ` ) ;
493528
494529 const postsResponse = await get < {
@@ -517,7 +552,7 @@ describe('v1 - mod', { sequential: true }, () => {
517552 reason : 'spam' ,
518553 } ;
519554
520- const replyResponse = await post ( `mod/post-restore` , body ) ;
555+ const replyResponse = await post ( `mod/post-restore` , body , 'WRITE' , bearerToken ) ;
521556 assert . isOk ( replyResponse ?. status === 200 , `response was not okay, got ${ JSON . stringify ( replyResponse ) } ` ) ;
522557
523558 const postsResponse = await get < {
@@ -546,7 +581,7 @@ describe('v1 - mod', { sequential: true }, () => {
546581 post_hash : postHash ,
547582 } ;
548583
549- const userRemoveResponse = await post ( `post-remove` , body ) ;
584+ const userRemoveResponse = await post ( `post-remove` , body , 'WRITE' , bearerToken ) ;
550585 assert . isOk ( userRemoveResponse ?. status === 200 , 'response was not okay' ) ;
551586
552587 // MOD tries to restore post
@@ -585,7 +620,7 @@ describe('v1 - mod', { sequential: true }, () => {
585620 reason : 'user too political' ,
586621 } ;
587622
588- const userBanResponse = await post ( `mod/ban` , body ) ;
623+ const userBanResponse = await post ( `mod/ban` , body , 'WRITE' , bearerToken ) ;
589624 assert . isOk ( userBanResponse ?. status === 200 , `response was not okay ${ JSON . stringify ( userBanResponse ) } ` ) ;
590625
591626 // post from user should be all hidden
@@ -617,7 +652,7 @@ describe('v1 - mod', { sequential: true }, () => {
617652 timestamp : '2025-04-16T19:46:42Z' ,
618653 } ;
619654
620- const response = await post ( `post` , body ) ;
655+ const response = await post ( `post` , body , 'WRITE' , bearerToken ) ;
621656 assert . isOk ( response ?. status === 200 , 'response was not okay' ) ;
622657
623658 // Even new post should be hidden
@@ -649,7 +684,7 @@ describe('v1 - mod', { sequential: true }, () => {
649684 reason : 'user too political' ,
650685 } ;
651686
652- const userBanResponse = await post ( `mod/unban` , body ) ;
687+ const userBanResponse = await post ( `mod/unban` , body , 'WRITE' , bearerToken ) ;
653688 assert . isOk ( userBanResponse ?. status === 200 , `response was not okay ${ JSON . stringify ( userBanResponse ) } ` ) ;
654689
655690 // Totally user should have 2 post as one was deleted by itself (including the one posted while banned)
@@ -682,7 +717,7 @@ describe('v1 - mod', { sequential: true }, () => {
682717 timestamp : '2025-04-16T19:46:42Z' ,
683718 } ;
684719
685- const response = await post ( `post` , body ) ;
720+ const response = await post ( `post` , body , 'WRITE' , bearerToken ) ;
686721 assert . isOk ( response ?. status === 200 , 'response was not okay' ) ;
687722
688723 // Even new post should be hidden
0 commit comments