Fix typo/bug in bans query for viewing "global board bans"

Add tests for editing ban duration, note, and unban on board level to catch this
This commit is contained in:
Thomas Lynch
2024-09-14 09:12:33 +10:00
parent dec57289b6
commit d6343cd071
3 changed files with 101 additions and 2 deletions
+5 -1
View File
@@ -48,7 +48,11 @@ module.exports = {
}
const showGlobal = res.locals.permissions.get(Permissions.VIEW_BOARD_GLOBAL_BANS);
res.locals.bansBoard = req.params.board ? showGlobal ? req.parms.board : { '$eq': req.params.board } : null;
res.locals.bansBoard = req.params.board
? (showGlobal
? req.params.board
: { '$eq': req.params.board })
: null;
let bans = [];
try {
+5 -1
View File
@@ -6,7 +6,11 @@ const { Bans } = require(__dirname+'/../../db/')
module.exports = async (req, res) => {
const showGlobal = res.locals.permissions.get(Permissions.VIEW_BOARD_GLOBAL_BANS);
const bansBoard = req.params.board ? (showGlobal ? req.parms.board : { '$eq': req.params.board }) : null;
const bansBoard = req.params && req.params.board
? (showGlobal
? req.params.board
: { '$eq': req.params.board })
: null;
return Bans.removeMany(bansBoard, req.body.checkedbans).then(result => result.deletedCount);
};
+91
View File
@@ -1,3 +1,4 @@
const fetch = require('node-fetch');
const FormData = require('form-data');
const fs = require('fs-extra');
@@ -375,6 +376,7 @@ __underline__
##2d9+3
https://example.com
[Board Rules](https://your.imageboard/a/custompage/rules.html)(staff only)
![embed](https://your.imageboard/image.png)
>>123
>>>/test/
>>>/test/123
@@ -609,6 +611,95 @@ int main() {...}
expect(response.ok).toBe(true);
});
test('edit board level ban duration', async () => {
const banPage = await fetch('http://localhost/test/manage/bans.html', {
headers: {
'cookie': sessionCookie,
},
}).then(res => res.text());
const checkString = 'name="checkedbans" value="';
const checkIndex = banPage.indexOf(checkString);
banId = banPage.substring(checkIndex+checkString.length, checkIndex+checkString.length+24);
const params = new URLSearchParams({
_csrf: csrfToken,
checkedbans: banId,
option: 'edit_duration',
ban_duration: '3d',
});
const response = await fetch('http://localhost/forms/board/test/editbans', {
headers: {
'x-using-xhr': 'true',
'cookie': sessionCookie,
},
method: 'POST',
body: params,
redirect: 'manual',
});
expect(response.ok).toBe(true);
});
test('edit board level ban note', async () => {
const banPage = await fetch('http://localhost/test/manage/bans.html', {
headers: {
'cookie': sessionCookie,
},
}).then(res => res.text());
const checkString = 'name="checkedbans" value="';
const checkIndex = banPage.indexOf(checkString);
banId = banPage.substring(checkIndex+checkString.length, checkIndex+checkString.length+24);
const params = new URLSearchParams({
_csrf: csrfToken,
checkedbans: banId,
option: 'edit_note',
ban_note: 'THIS IS A UNIQUE BAN NOTE',
});
const response = await fetch('http://localhost/forms/board/test/editbans', {
headers: {
'x-using-xhr': 'true',
'cookie': sessionCookie,
},
method: 'POST',
body: params,
redirect: 'manual',
});
expect(response.ok).toBe(true);
});
test('check updated board level ban note', async () => {
const banPage = await fetch('http://localhost/test/manage/bans.html', {
headers: {
'cookie': sessionCookie,
},
}).then(res => res.text());
expect(banPage.includes('THIS IS A UNIQUE BAN NOTE')).toBe(true);
});
test('remove board level ban', async () => {
const banPage = await fetch('http://localhost/test/manage/bans.html', {
headers: {
'cookie': sessionCookie,
},
}).then(res => res.text());
const checkString = 'name="checkedbans" value="';
const checkIndex = banPage.indexOf(checkString);
banId = banPage.substring(checkIndex+checkString.length, checkIndex+checkString.length+24);
const params = new URLSearchParams({
_csrf: csrfToken,
checkedbans: banId,
option: 'unban',
});
const response = await fetch('http://localhost/forms/board/test/editbans', {
headers: {
'x-using-xhr': 'true',
'cookie': sessionCookie,
},
method: 'POST',
body: params,
redirect: 'manual',
});
expect(response.ok).toBe(true);
});
test('test global ban', async () => {
const threads = await fetch('http://localhost/test/catalog.json').then(res => res.json());
const randomThreadId = threads[Math.floor(Math.random() * threads.length)].postId;