Require authentication to participate in chat (#4762)

* feat(chat): require authentication to participate in chat

* fix: it's pretty much impossible to bypass the auth requirement, addressing review feedback anyway

* feat(chat): render chat text input as disabled if chat auth is required

* Commit updated API documentation

---------

Co-authored-by: Owncast <owncast@owncast.online>
This commit is contained in:
Gabe Kangas
2026-01-28 11:49:07 -08:00
committed by GitHub
co-authored by Owncast
parent 83c8b2b3d5
commit 93b482871f
29 changed files with 5194 additions and 5143 deletions
@@ -119,3 +119,68 @@ test('verify message is in the chat feed', async () => {
expect(message.length).toBe(0);
});
// Chat authentication requirement tests
const unauthenticatedUserFailedChatMessage = {
body:
'this unauthenticated message should fail ' +
Math.floor(Math.random() * 100),
type: 'CHAT',
};
const unauthenticatedUserSucceedChatMessage = {
body:
'this unauthenticated message should succeed ' +
Math.floor(Math.random() * 100),
type: 'CHAT',
};
test('enable chat require authentication mode', async () => {
await sendAdminRequest('config/chat/requireauthentication', true);
});
test('send a message after require authentication is enabled', async () => {
const registration = await registerChat();
const accessToken = registration.accessToken;
await sendChatMessage(unauthenticatedUserFailedChatMessage, accessToken);
});
test('verify unauthenticated message is not in the chat feed', async () => {
await new Promise((r) => setTimeout(r, 1000));
const res = await getAdminResponse('chat/messages');
const expectedBody =
`<p>` + unauthenticatedUserFailedChatMessage.body + `</p>`;
const message = res.body.filter((obj) => {
return obj.body === expectedBody;
});
expect(message.length).toBe(0);
});
test('disable chat require authentication mode', async () => {
await sendAdminRequest('config/chat/requireauthentication', false);
});
test('send a message after require authentication is disabled', async () => {
const registration = await registerChat();
const accessToken = registration.accessToken;
await sendChatMessage(unauthenticatedUserSucceedChatMessage, accessToken);
});
test('verify message from unauthenticated user is now in the chat feed', async () => {
await new Promise((r) => setTimeout(r, 1000));
const res = await getAdminResponse('chat/messages');
const expectedBody =
`<p>` + unauthenticatedUserSucceedChatMessage.body + `</p>`;
const message = res.body.filter((obj) => {
return obj.body === expectedBody;
});
expect(message.length).toBe(1);
});