]> Untitled Git - lemmy.git/commitdiff
Adding a few more apub tests. (#1096)
authorDessalines <dessalines@users.noreply.github.com>
Thu, 20 Aug 2020 12:44:22 +0000 (08:44 -0400)
committerGitHub <noreply@github.com>
Thu, 20 Aug 2020 12:44:22 +0000 (12:44 +0000)
* Adding a few more apub tests.

* Fixing travis build, adding a get_post function.

13 files changed:
docker/federation-test/run-tests.sh
docker/federation-test/servers.sh
docker/federation-test/tests.sh
docker/federation/docker-compose.yml
docker/federation/nginx.conf
docker/federation/run-federation-test.bash
docker/travis/docker-compose.yml
docker/travis/run-tests.sh
server/src/api/comment.rs
server/src/api/mod.rs
ui/src/api_tests/comment.spec.ts
ui/src/api_tests/post.spec.ts
ui/src/api_tests/shared.ts

index 3848414b9b871de07b369b15b5300202e1d45334..f166d4903e6fd1b2f07b7fd344521457d1171313 100755 (executable)
@@ -13,8 +13,8 @@ pushd ../../ui
 yarn
 popd
 
-mkdir -p volumes/pictrs_{alpha,beta,gamma}
-sudo chown -R 991:991 volumes/pictrs_{alpha,beta,gamma}
+mkdir -p volumes/pictrs_{alpha,beta,gamma,delta,epsilon}
+sudo chown -R 991:991 volumes/pictrs_{alpha,beta,gamma,delta,epsilon}
 
 sudo docker build ../../ --file ../federation/Dockerfile --tag lemmy-federation:latest
 
@@ -28,6 +28,8 @@ echo "Waiting for Lemmy to start..."
 while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8540/api/v1/site')" != "200" ]]; do sleep 1; done
 while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8550/api/v1/site')" != "200" ]]; do sleep 1; done
 while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8560/api/v1/site')" != "200" ]]; do sleep 1; done
+while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8570/api/v1/site')" != "200" ]]; do sleep 1; done
+while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8580/api/v1/site')" != "200" ]]; do sleep 1; done
 yarn api-test || true
 popd
 
index b34e8c4efeaaca1d1971d26791bb51caac8add17..5b09bc952f76d2ba25e403b2ce21b92866d408e6 100755 (executable)
@@ -12,8 +12,8 @@ pushd ../../ui
 yarn
 popd
 
-mkdir -p volumes/pictrs_{alpha,beta,gamma}
-sudo chown -R 991:991 volumes/pictrs_{alpha,beta,gamma}
+mkdir -p volumes/pictrs_{alpha,beta,gamma,delta,epsilon}
+sudo chown -R 991:991 volumes/pictrs_{alpha,beta,gamma,delta,epsilon}
 
 sudo docker build ../../ --file ../federation/Dockerfile --tag lemmy-federation:latest
 
index 2e88ffb25c8316daffd254b95024213f035c86c8..58472e95cc424fb1d68de452ca1ba5866242fb8a 100755 (executable)
@@ -6,5 +6,7 @@ echo "Waiting for Lemmy to start..."
 while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8540/api/v1/site')" != "200" ]]; do sleep 1; done
 while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8550/api/v1/site')" != "200" ]]; do sleep 1; done
 while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8560/api/v1/site')" != "200" ]]; do sleep 1; done
+while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8570/api/v1/site')" != "200" ]]; do sleep 1; done
+while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8580/api/v1/site')" != "200" ]]; do sleep 1; done
 yarn api-test || true
 popd
index a3d0cf4313780077235735365ff89a37e23134d1..32fee74ab5bad3b0cfee0321921ba29ab4cb3a99 100644 (file)
@@ -7,16 +7,20 @@ services:
       - "8540:8540"
       - "8550:8550"
       - "8560:8560"
+      - "8570:8570"
+      - "8580:8580"
     volumes:
       # Hack to make this work from both docker/federation/ and docker/federation-test/
       - ../federation/nginx.conf:/etc/nginx/nginx.conf
     restart: on-failure
     depends_on:
-      - lemmy-alpha
       - pictrs
+      - iframely
+      - lemmy-alpha
       - lemmy-beta
       - lemmy-gamma
-      - iframely
+      - lemmy-delta
+      - lemmy-epsilon
 
   pictrs:
     restart: always
@@ -34,7 +38,7 @@ services:
       - LEMMY_FRONT_END_DIR=/app/dist
       - LEMMY_FEDERATION__ENABLED=true
       - LEMMY_FEDERATION__TLS_ENABLED=false
-      - LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-beta,lemmy-gamma
+      - LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-beta,lemmy-gamma,lemmy-delta,lemmy-epsilon
       - LEMMY_PORT=8540
       - LEMMY_SETUP__ADMIN_USERNAME=lemmy_alpha
       - LEMMY_SETUP__ADMIN_PASSWORD=lemmy
@@ -64,7 +68,7 @@ services:
       - LEMMY_FRONT_END_DIR=/app/dist
       - LEMMY_FEDERATION__ENABLED=true
       - LEMMY_FEDERATION__TLS_ENABLED=false
-      - LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-alpha,lemmy-gamma
+      - LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-alpha,lemmy-gamma,lemmy-delta,lemmy-epsilon
       - LEMMY_PORT=8550
       - LEMMY_SETUP__ADMIN_USERNAME=lemmy_beta
       - LEMMY_SETUP__ADMIN_PASSWORD=lemmy
@@ -94,7 +98,7 @@ services:
       - LEMMY_FRONT_END_DIR=/app/dist
       - LEMMY_FEDERATION__ENABLED=true
       - LEMMY_FEDERATION__TLS_ENABLED=false
-      - LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-alpha,lemmy-beta
+      - LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-alpha,lemmy-beta,lemmy-delta,lemmy-epsilon
       - LEMMY_PORT=8560
       - LEMMY_SETUP__ADMIN_USERNAME=lemmy_gamma
       - LEMMY_SETUP__ADMIN_PASSWORD=lemmy
@@ -115,6 +119,68 @@ services:
     volumes:
       - ./volumes/postgres_gamma:/var/lib/postgresql/data
 
+  # An instance with only an allowlist for beta
+  lemmy-delta:
+    image: lemmy-federation:latest
+    environment:
+      - LEMMY_HOSTNAME=lemmy-delta:8570
+      - LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_delta:5432/lemmy
+      - LEMMY_JWT_SECRET=changeme
+      - LEMMY_FRONT_END_DIR=/app/dist
+      - LEMMY_FEDERATION__ENABLED=true
+      - LEMMY_FEDERATION__TLS_ENABLED=false
+      - LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-beta
+      - LEMMY_PORT=8570
+      - LEMMY_SETUP__ADMIN_USERNAME=lemmy_delta
+      - LEMMY_SETUP__ADMIN_PASSWORD=lemmy
+      - LEMMY_SETUP__SITE_NAME=lemmy-delta
+      - LEMMY_RATE_LIMIT__POST=99999
+      - LEMMY_RATE_LIMIT__REGISTER=99999
+      - LEMMY_CAPTCHA__ENABLED=false
+      - RUST_BACKTRACE=1
+      - RUST_LOG=debug
+    depends_on:
+      - postgres_delta
+  postgres_delta:
+    image: postgres:12-alpine
+    environment:
+      - POSTGRES_USER=lemmy
+      - POSTGRES_PASSWORD=password
+      - POSTGRES_DB=lemmy
+    volumes:
+      - ./volumes/postgres_delta:/var/lib/postgresql/data
+
+  # An instance who has a blocklist, with lemmy-alpha blocked
+  lemmy-epsilon:
+    image: lemmy-federation:latest
+    environment:
+      - LEMMY_HOSTNAME=lemmy-epsilon:8580
+      - LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_epsilon:5432/lemmy
+      - LEMMY_JWT_SECRET=changeme
+      - LEMMY_FRONT_END_DIR=/app/dist
+      - LEMMY_FEDERATION__ENABLED=true
+      - LEMMY_FEDERATION__TLS_ENABLED=false
+      - LEMMY_FEDERATION__BLOCKED_INSTANCES=lemmy-alpha
+      - LEMMY_PORT=8580
+      - LEMMY_SETUP__ADMIN_USERNAME=lemmy_epsilon
+      - LEMMY_SETUP__ADMIN_PASSWORD=lemmy
+      - LEMMY_SETUP__SITE_NAME=lemmy-epsilon
+      - LEMMY_RATE_LIMIT__POST=99999
+      - LEMMY_RATE_LIMIT__REGISTER=99999
+      - LEMMY_CAPTCHA__ENABLED=false
+      - RUST_BACKTRACE=1
+      - RUST_LOG=debug
+    depends_on:
+      - postgres_epsilon
+  postgres_epsilon:
+    image: postgres:12-alpine
+    environment:
+      - POSTGRES_USER=lemmy
+      - POSTGRES_PASSWORD=password
+      - POSTGRES_DB=lemmy
+    volumes:
+      - ./volumes/postgres_epsilon:/var/lib/postgresql/data
+
   iframely:
     image: dogbin/iframely:latest
     volumes:
index b7901c19cf67c7dfd51123b2b4d09c9f322830b6..6d062f70b0cf1019feafd1ade621cdfd8f4f387d 100644 (file)
@@ -95,4 +95,66 @@ http {
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         }
     }
