Skip to content

Commit

Permalink
Merge branch 'LemmyNet:main' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
kroese authored Nov 22, 2023
2 parents 241dfcf + cafeb14 commit 218a841
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 3,227 deletions.
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "0.19.0-rc.5"
version = "0.19.0-rc.6"
edition = "2021"
description = "A link aggregator for the fediverse"
license = "AGPL-3.0"
Expand Down Expand Up @@ -84,16 +84,16 @@ unused_self = "deny"
unwrap_used = "deny"

[workspace.dependencies]
lemmy_api = { version = "=0.19.0-rc.5", path = "./crates/api" }
lemmy_api_crud = { version = "=0.19.0-rc.5", path = "./crates/api_crud" }
lemmy_apub = { version = "=0.19.0-rc.5", path = "./crates/apub" }
lemmy_utils = { version = "=0.19.0-rc.5", path = "./crates/utils" }
lemmy_db_schema = { version = "=0.19.0-rc.5", path = "./crates/db_schema" }
lemmy_api_common = { version = "=0.19.0-rc.5", path = "./crates/api_common" }
lemmy_routes = { version = "=0.19.0-rc.5", path = "./crates/routes" }
lemmy_db_views = { version = "=0.19.0-rc.5", path = "./crates/db_views" }
lemmy_db_views_actor = { version = "=0.19.0-rc.5", path = "./crates/db_views_actor" }
lemmy_db_views_moderator = { version = "=0.19.0-rc.5", path = "./crates/db_views_moderator" }
lemmy_api = { version = "=0.19.0-rc.6", path = "./crates/api" }
lemmy_api_crud = { version = "=0.19.0-rc.6", path = "./crates/api_crud" }
lemmy_apub = { version = "=0.19.0-rc.6", path = "./crates/apub" }
lemmy_utils = { version = "=0.19.0-rc.6", path = "./crates/utils" }
lemmy_db_schema = { version = "=0.19.0-rc.6", path = "./crates/db_schema" }
lemmy_api_common = { version = "=0.19.0-rc.6", path = "./crates/api_common" }
lemmy_routes = { version = "=0.19.0-rc.6", path = "./crates/routes" }
lemmy_db_views = { version = "=0.19.0-rc.6", path = "./crates/db_views" }
lemmy_db_views_actor = { version = "=0.19.0-rc.6", path = "./crates/db_views_actor" }
lemmy_db_views_moderator = { version = "=0.19.0-rc.6", path = "./crates/db_views_moderator" }
activitypub_federation = { version = "0.5.0-beta.5", default-features = false, features = [
"actix-web",
] }
Expand Down Expand Up @@ -163,7 +163,7 @@ lemmy_utils = { workspace = true }
lemmy_db_schema = { workspace = true }
lemmy_api_common = { workspace = true }
lemmy_routes = { workspace = true }
lemmy_federate = { version = "0.19.0-rc.5", path = "crates/federate" }
lemmy_federate = { version = "0.19.0-rc.6", path = "crates/federate" }
activitypub_federation = { workspace = true }
diesel = { workspace = true }
diesel-async = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions api_tests/prepare-drone-federation-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fi
./api_tests/pict-rs \
run -a 0.0.0.0:8080 \
--danger-dummy-mode \
--api-key "my-pictrs-key" \
filesystem -p /tmp/pictrs/files \
sled -p /tmp/pictrs/sled-repo 2>&1 &

Expand Down
5 changes: 1 addition & 4 deletions api_tests/src/comment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,7 @@ test.skip("Remove a comment from admin and community on the same instance", asyn
});

