mirror of
https://github.com/luxfi/pics.git
synced 2026-07-27 05:11:31 +00:00
Fix tests for new filters, add tests for matching/missing filter, update filter db caches to fix "undefined" instead of null board for global, and change to prevent possible race condition
This commit is contained in:
+18
-14
@@ -31,20 +31,19 @@ module.exports = {
|
||||
return filters;
|
||||
},
|
||||
|
||||
count: (board) => {
|
||||
count: (board=null) => {
|
||||
return db.countDocuments({'board': board});
|
||||
},
|
||||
|
||||
findOne: (board, id) => {
|
||||
findOne: (board=null, id) => {
|
||||
return db.findOne({
|
||||
'_id': id,
|
||||
'board': board,
|
||||
});
|
||||
},
|
||||
|
||||
updateOne: (board, id, filters, strictFiltering, filterMode, filterMessage, filterBanDuration, filterBanAppealable) => {
|
||||
cache.del(`filters:${board}`);
|
||||
return db.updateOne({
|
||||
updateOne: async (board=null, id, filters, strictFiltering, filterMode, filterMessage, filterBanDuration, filterBanAppealable) => {
|
||||
const updatedFilter = await db.updateOne({
|
||||
'_id': id,
|
||||
'board': board,
|
||||
}, {
|
||||
@@ -57,26 +56,31 @@ module.exports = {
|
||||
'filterBanAppealable': filterBanAppealable,
|
||||
}
|
||||
});
|
||||
await cache.del(`filters:${board}`);
|
||||
return updatedFilter;
|
||||
},
|
||||
|
||||
insertOne: (filter) => {
|
||||
cache.del(`filters:${filter.board}`);
|
||||
return db.insertOne(filter);
|
||||
insertOne: async (filter) => {
|
||||
const insertedFilter = await db.insertOne(filter);
|
||||
await cache.del(`filters:${filter.board}`);
|
||||
return insertedFilter;
|
||||
},
|
||||
|
||||
deleteMany: (board, ids) => {
|
||||
cache.del(`filters:${board}`);
|
||||
return db.deleteMany({
|
||||
deleteMany: async (board=null, ids) => {
|
||||
const deletedFilter = await db.deleteMany({
|
||||
'_id': {
|
||||
'$in': ids
|
||||
},
|
||||
'board': board
|
||||
});
|
||||
await cache.del(`filters:${board}`);
|
||||
return deletedFilter;
|
||||
},
|
||||
|
||||
deleteBoard: (board) => {
|
||||
cache.del(`filters:${board}`);
|
||||
return db.deleteMany({ 'board': board });
|
||||
deleteBoard: async (board=null) => {
|
||||
const deletedFilters = await db.deleteMany({ 'board': board });
|
||||
await cache.del(`filters:${board}`);
|
||||
return deletedFilters;
|
||||
},
|
||||
|
||||
deleteAll: () => {
|
||||
|
||||
+1
-1
@@ -689,7 +689,7 @@ int main() {...}
|
||||
_csrf: csrfToken,
|
||||
checkedbans: banId,
|
||||
option: 'edit_duration',
|
||||
ban_duration: '3d',
|
||||
ban_duration: '1s',
|
||||
});
|
||||
const response = await fetch('http://localhost/forms/global/editbans', {
|
||||
headers: {
|
||||
|
||||
+53
-11
@@ -231,7 +231,7 @@ testing 123`
|
||||
});
|
||||
|
||||
let filterId;
|
||||
test('add filter post', async () => {
|
||||
test('add filter to test board', async () => {
|
||||
const params = new URLSearchParams({
|
||||
_csrf: csrfToken,
|
||||
filters: `notgood
|
||||
@@ -252,25 +252,24 @@ bad words`,
|
||||
redirect: 'manual',
|
||||
});
|
||||
expect(response.ok).toBe(true);
|
||||
const filterPage = await fetch('http://localhost/test/manage/filter.html', {
|
||||
const filterPage = await fetch('http://localhost/test/manage/filters.html', {
|
||||
headers: {
|
||||
'cookie': sessionCookie,
|
||||
},
|
||||
}).then(res => res.text());
|
||||
const checkIndex = filterPage.indexOf('name="checkedfilter" value="');
|
||||
filterId = filterPage.substring(checkIndex+28, checkIndex+28+24);
|
||||
const checkIndex = filterPage.indexOf('name="checkedfilters" value="');
|
||||
filterId = filterPage.substring(checkIndex+29, checkIndex+29+24);
|
||||
});
|
||||
|
||||
test('edit filter post', async () => {
|
||||
test('edit filter on test board', async () => {
|
||||
const params = new URLSearchParams({
|
||||
_csrf: csrfToken,
|
||||
board: test,
|
||||
filter_id: filterId,
|
||||
filters: 'edited filters',
|
||||
strict_filtering: 'true',
|
||||
filter_mode: '0',
|
||||
filter_mode: '1',
|
||||
filter_message: 'edited message',
|
||||
filter_ban_duration: '0'
|
||||
filter_ban_duration: '1s'
|
||||
// filter_ban_appealable omitted to change to false
|
||||
});
|
||||
const response = await fetch('http://localhost/forms/board/test/editfilter', {
|
||||
@@ -283,7 +282,7 @@ bad words`,
|
||||
redirect: 'manual',
|
||||
});
|
||||
expect(response.ok).toBe(true);
|
||||
const filterPage = await fetch('http://localhost/test/manage/filter.html', {
|
||||
const filterPage = await fetch('http://localhost/test/manage/filters.html', {
|
||||
headers: {
|
||||
'cookie': sessionCookie,
|
||||
},
|
||||
@@ -292,10 +291,39 @@ bad words`,
|
||||
expect(editTextIndex).not.toBe(-1);
|
||||
});
|
||||
|
||||
test('delete filter post', async () => {
|
||||
test('make a post that doesnt hit board filter', async () => {
|
||||
const params = new URLSearchParams();
|
||||
params.append('message', 'blahblahblah');
|
||||
params.append('captcha', '000000');
|
||||
const response = await fetch('http://localhost/forms/board/test/post', {
|
||||
headers: {
|
||||
'x-using-xhr': 'true',
|
||||
},
|
||||
method: 'POST',
|
||||
body: params
|
||||
});
|
||||
expect(response.ok).toBe(true);
|
||||
});
|
||||
|
||||
test('make a post that hits board filter', async () => {
|
||||
const params = new URLSearchParams();
|
||||
params.append('message', 'edited filters');
|
||||
params.append('captcha', '000000');
|
||||
const response = await fetch('http://localhost/forms/board/test/post', {
|
||||
headers: {
|
||||
'x-using-xhr': 'true',
|
||||
},
|
||||
method: 'POST',
|
||||
body: params
|
||||
});
|
||||
expect(response.ok).not.toBe(true);
|
||||
await new Promise(res => setTimeout(res, 10000)); //let ban expire
|
||||
});
|
||||
|
||||
test('delete test board filter', async () => {
|
||||
const params = new URLSearchParams({
|
||||
_csrf: csrfToken,
|
||||
checkedfilter: filterId,
|
||||
checkedfilters: filterId,
|
||||
});
|
||||
const response = await fetch('http://localhost/forms/board/test/deletefilter', {
|
||||
headers: {
|
||||
@@ -309,6 +337,20 @@ bad words`,
|
||||
expect(response.ok).toBe(true);
|
||||
});
|
||||
|
||||
test('make a post that passes the deleted filter', async () => {
|
||||
const params = new URLSearchParams();
|
||||
params.append('message', 'editing filter');
|
||||
params.append('captcha', '000000');
|
||||
const response = await fetch('http://localhost/forms/board/test/post', {
|
||||
headers: {
|
||||
'x-using-xhr': 'true',
|
||||
},
|
||||
method: 'POST',
|
||||
body: params
|
||||
});
|
||||
expect(response.ok).toBe(true);
|
||||
});
|
||||
|
||||
test('add staff', async () => {
|
||||
const params = new URLSearchParams({
|
||||
_csrf: csrfToken,
|
||||
|
||||
+43
-12
@@ -99,7 +99,7 @@ testing 123`
|
||||
});
|
||||
|
||||
let filterId;
|
||||
test('add filter post', async () => {
|
||||
test('add global filter', async () => {
|
||||
const params = new URLSearchParams({
|
||||
_csrf: csrfToken,
|
||||
filters: `notgood
|
||||
@@ -120,26 +120,27 @@ bad words`,
|
||||
redirect: 'manual',
|
||||
});
|
||||
expect(response.ok).toBe(true);
|
||||
const filterPage = await fetch('http://localhost/globalmanage/filter.html', {
|
||||
const filterPage = await fetch('http://localhost/globalmanage/filters.html', {
|
||||
headers: {
|
||||
'cookie': sessionCookie,
|
||||
},
|
||||
}).then(res => res.text());
|
||||
const checkIndex = filterPage.indexOf('name="checkedfilter" value="');
|
||||
filterId = filterPage.substring(checkIndex+28, checkIndex+28+24);
|
||||
const checkIndex = filterPage.indexOf('name="checkedfilters" value="');
|
||||
filterId = filterPage.substring(checkIndex+29, checkIndex+29+24);
|
||||
});
|
||||
|
||||
test('edit filter post', async () => {
|
||||
test('edit global filter', async () => {
|
||||
const params = new URLSearchParams({
|
||||
_csrf: csrfToken,
|
||||
filter_id: filterId,
|
||||
filters: 'edited filters',
|
||||
filters: 'edited globalfilters',
|
||||
strict_filtering: 'true',
|
||||
filter_mode: '0',
|
||||
filter_mode: '1',
|
||||
filter_message: 'edited message',
|
||||
filter_ban_duration: '0'
|
||||
filter_ban_duration: '1s'
|
||||
// filter_ban_appealable omitted to change to false
|
||||
});
|
||||
console.log(params)
|
||||
const response = await fetch('http://localhost/forms/global/editfilter', {
|
||||
headers: {
|
||||
'x-using-xhr': 'true',
|
||||
@@ -150,19 +151,49 @@ bad words`,
|
||||
redirect: 'manual',
|
||||
});
|
||||
expect(response.ok).toBe(true);
|
||||
const filterPage = await fetch('http://localhost/globalmanage/filter.html', {
|
||||
const filterPage = await fetch('http://localhost/globalmanage/filters.html', {
|
||||
headers: {
|
||||
'cookie': sessionCookie,
|
||||
},
|
||||
}).then(res => res.text());
|
||||
const editTextIndex = filterPage.indexOf('edited filters');
|
||||
console.log(filterPage)
|
||||
const editTextIndex = filterPage.indexOf('edited globalfilters');
|
||||
expect(editTextIndex).not.toBe(-1);
|
||||
});
|
||||
|
||||
test('delete filter post', async () => {
|
||||
test('make post that doesnt hit global filter', async () => {
|
||||
const params = new URLSearchParams();
|
||||
params.append('message', 'blahblahblah');
|
||||
params.append('captcha', '000000');
|
||||
const response = await fetch('http://localhost/forms/board/test/post', {
|
||||
headers: {
|
||||
'x-using-xhr': 'true',
|
||||
},
|
||||
method: 'POST',
|
||||
body: params
|
||||
});
|
||||
expect(response.ok).toBe(true);
|
||||
});
|
||||
|
||||
test('make post that hits global filter', async () => {
|
||||
const params = new URLSearchParams();
|
||||
params.append('message', 'edited globalfilters');
|
||||
params.append('captcha', '000000');
|
||||
const response = await fetch('http://localhost/forms/board/test/post', {
|
||||
headers: {
|
||||
'x-using-xhr': 'true',
|
||||
},
|
||||
method: 'POST',
|
||||
body: params
|
||||
});
|
||||
expect(response.ok).not.toBe(true);
|
||||
await new Promise(res => setTimeout(res, 10000)); //let ban expire
|
||||
});
|
||||
|
||||
test('delete global filter', async () => {
|
||||
const params = new URLSearchParams({
|
||||
_csrf: csrfToken,
|
||||
checkedfilter: filterId,
|
||||
checkedfilters: filterId,
|
||||
});
|
||||
const response = await fetch('http://localhost/forms/global/deletefilter', {
|
||||
headers: {
|
||||
|
||||
@@ -2,8 +2,8 @@ describe('run integration tests', () => {
|
||||
require('./setup.js')();
|
||||
require('./posting.js')();
|
||||
require('./global.js')();
|
||||
require('./actions.js')();
|
||||
require('./board.js')();
|
||||
require('./actions.js')();
|
||||
require('./pages.js')();
|
||||
require('./cleanup.js')();
|
||||
require('./twofactor.js')();
|
||||
|
||||
+2
-1
@@ -103,7 +103,7 @@ module.exports = () => describe('login and create test board', () => {
|
||||
archive_links: 'https://archive.today/?run=1&url=%s',
|
||||
reverse_links: 'https://tineye.com/search?url=%s',
|
||||
prune_modlogs: '30',
|
||||
default_ban_duration: '31536000000',
|
||||
default_ban_duration: '1000',
|
||||
quote_limit: '25',
|
||||
preview_replies: '5',
|
||||
sticky_preview_replies: '5',
|
||||
@@ -178,6 +178,7 @@ module.exports = () => describe('login and create test board', () => {
|
||||
global_limits_custom_css_filters: '@\nurl(',
|
||||
global_limits_custom_css_strict: 'true',
|
||||
global_limits_custom_css_max: '10000',
|
||||
global_limits_filters_max: 100,
|
||||
global_limits_field_length_name: '100',
|
||||
global_limits_field_length_email: '100',
|
||||
global_limits_field_length_subject: '100',
|
||||
|
||||
Reference in New Issue
Block a user