mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-08-31 03:18:03 +02:00
Resolve merge conflicts, minify only .js files
This commit is contained in:
79
test/blacklist.js
Normal file
79
test/blacklist.js
Normal file
@@ -0,0 +1,79 @@
|
||||
'use strict';
|
||||
|
||||
/* global require, after, before*/
|
||||
|
||||
|
||||
var async = require('async');
|
||||
var assert = require('assert');
|
||||
|
||||
var db = require('./mocks/databasemock');
|
||||
var groups = require('../src/groups');
|
||||
var user = require('../src/user');
|
||||
var blacklist = require('../src/meta/blacklist');
|
||||
|
||||
describe('blacklist', function () {
|
||||
var adminUid;
|
||||
|
||||
before(function (done) {
|
||||
groups.resetCache();
|
||||
user.create({ username: 'admin' }, function (err, uid) {
|
||||
assert.ifError(err);
|
||||
adminUid = uid;
|
||||
groups.join('administrators', adminUid, done);
|
||||
});
|
||||
});
|
||||
|
||||
var socketBlacklist = require('../src/socket.io/blacklist');
|
||||
var rules = '1.1.1.1\n2.2.2.2\n::ffff:0:2.2.2.2\n127.0.0.1\n192.168.100.0/22';
|
||||
|
||||
it('should validate blacklist', function (done) {
|
||||
socketBlacklist.validate({ uid: adminUid }, {
|
||||
rules: rules,
|
||||
}, function (err, data) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should error if not admin', function (done) {
|
||||
socketBlacklist.save({ uid: 0 }, rules, function (err) {
|
||||
assert.equal(err.message, '[[error:no-privileges]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should save blacklist', function (done) {
|
||||
socketBlacklist.save({ uid: adminUid }, rules, function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should pass ip test against blacklist async', function (done) {
|
||||
blacklist.test('3.3.3.3', function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should pass ip test against blacklist sync', function (done) {
|
||||
assert(!blacklist.test('3.3.3.3'));
|
||||
done();
|
||||
});
|
||||
|
||||
it('should fail ip test against blacklist async', function (done) {
|
||||
blacklist.test('1.1.1.1', function (err) {
|
||||
assert.equal(err.message, '[[error:blacklisted-ip]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail ip test against blacklist sync', function (done) {
|
||||
assert(blacklist.test('1.1.1.1'));
|
||||
done();
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
db.emptydb(done);
|
||||
});
|
||||
});
|
||||
@@ -6,6 +6,7 @@ var db = require('./mocks/databasemock');
|
||||
|
||||
describe('Build', function () {
|
||||
it('should build all assets', function (done) {
|
||||
this.timeout(50000);
|
||||
var build = require('../src/meta/build');
|
||||
build.buildAll(function (err) {
|
||||
assert.ifError(err);
|
||||
|
||||
@@ -29,6 +29,12 @@ describe('Controllers', function () {
|
||||
user: function (next) {
|
||||
user.create({ username: 'foo', password: 'barbar' }, next);
|
||||
},
|
||||
navigation: function (next) {
|
||||
var navigation = require('../src/navigation/admin');
|
||||
var data = require('../install/data/navigation.json');
|
||||
|
||||
navigation.save(data, next);
|
||||
},
|
||||
}, function (err, results) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
|
||||
177
test/files/503.html
Normal file
177
test/files/503.html
Normal file
@@ -0,0 +1,177 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Excessive Load Warning</title>
|
||||
<link href='https://fonts.googleapis.com/css?family=Ubuntu:400,500,700' rel='stylesheet' type='text/css'>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<style type="text/css">
|
||||
body {
|
||||
background: #00A9EA;
|
||||
color: white;
|
||||
font-family: 'Ubuntu', sans-serif;
|
||||
text-align: center;
|
||||
-webkit-transform-style: preserve-3d;
|
||||
-moz-transform-style: preserve-3d;
|
||||
transform-style: preserve-3d;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 250px;
|
||||
color: #fff;
|
||||
opacity: 0.5;
|
||||
margin: 10px;
|
||||
cursor: pointer;
|
||||
-moz-user-select: none;
|
||||
-khtml-user-select: none;
|
||||
-webkit-user-select: none;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
p strong {
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
h1 {
|
||||
font-size: 125px;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
p strong {
|
||||
font-size: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
.center {
|
||||
position: relative;
|
||||
top: 50%;
|
||||
-webkit-transform: translateY(50%);
|
||||
-ms-transform: translateY(50%);
|
||||
transform: translateY(50%);
|
||||
}
|
||||
|
||||
@-webkit-keyframes bounce {
|
||||
0%, 20%, 53%, 80%, 100% {
|
||||
-webkit-transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
|
||||
transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
|
||||
-webkit-transform: translate3d(0,0,0);
|
||||
transform: translate3d(0,0,0);
|
||||
}
|
||||
|
||||
40%, 43% {
|
||||
-webkit-transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
|
||||
transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
|
||||
-webkit-transform: translate3d(0, -30px, 0);
|
||||
transform: translate3d(0, -30px, 0);
|
||||
}
|
||||
|
||||
70% {
|
||||
-webkit-transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
|
||||
transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
|
||||
-webkit-transform: translate3d(0, -15px, 0);
|
||||
transform: translate3d(0, -15px, 0);
|
||||
}
|
||||
|
||||
90% {
|
||||
-webkit-transform: translate3d(0,-4px,0);
|
||||
transform: translate3d(0,-4px,0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes bounce {
|
||||
0%, 20%, 53%, 80%, 100% {
|
||||
-webkit-transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
|
||||
transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
|
||||
-webkit-transform: translate3d(0,0,0);
|
||||
transform: translate3d(0,0,0);
|
||||
}
|
||||
|
||||
40%, 43% {
|
||||
-webkit-transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
|
||||
transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
|
||||
-webkit-transform: translate3d(0, -30px, 0);
|
||||
transform: translate3d(0, -30px, 0);
|
||||
}
|
||||
|
||||
70% {
|
||||
-webkit-transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
|
||||
transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
|
||||
-webkit-transform: translate3d(0, -15px, 0);
|
||||
transform: translate3d(0, -15px, 0);
|
||||
}
|
||||
|
||||
90% {
|
||||
-webkit-transform: translate3d(0,-4px,0);
|
||||
transform: translate3d(0,-4px,0);
|
||||
}
|
||||
}
|
||||
|
||||
.bounce {
|
||||
-webkit-animation-name: bounce;
|
||||
animation-name: bounce;
|
||||
-webkit-transform-origin: center bottom;
|
||||
-ms-transform-origin: center bottom;
|
||||
transform-origin: center bottom;
|
||||
}
|
||||
|
||||
.animated {
|
||||
-webkit-animation-duration: 1s;
|
||||
animation-duration: 1s;
|
||||
-webkit-animation-fill-mode: both;
|
||||
animation-fill-mode: both;
|
||||
}
|
||||
|
||||
.animated.infinite {
|
||||
-webkit-animation-iteration-count: infinite;
|
||||
animation-iteration-count: infinite;
|
||||
}
|
||||
|
||||
.animated.hinge {
|
||||
-webkit-animation-duration: 2s;
|
||||
animation-duration: 2s;
|
||||
}
|
||||
|
||||
.hide {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
window.onload = function() {
|
||||
var count = 0,
|
||||
bounce = document.getElementById('click-me');
|
||||
bounce.onclick = function() {
|
||||
count++;
|
||||
bounce.className = '';
|
||||
setTimeout(function() {
|
||||
bounce.className = 'animated bounce';
|
||||
}, 50);
|
||||
|
||||
if (count > 5) {
|
||||
document.getElementById('hide').className = '';
|
||||
}
|
||||
};
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="wrapper">
|
||||
<div class="center">
|
||||
<h1 id="click-me" class="animated bounce">503</h1>
|
||||
<p>
|
||||
<strong>This forum is temporarily unavailable due to excessive load.</strong>
|
||||
</p>
|
||||
<p>
|
||||
We shouldn't be down for long. Please check back shortly. Sorry for the inconvenience!
|
||||
</p>
|
||||
<p>
|
||||
<small id="hide" class="hide">Alright. You can stop clicking... it's not going to make the site come back sooner!</small>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
BIN
test/files/favicon.ico
Normal file
BIN
test/files/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
BIN
test/files/test.png
Normal file
BIN
test/files/test.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.0 KiB |
@@ -705,8 +705,8 @@ describe('Groups', function () {
|
||||
describe('groups cover', function () {
|
||||
var socketGroups = require('../src/socket.io/groups');
|
||||
var regularUid;
|
||||
var logoPath = path.join(__dirname, '../public/logo.png');
|
||||
var imagePath = path.join(__dirname, '../public/groupcover.png');
|
||||
var logoPath = path.join(__dirname, '../test/files/test.png');
|
||||
var imagePath = path.join(__dirname, '../test/files/groupcover.png');
|
||||
before(function (done) {
|
||||
User.create({ username: 'regularuser', password: '123456' }, function (err, uid) {
|
||||
assert.ifError(err);
|
||||
|
||||
@@ -40,6 +40,7 @@ helpers.loginUser = function (username, password, callback) {
|
||||
this.open = function () {
|
||||
stdOpen.apply(this, arguments);
|
||||
this.setRequestHeader('Cookie', res.headers['set-cookie'][0].split(';')[0]);
|
||||
this.setRequestHeader('Origin', nconf.get('url'));
|
||||
};
|
||||
};
|
||||
|
||||
@@ -74,6 +75,7 @@ helpers.initSocketIO = function (callback) {
|
||||
this.open = function () {
|
||||
stdOpen.apply(this, arguments);
|
||||
this.setRequestHeader('Cookie', res.headers['set-cookie'][0].split(';')[0]);
|
||||
this.setRequestHeader('Origin', nconf.get('url'));
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -121,6 +121,28 @@ describe('Messaging Library', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should notify offline users of message', function (done) {
|
||||
Messaging.notificationSendDelay = 100;
|
||||
|
||||
db.sortedSetAdd('users:online', Date.now() - 350000, herpUid, function (err) {
|
||||
assert.ifError(err);
|
||||
socketModules.chats.send({ uid: fooUid }, { roomId: roomId, message: 'second chat message' }, function (err) {
|
||||
assert.ifError(err);
|
||||
setTimeout(function () {
|
||||
User.notifications.get(herpUid, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data.unread[0]);
|
||||
var notification = data.unread[0];
|
||||
assert.equal(notification.bodyShort, '[[notifications:new_message_from, foo]]');
|
||||
assert.equal(notification.nid, 'chat_' + fooUid + '_' + roomId);
|
||||
assert.equal(notification.path, '/chats/' + roomId);
|
||||
done();
|
||||
});
|
||||
}, 1500);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should get messages from room', function (done) {
|
||||
socketModules.chats.getMessages({ uid: fooUid }, {
|
||||
uid: fooUid,
|
||||
|
||||
137
test/posts.js
137
test/posts.js
@@ -754,6 +754,143 @@ describe('Post\'s', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('socket methods', function () {
|
||||
var pid;
|
||||
before(function (done) {
|
||||
topics.reply({
|
||||
uid: voterUid,
|
||||
tid: topicData.tid,
|
||||
timestamp: Date.now(),
|
||||
content: 'raw content',
|
||||
}, function (err, postData) {
|
||||
assert.ifError(err);
|
||||
pid = postData.pid;
|
||||
privileges.categories.rescind(['read'], cid, 'guests', done);
|
||||
});
|
||||
});
|
||||
|
||||
var socketPosts = require('../src/socket.io/posts');
|
||||
it('should error with invalid data', function (done) {
|
||||
socketPosts.reply({ uid: 0 }, null, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should error with invalid tid', function (done) {
|
||||
socketPosts.reply({ uid: 0 }, { tid: 0, content: 'derp' }, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail to get raw post because of privilege', function (done) {
|
||||
socketPosts.getRawPost({ uid: 0 }, pid, function (err) {
|
||||
assert.equal(err.message, '[[error:no-privileges]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail to get raw post because post is deleted', function (done) {
|
||||
posts.setPostField(pid, 'deleted', 1, function (err) {
|
||||
assert.ifError(err);
|
||||
socketPosts.getRawPost({ uid: voterUid }, pid, function (err) {
|
||||
assert.equal(err.message, '[[error:no-post]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should get raw post content', function (done) {
|
||||
posts.setPostField(pid, 'deleted', 0, function (err) {
|
||||
assert.ifError(err);
|
||||
socketPosts.getRawPost({ uid: voterUid }, pid, function (err, postContent) {
|
||||
assert.ifError(err);
|
||||
assert.equal(postContent, 'raw content');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should get post', function (done) {
|
||||
socketPosts.getPost({ uid: voterUid }, pid, function (err, postData) {
|
||||
assert.ifError(err);
|
||||
assert(postData);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('shold error with invalid data', function (done) {
|
||||
socketPosts.loadMoreBookmarks({ uid: voterUid }, { uid: voterUid, after: null }, function (err, postData) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should load more bookmarks', function (done) {
|
||||
socketPosts.loadMoreBookmarks({ uid: voterUid }, { uid: voterUid, after: 0 }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should load more user posts', function (done) {
|
||||
socketPosts.loadMoreUserPosts({ uid: voterUid }, { uid: voterUid, after: 0 }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should load more best posts', function (done) {
|
||||
socketPosts.loadMoreBestPosts({ uid: voterUid }, { uid: voterUid, after: 0 }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should load more up voted posts', function (done) {
|
||||
socketPosts.loadMoreUpVotedPosts({ uid: voterUid }, { uid: voterUid, after: 0 }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should load more down voted posts', function (done) {
|
||||
socketPosts.loadMoreDownVotedPosts({ uid: voterUid }, { uid: voterUid, after: 0 }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should get post category', function (done) {
|
||||
socketPosts.getCategory({ uid: voterUid }, pid, function (err, postCid) {
|
||||
assert.ifError(err);
|
||||
assert.equal(cid, postCid);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should error with invalid data', function (done) {
|
||||
socketPosts.getPidIndex({ uid: voterUid }, null, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should get pid index', function (done) {
|
||||
socketPosts.getPidIndex({ uid: voterUid }, { pid: pid, tid: topicData.tid, topicPostSort: 'oldest-to-newest' }, function (err, index) {
|
||||
assert.ifError(err);
|
||||
assert.equal(index, 2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
after(function (done) {
|
||||
db.emptydb(done);
|
||||
});
|
||||
|
||||
@@ -73,6 +73,7 @@ describe('socket.io', function () {
|
||||
this.open = function () {
|
||||
stdOpen.apply(this, arguments);
|
||||
this.setRequestHeader('Cookie', res.headers['set-cookie'][0].split(';')[0]);
|
||||
this.setRequestHeader('Origin', nconf.get('url'));
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -129,6 +129,13 @@ describe('Topic\'s', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should error if pid is not a number', function (done) {
|
||||
socketPosts.getReplies({ uid: 0 }, 'abc', function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail to create new reply with invalid user id', function (done) {
|
||||
topics.reply({ uid: null, content: 'test post', tid: newTopic.tid }, function (err) {
|
||||
assert.equal(err.message, '[[error:no-privileges]]');
|
||||
@@ -174,9 +181,24 @@ describe('Topic\'s', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('.getTopicData', function () {
|
||||
it('should not receive errors', function (done) {
|
||||
topics.getTopicData(newTopic.tid, done);
|
||||
|
||||
it('should not receive errors', function (done) {
|
||||
topics.getTopicData(newTopic.tid, done);
|
||||
});
|
||||
|
||||
it('should get topic title by pid', function (done) {
|
||||
topics.getTitleByPid(newPost.pid, function (err, title) {
|
||||
assert.ifError(err);
|
||||
assert.equal(title, topic.title);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should get topic data by pid', function (done) {
|
||||
topics.getTopicDataByPid(newPost.pid, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data.tid, newTopic.tid);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -66,18 +66,18 @@ describe('Upload Controllers', function () {
|
||||
});
|
||||
|
||||
it('should upload a profile picture', function (done) {
|
||||
helpers.uploadFile(nconf.get('url') + '/api/user/regular/uploadpicture', path.join(__dirname, '../public/logo.png'), {}, jar, csrf_token, function (err, res, body) {
|
||||
helpers.uploadFile(nconf.get('url') + '/api/user/regular/uploadpicture', path.join(__dirname, '../test/files/test.png'), {}, jar, csrf_token, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(Array.isArray(body));
|
||||
assert.equal(body.length, 1);
|
||||
assert.equal(body[0].url, '/assets/uploads/profile/' + regularUid + '-profileimg.png');
|
||||
assert.equal(body[0].url, '/assets/uploads/profile/' + regularUid + '-profileavatar.png');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should upload an image to a post', function (done) {
|
||||
helpers.uploadFile(nconf.get('url') + '/api/post/upload', path.join(__dirname, '../public/logo.png'), { cid: cid }, jar, csrf_token, function (err, res, body) {
|
||||
helpers.uploadFile(nconf.get('url') + '/api/post/upload', path.join(__dirname, '../test/files/test.png'), { cid: cid }, jar, csrf_token, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(Array.isArray(body));
|
||||
@@ -90,7 +90,7 @@ describe('Upload Controllers', function () {
|
||||
|
||||
it('should upload a file to a post', function (done) {
|
||||
meta.config.allowFileUploads = 1;
|
||||
helpers.uploadFile(nconf.get('url') + '/api/post/upload', path.join(__dirname, '../public/503.html'), { cid: cid }, jar, csrf_token, function (err, res, body) {
|
||||
helpers.uploadFile(nconf.get('url') + '/api/post/upload', path.join(__dirname, '../test/files/503.html'), { cid: cid }, jar, csrf_token, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(Array.isArray(body));
|
||||
@@ -116,7 +116,7 @@ describe('Upload Controllers', function () {
|
||||
});
|
||||
|
||||
it('should upload site logo', function (done) {
|
||||
helpers.uploadFile(nconf.get('url') + '/api/admin/uploadlogo', path.join(__dirname, '../public/logo.png'), {}, jar, csrf_token, function (err, res, body) {
|
||||
helpers.uploadFile(nconf.get('url') + '/api/admin/uploadlogo', path.join(__dirname, '../test/files/test.png'), {}, jar, csrf_token, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(Array.isArray(body));
|
||||
@@ -126,7 +126,7 @@ describe('Upload Controllers', function () {
|
||||
});
|
||||
|
||||
it('should upload category image', function (done) {
|
||||
helpers.uploadFile(nconf.get('url') + '/api/admin/category/uploadpicture', path.join(__dirname, '../public/logo.png'), { params: JSON.stringify({ cid: cid }) }, jar, csrf_token, function (err, res, body) {
|
||||
helpers.uploadFile(nconf.get('url') + '/api/admin/category/uploadpicture', path.join(__dirname, '../test/files/test.png'), { params: JSON.stringify({ cid: cid }) }, jar, csrf_token, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(Array.isArray(body));
|
||||
@@ -136,7 +136,7 @@ describe('Upload Controllers', function () {
|
||||
});
|
||||
|
||||
it('should upload favicon', function (done) {
|
||||
helpers.uploadFile(nconf.get('url') + '/api/admin/uploadfavicon', path.join(__dirname, '../public/favicon.ico'), {}, jar, csrf_token, function (err, res, body) {
|
||||
helpers.uploadFile(nconf.get('url') + '/api/admin/uploadfavicon', path.join(__dirname, '../test/files/favicon.ico'), {}, jar, csrf_token, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(Array.isArray(body));
|
||||
@@ -146,7 +146,7 @@ describe('Upload Controllers', function () {
|
||||
});
|
||||
|
||||
it('should upload touch icon', function (done) {
|
||||
helpers.uploadFile(nconf.get('url') + '/api/admin/uploadTouchIcon', path.join(__dirname, '../public/logo.png'), {}, jar, csrf_token, function (err, res, body) {
|
||||
helpers.uploadFile(nconf.get('url') + '/api/admin/uploadTouchIcon', path.join(__dirname, '../test/files/test.png'), {}, jar, csrf_token, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert(Array.isArray(body));
|
||||
|
||||
221
test/user.js
221
test/user.js
@@ -2,6 +2,7 @@
|
||||
|
||||
var assert = require('assert');
|
||||
var async = require('async');
|
||||
var path = require('path');
|
||||
var nconf = require('nconf');
|
||||
var request = require('request');
|
||||
|
||||
@@ -508,27 +509,34 @@ describe('User', function () {
|
||||
});
|
||||
|
||||
it('should upload profile picture', function (done) {
|
||||
var path = require('path');
|
||||
var picture = {
|
||||
path: path.join(nconf.get('base_dir'), 'public', 'logo.png'),
|
||||
size: 7189,
|
||||
name: 'logo.png',
|
||||
};
|
||||
User.uploadPicture(uid, picture, function (err, uploadedPicture) {
|
||||
assert.ifError(err);
|
||||
assert.equal(uploadedPicture.url, '/assets/uploads/profile/' + uid + '-profileimg.png');
|
||||
assert.equal(uploadedPicture.path, path.join(nconf.get('base_dir'), 'public', 'uploads', 'profile', uid + '-profileimg.png'));
|
||||
done();
|
||||
});
|
||||
helpers.copyFile(
|
||||
path.join(nconf.get('base_dir'), 'test/files/test.png'),
|
||||
path.join(nconf.get('base_dir'), 'test/files/test_copy.png'),
|
||||
function (err) {
|
||||
assert.ifError(err);
|
||||
var picture = {
|
||||
path: path.join(nconf.get('base_dir'), 'test/files/test_copy.png'),
|
||||
size: 7189,
|
||||
name: 'test_copy.png',
|
||||
type: 'image/png',
|
||||
};
|
||||
User.uploadPicture(uid, picture, function (err, uploadedPicture) {
|
||||
assert.ifError(err);
|
||||
assert.equal(uploadedPicture.url, '/assets/uploads/profile/' + uid + '-profileavatar.png');
|
||||
assert.equal(uploadedPicture.path, path.join(nconf.get('base_dir'), 'public', 'uploads', 'profile', uid + '-profileavatar.png'));
|
||||
done();
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should return error if profile image uploads disabled', function (done) {
|
||||
meta.config.allowProfileImageUploads = 0;
|
||||
var path = require('path');
|
||||
var picture = {
|
||||
path: path.join(nconf.get('base_dir'), 'public', 'logo.png'),
|
||||
path: path.join(nconf.get('base_dir'), 'test/files/test.png'),
|
||||
size: 7189,
|
||||
name: 'logo.png',
|
||||
name: 'test.png',
|
||||
type: 'image/png',
|
||||
};
|
||||
User.uploadPicture(uid, picture, function (err) {
|
||||
assert.equal(err.message, '[[error:profile-image-uploads-disabled]]');
|
||||
@@ -538,11 +546,11 @@ describe('User', function () {
|
||||
|
||||
it('should return error if profile image is too big', function (done) {
|
||||
meta.config.allowProfileImageUploads = 1;
|
||||
var path = require('path');
|
||||
var picture = {
|
||||
path: path.join(nconf.get('base_dir'), 'public', 'logo.png'),
|
||||
path: path.join(nconf.get('base_dir'), 'test/files/test.png'),
|
||||
size: 265000,
|
||||
name: 'logo.png',
|
||||
name: 'test.png',
|
||||
type: 'image/png',
|
||||
};
|
||||
User.uploadPicture(uid, picture, function (err) {
|
||||
assert.equal(err.message, '[[error:file-too-big, 256]]');
|
||||
@@ -550,12 +558,11 @@ describe('User', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should return error if profile image file has no extension', function (done) {
|
||||
var path = require('path');
|
||||
it('should return error if profile image has no mime type', function (done) {
|
||||
var picture = {
|
||||
path: path.join(nconf.get('base_dir'), 'public', 'logo.png'),
|
||||
path: path.join(nconf.get('base_dir'), 'test/files/test.png'),
|
||||
size: 7189,
|
||||
name: 'logo',
|
||||
name: 'test',
|
||||
};
|
||||
User.uploadPicture(uid, picture, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-image-extension]]');
|
||||
@@ -564,7 +571,7 @@ describe('User', function () {
|
||||
});
|
||||
|
||||
it('should return error if no plugins listening for filter:uploadImage when uploading from url', function (done) {
|
||||
var url = nconf.get('url') + '/logo.png';
|
||||
var url = nconf.get('url') + '/assets/logo.png';
|
||||
User.uploadFromUrl(uid, url, function (err) {
|
||||
assert.equal(err.message, '[[error:no-plugin]]');
|
||||
done();
|
||||
@@ -575,7 +582,6 @@ describe('User', function () {
|
||||
var url = nconf.get('url') + '/favicon.ico';
|
||||
|
||||
function filterMethod(data, callback) {
|
||||
data.foo += 5;
|
||||
callback(null, data);
|
||||
}
|
||||
|
||||
@@ -588,11 +594,10 @@ describe('User', function () {
|
||||
});
|
||||
|
||||
it('should return error if the file is too big when uploading from url', function (done) {
|
||||
var url = nconf.get('url') + '/logo.png';
|
||||
var url = nconf.get('url') + '/assets/logo.png';
|
||||
meta.config.maximumProfileImageSize = 1;
|
||||
|
||||
function filterMethod(data, callback) {
|
||||
data.foo += 5;
|
||||
callback(null, data);
|
||||
}
|
||||
|
||||
@@ -604,20 +609,29 @@ describe('User', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should error with invalid data', function (done) {
|
||||
var socketUser = require('../src/socket.io/user');
|
||||
|
||||
socketUser.uploadProfileImageFromUrl({ uid: uid }, { uid: uid, url: '' }, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should upload picture when uploading from url', function (done) {
|
||||
var url = nconf.get('url') + '/logo.png';
|
||||
var socketUser = require('../src/socket.io/user');
|
||||
var url = nconf.get('url') + '/assets/logo.png';
|
||||
meta.config.maximumProfileImageSize = '';
|
||||
|
||||
function filterMethod(data, callback) {
|
||||
data.foo += 5;
|
||||
callback(null, { url: url });
|
||||
}
|
||||
|
||||
plugins.registerHook('test-plugin', { hook: 'filter:uploadImage', method: filterMethod });
|
||||
|
||||
User.uploadFromUrl(uid, url, function (err, uploadedPicture) {
|
||||
socketUser.uploadProfileImageFromUrl({ uid: uid }, { uid: uid, url: url }, function (err, uploadedPicture) {
|
||||
assert.ifError(err);
|
||||
assert.equal(uploadedPicture.url, url);
|
||||
assert.equal(uploadedPicture, url);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -991,6 +1005,153 @@ describe('User', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('invites', function () {
|
||||
var socketUser = require('../src/socket.io/user');
|
||||
var inviterUid;
|
||||
|
||||
before(function (done) {
|
||||
User.create({
|
||||
username: 'inviter',
|
||||
email: 'inviter@nodebb.org',
|
||||
}, function (err, uid) {
|
||||
assert.ifError(err);
|
||||
inviterUid = uid;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should error with invalid data', function (done) {
|
||||
socketUser.invite({ uid: inviterUid }, null, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should eror if forum is not invite only', function (done) {
|
||||
socketUser.invite({ uid: inviterUid }, 'invite1@test.com', function (err) {
|
||||
assert.equal(err.message, '[[error:forum-not-invite-only]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should error if user is not admin and type is admin-invite-only', function (done) {
|
||||
meta.config.registrationType = 'admin-invite-only';
|
||||
socketUser.invite({ uid: inviterUid }, 'invite1@test.com', function (err) {
|
||||
assert.equal(err.message, '[[error:no-privileges]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should send invitation email', function (done) {
|
||||
meta.config.registrationType = 'invite-only';
|
||||
socketUser.invite({ uid: inviterUid }, 'invite1@test.com', function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should error if ouf of invitations', function (done) {
|
||||
meta.config.maximumInvites = 1;
|
||||
socketUser.invite({ uid: inviterUid }, 'invite2@test.com', function (err) {
|
||||
assert.equal(err.message, '[[error:invite-maximum-met, ' + 1 + ', ' + 1 + ']]');
|
||||
meta.config.maximumInvites = 5;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should error if email exists', function (done) {
|
||||
socketUser.invite({ uid: inviterUid }, 'inviter@nodebb.org', function (err) {
|
||||
assert.equal(err.message, '[[error:email-taken]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should send invitation email', function (done) {
|
||||
socketUser.invite({ uid: inviterUid }, 'invite2@test.com', function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should get user\'s invites', function (done) {
|
||||
User.getInvites(inviterUid, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.notEqual(data.indexOf('invite1@test.com'), -1);
|
||||
assert.notEqual(data.indexOf('invite2@test.com'), -1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should get all invites', function (done) {
|
||||
User.getAllInvites(function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert.equal(data[0].uid, inviterUid);
|
||||
assert.notEqual(data[0].invitations.indexOf('invite1@test.com'), -1);
|
||||
assert.notEqual(data[0].invitations.indexOf('invite2@test.com'), -1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail to verify invitation with invalid data', function (done) {
|
||||
User.verifyInvitation({ token: '', email: '' }, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-data]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail to verify invitation with invalid email', function (done) {
|
||||
User.verifyInvitation({ token: 'test', email: 'doesnotexist@test.com' }, function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-token]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should verify installation with no errors', function (done) {
|
||||
var email = 'invite1@test.com';
|
||||
db.get('invitation:email:' + email, function (err, token) {
|
||||
assert.ifError(err);
|
||||
User.verifyInvitation({ token: token, email: 'invite1@test.com' }, function (err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should error with invalid username', function (done) {
|
||||
User.deleteInvitation('doesnotexist', 'test@test.com', function (err) {
|
||||
assert.equal(err.message, '[[error:invalid-username]]');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should delete invitation', function (done) {
|
||||
var socketAdmin = require('../src/socket.io/admin');
|
||||
socketAdmin.user.deleteInvitation({ uid: inviterUid }, { invitedBy: 'inviter', email: 'invite1@test.com' }, function (err) {
|
||||
assert.ifError(err);
|
||||
db.isSetMember('invitation:uid:' + inviterUid, 'invite1@test.com', function (err, isMember) {
|
||||
assert.ifError(err);
|
||||
assert.equal(isMember, false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should delete invitation key', function (done) {
|
||||
User.deleteInvitationKey('invite2@test.com', function (err) {
|
||||
assert.ifError(err);
|
||||
db.isSetMember('invitation:uid:' + inviterUid, 'invite2@test.com', function (err, isMember) {
|
||||
assert.ifError(err);
|
||||
assert.equal(isMember, false);
|
||||
db.isSetMember('invitation:uids', inviterUid, function (err, isMember) {
|
||||
assert.ifError(err);
|
||||
assert.equal(isMember, false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
after(function (done) {
|
||||
db.emptydb(done);
|
||||
|
||||
Reference in New Issue
Block a user