+
+    server {
+        listen 8570;
+        server_name 127.0.0.1;
+        access_log off;
+
+        # Upload limit for pictshare
+        client_max_body_size 50M;
+
+        location / {
+            proxy_pass http://lemmy-delta:8570;
+            proxy_set_header X-Real-IP $remote_addr;
+            proxy_set_header Host $host;
+            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+
+            # Cuts off the trailing slash on URLs to make them valid
+            rewrite ^(.+)/+$ $1 permanent;
+
+            # WebSocket support
+            proxy_http_version 1.1;
+            proxy_set_header Upgrade $http_upgrade;
+            proxy_set_header Connection "upgrade";
+        }
+
+        location /iframely/ {
+            proxy_pass http://iframely:80/;
+            proxy_set_header X-Real-IP $remote_addr;
+            proxy_set_header Host $host;
+            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+        }
+    }
+
+    server {
+        listen 8580;
+        server_name 127.0.0.1;
+        access_log off;
+
+        # Upload limit for pictshare
+        client_max_body_size 50M;
+
+        location / {
+            proxy_pass http://lemmy-epsilon:8580;
+            proxy_set_header X-Real-IP $remote_addr;
+            proxy_set_header Host $host;
+            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+
+            # Cuts off the trailing slash on URLs to make them valid
+            rewrite ^(.+)/+$ $1 permanent;
+
+            # WebSocket support
+            proxy_http_version 1.1;
+            proxy_set_header Upgrade $http_upgrade;
+            proxy_set_header Connection "upgrade";
+        }
+
+        location /iframely/ {
+            proxy_pass http://iframely:80/;
+            proxy_set_header X-Real-IP $remote_addr;
+            proxy_set_header Host $host;
+            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+        }
+    }
 }