test("Remove a comment from admin and community on different instance", async () => {
let alpha_user = await registerUser(alpha);
let newAlphaApi = new LemmyHttp(alphaUrl, {
headers: { Authorization: `Bearer ${alpha_user.jwt ?? ""}` },
});
let newAlphaApi = await registerUser(alpha, alphaUrl);

// New alpha user creates a community, post, and comment.
let newCommunity = await createCommunity(newAlphaApi);
Expand Down
5 changes: 1 addition & 4 deletions api_tests/src/community.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,7 @@ test("Admin actions in remote community are not federated to origin", async () =

test("moderator view", async () => {
// register a new user with their own community on alpha and post to it
let registerUserRes = await registerUser(alpha);
let otherUser = new LemmyHttp(alphaUrl, {
headers: { Authorization: `Bearer ${registerUserRes.jwt ?? ""}` },
});
let otherUser = await registerUser(alpha, alphaUrl);

let otherCommunity = (await createCommunity(otherUser)).community_view;
expect(otherCommunity.community.name).toBeDefined();
Expand Down
9 changes: 2 additions & 7 deletions api_tests/src/follow.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
jest.setTimeout(120000);

import { LemmyHttp } from "lemmy-js-client";
import {
alpha,
setupLogins,
Expand All @@ -10,8 +9,8 @@ import {
getSite,
waitUntil,
beta,
registerUser,
betaUrl,
registerUser,
} from "./shared";

beforeAll(setupLogins);
Expand All @@ -21,11 +20,7 @@ afterAll(() => {
});

test("Follow local community", async () => {
let userRes = await registerUser(beta);
expect(userRes.jwt).toBeDefined();
let user = new LemmyHttp(betaUrl, {
headers: { Authorization: `Bearer ${userRes.jwt ?? ""}` },
});
let user = await registerUser(beta, betaUrl);

let community = (await resolveBetaCommunity(user)).community!;
expect(community.counts.subscribers).toBe(1);
Expand Down
90 changes: 86 additions & 4 deletions api_tests/src/image.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
jest.setTimeout(120000);

import { UploadImage, DeleteImage } from "lemmy-js-client";
import { alpha, setupLogins, unfollowRemotes } from "./shared";
import {
UploadImage,
DeleteImage,
PurgePerson,
PurgePost,
} from "lemmy-js-client";
import {
alpha,
alphaUrl,
beta,
betaUrl,
createPost,
getSite,
registerUser,
resolveBetaCommunity,
setupLogins,
unfollowRemotes,
} from "./shared";
import fs = require("fs");
const downloadFileSync = require("download-file-sync");

Expand All @@ -18,7 +34,6 @@ test("Upload image and delete it", async () => {
image: upload_image,
};
const upload = await alpha.uploadImage(upload_form);
console.log(upload);
expect(upload.files![0].file).toBeDefined();
expect(upload.files![0].delete_token).toBeDefined();
expect(upload.url).toBeDefined();
Expand All @@ -41,4 +56,71 @@ test("Upload image and delete it", async () => {
expect(content2).toBe("");
});

// TODO: add tests for image purging
test("Purge user, uploaded image removed", async () => {
let user = await registerUser(alpha, alphaUrl);

// upload test image
const upload_image = fs.readFileSync("test.png");
const upload_form: UploadImage = {
image: upload_image,
};
const upload = await user.uploadImage(upload_form);
expect(upload.files![0].file).toBeDefined();
expect(upload.files![0].delete_token).toBeDefined();
expect(upload.url).toBeDefined();
expect(upload.delete_url).toBeDefined();

// ensure that image download is working. theres probably a better way to do this
const content = downloadFileSync(upload.url);
expect(content.length).toBeGreaterThan(0);

// purge user
let site = await getSite(user);
const purge_form: PurgePerson = {
person_id: site.my_user!.local_user_view.person.id,
};
const delete_ = await alpha.purgePerson(purge_form);
expect(delete_.success).toBe(true);

// ensure that image is deleted
const content2 = downloadFileSync(upload.url);
expect(content2).toBe("");
});

test("Purge post, linked image removed", async () => {
let user = await registerUser(beta, betaUrl);

// upload test image
const upload_image = fs.readFileSync("test.png");
const upload_form: UploadImage = {
image: upload_image,
};
const upload = await user.uploadImage(upload_form);
expect(upload.files![0].file).toBeDefined();
expect(upload.files![0].delete_token).toBeDefined();
expect(upload.url).toBeDefined();
expect(upload.delete_url).toBeDefined();

// ensure that image download is working. theres probably a better way to do this
const content = downloadFileSync(upload.url);
expect(content.length).toBeGreaterThan(0);

let community = await resolveBetaCommunity(user);
let post = await createPost(
user,
community.community!.community.id,
upload.url,
);
expect(post.post_view.post.url).toBe(upload.url);

// purge post
const purge_form: PurgePost = {
post_id: post.post_view.post.id,
};
const delete_ = await beta.purgePost(purge_form);
expect(delete_.success).toBe(true);

// ensure that image is deleted
const content2 = downloadFileSync(upload.url);
expect(content2).toBe("");
});
6 changes: 1 addition & 5 deletions api_tests/src/post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,7 @@ test("Enforce site ban for federated user", async () => {
throw "Missing beta community";
}
// create a test user
let alphaUserJwt = await registerUser(alpha);
expect(alphaUserJwt).toBeDefined();
let alpha_user = new LemmyHttp(alphaUrl, {
headers: { Authorization: `Bearer ${alphaUserJwt.jwt ?? ""}` },
});
let alpha_user = await registerUser(alpha, alphaUrl);
let alphaUserPerson = (await getSite(alpha_user)).my_user?.local_user_view
.person;
let alphaUserActorId = alphaUserPerson?.actor_id;
Expand Down
17 changes: 12 additions & 5 deletions api_tests/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,11 @@ export async function setupLogins() {
export async function createPost(
api: LemmyHttp,
community_id: number,
// use example.com for consistent title and embed description
url: string = "https://example.com/",
): Promise<PostResponse> {
let name = randomString(5);
let body = randomString(10);
// switch from google.com to example.com for consistent title (embed_title and embed_description)
// google switches description when a google doodle appears
let url = "https://example.com/";
let form: CreatePost = {
name,
url,
Expand Down Expand Up @@ -290,6 +289,7 @@ export async function searchPostLocal(
q: post.name,
type_: "Posts",
sort: "TopAll",
listing_type: "All",
};
return api.search(form);
}
Expand Down Expand Up @@ -614,15 +614,22 @@ export async function deletePrivateMessage(

export async function registerUser(
api: LemmyHttp,
url: string,
username: string = randomString(5),
): Promise<LoginResponse> {
): Promise<LemmyHttp> {
let form: Register = {
username,
password,
password_verify: password,
show_nsfw: true,
};
return api.register(form);
let login_response = await api.register(form);

expect(login_response.jwt).toBeDefined();
let lemmy_http = new LemmyHttp(url, {
headers: { Authorization: `Bearer ${login_response.jwt ?? ""}` },
});
return lemmy_http;
}

export async function loginUser(
Expand Down
Loading

0 comments on commit 218a841

Please sign in to comment.