Skip to content

Node.js based forum software built for the modern web

test: fix tests

Barış Soner Uşaklı74086f185304
diff --git a/src/database/mongo/main.js b/src/database/mongo/main.js
index aa5892389b..4247834294 100644
--- a/src/database/mongo/main.js
+++ b/src/database/mongo/main.js
@@ -117,16 +117,24 @@ module.exports = function (module) {
if (!key) {
return;
}
- const result = await module.client.collection('objects').findOneAndUpdate({
- _key: key,
- }, {
- $inc: { data: 1 },
- }, {
- returnDocument: 'after',
- includeResultMetadata: true,
- upsert: true,
- });
- return result && result.value ? result.value.data : null;
+ try {
+ const result = await module.client.collection('objects').findOneAndUpdate({
+ _key: key,
+ }, {
+ $inc: { data: 1 },
+ }, {
+ returnDocument: 'after',
+ includeResultMetadata: true,
+ upsert: true,
+ });
+ return result && result.value ? result.value.data : null;
+ } catch (err) {
+ if (err && err.message.includes('E11000 duplicate key error')) {
+ console.log(new Error('e11000').stack, key);
+ return await module.increment(key);
+ }
+ throw err;
+ }
};
module.rename = async function (oldKey, newKey) {
diff --git a/test/feeds.js b/test/feeds.js
index 90701a9dad..23be4080c4 100644
--- a/test/feeds.js
+++ b/test/feeds.js
@@ -106,11 +106,8 @@ describe('feeds', () => {
it('should not allow access if uid or token is missing', async () => {
await privileges.categories.rescind(['groups:read'], cid, 'guests');
- const [test1, test2] = await Promise.all([
- request.get(`${nconf.get('url')}/category/${cid}.rss?uid=${fooUid}`, { }),
- request.get(`${nconf.get('url')}/category/${cid}.rss?token=sometoken`, { }),
- ]);
-
+ const test1 = await request.get(`${nconf.get('url')}/category/${cid}.rss?uid=${fooUid}`, { });
+ const test2 = await request.get(`${nconf.get('url')}/category/${cid}.rss?token=sometoken`, { });
assert.equal(test1.response.statusCode, 200);
assert.equal(test2.response.statusCode, 200);
assert(test1.body.includes('Login to your account'));
diff --git a/test/topics/events.js b/test/topics/events.js
index c83c617c7f..8b05921d59 100644
--- a/test/topics/events.js
+++ b/test/topics/events.js
@@ -106,8 +106,10 @@ describe('Topic Events', () => {
});
it('should properly escape topic events with HTML and tx tokens in their arguments', async () => {
- const oldVlaueShowFullnameAsDisplayName = meta.config.showFullnameAsDisplayName;
+ const oldValueShowFullnameAsDisplayName = meta.config.showFullnameAsDisplayName;
+ const oldValueHideFullname = meta.config.hideFullname;
meta.config.showFullnameAsDisplayName = 1;
+ meta.config.hideFullname = 0;
const { topicData } = await topics.post({
title: 'topic events testing',
content: 'foobar one two three',
@@ -129,7 +131,8 @@ describe('Topic Events', () => {
assert.deepStrictEqual(events[0].text, `<span title="&quot;&gt;&lt;script&gt;alert(&quot;xss&quot;)&lt;/script&gt; [[global:posts]]" data-uid="${uid}" class="avatar avatar-rounded" component="avatar/icon" style="--avatar-size:16px;background-color:#827717">B</span> <a href="${nconf.get('relative_path')}/user/bar">"&gt;&lt;script&gt;alert("xss")&lt;/script&gt; [[global:posts]]</a> <a href="${nconf.get('relative_path')}/topic/${topicData.tid}">forked</a> this topic <span class="timeago timeline-text" title="${new Date(now).toISOString()}"></span>`);
- meta.config.showFullnameAsDisplayName = oldVlaueShowFullnameAsDisplayName;
+ meta.config.showFullnameAsDisplayName = oldValueShowFullnameAsDisplayName;
+ meta.config.hideFullname = oldValueHideFullname;
});
it('should properly escape topic event with plain text in their arguments', async () => {
diff --git a/test/uploads.js b/test/uploads.js
index 55d8a0db49..00dac2ac5a 100644
--- a/test/uploads.js
+++ b/test/uploads.js
@@ -587,14 +587,13 @@ describe('Upload Controllers', () => {
`/assets/x/../uploads/xss-dirty.xml`,
`/assets/uploads/%2e%2e/uploads/xss-dirty.xml`,
`/assets/uploads/%2e/xss-dirty.xml`,
- `/assets/uploads%5cxss-dirty.xml`,
];
for (const url of urlsToTest) {
// eslint-disable-next-line no-await-in-loop
const { response: fileResponse } = await request.get(`${nconf.get('url')}${url}`);
assert.strictEqual(fileResponse.headers['content-disposition'], 'attachment; filename="xss-dirty.xml"');
- assert.equal(fileResponse.statusCode, 200);
+ assert.equal(fileResponse.statusCode, 200, `Failed for url: ${url}`);
}
});