index 77cc981f40d46f63ade9256eedf33a0d5b425cdb..0fe03aa176b089342aa4730fb53cfc3165abf648 100755 (executable)
@@ -20,7 +20,7 @@ popd || exit
 
 sudo docker build ../../ --file Dockerfile -t lemmy-federation:latest
 
-for Item in alpha beta gamma ; do
+for Item in alpha beta gamma delta epsilon ; do
   sudo mkdir -p volumes/pictrs_$Item
   sudo chown -R 991:991 volumes/pictrs_$Item
 done
index 7314e495d09bd5c9f6057412d4094f62db8ae67e..9aa7750c0f88f4233ff9fcb3c33a0bfc8b99843b 100644 (file)
@@ -7,16 +7,20 @@ services:
       - "8540:8540"
       - "8550:8550"
       - "8560:8560"
+      - "8570:8570"
+      - "8580:8580"
     volumes:
       # Hack to make this work from both docker/federation/ and docker/federation-test/
       - ../federation/nginx.conf:/etc/nginx/nginx.conf
     restart: on-failure
     depends_on:
-      - lemmy-alpha
       - pictrs
+      - iframely
+      - lemmy-alpha
       - lemmy-beta
       - lemmy-gamma
-      - iframely
+      - lemmy-delta
+      - lemmy-epsilon
 
   pictrs:
     restart: always
@@ -34,7 +38,7 @@ services:
       - LEMMY_FRONT_END_DIR=/app/dist
       - LEMMY_FEDERATION__ENABLED=true
       - LEMMY_FEDERATION__TLS_ENABLED=false
-      - LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-beta,lemmy-gamma
+      - LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-beta,lemmy-gamma,lemmy-delta,lemmy-epsilon
       - LEMMY_PORT=8540
       - LEMMY_SETUP__ADMIN_USERNAME=lemmy_alpha
       - LEMMY_SETUP__ADMIN_PASSWORD=lemmy
