2020-09-15 19:26:47 +00:00
|
|
|
jest.setTimeout(120000);
|
2022-07-30 03:55:59 +00:00
|
|
|
|
2023-04-26 04:26:10 +00:00
|
|
|
import { PersonView } from "lemmy-js-client/dist/types/PersonView";
|
2020-08-04 15:06:27 +00:00
|
|
|
import {
|
|
|
|
alpha,
|
|
|
|
beta,
|
|
|
|
registerUser,
|
2021-08-23 15:25:39 +00:00
|
|
|
resolvePerson,
|
2020-08-04 15:06:27 +00:00
|
|
|
getSite,
|
2022-04-07 20:52:17 +00:00
|
|
|
createPost,
|
|
|
|
resolveCommunity,
|
|
|
|
createComment,
|
|
|
|
resolveBetaCommunity,
|
|
|
|
deleteUser,
|
|
|
|
resolvePost,
|
|
|
|
resolveComment,
|
2022-07-30 03:55:59 +00:00
|
|
|
saveUserSettingsFederated,
|
2022-10-13 16:30:31 +00:00
|
|
|
setupLogins,
|
2023-09-21 10:42:28 +00:00
|
|
|
alphaUrl,
|
2022-10-27 09:24:07 +00:00
|
|
|
} from "./shared";
|
2023-05-25 14:50:07 +00:00
|
|
|
import { LemmyHttp } from "lemmy-js-client";
|
|
|
|
import { GetPosts } from "lemmy-js-client/dist/types/GetPosts";
|
2020-08-04 15:06:27 +00:00
|
|
|
|
2022-10-13 16:30:31 +00:00
|
|
|
beforeAll(async () => {
|
|
|
|
await setupLogins();
|
|
|
|
});
|
|
|
|
|
2020-08-04 15:06:27 +00:00
|
|
|
let apShortname: string;
|
|
|
|
|
2023-04-17 19:19:51 +00:00
|
|
|
function assertUserFederation(userOne?: PersonView, userTwo?: PersonView) {
|
2023-01-04 15:59:26 +00:00
|
|
|
expect(userOne?.person.name).toBe(userTwo?.person.name);
|
|
|
|
expect(userOne?.person.display_name).toBe(userTwo?.person.display_name);
|
|
|
|
expect(userOne?.person.bio).toBe(userTwo?.person.bio);
|
|
|
|
expect(userOne?.person.actor_id).toBe(userTwo?.person.actor_id);
|
|
|
|
expect(userOne?.person.avatar).toBe(userTwo?.person.avatar);
|
|
|
|
expect(userOne?.person.banner).toBe(userTwo?.person.banner);
|
|
|
|
expect(userOne?.person.published).toBe(userTwo?.person.published);
|
2020-09-17 15:41:51 +00:00
|
|
|
}
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
test("Create user", async () => {
|
2020-08-04 15:06:27 +00:00
|
|
|
let userRes = await registerUser(alpha);
|
|
|
|
expect(userRes.jwt).toBeDefined();
|
2023-09-21 10:42:28 +00:00
|
|
|
let user = new LemmyHttp(alphaUrl, {
|
|
|
|
headers: { auth: userRes.jwt ?? "" },
|
|
|
|
});
|
2022-10-27 09:24:07 +00:00
|
|
|
|
2023-09-21 10:42:28 +00:00
|
|
|
let site = await getSite(user);
|
2020-08-04 15:06:27 +00:00
|
|
|
expect(site.my_user).toBeDefined();
|
2023-01-04 15:59:26 +00:00
|
|
|
if (!site.my_user) {
|
|
|
|
throw "Missing site user";
|
|
|
|
}
|
|
|
|
apShortname = `@${site.my_user.local_user_view.person.name}@lemmy-alpha:8541`;
|
2020-08-04 15:06:27 +00:00
|
|
|
});
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
test("Set some user settings, check that they are federated", async () => {
|
2022-07-30 03:55:59 +00:00
|
|
|
await saveUserSettingsFederated(alpha);
|
2023-01-04 15:59:26 +00:00
|
|
|
let alphaPerson = (await resolvePerson(alpha, apShortname)).person;
|
|
|
|
let betaPerson = (await resolvePerson(beta, apShortname)).person;
|
2021-08-23 15:25:39 +00:00
|
|
|
assertUserFederation(alphaPerson, betaPerson);
|
2020-09-18 11:04:12 +00:00
|
|
|
});
|
2022-04-07 20:52:17 +00:00
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
test("Delete user", async () => {
|
2022-04-07 20:52:17 +00:00
|
|
|
let userRes = await registerUser(alpha);
|
|
|
|
expect(userRes.jwt).toBeDefined();
|
2023-09-21 10:42:28 +00:00
|
|
|
let user = new LemmyHttp(alphaUrl, {
|
|
|
|
headers: { auth: userRes.jwt ?? "" },
|
|
|
|
});
|
2022-04-07 20:52:17 +00:00
|
|
|
|
|
|
|
// make a local post and comment
|
2023-01-04 15:59:26 +00:00
|
|
|
let alphaCommunity = (await resolveCommunity(user, "!main@lemmy-alpha:8541"))
|
|
|
|
.community;
|
|
|
|
if (!alphaCommunity) {
|
|
|
|
throw "Missing alpha community";
|
|
|
|
}
|
2022-10-27 09:24:07 +00:00
|
|
|
let localPost = (await createPost(user, alphaCommunity.community.id))
|
|
|
|
.post_view.post;
|
2022-04-07 20:52:17 +00:00
|
|
|
expect(localPost).toBeDefined();
|
2023-01-04 15:59:26 +00:00
|
|
|
let localComment = (await createComment(user, localPost.id)).comment_view
|
|
|
|
.comment;
|
2022-04-07 20:52:17 +00:00
|
|
|
expect(localComment).toBeDefined();
|
|
|
|
|
|
|
|
// make a remote post and comment
|
2023-01-04 15:59:26 +00:00
|
|
|
let betaCommunity = (await resolveBetaCommunity(user)).community;
|
|
|
|
if (!betaCommunity) {
|
|
|
|
throw "Missing beta community";
|
|
|
|
}
|
2022-10-27 09:24:07 +00:00
|
|
|
let remotePost = (await createPost(user, betaCommunity.community.id))
|
|
|
|
.post_view.post;
|
2022-04-07 20:52:17 +00:00
|
|
|
expect(remotePost).toBeDefined();
|
2023-01-04 15:59:26 +00:00
|
|
|
let remoteComment = (await createComment(user, remotePost.id)).comment_view
|
|
|
|
.comment;
|
2022-04-07 20:52:17 +00:00
|
|
|
expect(remoteComment).toBeDefined();
|
|
|
|
|
|
|
|
await deleteUser(user);
|
|
|
|
|
2023-07-21 09:47:56 +00:00
|
|
|
await expect(resolvePost(alpha, localPost)).rejects.toBe(
|
|
|
|
"couldnt_find_object",
|
|
|
|
);
|
|
|
|
await expect(resolveComment(alpha, localComment)).rejects.toBe(
|
|
|
|
"couldnt_find_object",
|
|
|
|
);
|
|
|
|
await expect(resolvePost(alpha, remotePost)).rejects.toBe(
|
|
|
|
"couldnt_find_object",
|
|
|
|
);
|
|
|
|
await expect(resolveComment(alpha, remoteComment)).rejects.toBe(
|
|
|
|
"couldnt_find_object",
|
|
|
|
);
|
2022-04-07 20:52:17 +00:00
|
|
|
});
|
2023-05-25 14:50:07 +00:00
|
|
|
|
|
|
|
test("Requests with invalid auth should be treated as unauthenticated", async () => {
|
2023-09-21 10:42:28 +00:00
|
|
|
let invalid_auth = new LemmyHttp(alphaUrl, {
|
|
|
|
headers: { auth: "" },
|
|
|
|
});
|
2023-05-25 14:50:07 +00:00
|
|
|
let site = await getSite(invalid_auth);
|
|
|
|
expect(site.my_user).toBeUndefined();
|
|
|
|
expect(site.site_view).toBeDefined();
|
|
|
|
|
2023-09-21 10:42:28 +00:00
|
|
|
let form: GetPosts = {};
|
|
|
|
let posts = invalid_auth.getPosts(form);
|
2023-05-25 14:50:07 +00:00
|
|
|
expect((await posts).posts).toBeDefined();
|
|
|
|
});
|