Skip to content

Commit 1eeec20

Browse files
authored
fix: allow guests to access etherpad (#1861)
* fix: add test checking for guest access to etherpad * fix: allow guests to access etherpad
1 parent f271c5d commit 1eeec20

2 files changed

Lines changed: 52 additions & 4 deletions

File tree

src/services/item/plugins/etherpad/etherpad.controller.test.ts

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const expectExpiration = (expires: Date) => {
4343
expect(isBefore(expires, add(oneDayFromNow, { minutes: 1 }))).toBeTruthy();
4444
};
4545

46-
const createEtherpad = async (app) => {
46+
const createEtherpad = async (app, parentId?: string) => {
4747
// create an existing etherpad item to test reading it
4848
setUpApi({
4949
createGroupIfNotExistsFor: [
@@ -58,6 +58,7 @@ const createEtherpad = async (app) => {
5858
payload: {
5959
name: faker.word.sample(),
6060
},
61+
query: parentId ? { parentId } : undefined,
6162
});
6263
expect(res.statusCode).toBe(StatusCodes.OK);
6364
const item = res.json();
@@ -271,7 +272,7 @@ describe('Etherpad service API', () => {
271272
mode,
272273
},
273274
});
274-
it('views a pad in read mode successfully', async () => {
275+
it('member views a pad in read mode successfully', async () => {
275276
const { actor } = await seedFromJson();
276277
assertIsDefined(actor);
277278
mockAuthenticate(actor);
@@ -301,6 +302,53 @@ describe('Etherpad service API', () => {
301302
padUrl: `${ETHERPAD_PUBLIC_URL}/p/${MOCK_PAD_READ_ONLY_ID}`,
302303
});
303304
});
305+
it('guest views a pad in read mode successfully', async () => {
306+
const {
307+
actor,
308+
guests: [guest],
309+
items: [parentItem],
310+
} = await seedFromJson({
311+
items: [
312+
{
313+
memberships: [{ permission: 'write', account: 'actor' }],
314+
type: 'folder',
315+
itemLoginSchema: { guests: [{}] },
316+
},
317+
],
318+
});
319+
assertIsDefined(guest);
320+
assertIsDefined(actor);
321+
// authenticate as actor
322+
mockAuthenticate(actor);
323+
324+
const item = await createEtherpad(app, parentItem.id);
325+
326+
// switch to guest authentication
327+
mockAuthenticate(guest);
328+
329+
const reqParams = setUpApi({
330+
getReadOnlyID: [
331+
StatusCodes.OK,
332+
{ code: 0, message: 'ok', data: { readOnlyID: MOCK_PAD_READ_ONLY_ID } },
333+
],
334+
createAuthorIfNotExistsFor: [
335+
StatusCodes.OK,
336+
{ code: 0, message: 'ok', data: { authorID: MOCK_AUTHOR_ID } },
337+
],
338+
createSession: [
339+
StatusCodes.OK,
340+
{ code: 0, message: 'ok', data: { sessionID: MOCK_SESSION_ID } },
341+
],
342+
listSessionsOfAuthor: [StatusCodes.OK, { code: 0, message: 'ok', data: null }],
343+
});
344+
const res = await app.inject(payloadView('read', item.id));
345+
const { getReadOnlyID } = await reqParams;
346+
expect(getReadOnlyID?.get('padID')).toEqual(item.extra.etherpad.padID);
347+
expect(res.statusCode).toEqual(StatusCodes.OK);
348+
expect(res.json()).toEqual({
349+
padUrl: `${ETHERPAD_PUBLIC_URL}/p/${MOCK_PAD_READ_ONLY_ID}`,
350+
});
351+
});
304352
it('views a pad in write mode successfully', async () => {
305353
const { actor } = await seedFromJson();
306354
assertIsDefined(actor);

src/services/item/plugins/etherpad/etherpad.controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import fp from 'fastify-plugin';
66

77
import { resolveDependency } from '../../../../di/utils';
88
import { db } from '../../../../drizzle/db';
9-
import { asDefined } from '../../../../utils/assertions';
9+
import { asDefined, assertIsMemberOrGuest } from '../../../../utils/assertions';
1010
import { isAuthenticated, matchOne } from '../../../auth/plugins/passport';
1111
import { assertIsMember } from '../../../authentication';
1212
import { validatedMemberAccountRole } from '../../../member/strategies/validatedMemberAccountRole';
@@ -82,7 +82,7 @@ const endpoints: FastifyPluginAsyncTypebox = async (fastify) => {
8282
query: { mode = 'read' },
8383
} = request;
8484
const account = asDefined(user?.account);
85-
assertIsMember(account);
85+
assertIsMemberOrGuest(account);
8686

8787
const { cookie, padUrl } = await etherpadItemService.getEtherpadFromItem(
8888
db,

0 commit comments

Comments
 (0)