@@ -64,7 +68,7 @@ services:
       - LEMMY_FRONT_END_DIR=/app/dist
       - LEMMY_FEDERATION__ENABLED=true
       - LEMMY_FEDERATION__TLS_ENABLED=false
-      - LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-alpha,lemmy-gamma
+      - LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-alpha,lemmy-gamma,lemmy-delta,lemmy-epsilon
       - LEMMY_PORT=8550
       - LEMMY_SETUP__ADMIN_USERNAME=lemmy_beta
       - LEMMY_SETUP__ADMIN_PASSWORD=lemmy
@@ -94,7 +98,7 @@ services:
       - LEMMY_FRONT_END_DIR=/app/dist
       - LEMMY_FEDERATION__ENABLED=true
       - LEMMY_FEDERATION__TLS_ENABLED=false
-      - LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-alpha,lemmy-beta
+      - LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-alpha,lemmy-beta,lemmy-delta,lemmy-epsilon
       - LEMMY_PORT=8560
       - LEMMY_SETUP__ADMIN_USERNAME=lemmy_gamma
       - LEMMY_SETUP__ADMIN_PASSWORD=lemmy
@@ -115,6 +119,68 @@ services:
     volumes:
       - ./volumes/postgres_gamma:/var/lib/postgresql/data
 
+  # An instance with only an allowlist for beta
+  lemmy-delta:
+    image: dessalines/lemmy:travis
+    environment:
+      - LEMMY_HOSTNAME=lemmy-delta:8570
+      - LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_delta:5432/lemmy
+      - LEMMY_JWT_SECRET=changeme
+      - LEMMY_FRONT_END_DIR=/app/dist
+      - LEMMY_FEDERATION__ENABLED=true
+      - LEMMY_FEDERATION__TLS_ENABLED=false
+      - LEMMY_FEDERATION__ALLOWED_INSTANCES=lemmy-beta
+      - LEMMY_PORT=8570
+      - LEMMY_SETUP__ADMIN_USERNAME=lemmy_delta
+      - LEMMY_SETUP__ADMIN_PASSWORD=lemmy
+      - LEMMY_SETUP__SITE_NAME=lemmy-delta
+      - LEMMY_RATE_LIMIT__POST=99999
+      - LEMMY_RATE_LIMIT__REGISTER=99999
+      - LEMMY_CAPTCHA__ENABLED=false
+      - RUST_BACKTRACE=1
+      - RUST_LOG=debug
+    depends_on:
+      - postgres_delta
+  postgres_delta:
+    image: postgres:12-alpine
+    environment:
+      - POSTGRES_USER=lemmy
+      - POSTGRES_PASSWORD=password
+      - POSTGRES_DB=lemmy
+    volumes:
+      - ./volumes/postgres_delta:/var/lib/postgresql/data
+
+  # An instance who has a blocklist, with lemmy-alpha blocked
+  lemmy-epsilon:
+    image: dessalines/lemmy:travis
+    environment:
+      - LEMMY_HOSTNAME=lemmy-epsilon:8580
+      - LEMMY_DATABASE_URL=postgres://lemmy:password@postgres_epsilon:5432/lemmy
+      - LEMMY_JWT_SECRET=changeme
+      - LEMMY_FRONT_END_DIR=/app/dist
+      - LEMMY_FEDERATION__ENABLED=true
+      - LEMMY_FEDERATION__TLS_ENABLED=false
+      - LEMMY_FEDERATION__BLOCKED_INSTANCES=lemmy-alpha
+      - LEMMY_PORT=8580
+      - LEMMY_SETUP__ADMIN_USERNAME=lemmy_epsilon
+      - LEMMY_SETUP__ADMIN_PASSWORD=lemmy
+      - LEMMY_SETUP__SITE_NAME=lemmy-epsilon
+      - LEMMY_RATE_LIMIT__POST=99999
+      - LEMMY_RATE_LIMIT__REGISTER=99999
+      - LEMMY_CAPTCHA__ENABLED=false
+      - RUST_BACKTRACE=1
+      - RUST_LOG=debug
+    depends_on:
+      - postgres_epsilon
+  postgres_epsilon:
+    image: postgres:12-alpine
+    environment:
+      - POSTGRES_USER=lemmy
+      - POSTGRES_PASSWORD=password
+      - POSTGRES_DB=lemmy
+    volumes:
+      - ./volumes/postgres_epsilon:/var/lib/postgresql/data
+
   iframely:
     image: dogbin/iframely:latest
     volumes:
