Merge branch 'main' into no-send-blocked-dess

This commit is contained in:
Dessalines 2020-10-01 15:57:47 -05:00
commit f5b511ccce
8 changed files with 44 additions and 32 deletions

View file

@ -1,4 +1,4 @@
jest.setTimeout(120000); jest.setTimeout(180000);
import { import {
alpha, alpha,
beta, beta,
@ -21,6 +21,7 @@ import {
registerUser, registerUser,
API, API,
delay, delay,
longDelay,
} from './shared'; } from './shared';
import { import {
Comment, Comment,
@ -35,7 +36,7 @@ beforeAll(async () => {
await followBeta(alpha); await followBeta(alpha);
await followBeta(gamma); await followBeta(gamma);
let search = await searchForBetaCommunity(alpha); let search = await searchForBetaCommunity(alpha);
await delay(10000); await longDelay();
postRes = await createPost( postRes = await createPost(
alpha, alpha,
search.communities.filter(c => c.local == false)[0].id search.communities.filter(c => c.local == false)[0].id
@ -66,7 +67,7 @@ test('Create a comment', async () => {
expect(commentRes.comment.community_local).toBe(false); expect(commentRes.comment.community_local).toBe(false);
expect(commentRes.comment.creator_local).toBe(true); expect(commentRes.comment.creator_local).toBe(true);
expect(commentRes.comment.score).toBe(1); expect(commentRes.comment.score).toBe(1);
await delay(); await longDelay();
// Make sure that comment is liked on beta // Make sure that comment is liked on beta
let searchBeta = await searchComment(beta, commentRes.comment); let searchBeta = await searchComment(beta, commentRes.comment);
@ -147,7 +148,7 @@ test('Remove a comment from admin and community on the same instance', async ()
// The beta admin removes it (the community lives on beta) // The beta admin removes it (the community lives on beta)
let removeCommentRes = await removeComment(beta, true, betaCommentId); let removeCommentRes = await removeComment(beta, true, betaCommentId);
expect(removeCommentRes.comment.removed).toBe(true); expect(removeCommentRes.comment.removed).toBe(true);
await delay(); await longDelay();
// Make sure that comment is removed on alpha (it gets pushed since an admin from beta removed it) // Make sure that comment is removed on alpha (it gets pushed since an admin from beta removed it)
let refetchedPost = await getPost(alpha, postRes.post.id); let refetchedPost = await getPost(alpha, postRes.post.id);
@ -155,7 +156,7 @@ test('Remove a comment from admin and community on the same instance', async ()
let unremoveCommentRes = await removeComment(beta, false, betaCommentId); let unremoveCommentRes = await removeComment(beta, false, betaCommentId);
expect(unremoveCommentRes.comment.removed).toBe(false); expect(unremoveCommentRes.comment.removed).toBe(false);
await delay(); await longDelay();
// Make sure that comment is unremoved on beta // Make sure that comment is unremoved on beta
let refetchedPost2 = await getPost(alpha, postRes.post.id); let refetchedPost2 = await getPost(alpha, postRes.post.id);
@ -210,7 +211,7 @@ test('Unlike a comment', async () => {
test('Federated comment like', async () => { test('Federated comment like', async () => {
let commentRes = await createComment(alpha, postRes.post.id); let commentRes = await createComment(alpha, postRes.post.id);
await delay(); await longDelay();
// Find the comment on beta // Find the comment on beta
let searchBeta = await searchComment(beta, commentRes.comment); let searchBeta = await searchComment(beta, commentRes.comment);
@ -218,7 +219,7 @@ test('Federated comment like', async () => {
let like = await likeComment(beta, 1, betaComment); let like = await likeComment(beta, 1, betaComment);
expect(like.comment.score).toBe(2); expect(like.comment.score).toBe(2);
await delay(); await longDelay();
// Get the post from alpha, check the likes // Get the post from alpha, check the likes
let post = await getPost(alpha, postRes.post.id); let post = await getPost(alpha, postRes.post.id);
@ -241,7 +242,7 @@ test('Reply to a comment', async () => {
expect(replyRes.comment.creator_local).toBe(true); expect(replyRes.comment.creator_local).toBe(true);
expect(replyRes.comment.parent_id).toBe(betaComment.id); expect(replyRes.comment.parent_id).toBe(betaComment.id);
expect(replyRes.comment.score).toBe(1); expect(replyRes.comment.score).toBe(1);
await delay(); await longDelay();
// Make sure that comment is seen on alpha // Make sure that comment is seen on alpha
// TODO not sure why, but a searchComment back to alpha, for the ap_id of betas // TODO not sure why, but a searchComment back to alpha, for the ap_id of betas
@ -310,7 +311,7 @@ test('A and G subscribe to B (center) A posts, G mentions B, it gets announced t
expect(commentRes.comment.community_local).toBe(false); expect(commentRes.comment.community_local).toBe(false);
expect(commentRes.comment.creator_local).toBe(true); expect(commentRes.comment.creator_local).toBe(true);
expect(commentRes.comment.score).toBe(1); expect(commentRes.comment.score).toBe(1);
await delay(); await longDelay();
// Make sure alpha sees it // Make sure alpha sees it
let alphaPost2 = await getPost(alpha, alphaPost.post.id); let alphaPost2 = await getPost(alpha, alphaPost.post.id);
@ -319,6 +320,7 @@ test('A and G subscribe to B (center) A posts, G mentions B, it gets announced t
expect(alphaPost2.comments[0].creator_local).toBe(false); expect(alphaPost2.comments[0].creator_local).toBe(false);
expect(alphaPost2.comments[0].score).toBe(1); expect(alphaPost2.comments[0].score).toBe(1);
assertCommentFederation(alphaPost2.comments[0], commentRes.comment); assertCommentFederation(alphaPost2.comments[0], commentRes.comment);
await delay();
// Make sure beta has mentions // Make sure beta has mentions
let mentionsRes = await getMentions(beta); let mentionsRes = await getMentions(beta);
@ -381,7 +383,7 @@ test('Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedde
// Get the post from alpha // Get the post from alpha
let search = await searchPost(alpha, postRes.post); let search = await searchPost(alpha, postRes.post);
let alphaPostB = search.posts[0]; let alphaPostB = search.posts[0];
await delay(); await longDelay();
let alphaPost = await getPost(alpha, alphaPostB.id); let alphaPost = await getPost(alpha, alphaPostB.id);
expect(alphaPost.post.name).toBeDefined(); expect(alphaPost.post.name).toBeDefined();

View file

@ -7,6 +7,7 @@ import {
checkFollowedCommunities, checkFollowedCommunities,
unfollowRemotes, unfollowRemotes,
delay, delay,
longDelay,
} from './shared'; } from './shared';
beforeAll(async () => { beforeAll(async () => {
@ -24,10 +25,11 @@ test('Follow federated community', async () => {
// Make sure the follow response went through // Make sure the follow response went through
expect(follow.community.local).toBe(false); expect(follow.community.local).toBe(false);
expect(follow.community.name).toBe('main'); expect(follow.community.name).toBe('main');
await delay(); await longDelay();
// Check it from local // Check it from local
let followCheck = await checkFollowedCommunities(alpha); let followCheck = await checkFollowedCommunities(alpha);
await delay();
let remoteCommunityId = followCheck.communities.filter( let remoteCommunityId = followCheck.communities.filter(
c => c.community_local == false c => c.community_local == false
)[0].community_id; )[0].community_id;

View file

@ -20,6 +20,7 @@ import {
getPost, getPost,
unfollowRemotes, unfollowRemotes,
delay, delay,
longDelay,
} from './shared'; } from './shared';
import { import {
Post, Post,
@ -31,7 +32,7 @@ beforeAll(async () => {
await followBeta(gamma); await followBeta(gamma);
await followBeta(delta); await followBeta(delta);
await followBeta(epsilon); await followBeta(epsilon);
await delay(10000); await longDelay();
}); });
afterAll(async () => { afterAll(async () => {
@ -67,7 +68,7 @@ test('Create a post', async () => {
expect(postRes.post.community_local).toBe(false); expect(postRes.post.community_local).toBe(false);
expect(postRes.post.creator_local).toBe(true); expect(postRes.post.creator_local).toBe(true);
expect(postRes.post.score).toBe(1); expect(postRes.post.score).toBe(1);
await delay(); await longDelay();
// Make sure that post is liked on beta // Make sure that post is liked on beta
let searchBeta = await searchPost(beta, postRes.post); let searchBeta = await searchPost(beta, postRes.post);
@ -104,7 +105,7 @@ test('Unlike a post', async () => {
// Try to unlike it again, make sure it stays at 0 // Try to unlike it again, make sure it stays at 0
let unlike2 = await likePost(alpha, 0, postRes.post); let unlike2 = await likePost(alpha, 0, postRes.post);
expect(unlike2.post.score).toBe(0); expect(unlike2.post.score).toBe(0);
await delay(); await longDelay();
// Make sure that post is unliked on beta // Make sure that post is unliked on beta
let searchBeta = await searchPost(beta, postRes.post); let searchBeta = await searchPost(beta, postRes.post);
@ -284,31 +285,32 @@ test('Remove a post from admin and community on different instance', async () =>
test('Remove a post from admin and community on same instance', async () => { test('Remove a post from admin and community on same instance', async () => {
let search = await searchForBetaCommunity(alpha); let search = await searchForBetaCommunity(alpha);
let postRes = await createPost(alpha, search.communities[0].id); let postRes = await createPost(alpha, search.communities[0].id);
await delay(); await longDelay();
// Get the id for beta // Get the id for beta
let searchBeta = await searchPost(beta, postRes.post); let searchBeta = await searchPost(beta, postRes.post);
let betaPost = searchBeta.posts[0]; let betaPost = searchBeta.posts[0];
await delay(); await longDelay();
// The beta admin removes it (the community lives on beta) // The beta admin removes it (the community lives on beta)
let removePostRes = await removePost(beta, true, betaPost); let removePostRes = await removePost(beta, true, betaPost);
expect(removePostRes.post.removed).toBe(true); expect(removePostRes.post.removed).toBe(true);
await delay(); await longDelay();
// Make sure lemmy alpha sees post is removed // Make sure lemmy alpha sees post is removed
let alphaPost = await getPost(alpha, postRes.post.id); let alphaPost = await getPost(alpha, postRes.post.id);
expect(alphaPost.post.removed).toBe(true); expect(alphaPost.post.removed).toBe(true);
assertPostFederation(alphaPost.post, removePostRes.post); assertPostFederation(alphaPost.post, removePostRes.post);
await delay(); await longDelay();
// Undelete // Undelete
let undeletedPost = await removePost(beta, false, betaPost); let undeletedPost = await removePost(beta, false, betaPost);
expect(undeletedPost.post.removed).toBe(false); expect(undeletedPost.post.removed).toBe(false);
await delay(); await longDelay();
// Make sure lemmy alpha sees post is undeleted // Make sure lemmy alpha sees post is undeleted
let alphaPost2 = await getPost(alpha, postRes.post.id); let alphaPost2 = await getPost(alpha, postRes.post.id);
await delay();
expect(alphaPost2.post.removed).toBe(false); expect(alphaPost2.post.removed).toBe(false);
assertPostFederation(alphaPost2.post, undeletedPost.post); assertPostFederation(alphaPost2.post, undeletedPost.post);
}); });

View file

@ -10,6 +10,7 @@ import {
deletePrivateMessage, deletePrivateMessage,
unfollowRemotes, unfollowRemotes,
delay, delay,
longDelay,
} from './shared'; } from './shared';
let recipient_id: number; let recipient_id: number;
@ -17,7 +18,7 @@ let recipient_id: number;
beforeAll(async () => { beforeAll(async () => {
await setupLogins(); await setupLogins();
let follow = await followBeta(alpha); let follow = await followBeta(alpha);
await delay(10000); await longDelay();
recipient_id = follow.community.creator_id; recipient_id = follow.community.creator_id;
}); });
@ -46,7 +47,7 @@ test('Update a private message', async () => {
let pmRes = await createPrivateMessage(alpha, recipient_id); let pmRes = await createPrivateMessage(alpha, recipient_id);
let pmUpdated = await updatePrivateMessage(alpha, pmRes.message.id); let pmUpdated = await updatePrivateMessage(alpha, pmRes.message.id);
expect(pmUpdated.message.content).toBe(updatedContent); expect(pmUpdated.message.content).toBe(updatedContent);
await delay(); await longDelay();
let betaPms = await listPrivateMessages(beta); let betaPms = await listPrivateMessages(beta);
expect(betaPms.messages[0].content).toBe(updatedContent); expect(betaPms.messages[0].content).toBe(updatedContent);
@ -74,7 +75,7 @@ test('Delete a private message', async () => {
pmRes.message.id pmRes.message.id
); );
expect(undeletedPmRes.message.deleted).toBe(false); expect(undeletedPmRes.message.deleted).toBe(false);
await delay(); await longDelay();
let betaPms3 = await listPrivateMessages(beta); let betaPms3 = await listPrivateMessages(beta);
expect(betaPms3.messages.length).toBe(betaPms1.messages.length); expect(betaPms3.messages.length).toBe(betaPms1.messages.length);

View file

@ -554,10 +554,15 @@ export async function followBeta(api: API): Promise<CommunityResponse> {
} }
} }
export const delay = (millis: number = 1500) => export function delay(millis: number = 500) {
new Promise((resolve, _reject) => { return new Promise((resolve, _reject) => {
setTimeout(_ => resolve(), millis); setTimeout(_ => resolve(), millis);
}); });
}
export function longDelay() {
return delay(10000);
}
export function wrapper(form: any): string { export function wrapper(form: any): string {
return JSON.stringify(form); return JSON.stringify(form);

View file

@ -8,7 +8,7 @@ services:
- LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_alpha:5432/lemmy - LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_alpha:5432/lemmy
- LEMMY_JWT_SECRET=changeme - LEMMY_JWT_SECRET=changeme
- LEMMY_FEDERATION__ENABLED=true - LEMMY_FEDERATION__ENABLED=true
- LEMMY_FEDERATION__TLS_ENABLED=false - LEMMY_TLS_ENABLED=false
- LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-beta,lemmy-gamma,lemmy-delta,lemmy-epsilon - LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-beta,lemmy-gamma,lemmy-delta,lemmy-epsilon
- LEMMY_PORT=8541 - LEMMY_PORT=8541
- LEMMY_SETUP__ADMIN_USERNAME=lemmy_alpha - LEMMY_SETUP__ADMIN_USERNAME=lemmy_alpha
@ -39,7 +39,7 @@ services:
- LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_beta:5432/lemmy - LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_beta:5432/lemmy
- LEMMY_JWT_SECRET=changeme - LEMMY_JWT_SECRET=changeme
- LEMMY_FEDERATION__ENABLED=true - LEMMY_FEDERATION__ENABLED=true
- LEMMY_FEDERATION__TLS_ENABLED=false - LEMMY_TLS_ENABLED=false
- LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-alpha,lemmy-gamma,lemmy-delta,lemmy-epsilon - LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-alpha,lemmy-gamma,lemmy-delta,lemmy-epsilon
- LEMMY_PORT=8551 - LEMMY_PORT=8551
- LEMMY_SETUP__ADMIN_USERNAME=lemmy_beta - LEMMY_SETUP__ADMIN_USERNAME=lemmy_beta
@ -70,7 +70,7 @@ services:
- LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_gamma:5432/lemmy - LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_gamma:5432/lemmy
- LEMMY_JWT_SECRET=changeme - LEMMY_JWT_SECRET=changeme
- LEMMY_FEDERATION__ENABLED=true - LEMMY_FEDERATION__ENABLED=true
- LEMMY_FEDERATION__TLS_ENABLED=false - LEMMY_TLS_ENABLED=false
- LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-alpha,lemmy-beta,lemmy-delta,lemmy-epsilon - LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-alpha,lemmy-beta,lemmy-delta,lemmy-epsilon
- LEMMY_PORT=8561 - LEMMY_PORT=8561
- LEMMY_SETUP__ADMIN_USERNAME=lemmy_gamma - LEMMY_SETUP__ADMIN_USERNAME=lemmy_gamma
@ -102,7 +102,7 @@ services:
- LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_delta:5432/lemmy - LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_delta:5432/lemmy
- LEMMY_JWT_SECRET=changeme - LEMMY_JWT_SECRET=changeme
- LEMMY_FEDERATION__ENABLED=true - LEMMY_FEDERATION__ENABLED=true
- LEMMY_FEDERATION__TLS_ENABLED=false - LEMMY_TLS_ENABLED=false
- LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-beta - LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-beta
- LEMMY_PORT=8571 - LEMMY_PORT=8571
- LEMMY_SETUP__ADMIN_USERNAME=lemmy_delta - LEMMY_SETUP__ADMIN_USERNAME=lemmy_delta
@ -134,7 +134,7 @@ services:
- LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_epsilon:5432/lemmy - LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_epsilon:5432/lemmy
- LEMMY_JWT_SECRET=changeme - LEMMY_JWT_SECRET=changeme
- LEMMY_FEDERATION__ENABLED=true - LEMMY_FEDERATION__ENABLED=true
- LEMMY_FEDERATION__TLS_ENABLED=false - LEMMY_TLS_ENABLED=false
- LEMMY_FEDERATION__BLOCKED_INSTANCES=lemmy-alpha - LEMMY_FEDERATION__BLOCKED_INSTANCES=lemmy-alpha
- LEMMY_PORT=8581 - LEMMY_PORT=8581
- LEMMY_SETUP__ADMIN_USERNAME=lemmy_epsilon - LEMMY_SETUP__ADMIN_USERNAME=lemmy_epsilon

View file

@ -1,7 +1,7 @@
use crate::{ use crate::{
check_is_apub_id_valid, check_is_apub_id_valid,
community::do_announce, community::do_announce,
extensions::signatures::sign, extensions::signatures::sign_and_send,
insert_activity, insert_activity,
ActorType, ActorType,
}; };
@ -210,7 +210,7 @@ impl ActixJob for SendActivityTask {
for to_url in &self.to { for to_url in &self.to {
let mut headers = BTreeMap::<String, String>::new(); let mut headers = BTreeMap::<String, String>::new();
headers.insert("Content-Type".into(), "application/json".into()); headers.insert("Content-Type".into(), "application/json".into());
let result = sign( let result = sign_and_send(
&state.client, &state.client,
headers, headers,
to_url, to_url,

View file

@ -25,7 +25,7 @@ lazy_static! {
} }
/// Signs request headers with the given keypair. /// Signs request headers with the given keypair.
pub async fn sign( pub async fn sign_and_send(
client: &Client, client: &Client,
headers: BTreeMap<String, String>, headers: BTreeMap<String, String>,
url: &Url, url: &Url,