Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/app/api/settings/disappearing-messages/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@ export async function PUT(request) {
return NextResponse.json({ error: 'Invalid token' }, { status: 401 });
}

const { default_message_retention_days } = await request.json();
let body;
try {
body = await request.json();
} catch {
return NextResponse.json({ error: 'Invalid JSON body' }, { status: 400 });
}

const { default_message_retention_days } = body;

// Validate input
if (
Expand Down
20 changes: 20 additions & 0 deletions src/app/api/settings/disappearing-messages/route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,24 @@ describe('settings disappearing messages authentication', () => {
expect(mocks.from).not.toHaveBeenCalled();
expect(mocks.updateEq).not.toHaveBeenCalled();
});

it('rejects malformed JSON before updating settings', async () => {
const { PUT } = await import('./route.js');
const malformed = new Request('https://qrypt.chat/api/settings/disappearing-messages', {
method: 'PUT',
headers: {
authorization: 'Bearer valid-token',
'content-type': 'application/json'
},
body: '{"default_message_retention_days":'
});

const response = await PUT(malformed);
const body = await response.json();

expect(response.status).toBe(400);
expect(body.error).toBe('Invalid JSON body');
expect(mocks.from).not.toHaveBeenCalled();
expect(mocks.updateEq).not.toHaveBeenCalled();
});
});
Loading