@ -23,7 +23,6 @@ import {
unfollowRemotes ,
resolvePerson ,
banPersonFromSite ,
searchPostLocal ,
followCommunity ,
banPersonFromCommunity ,
reportPost ,
@ -38,10 +37,9 @@ import {
alphaUrl ,
loginUser ,
createCommunity ,
getPosts ,
} from "./shared" ;
import { PostView } from "lemmy-js-client/dist/types/PostView" ;
import { EditSite , ListingType, ResolveObject } from "lemmy-js-client" ;
import { EditSite , ResolveObject } from "lemmy-js-client" ;
let betaCommunity : CommunityView | undefined ;
@ -239,12 +237,14 @@ test("Collection of featured posts gets federated", async () => {
beta ,
community . community_view . community . actor_id ,
) ;
expect ( betaCommunity ) . toBeDefined ( ) ;
const betaPost = await waitForPost (
beta ,
post . post_view . post ,
post = > post ? . post . featured_community === true ,
) ;
expect ( betaPost ) . toBeDefined ( ) ;
} ) ;
test ( "Lock a post" , async ( ) = > {
@ -428,30 +428,34 @@ test("Search for a post", async () => {
expect ( betaPost ? . post . name ) . toBeDefined ( ) ;
} ) ;
test ( "Enforce site ban f or federated user", async ( ) = > {
test ( "Enforce site ban f ederation for local user", async ( ) = > {
if ( ! betaCommunity ) {
throw "Missing beta community" ;
}
// create a test user
let alpha _user = await registerUser ( alpha , alphaUrl ) ;
let alphaUserPerson = ( await getSite ( alpha _user ) ) . my_user ? . local_user_view
let alpha UserHttp = await registerUser ( alpha , alphaUrl ) ;
let alphaUserPerson = ( await getSite ( alpha UserHttp ) ) . my_user ? . local_user_view
. person ;
let alphaUserActorId = alphaUserPerson ? . actor_id ;
if ( ! alphaUserActorId ) {
throw "Missing alpha user actor id" ;
}
expect ( alphaUserActorId ) . toBeDefined ( ) ;
let alphaPerson = ( await resolvePerson ( alpha_user , alphaUserActorId ! ) ) . person ;
await followBeta ( alphaUserHttp ) ;
let alphaPerson = ( await resolvePerson ( alphaUserHttp , alphaUserActorId ! ) )
. person ;
if ( ! alphaPerson ) {
throw "Missing alpha person" ;
}
expect ( alphaPerson ) . toBeDefined ( ) ;
// alpha makes post in beta community, it federates to beta instance
let postRes1 = await createPost ( alpha _user , betaCommunity . community . id ) ;
let postRes1 = await createPost ( alpha UserHttp , betaCommunity . community . id ) ;
let searchBeta1 = await waitForPost ( beta , postRes1 . post_view . post ) ;
// ban alpha from its instance
// ban alpha from its own instance
let banAlpha = await banPersonFromSite (
alpha ,
alphaPerson . person . id ,
@ -468,10 +472,11 @@ test("Enforce site ban for federated user", async () => {
expect ( alphaUserOnBeta1 . person ? . person . banned ) . toBe ( true ) ;
// existing alpha post should be removed on beta
await waitUntil (
let betaBanRes = await waitUntil (
( ) = > getPost ( beta , searchBeta1 . post . id ) ,
s = > s . post_view . post . removed ,
) ;
expect ( betaBanRes . post_view . post . removed ) . toBe ( true ) ;
// Unban alpha
let unBanAlpha = await banPersonFromSite (
@ -487,21 +492,84 @@ test("Enforce site ban for federated user", async () => {
throw "Missing alpha person" ;
}
let newAlphaUserJwt = await loginUser ( alpha , alphaUserPerson . name ) ;
alpha _user . setHeaders ( {
alpha UserHttp . setHeaders ( {
Authorization : "Bearer " + newAlphaUserJwt . jwt ? ? "" ,
} ) ;
// alpha makes new post in beta community, it federates
let postRes2 = await createPost ( alpha _user , betaCommunity ! . community . id ) ;
let postRes2 = await createPost ( alpha UserHttp , betaCommunity ! . community . id ) ;
await waitForPost ( beta , postRes2 . post_view . post ) ;
await unfollowRemotes ( alpha ) ;
} ) ;
test ( "Enforce site ban federation for federated user" , async ( ) = > {
if ( ! betaCommunity ) {
throw "Missing beta community" ;
}
// create a test user
let alphaUserHttp = await registerUser ( alpha , alphaUrl ) ;
let alphaUserPerson = ( await getSite ( alphaUserHttp ) ) . my_user ? . local_user_view
. person ;
let alphaUserActorId = alphaUserPerson ? . actor_id ;
if ( ! alphaUserActorId ) {
throw "Missing alpha user actor id" ;
}
expect ( alphaUserActorId ) . toBeDefined ( ) ;
await followBeta ( alphaUserHttp ) ;
let alphaUserOnBeta2 = await resolvePerson ( beta , alphaUserActorId ! ) ;
expect ( alphaUserOnBeta2 . person ? . person . banned ) . toBe ( false ) ;
if ( ! alphaUserOnBeta2 . person ) {
throw "Missing alpha person" ;
}
// alpha makes post in beta community, it federates to beta instance
let postRes1 = await createPost ( alphaUserHttp , betaCommunity . community . id ) ;
let searchBeta1 = await waitForPost ( beta , postRes1 . post_view . post ) ;
expect ( searchBeta1 . post ) . toBeDefined ( ) ;
// Now ban and remove their data from beta
let banAlphaOnBeta = await banPersonFromSite (
beta ,
alphaUserOnBeta2 . person . person . id ,
true ,
true ,
) ;
expect ( banAlphaOnBeta . banned ) . toBe ( true ) ;
// The beta site ban should NOT be federated to alpha
let alphaPerson2 = ( await getSite ( alphaUserHttp ) ) . my_user ! . local_user_view
. person ;
expect ( alphaPerson2 . banned ) . toBe ( false ) ;
// existing alpha post should be removed on beta
let betaBanRes = await waitUntil (
( ) = > getPost ( beta , searchBeta1 . post . id ) ,
s = > s . post_view . post . removed ,
) ;
expect ( betaBanRes . post_view . post . removed ) . toBe ( true ) ;
// existing alpha's post to the beta community should be removed on alpha
let alphaPostAfterRemoveOnBeta = await waitUntil (
( ) = > getPost ( alpha , postRes1 . post_view . post . id ) ,
s = > s . post_view . post . removed ,
) ;
expect ( betaBanRes . post_view . post . removed ) . toBe ( true ) ;
expect ( alphaPostAfterRemoveOnBeta . post_view . post . removed ) . toBe ( true ) ;
expect (
alphaPostAfterRemoveOnBeta . post_view . creator_banned_from_community ,
) . toBe ( true ) ;
await unfollowRemotes ( alpha ) ;
} ) ;
test . skip ( "Enforce community ban for federated user" , async ( ) = > {
test ("Enforce community ban for federated user" , async ( ) = > {
if ( ! betaCommunity ) {
throw "Missing beta community" ;
}
await followBeta ( alpha ) ;
let alphaShortname = ` @lemmy_alpha@lemmy-alpha:8541 ` ;
let alphaPerson = ( await resolvePerson ( beta , alphaShortname ) ) . person ;
if ( ! alphaPerson ) {
@ -511,38 +579,46 @@ test.skip("Enforce community ban for federated user", async () => {
// make a post in beta, it goes through
let postRes1 = await createPost ( alpha , betaCommunity . community . id ) ;
let searchBeta1 = await searchPostLocal ( beta , postRes1 . post_view . post ) ;
expect ( searchBeta1 . post s[ 0 ] ) . toBeDefined ( ) ;
let searchBeta1 = await waitForPost ( beta , postRes1 . post_view . post ) ;
expect ( searchBeta1 . post ) . toBeDefined ( ) ;
// ban alpha from beta community
let banAlpha = await banPersonFromCommunity (
beta ,
alphaPerson . person . id ,
2 ,
searchBeta1 . community . id ,
true ,
true ,
) ;
expect ( banAlpha . banned ) . toBe ( true ) ;
// ensure that the post by alpha got removed
await expect ( getPost ( alpha , searchBeta1 . posts [ 0 ] . post . id ) ) . rejects . toBe (
Error ( "unknown" ) ,
let removePostRes = await waitUntil (
( ) = > getPost ( alpha , postRes1 . post_view . post . id ) ,
s = > s . post_view . post . removed ,
) ;
expect ( removePostRes . post_view . post . removed ) . toBe ( true ) ;
expect ( removePostRes . post_view . creator_banned_from_community ) . toBe ( true ) ;
expect ( removePostRes . community_view . banned_from_community ) . toBe ( true ) ;
// Alpha tries to make post on beta, but it fails because of ban
await expect ( createPost ( alpha , betaCommunity . community . id ) ) . rejects . toBe (
Error ( "banned_from_community" ) ,
) ;
await expect (
createPost ( alpha , betaCommunity . community . id ) ,
) .rejects . toStrictEqual ( Error ( "banned_from_community" ) ) ;
// Unban alpha
let unBanAlpha = await banPersonFromCommunity (
beta ,
alphaPerson . person . id ,
2 ,
searchBeta1 . community . id ,
false ,
false ,
) ;
expect ( unBanAlpha . banned ) . toBe ( false ) ;
// Need to re-follow the community
await followBeta ( alpha ) ;
let postRes3 = await createPost ( alpha , betaCommunity . community . id ) ;
expect ( postRes3 . post_view . post ) . toBeDefined ( ) ;
expect ( postRes3 . post_view . community . local ) . toBe ( false ) ;
@ -550,19 +626,25 @@ test.skip("Enforce community ban for federated user", async () => {
expect ( postRes3 . post_view . counts . score ) . toBe ( 1 ) ;
// Make sure that post makes it to beta community
let searchBeta2 = await searchPostLocal ( beta , postRes3 . post_view . post ) ;
expect ( searchBeta2 . posts [ 0 ] ) . toBeDefined ( ) ;
let postRes4 = await waitForPost ( beta , postRes3 . post_view . post ) ;
expect ( postRes4 . post ) . toBeDefined ( ) ;
expect ( postRes4 . creator_banned_from_community ) . toBe ( false ) ;
await unfollowRemotes ( alpha ) ;
} ) ;
test ( "A and G subscribe to B (center) A posts, it gets announced to G" , async ( ) = > {
if ( ! betaCommunity ) {
throw "Missing beta community" ;
}
await followBeta ( alpha ) ;
let postRes = await createPost ( alpha , betaCommunity . community . id ) ;
expect ( postRes . post_view . post ) . toBeDefined ( ) ;
let betaPost = ( await resolvePost ( gamma , postRes . post_view . post ) ) . post ;
expect ( betaPost ? . post . name ) . toBeDefined ( ) ;
await unfollowRemotes ( alpha ) ;
} ) ;
test ( "Report a post" , async ( ) = > {
@ -571,6 +653,7 @@ test("Report a post", async () => {
if ( ! betaCommunity ) {
throw "Missing beta community" ;
}
await followBeta ( alpha ) ;
let postRes = await createPost ( beta , betaCommunity . community . id ) ;
expect ( postRes . post_view . post ) . toBeDefined ( ) ;
@ -598,9 +681,11 @@ test("Report a post", async () => {
expect ( betaReport . original_post_url ) . toBe ( alphaReport . original_post_url ) ;
expect ( betaReport . original_post_body ) . toBe ( alphaReport . original_post_body ) ;
expect ( betaReport . reason ) . toBe ( alphaReport . reason ) ;
await unfollowRemotes ( alpha ) ;
} ) ;
test ( "Fetch post via redirect" , async ( ) = > {
await followBeta ( alpha ) ;
let alphaPost = await createPost ( alpha , betaCommunity ! . community . id ) ;
expect ( alphaPost . post_view . post ) . toBeDefined ( ) ;
// Make sure that post is liked on beta
@ -621,4 +706,5 @@ test("Fetch post via redirect", async () => {
let gammaPost = await gamma . resolveObject ( form ) ;
expect ( gammaPost ) . toBeDefined ( ) ;
expect ( gammaPost . post ? . post . ap_id ) . toBe ( alphaPost . post_view . post . ap_id ) ;
await unfollowRemotes ( alpha ) ;
} ) ;