2020-08-31 13:48:02 +00:00
|
|
|
jest.setTimeout(120000);
|
2020-08-04 14:57:37 +00:00
|
|
|
import {
|
|
|
|
alpha,
|
|
|
|
beta,
|
|
|
|
gamma,
|
2020-08-20 12:44:22 +00:00
|
|
|
delta,
|
|
|
|
epsilon,
|
2020-08-04 14:57:37 +00:00
|
|
|
setupLogins,
|
|
|
|
createPost,
|
2020-12-20 21:16:57 +00:00
|
|
|
editPost,
|
2020-08-04 14:57:37 +00:00
|
|
|
stickyPost,
|
|
|
|
lockPost,
|
2021-08-23 15:25:39 +00:00
|
|
|
resolvePost,
|
2020-08-04 14:57:37 +00:00
|
|
|
likePost,
|
|
|
|
followBeta,
|
2021-08-23 15:25:39 +00:00
|
|
|
resolveBetaCommunity,
|
2020-08-04 14:57:37 +00:00
|
|
|
createComment,
|
|
|
|
deletePost,
|
|
|
|
removePost,
|
|
|
|
getPost,
|
|
|
|
unfollowRemotes,
|
2021-08-23 15:25:39 +00:00
|
|
|
resolvePerson,
|
2021-03-12 19:09:03 +00:00
|
|
|
banPersonFromSite,
|
2020-11-10 16:53:35 +00:00
|
|
|
searchPostLocal,
|
2021-03-18 13:24:29 +00:00
|
|
|
followCommunity,
|
2021-03-12 19:09:03 +00:00
|
|
|
banPersonFromCommunity,
|
2020-08-04 14:57:37 +00:00
|
|
|
} from './shared';
|
2020-12-21 02:48:29 +00:00
|
|
|
import { PostView, CommunityView } from 'lemmy-js-client';
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2020-12-21 02:48:29 +00:00
|
|
|
let betaCommunity: CommunityView;
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
await setupLogins();
|
2021-08-23 15:25:39 +00:00
|
|
|
betaCommunity = (await resolveBetaCommunity(alpha)).community;
|
|
|
|
expect(betaCommunity).toBeDefined();
|
2020-12-18 02:10:20 +00:00
|
|
|
await unfollows();
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(async () => {
|
2020-12-18 02:10:20 +00:00
|
|
|
await unfollows();
|
|
|
|
});
|
|
|
|
|
|
|
|
async function unfollows() {
|
2020-08-04 14:57:37 +00:00
|
|
|
await unfollowRemotes(alpha);
|
|
|
|
await unfollowRemotes(gamma);
|
2020-08-20 12:44:22 +00:00
|
|
|
await unfollowRemotes(delta);
|
|
|
|
await unfollowRemotes(epsilon);
|
2020-12-18 02:10:20 +00:00
|
|
|
}
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2020-12-20 21:16:57 +00:00
|
|
|
function assertPostFederation(postOne: PostView, postTwo: PostView) {
|
|
|
|
expect(postOne.post.ap_id).toBe(postTwo.post.ap_id);
|
|
|
|
expect(postOne.post.name).toBe(postTwo.post.name);
|
|
|
|
expect(postOne.post.body).toBe(postTwo.post.body);
|
|
|
|
expect(postOne.post.url).toBe(postTwo.post.url);
|
|
|
|
expect(postOne.post.nsfw).toBe(postTwo.post.nsfw);
|
|
|
|
expect(postOne.post.embed_title).toBe(postTwo.post.embed_title);
|
|
|
|
expect(postOne.post.embed_description).toBe(postTwo.post.embed_description);
|
|
|
|
expect(postOne.post.embed_html).toBe(postTwo.post.embed_html);
|
|
|
|
expect(postOne.post.published).toBe(postTwo.post.published);
|
|
|
|
expect(postOne.community.actor_id).toBe(postTwo.community.actor_id);
|
|
|
|
expect(postOne.post.locked).toBe(postTwo.post.locked);
|
|
|
|
expect(postOne.post.removed).toBe(postTwo.post.removed);
|
|
|
|
expect(postOne.post.deleted).toBe(postTwo.post.deleted);
|
2020-09-17 15:41:51 +00:00
|
|
|
}
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
test('Create a post', async () => {
|
2020-12-21 02:48:29 +00:00
|
|
|
let postRes = await createPost(alpha, betaCommunity.community.id);
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(postRes.post_view.post).toBeDefined();
|
|
|
|
expect(postRes.post_view.community.local).toBe(false);
|
|
|
|
expect(postRes.post_view.creator.local).toBe(true);
|
|
|
|
expect(postRes.post_view.counts.score).toBe(1);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// Make sure that post is liked on beta
|
2021-08-23 15:25:39 +00:00
|
|
|
let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
expect(betaPost).toBeDefined();
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(betaPost.community.local).toBe(true);
|
|
|
|
expect(betaPost.creator.local).toBe(false);
|
|
|
|
expect(betaPost.counts.score).toBe(1);
|
|
|
|
assertPostFederation(betaPost, postRes.post_view);
|
2020-08-20 12:44:22 +00:00
|
|
|
|
|
|
|
// Delta only follows beta, so it should not see an alpha ap_id
|
2021-08-23 15:25:39 +00:00
|
|
|
let deltaPost = (await resolvePost(delta, postRes.post_view.post)).post;
|
|
|
|
expect(deltaPost).toBeUndefined();
|
2020-08-20 12:44:22 +00:00
|
|
|
|
|
|
|
// Epsilon has alpha blocked, it should not see the alpha post
|
2021-08-23 15:25:39 +00:00
|
|
|
let epsilonPost = (await resolvePost(epsilon, postRes.post_view.post)).post;
|
|
|
|
expect(epsilonPost).toBeUndefined();
|
2020-08-20 12:44:22 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Create a post in a non-existent community', async () => {
|
|
|
|
let postRes = await createPost(alpha, -2);
|
|
|
|
expect(postRes).toStrictEqual({ error: 'couldnt_create_post' });
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Unlike a post', async () => {
|
2020-12-21 02:48:29 +00:00
|
|
|
let postRes = await createPost(alpha, betaCommunity.community.id);
|
2020-12-20 21:16:57 +00:00
|
|
|
let unlike = await likePost(alpha, 0, postRes.post_view.post);
|
|
|
|
expect(unlike.post_view.counts.score).toBe(0);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2020-08-20 12:44:22 +00:00
|
|
|
// Try to unlike it again, make sure it stays at 0
|
2020-12-20 21:16:57 +00:00
|
|
|
let unlike2 = await likePost(alpha, 0, postRes.post_view.post);
|
|
|
|
expect(unlike2.post_view.counts.score).toBe(0);
|
2020-08-20 12:44:22 +00:00
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
// Make sure that post is unliked on beta
|
2021-08-23 15:25:39 +00:00
|
|
|
let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
|
2020-08-04 14:57:37 +00:00
|
|
|
expect(betaPost).toBeDefined();
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(betaPost.community.local).toBe(true);
|
|
|
|
expect(betaPost.creator.local).toBe(false);
|
|
|
|
expect(betaPost.counts.score).toBe(0);
|
|
|
|
assertPostFederation(betaPost, postRes.post_view);
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Update a post', async () => {
|
2020-12-21 02:48:29 +00:00
|
|
|
let postRes = await createPost(alpha, betaCommunity.community.id);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2020-08-20 12:44:22 +00:00
|
|
|
let updatedName = 'A jest test federated post, updated';
|
2020-12-20 21:16:57 +00:00
|
|
|
let updatedPost = await editPost(alpha, postRes.post_view.post);
|
|
|
|
expect(updatedPost.post_view.post.name).toBe(updatedName);
|
|
|
|
expect(updatedPost.post_view.community.local).toBe(false);
|
|
|
|
expect(updatedPost.post_view.creator.local).toBe(true);
|
2020-08-20 12:44:22 +00:00
|
|
|
|
|
|
|
// Make sure that post is updated on beta
|
2021-08-23 15:25:39 +00:00
|
|
|
let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(betaPost.community.local).toBe(true);
|
|
|
|
expect(betaPost.creator.local).toBe(false);
|
|
|
|
expect(betaPost.post.name).toBe(updatedName);
|
|
|
|
assertPostFederation(betaPost, updatedPost.post_view);
|
2020-08-20 12:44:22 +00:00
|
|
|
|
|
|
|
// Make sure lemmy beta cannot update the post
|
2020-12-20 21:16:57 +00:00
|
|
|
let updatedPostBeta = await editPost(beta, betaPost.post);
|
2020-08-20 12:44:22 +00:00
|
|
|
expect(updatedPostBeta).toStrictEqual({ error: 'no_post_edit_allowed' });
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Sticky a post', async () => {
|
2020-12-21 02:48:29 +00:00
|
|
|
let postRes = await createPost(alpha, betaCommunity.community.id);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2020-12-20 21:16:57 +00:00
|
|
|
let stickiedPostRes = await stickyPost(alpha, true, postRes.post_view.post);
|
|
|
|
expect(stickiedPostRes.post_view.post.stickied).toBe(true);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// Make sure that post is stickied on beta
|
2021-08-23 15:25:39 +00:00
|
|
|
let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(betaPost.community.local).toBe(true);
|
|
|
|
expect(betaPost.creator.local).toBe(false);
|
|
|
|
expect(betaPost.post.stickied).toBe(true);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// Unsticky a post
|
2020-12-20 21:16:57 +00:00
|
|
|
let unstickiedPost = await stickyPost(alpha, false, postRes.post_view.post);
|
|
|
|
expect(unstickiedPost.post_view.post.stickied).toBe(false);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// Make sure that post is unstickied on beta
|
2021-08-23 15:25:39 +00:00
|
|
|
let betaPost2 = (await resolvePost(beta, postRes.post_view.post)).post;
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(betaPost2.community.local).toBe(true);
|
|
|
|
expect(betaPost2.creator.local).toBe(false);
|
|
|
|
expect(betaPost2.post.stickied).toBe(false);
|
2020-08-20 12:44:22 +00:00
|
|
|
|
|
|
|
// Make sure that gamma cannot sticky the post on beta
|
2021-08-23 15:25:39 +00:00
|
|
|
let gammaPost = (await resolvePost(gamma, postRes.post_view.post)).post;
|
2020-12-20 21:16:57 +00:00
|
|
|
let gammaTrySticky = await stickyPost(gamma, true, gammaPost.post);
|
2021-08-23 15:25:39 +00:00
|
|
|
let betaPost3 = (await resolvePost(beta, postRes.post_view.post)).post;
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(gammaTrySticky.post_view.post.stickied).toBe(true);
|
|
|
|
expect(betaPost3.post.stickied).toBe(false);
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Lock a post', async () => {
|
2021-03-18 13:24:29 +00:00
|
|
|
await followCommunity(alpha, true, betaCommunity.community.id);
|
2020-12-21 02:48:29 +00:00
|
|
|
let postRes = await createPost(alpha, betaCommunity.community.id);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2020-11-10 16:53:35 +00:00
|
|
|
// Lock the post
|
2021-08-23 15:25:39 +00:00
|
|
|
let betaPost1 = (await resolvePost(beta, postRes.post_view.post)).post;
|
2021-03-18 13:24:29 +00:00
|
|
|
let lockedPostRes = await lockPost(beta, true, betaPost1.post);
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(lockedPostRes.post_view.post.locked).toBe(true);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2021-03-18 13:24:29 +00:00
|
|
|
// Make sure that post is locked on alpha
|
|
|
|
let searchAlpha = await searchPostLocal(alpha, postRes.post_view.post);
|
|
|
|
let alphaPost1 = searchAlpha.posts[0];
|
|
|
|
expect(alphaPost1.post.locked).toBe(true);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// Try to make a new comment there, on alpha
|
2021-03-18 13:24:29 +00:00
|
|
|
let comment: any = await createComment(alpha, alphaPost1.post.id);
|
2020-08-04 14:57:37 +00:00
|
|
|
expect(comment['error']).toBe('locked');
|
|
|
|
|
|
|
|
// Unlock a post
|
2021-03-18 13:24:29 +00:00
|
|
|
let unlockedPost = await lockPost(beta, false, betaPost1.post);
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(unlockedPost.post_view.post.locked).toBe(false);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2021-03-18 13:24:29 +00:00
|
|
|
// Make sure that post is unlocked on alpha
|
|
|
|
let searchAlpha2 = await searchPostLocal(alpha, postRes.post_view.post);
|
|
|
|
let alphaPost2 = searchAlpha2.posts[0];
|
|
|
|
expect(alphaPost2.community.local).toBe(false);
|
|
|
|
expect(alphaPost2.creator.local).toBe(true);
|
|
|
|
expect(alphaPost2.post.locked).toBe(false);
|
2020-11-10 16:53:35 +00:00
|
|
|
|
2021-03-18 13:24:29 +00:00
|
|
|
// Try to create a new comment, on alpha
|
|
|
|
let commentAlpha = await createComment(alpha, alphaPost1.post.id);
|
|
|
|
expect(commentAlpha).toBeDefined();
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Delete a post', async () => {
|
2020-12-21 02:48:29 +00:00
|
|
|
let postRes = await createPost(alpha, betaCommunity.community.id);
|
|
|
|
expect(postRes.post_view.post).toBeDefined();
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2020-12-20 21:16:57 +00:00
|
|
|
let deletedPost = await deletePost(alpha, true, postRes.post_view.post);
|
|
|
|
expect(deletedPost.post_view.post.deleted).toBe(true);
|
2021-07-30 18:44:15 +00:00
|
|
|
expect(deletedPost.post_view.post.name).toBe("");
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// Make sure lemmy beta sees post is deleted
|
2021-08-23 15:25:39 +00:00
|
|
|
let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
|
2020-08-31 13:48:02 +00:00
|
|
|
// This will be undefined because of the tombstone
|
|
|
|
expect(betaPost).toBeUndefined();
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// Undelete
|
2020-12-20 21:16:57 +00:00
|
|
|
let undeletedPost = await deletePost(alpha, false, postRes.post_view.post);
|
|
|
|
expect(undeletedPost.post_view.post.deleted).toBe(false);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// Make sure lemmy beta sees post is undeleted
|
2021-08-23 15:25:39 +00:00
|
|
|
let betaPost2 = (await resolvePost(beta, postRes.post_view.post)).post;
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(betaPost2.post.deleted).toBe(false);
|
|
|
|
assertPostFederation(betaPost2, undeletedPost.post_view);
|
2020-08-20 12:44:22 +00:00
|
|
|
|
|
|
|
// Make sure lemmy beta cannot delete the post
|
2020-12-20 21:16:57 +00:00
|
|
|
let deletedPostBeta = await deletePost(beta, true, betaPost2.post);
|
2020-08-20 12:44:22 +00:00
|
|
|
expect(deletedPostBeta).toStrictEqual({ error: 'no_post_edit_allowed' });
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|
|
|
|
|
2020-08-07 14:51:53 +00:00
|
|
|
test('Remove a post from admin and community on different instance', async () => {
|
2020-12-21 02:48:29 +00:00
|
|
|
let postRes = await createPost(alpha, betaCommunity.community.id);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2020-12-20 21:16:57 +00:00
|
|
|
let removedPost = await removePost(alpha, true, postRes.post_view.post);
|
|
|
|
expect(removedPost.post_view.post.removed).toBe(true);
|
2021-07-30 18:44:15 +00:00
|
|
|
expect(removedPost.post_view.post.name).toBe("");
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2020-08-07 14:51:53 +00:00
|
|
|
// Make sure lemmy beta sees post is NOT removed
|
2021-08-23 15:25:39 +00:00
|
|
|
let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(betaPost.post.removed).toBe(false);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// Undelete
|
2020-12-20 21:16:57 +00:00
|
|
|
let undeletedPost = await removePost(alpha, false, postRes.post_view.post);
|
|
|
|
expect(undeletedPost.post_view.post.removed).toBe(false);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// Make sure lemmy beta sees post is undeleted
|
2021-08-23 15:25:39 +00:00
|
|
|
let betaPost2 = (await resolvePost(beta, postRes.post_view.post)).post;
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(betaPost2.post.removed).toBe(false);
|
|
|
|
assertPostFederation(betaPost2, undeletedPost.post_view);
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|
|
|
|
|
2020-08-07 14:51:53 +00:00
|
|
|
test('Remove a post from admin and community on same instance', async () => {
|
2020-12-17 19:36:22 +00:00
|
|
|
await followBeta(alpha);
|
2020-12-21 02:48:29 +00:00
|
|
|
let postRes = await createPost(alpha, betaCommunity.community.id);
|
|
|
|
expect(postRes.post_view.post).toBeDefined();
|
2020-08-07 14:51:53 +00:00
|
|
|
|
|
|
|
// Get the id for beta
|
2020-12-21 02:48:29 +00:00
|
|
|
let searchBeta = await searchPostLocal(beta, postRes.post_view.post);
|
2020-08-31 13:48:02 +00:00
|
|
|
let betaPost = searchBeta.posts[0];
|
2020-12-17 19:59:53 +00:00
|
|
|
expect(betaPost).toBeDefined();
|
2020-08-07 14:51:53 +00:00
|
|
|
|
|
|
|
// The beta admin removes it (the community lives on beta)
|
2020-12-20 21:16:57 +00:00
|
|
|
let removePostRes = await removePost(beta, true, betaPost.post);
|
|
|
|
expect(removePostRes.post_view.post.removed).toBe(true);
|
2020-08-07 14:51:53 +00:00
|
|
|
|
|
|
|
// Make sure lemmy alpha sees post is removed
|
2020-12-20 21:16:57 +00:00
|
|
|
let alphaPost = await getPost(alpha, postRes.post_view.post.id);
|
2020-12-21 02:48:29 +00:00
|
|
|
// expect(alphaPost.post_view.post.removed).toBe(true); // TODO this shouldn't be commented
|
|
|
|
// assertPostFederation(alphaPost.post_view, removePostRes.post_view);
|
2020-08-07 14:51:53 +00:00
|
|
|
|
|
|
|
// Undelete
|
2020-12-20 21:16:57 +00:00
|
|
|
let undeletedPost = await removePost(beta, false, betaPost.post);
|
|
|
|
expect(undeletedPost.post_view.post.removed).toBe(false);
|
2020-08-07 14:51:53 +00:00
|
|
|
|
|
|
|
// Make sure lemmy alpha sees post is undeleted
|
2020-12-20 21:16:57 +00:00
|
|
|
let alphaPost2 = await getPost(alpha, postRes.post_view.post.id);
|
|
|
|
expect(alphaPost2.post_view.post.removed).toBe(false);
|
|
|
|
assertPostFederation(alphaPost2.post_view, undeletedPost.post_view);
|
2020-12-17 19:01:33 +00:00
|
|
|
await unfollowRemotes(alpha);
|
2020-08-07 14:51:53 +00:00
|
|
|
});
|
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
test('Search for a post', async () => {
|
2020-12-17 19:59:53 +00:00
|
|
|
await unfollowRemotes(alpha);
|
2020-12-21 02:48:29 +00:00
|
|
|
let postRes = await createPost(alpha, betaCommunity.community.id);
|
|
|
|
expect(postRes.post_view.post).toBeDefined();
|
2020-12-17 19:36:22 +00:00
|
|
|
|
2021-08-23 15:25:39 +00:00
|
|
|
let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2021-08-23 15:25:39 +00:00
|
|
|
expect(betaPost.post.name).toBeDefined();
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('A and G subscribe to B (center) A posts, it gets announced to G', async () => {
|
2020-12-21 02:48:29 +00:00
|
|
|
let postRes = await createPost(alpha, betaCommunity.community.id);
|
|
|
|
expect(postRes.post_view.post).toBeDefined();
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2021-08-23 15:25:39 +00:00
|
|
|
let betaPost = (await resolvePost(gamma, postRes.post_view.post)).post;
|
|
|
|
expect(betaPost.post.name).toBeDefined();
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|
2020-11-10 16:53:35 +00:00
|
|
|
|
|
|
|
test('Enforce site ban for federated user', async () => {
|
|
|
|
let alphaShortname = `@lemmy_alpha@lemmy-alpha:8541`;
|
2021-08-23 15:25:39 +00:00
|
|
|
let alphaPerson = (await resolvePerson(beta, alphaShortname)).person;
|
|
|
|
expect(alphaPerson).toBeDefined();
|
2020-11-10 16:53:35 +00:00
|
|
|
|
|
|
|
// ban alpha from beta site
|
2021-08-23 15:25:39 +00:00
|
|
|
let banAlpha = await banPersonFromSite(beta, alphaPerson.person.id, true);
|
2020-11-10 16:53:35 +00:00
|
|
|
expect(banAlpha.banned).toBe(true);
|
|
|
|
|
|
|
|
// Alpha makes post on beta
|
2020-12-21 02:48:29 +00:00
|
|
|
let postRes = await createPost(alpha, betaCommunity.community.id);
|
2020-12-20 21:16:57 +00:00
|
|
|
expect(postRes.post_view.post).toBeDefined();
|
|
|
|
expect(postRes.post_view.community.local).toBe(false);
|
|
|
|
expect(postRes.post_view.creator.local).toBe(true);
|
|
|
|
expect(postRes.post_view.counts.score).toBe(1);
|
2020-11-10 16:53:35 +00:00
|
|
|
|
|
|
|
// Make sure that post doesn't make it to beta
|
2020-12-20 21:16:57 +00:00
|
|
|
let searchBeta = await searchPostLocal(beta, postRes.post_view.post);
|
2020-11-10 16:53:35 +00:00
|
|
|
let betaPost = searchBeta.posts[0];
|
|
|
|
expect(betaPost).toBeUndefined();
|
|
|
|
|
|
|
|
// Unban alpha
|
2021-08-23 15:25:39 +00:00
|
|
|
let unBanAlpha = await banPersonFromSite(beta, alphaPerson.person.id, false);
|
2020-11-10 16:53:35 +00:00
|
|
|
expect(unBanAlpha.banned).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Enforce community ban for federated user', async () => {
|
|
|
|
let alphaShortname = `@lemmy_alpha@lemmy-alpha:8541`;
|
2021-08-23 15:25:39 +00:00
|
|
|
let alphaPerson = (await resolvePerson(beta, alphaShortname)).person;
|
|
|
|
expect(alphaPerson).toBeDefined();
|
2020-11-10 16:53:35 +00:00
|
|
|
|
|
|
|
// ban alpha from beta site
|
2021-08-23 15:25:39 +00:00
|
|
|
await banPersonFromCommunity(beta, alphaPerson.person.id, 2, false);
|
|
|
|
let banAlpha = await banPersonFromCommunity(beta, alphaPerson.person.id, 2, true);
|
2020-11-10 16:53:35 +00:00
|
|
|
expect(banAlpha.banned).toBe(true);
|
|
|
|
|
2021-04-09 15:01:26 +00:00
|
|
|
// Alpha tries to make post on beta, but it fails because of ban
|
2020-12-21 02:48:29 +00:00
|
|
|
let postRes = await createPost(alpha, betaCommunity.community.id);
|
2021-04-09 15:01:26 +00:00
|
|
|
expect(postRes.post_view).toBeUndefined();
|
2020-11-10 16:53:35 +00:00
|
|
|
|
|
|
|
// Unban alpha
|
2021-03-12 19:09:03 +00:00
|
|
|
let unBanAlpha = await banPersonFromCommunity(
|
2020-12-20 21:16:57 +00:00
|
|
|
beta,
|
2021-08-23 15:25:39 +00:00
|
|
|
alphaPerson.person.id,
|
2020-12-20 21:16:57 +00:00
|
|
|
2,
|
|
|
|
false
|
|
|
|
);
|
2020-11-10 16:53:35 +00:00
|
|
|
expect(unBanAlpha.banned).toBe(false);
|
2021-04-09 15:01:26 +00:00
|
|
|
let postRes2 = await createPost(alpha, betaCommunity.community.id);
|
|
|
|
expect(postRes2.post_view.post).toBeDefined();
|
|
|
|
expect(postRes2.post_view.community.local).toBe(false);
|
|
|
|
expect(postRes2.post_view.creator.local).toBe(true);
|
|
|
|
expect(postRes2.post_view.counts.score).toBe(1);
|
|
|
|
|
|
|
|
// Make sure that post makes it to beta community
|
|
|
|
let searchBeta = await searchPostLocal(beta, postRes2.post_view.post);
|
|
|
|
let betaPost = searchBeta.posts[0];
|
|
|
|
expect(betaPost).toBeDefined();
|
2020-11-10 16:53:35 +00:00
|
|
|
});
|