+test("Enforce site ban for federated user", async () => {
+ if (!betaCommunity) {
+ throw "Missing beta community";
+ }
+ // create a test user
+ let alphaUserJwt = await registerUser(alpha);
+ expect(alphaUserJwt).toBeDefined();
+ let alpha_user: API = {
+ client: alpha.client,
+ auth: alphaUserJwt.jwt ?? "",
+ };
+ let alphaUserActorId = (await getSite(alpha_user)).my_user?.local_user_view
+ .person.actor_id;
+ if (!alphaUserActorId) {
+ throw "Missing alpha user actor id";
+ }
+ expect(alphaUserActorId).toBeDefined();
+ let alphaPerson = (await resolvePerson(alpha_user, 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 searchBeta1 = await searchPostLocal(beta, postRes1.post_view.post);
+ expect(searchBeta1.posts[0]).toBeDefined();
+
+ // ban alpha from its instance
+ let banAlpha = await banPersonFromSite(
+ alpha,
+ alphaPerson.person.id,
+ true,
+ true,
+ );
+ expect(banAlpha.banned).toBe(true);
+
+ // alpha ban should be federated to beta
+ let alphaUserOnBeta1 = await resolvePerson(beta, alphaUserActorId);
+ expect(alphaUserOnBeta1.person?.person.banned).toBe(true);
+
+ // existing alpha post should be removed on beta
+ let searchBeta2 = await getPost(beta, searchBeta1.posts[0].post.id);
+ expect(searchBeta2.post_view.post.removed).toBe(true);
+
+ // Unban alpha
+ let unBanAlpha = await banPersonFromSite(
+ alpha,
+ alphaPerson.person.id,
+ false,
+ false,
+ );
+ expect(unBanAlpha.banned).toBe(false);
+
+ // alpha makes new post in beta community, it federates
+ let postRes2 = await createPost(alpha_user, betaCommunity.community.id);
+ let searchBeta3 = await searchPostLocal(beta, postRes2.post_view.post);
+ expect(searchBeta3.posts[0]).toBeDefined();
+
+ let alphaUserOnBeta2 = await resolvePerson(beta, alphaUserActorId);
+ expect(alphaUserOnBeta2.person?.person.banned).toBe(false);
+});
+
+test.skip("Enforce community ban for federated user", async () => {
+ if (!betaCommunity) {
+ throw "Missing beta community";
+ }
+ let alphaShortname = `@lemmy_alpha@lemmy-alpha:8541`;
+ let alphaPerson = (await resolvePerson(beta, alphaShortname)).person;
+ if (!alphaPerson) {
+ throw "Missing alpha person";
+ }
+ expect(alphaPerson).toBeDefined();
+
+ // 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.posts[0]).toBeDefined();
+
+ // ban alpha from beta community
+ let banAlpha = await banPersonFromCommunity(
+ beta,
+ alphaPerson.person.id,
+ 2,
+ 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(
+ "unknown",
+ );
+
+ // Alpha tries to make post on beta, but it fails because of ban
+ await expect(createPost(alpha, betaCommunity.community.id)).rejects.toBe(
+ "banned_from_community",
+ );
+
+ // Unban alpha
+ let unBanAlpha = await banPersonFromCommunity(
+ beta,
+ alphaPerson.person.id,
+ 2,
+ false,
+ false,
+ );
+ expect(unBanAlpha.banned).toBe(false);
+ let postRes3 = await createPost(alpha, betaCommunity.community.id);
+ expect(postRes3.post_view.post).toBeDefined();
+ expect(postRes3.post_view.community.local).toBe(false);
+ expect(postRes3.post_view.creator.local).toBe(true);
+ 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();
+});
+
+test("A and G subscribe to B (center) A posts, it gets announced to G", async () => {
+ if (!betaCommunity) {
+ throw "Missing beta community";
+ }
+ 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();
+});
+
+test("Report a post", async () => {
+ // Note, this is a different one from the setup
+ let betaCommunity = (await resolveBetaCommunity(beta)).community;
+ if (!betaCommunity) {
+ throw "Missing beta community";
+ }
+ let postRes = await createPost(beta, betaCommunity.community.id);
+ expect(postRes.post_view.post).toBeDefined();
+
+ let alphaPost = (await resolvePost(alpha, postRes.post_view.post)).post;
+ if (!alphaPost) {
+ throw "Missing alpha post";
+ }
+ let alphaReport = (
+ await reportPost(alpha, alphaPost.post.id, randomString(10))
+ ).post_report_view.post_report;
+
+ let betaReport = (await listPostReports(beta)).post_reports[0].post_report;
+ expect(betaReport).toBeDefined();
+ expect(betaReport.resolved).toBe(false);
+ expect(betaReport.original_post_name).toBe(alphaReport.original_post_name);
+ 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);
+});