index f09b73c2b52bcae22b58c91605672645db58bff2..658ffc0e40d6e0b8a7b4ec79ac6fb196bbb28ff5 100755 (executable)
@@ -5,8 +5,8 @@ set -e
 sudo docker-compose down
 sudo rm -rf volumes
 
-mkdir -p volumes/pictrs_{alpha,beta,gamma}
-sudo chown -R 991:991 volumes/pictrs_{alpha,beta,gamma}
+mkdir -p volumes/pictrs_{alpha,beta,gamma,delta,epsilon}
+sudo chown -R 991:991 volumes/pictrs_{alpha,beta,gamma,delta,epsilon}
 
 sudo docker build ../../ --file ../prod/Dockerfile --tag dessalines/lemmy:travis
 
@@ -17,6 +17,8 @@ echo "Waiting for Lemmy to start..."
 while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8540/api/v1/site')" != "200" ]]; do sleep 1; done
 while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8550/api/v1/site')" != "200" ]]; do sleep 1; done
 while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8560/api/v1/site')" != "200" ]]; do sleep 1; done
+while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8570/api/v1/site')" != "200" ]]; do sleep 1; done
+while [[ "$(curl -s -o /dev/null -w '%{http_code}' 'localhost:8580/api/v1/site')" != "200" ]]; do sleep 1; done
 yarn
 yarn api-test
 popd
index 63f53a4d7018b6e27b6c052c410e2b2474a1fc47..24055d4d7279f82b023f3630d7a69364f30a8601 100644 (file)
@@ -1,6 +1,7 @@
 use crate::{
   api::{
     check_community_ban,
+    get_post,
     get_user_from_jwt,
     get_user_from_jwt_opt,
     is_mod_or_admin,
@@ -151,7 +152,7 @@ impl Perform for CreateComment {
 
     // Check for a community ban
     let post_id = data.post_id;
-    let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
+    let post = get_post(post_id, context.pool()).await?;
 
     check_community_ban(user.id, post.community_id, context.pool()).await?;
 
@@ -283,7 +284,7 @@ impl Perform for EditComment {
 
     // Do the mentions / recipients
     let post_id = orig_comment.post_id;
-    let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
+    let post = get_post(post_id, context.pool()).await?;
 
     let updated_comment_content = updated_comment.content.to_owned();
     let mentions = scrape_text_for_mentions(&updated_comment_content);
@@ -379,7 +380,7 @@ impl Perform for DeleteComment {
 
     // Build the recipients
     let post_id = comment_view.post_id;
-    let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
+    let post = get_post(post_id, context.pool()).await?;
     let mentions = vec![];
     let recipient_ids = send_local_notifs(
       mentions,
@@ -476,7 +477,7 @@ impl Perform for RemoveComment {
 
     // Build the recipients
     let post_id = comment_view.post_id;
-    let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
+    let post = get_post(post_id, context.pool()).await?;
     let mentions = vec![];
     let recipient_ids = send_local_notifs(
       mentions,
@@ -655,7 +656,7 @@ impl Perform for CreateCommentLike {
     .await??;
 
     let post_id = orig_comment.post_id;
-    let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
+    let post = get_post(post_id, context.pool()).await?;
     check_community_ban(user.id, post.community_id, context.pool()).await?;
 
     let comment_id = data.comment_id;
index 6fed9d05d0ad0b99504b06ac07ce077f3d811745..c64707f94d2adbb7c1336e7cc425c60d4e1955ad 100644 (file)
@@ -11,6 +11,7 @@ use lemmy_db::{
   community::*,
   community_view::*,
   moderator::*,
+  post::Post,
   site::*,
   user::*,
   user_view::*,
@@ -73,6 +74,13 @@ pub async fn is_admin(pool: &DbPool, user_id: i32) -> Result<(), LemmyError> {
   Ok(())
 }
 
+pub(in crate::api) async fn get_post(post_id: i32, pool: &DbPool) -> Result<Post, LemmyError> {
+  match blocking(pool, move |conn| Post::read(conn, post_id)).await? {
+    Ok(post) => Ok(post),
+    Err(_e) => Err(APIError::err("couldnt_find_post").into()),
+  }
+}
+
 pub(in crate::api) async fn get_user_from_jwt(
   jwt: &str,
   pool: &DbPool,
index 02cc683c4fb3ca5498a0d412fbb67b415732ad63..24aca55f921cb3e1bf9b8563796ac9fd5cada4a2 100644 (file)
@@ -57,6 +57,11 @@ test('Create a comment', async () => {
   expect(betaComment.score).toBe(1);
 });
 
+test('Create a comment in a non-existent post', async () => {
+  let commentRes = await createComment(alpha, -1);
+  expect(commentRes).toStrictEqual({ error: 'couldnt_find_post' });
+});
+
 test('Update a comment', async () => {
   let commentRes = await createComment(alpha, postRes.post.id);
   let updateCommentRes = await updateComment(alpha, commentRes.comment.id);
index 5da72e5a103b0aef238f0baf66c56253d9edeb60..ab9c63fb16c82895396c1d367f45f922312afc2d 100644 (file)
@@ -2,6 +2,8 @@ import {
   alpha,
   beta,
   gamma,
+  delta,
+  epsilon,
   setupLogins,
   createPost,
   updatePost,
@@ -22,11 +24,15 @@ beforeAll(async () => {
   await setupLogins();
   await followBeta(alpha);
   await followBeta(gamma);
+  await followBeta(delta);
+  await followBeta(epsilon);
 });
 
 afterAll(async () => {
   await unfollowRemotes(alpha);
   await unfollowRemotes(gamma);
+  await unfollowRemotes(delta);
+  await unfollowRemotes(epsilon);
 });
 
 test('Create a post', async () => {
@@ -45,6 +51,19 @@ test('Create a post', async () => {
   expect(betaPost.community_local).toBe(true);
   expect(betaPost.creator_local).toBe(false);
   expect(betaPost.score).toBe(1);
+
+  // Delta only follows beta, so it should not see an alpha ap_id
+  let searchDelta = await searchPost(delta, postRes.post);
+  expect(searchDelta.posts[0]).toBeUndefined();
+
+  // Epsilon has alpha blocked, it should not see the alpha post
+  let searchEpsilon = await searchPost(epsilon, postRes.post);
+  expect(searchEpsilon.posts[0]).toBeUndefined();
+});
+
+test('Create a post in a non-existent community', async () => {
+  let postRes = await createPost(alpha, -2);
+  expect(postRes).toStrictEqual({ error: 'couldnt_create_post' });
 });
 
 test('Unlike a post', async () => {
@@ -53,6 +72,10 @@ test('Unlike a post', async () => {
   let unlike = await likePost(alpha, 0, postRes.post);
   expect(unlike.post.score).toBe(0);
 
+  // Try to unlike it again, make sure it stays at 0
+  let unlike2 = await likePost(alpha, 0, postRes.post);
+  expect(unlike2.post.score).toBe(0);
+
   // Make sure that post is unliked on beta
   let searchBeta = await searchPost(beta, postRes.post);
   let betaPost = searchBeta.posts[0];
@@ -67,10 +90,22 @@ test('Update a post', async () => {
   let search = await searchForBetaCommunity(alpha);
   let postRes = await createPost(alpha, search.communities[0].id);
 
+  let updatedName = 'A jest test federated post, updated';
   let updatedPost = await updatePost(alpha, postRes.post);
-  expect(updatedPost.post.name).toBe('A jest test federated post, updated');
+  expect(updatedPost.post.name).toBe(updatedName);
   expect(updatedPost.post.community_local).toBe(false);
   expect(updatedPost.post.creator_local).toBe(true);
+
+  // Make sure that post is updated on beta
+  let searchBeta = await searchPost(beta, postRes.post);
+  let betaPost = searchBeta.posts[0];
+  expect(betaPost.community_local).toBe(true);
+  expect(betaPost.creator_local).toBe(false);
+  expect(betaPost.name).toBe(updatedName);
+
+  // Make sure lemmy beta cannot update the post
+  let updatedPostBeta = await updatePost(beta, betaPost);
+  expect(updatedPostBeta).toStrictEqual({ error: 'no_post_edit_allowed' });
 });
 
 test('Sticky a post', async () => {
@@ -97,6 +132,15 @@ test('Sticky a post', async () => {
   expect(betaPost2.community_local).toBe(true);
   expect(betaPost2.creator_local).toBe(false);
   expect(betaPost2.stickied).toBe(false);
+
+  // Make sure that gamma cannot sticky the post on beta
+  let searchGamma = await searchPost(gamma, postRes.post);
+  let gammaPost = searchGamma.posts[0];
+  let gammaTrySticky = await stickyPost(gamma, true, gammaPost);
+  let searchBeta3 = await searchPost(beta, postRes.post);
+  let betaPost3 = searchBeta3.posts[0];
+  expect(gammaTrySticky.post.stickied).toBe(true);
+  expect(betaPost3.stickied).toBe(false);
 });
 
 test('Lock a post', async () => {
@@ -152,6 +196,10 @@ test('Delete a post', async () => {
   // Make sure lemmy beta sees post is undeleted
   let betaPost2 = await getPost(beta, createFakeBetaPostToGetId);
   expect(betaPost2.post.deleted).toBe(false);
+
+  // Make sure lemmy beta cannot delete the post
+  let deletedPostBeta = await deletePost(beta, true, betaPost2.post);
+  expect(deletedPostBeta).toStrictEqual({ error: 'no_post_edit_allowed' });
 });
 
 test('Remove a post from admin and community on different instance', async () => {
index 31530ef7ec8fcb783bf0f6740e1dbe62ae750e7e..29aaff25f957c2eff31182e824ae3db74c45eb82 100644 (file)
@@ -59,50 +59,96 @@ export let gamma: API = {
   url: 'http://localhost:8560',
 };
 
+export let delta: API = {
+  url: 'http://localhost:8570',
+};
+
+export let epsilon: API = {
+  url: 'http://localhost:8580',
+};
+
 export async function setupLogins() {
-  let form: LoginForm = {
+  let formAlpha: LoginForm = {
     username_or_email: 'lemmy_alpha',
     password: 'lemmy',
   };
 
-  let resA: Promise<LoginResponse> = fetch(`${apiUrl(alpha)}/user/login`, {
+  let resAlpha: Promise<LoginResponse> = fetch(`${apiUrl(alpha)}/user/login`, {
     method: 'POST',
     headers: {
       'Content-Type': 'application/json',
     },
-    body: wrapper(form),
+    body: wrapper(formAlpha),
   }).then(d => d.json());
 
-  let formB = {
+  let formBeta = {
     username_or_email: 'lemmy_beta',
     password: 'lemmy',
   };
 
-  let resB: Promise<LoginResponse> = fetch(`${apiUrl(beta)}/user/login`, {
+  let resBeta: Promise<LoginResponse> = fetch(`${apiUrl(beta)}/user/login`, {
     method: 'POST',
     headers: {
       'Content-Type': 'application/json',
     },
-    body: wrapper(formB),
+    body: wrapper(formBeta),
   }).then(d => d.json());
 
-  let formC = {
+  let formGamma = {
     username_or_email: 'lemmy_gamma',
     password: 'lemmy',
   };
 
-  let resG: Promise<LoginResponse> = fetch(`${apiUrl(gamma)}/user/login`, {
+  let resGamma: Promise<LoginResponse> = fetch(`${apiUrl(gamma)}/user/login`, {
+    method: 'POST',
+    headers: {
+      'Content-Type': 'application/json',
+    },
+    body: wrapper(formGamma),
+  }).then(d => d.json());
+
+  let formDelta = {
+    username_or_email: 'lemmy_delta',
+    password: 'lemmy',
+  };
+
+  let resDelta: Promise<LoginResponse> = fetch(`${apiUrl(delta)}/user/login`, {
     method: 'POST',
     headers: {
       'Content-Type': 'application/json',
     },
-    body: wrapper(formC),
+    body: wrapper(formDelta),
   }).then(d => d.json());
 
-  let res = await Promise.all([resA, resB, resG]);
+  let formEpsilon = {
+    username_or_email: 'lemmy_epsilon',
+    password: 'lemmy',
+  };
+
+  let resEpsilon: Promise<LoginResponse> = fetch(
+    `${apiUrl(epsilon)}/user/login`,
+    {
+      method: 'POST',
+      headers: {
+        'Content-Type': 'application/json',
+      },
+      body: wrapper(formEpsilon),
+    }
+  ).then(d => d.json());
+
+  let res = await Promise.all([
+    resAlpha,
+    resBeta,
+    resGamma,
+    resDelta,
+    resEpsilon,
+  ]);
+
   alpha.auth = res[0].jwt;
   beta.auth = res[1].jwt;
   gamma.auth = res[2].jwt;
+  delta.auth = res[3].jwt;
+  epsilon.auth = res[4].jwt;
 }
 
 export async function createPost(