| 
									
										
										
										
											2016-10-31 13:52:26 +03:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var async = require('async'); | 
					
						
							|  |  |  | var	assert = require('assert'); | 
					
						
							|  |  |  | var nconf = require('nconf'); | 
					
						
							|  |  |  | var request = require('request'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var db = require('./mocks/databasemock'); | 
					
						
							|  |  |  | var categories = require('../src/categories'); | 
					
						
							|  |  |  | var topics = require('../src/topics'); | 
					
						
							|  |  |  | var user = require('../src/user'); | 
					
						
							|  |  |  | var groups = require('../src/groups'); | 
					
						
							|  |  |  | var helpers = require('./helpers'); | 
					
						
							| 
									
										
										
										
											2017-11-29 14:04:45 -05:00
										 |  |  | var meta = require('../src/meta'); | 
					
						
							| 
									
										
										
										
											2016-10-31 13:52:26 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe('Admin Controllers', function () { | 
					
						
							|  |  |  | 	var tid; | 
					
						
							|  |  |  | 	var cid; | 
					
						
							|  |  |  | 	var pid; | 
					
						
							|  |  |  | 	var adminUid; | 
					
						
							| 
									
										
										
										
											2016-11-01 13:02:12 +03:00
										 |  |  | 	var regularUid; | 
					
						
							| 
									
										
										
										
											2017-05-09 14:31:32 -04:00
										 |  |  | 	var moderatorUid; | 
					
						
							| 
									
										
										
										
											2016-10-31 13:52:26 +03:00
										 |  |  | 	var jar; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	before(function (done) { | 
					
						
							|  |  |  | 		async.series({ | 
					
						
							|  |  |  | 			category: function (next) { | 
					
						
							|  |  |  | 				categories.create({ | 
					
						
							|  |  |  | 					name: 'Test Category', | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 					description: 'Test category created by testing script', | 
					
						
							| 
									
										
										
										
											2016-10-31 13:52:26 +03:00
										 |  |  | 				}, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2016-11-01 13:02:12 +03:00
										 |  |  | 			adminUid: function (next) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 				user.create({ username: 'admin', password: 'barbar' }, next); | 
					
						
							| 
									
										
										
										
											2016-11-01 13:02:12 +03:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			regularUid: function (next) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 				user.create({ username: 'regular' }, next); | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2017-05-09 14:31:32 -04:00
										 |  |  | 			moderatorUid: function (next) { | 
					
						
							|  |  |  | 				user.create({ username: 'moderator', password: 'modmod' }, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2016-10-31 13:52:26 +03:00
										 |  |  | 		}, function (err, results) { | 
					
						
							|  |  |  | 			if (err) { | 
					
						
							|  |  |  | 				return done(err); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-11-01 13:02:12 +03:00
										 |  |  | 			adminUid = results.adminUid; | 
					
						
							|  |  |  | 			regularUid = results.regularUid; | 
					
						
							| 
									
										
										
										
											2017-05-09 14:31:32 -04:00
										 |  |  | 			moderatorUid = results.moderatorUid; | 
					
						
							| 
									
										
										
										
											2016-10-31 13:52:26 +03:00
										 |  |  | 			cid = results.category.cid; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			topics.post({ uid: adminUid, title: 'test topic title', content: 'test topic content', cid: results.category.cid }, function (err, result) { | 
					
						
							| 
									
										
										
										
											2017-03-03 21:04:01 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2016-10-31 13:52:26 +03:00
										 |  |  | 				tid = result.topicData.tid; | 
					
						
							|  |  |  | 				pid = result.postData.pid; | 
					
						
							| 
									
										
										
										
											2017-03-03 21:04:01 +03:00
										 |  |  | 				done(); | 
					
						
							| 
									
										
										
										
											2016-10-31 13:52:26 +03:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should 403 if user is not admin', function (done) { | 
					
						
							|  |  |  | 		helpers.loginUser('admin', 'barbar', function (err, _jar) { | 
					
						
							|  |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			jar = _jar; | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			request(nconf.get('url') + '/admin', { jar: jar }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-10-31 13:52:26 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(res.statusCode, 403); | 
					
						
							|  |  |  | 				assert(body); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load admin dashboard', function (done) { | 
					
						
							|  |  |  | 		groups.join('administrators', adminUid, function (err) { | 
					
						
							|  |  |  | 			assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			request(nconf.get('url') + '/admin', { jar: jar }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-10-31 13:52:26 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(res.statusCode, 200); | 
					
						
							|  |  |  | 				assert(body); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load groups page', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/admin/manage/groups', { jar: jar }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-10-31 13:52:26 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert.equal(res.statusCode, 200); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load groups detail page', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/admin/manage/groups/administrators', { jar: jar }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-10-31 13:52:26 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert.equal(res.statusCode, 200); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-26 11:13:46 -04:00
										 |  |  | 	it('should load global privileges page', function (done) { | 
					
						
							|  |  |  | 		request(nconf.get('url') + '/admin/manage/privileges', { jar: jar }, function (err, res, body) { | 
					
						
							|  |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert.equal(res.statusCode, 200); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load privileges page for category 1', function (done) { | 
					
						
							|  |  |  | 		request(nconf.get('url') + '/admin/manage/privileges/1', { jar: jar }, function (err, res, body) { | 
					
						
							|  |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert.equal(res.statusCode, 200); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load manage uploads', function (done) { | 
					
						
							|  |  |  | 		request(nconf.get('url') + '/admin/manage/uploads', { jar: jar }, function (err, res, body) { | 
					
						
							|  |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert.equal(res.statusCode, 200); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2016-10-31 13:52:26 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	it('should load general settings page', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/admin/settings', { jar: jar }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-10-31 13:52:26 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert.equal(res.statusCode, 200); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load email settings page', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/admin/settings/email', { jar: jar }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-10-31 13:52:26 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert.equal(res.statusCode, 200); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-18 15:16:13 -04:00
										 |  |  | 	it('should load user settings page', function (done) { | 
					
						
							|  |  |  | 		request(nconf.get('url') + '/admin/settings/user', { jar: jar }, function (err, res, body) { | 
					
						
							|  |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert.equal(res.statusCode, 200); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-01 13:02:12 +03:00
										 |  |  | 	it('should load info page for a user', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/user/regular/info', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-01 13:02:12 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert.equal(res.statusCode, 200); | 
					
						
							|  |  |  | 			assert(body.history); | 
					
						
							|  |  |  | 			assert(Array.isArray(body.history.flags)); | 
					
						
							|  |  |  | 			assert(Array.isArray(body.history.bans)); | 
					
						
							|  |  |  | 			assert(Array.isArray(body.sessions)); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-24 11:02:53 +03:00
										 |  |  | 	it('should 404 for edit/email page if user does not exist', function (done) { | 
					
						
							| 
									
										
										
										
											2017-05-09 14:31:32 -04:00
										 |  |  | 		request(nconf.get('url') + '/api/user/doesnotexist/edit/email', { jar: jar, json: true }, function (err, res) { | 
					
						
							| 
									
										
										
										
											2016-11-24 11:02:53 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert.equal(res.statusCode, 404); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-01 14:34:15 +03:00
										 |  |  | 	it('should load /admin/general/homepage', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/general/homepage', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-01 14:34:15 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert.equal(res.statusCode, 200); | 
					
						
							|  |  |  | 			assert(body.routes); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/advanced/database', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/advanced/database', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-01 14:34:15 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert.equal(res.statusCode, 200); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (nconf.get('redis')) { | 
					
						
							|  |  |  | 				assert(body.redis); | 
					
						
							|  |  |  | 			} else if (nconf.get('mongo')) { | 
					
						
							|  |  |  | 				assert(body.mongo); | 
					
						
							| 
									
										
										
										
											2018-08-08 14:13:48 -05:00
										 |  |  | 			} else if (nconf.get('postgres')) { | 
					
						
							|  |  |  | 				assert(body.postgres); | 
					
						
							| 
									
										
										
										
											2016-11-01 14:34:15 +03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/extend/plugins', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/extend/plugins', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-01 14:34:15 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body.hasOwnProperty('installed')); | 
					
						
							|  |  |  | 			assert(body.hasOwnProperty('upgradeCount')); | 
					
						
							|  |  |  | 			assert(body.hasOwnProperty('download')); | 
					
						
							|  |  |  | 			assert(body.hasOwnProperty('incompatible')); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 	it('should load /admin/manage/users', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/manage/users', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/manage/users/search', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/manage/users/search', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body.users); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/manage/users/not-validated', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/manage/users/not-validated', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/manage/users/no-posts', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/manage/users/no-posts', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/manage/users/top-posters', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/manage/users/top-posters', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/manage/users/most-reputation', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/manage/users/most-reputation', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/manage/users/inactive', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/manage/users/inactive', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/manage/users/flagged', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/manage/users/flagged', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/manage/users/banned', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/manage/users/banned', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/manage/registration', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/manage/registration', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-05 14:44:18 -05:00
										 |  |  | 	it('should load /admin/manage/admins-mods', function (done) { | 
					
						
							|  |  |  | 		request(nconf.get('url') + '/api/admin/manage/admins-mods', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							|  |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-01 18:16:59 -05:00
										 |  |  | 	it('should return 403 if no referer', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/users/csv', { jar: jar }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-12-01 18:16:59 -05:00
										 |  |  | 			assert.equal(res.statusCode, 403); | 
					
						
							|  |  |  | 			assert.equal(body, '[[error:invalid-origin]]'); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should return 403 if referer is not /admin/users/csv', function (done) { | 
					
						
							|  |  |  | 		request(nconf.get('url') + '/api/admin/users/csv', { | 
					
						
							|  |  |  | 			jar: jar, | 
					
						
							|  |  |  | 			headers: { | 
					
						
							|  |  |  | 				referer: '/topic/1/test', | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, function (err, res, body) { | 
					
						
							|  |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert.equal(res.statusCode, 403); | 
					
						
							|  |  |  | 			assert.equal(body, '[[error:invalid-origin]]'); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/users/csv', function (done) { | 
					
						
							|  |  |  | 		request(nconf.get('url') + '/api/admin/users/csv', { | 
					
						
							|  |  |  | 			jar: jar, | 
					
						
							|  |  |  | 			headers: { | 
					
						
							|  |  |  | 				referer: nconf.get('url') + '/admin/manage/users', | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, function (err, res, body) { | 
					
						
							|  |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert.equal(res.statusCode, 200); | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/manage/flags', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/manage/flags', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-22 22:23:50 -04:00
										 |  |  | 	it('should load /admin/advanced/hooks', function (done) { | 
					
						
							|  |  |  | 		request(nconf.get('url') + '/api/admin/advanced/hooks', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							|  |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 	it('should load /admin/advanced/cache', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/advanced/cache', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/advanced/errors', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/advanced/errors', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/advanced/errors/export', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/advanced/errors/export', { jar: jar }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/advanced/logs', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/advanced/logs', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/general/navigation', function (done) { | 
					
						
							| 
									
										
										
										
											2017-05-24 13:25:47 -04:00
										 |  |  | 		var navigation = require('../src/navigation/admin'); | 
					
						
							|  |  |  | 		var data = require('../install/data/navigation.json'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		navigation.save(data, function (err) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-05-24 13:25:47 -04:00
										 |  |  | 			request(nconf.get('url') + '/api/admin/general/navigation', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert(body); | 
					
						
							|  |  |  | 				assert(body.available); | 
					
						
							|  |  |  | 				assert(body.enabled); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/development/info', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/development/info', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/development/logger', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/development/logger', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/advanced/events', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/advanced/events', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/general/sounds', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/general/sounds', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/manage/categories', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/manage/categories', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/manage/categories/1', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/manage/categories/1', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/manage/categories/1/analytics', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/manage/categories/1/analytics', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/extend/rewards', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/extend/rewards', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/extend/widgets', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/extend/widgets', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/general/languages', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/general/languages', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/general/social', function (done) { | 
					
						
							| 
									
										
										
										
											2017-05-23 20:43:09 -04:00
										 |  |  | 		var socketAdmin = require('../src/socket.io/admin'); | 
					
						
							|  |  |  | 		socketAdmin.social.savePostSharingNetworks({ uid: adminUid }, ['facebook', 'twitter', 'google'], function (err) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-05-23 20:43:09 -04:00
										 |  |  | 			request(nconf.get('url') + '/api/admin/general/social', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert(body); | 
					
						
							|  |  |  | 				body = body.posts.map(function (network) { | 
					
						
							|  |  |  | 					return network && network.id; | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2018-10-20 14:40:48 -04:00
										 |  |  | 				assert(body.includes('facebook')); | 
					
						
							|  |  |  | 				assert(body.includes('twitter')); | 
					
						
							|  |  |  | 				assert(body.includes('google')); | 
					
						
							| 
									
										
										
										
											2017-05-23 20:43:09 -04:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/manage/tags', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/manage/tags', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-08-15 12:59:40 -04:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/manage/post-queue', function (done) { | 
					
						
							|  |  |  | 		request(nconf.get('url') + '/api/admin/manage/post-queue', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							|  |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('/post-queue should 404 for regular user', function (done) { | 
					
						
							|  |  |  | 		request(nconf.get('url') + '/api/post-queue', { json: true }, function (err, res, body) { | 
					
						
							|  |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			assert.equal(res.statusCode, 404); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /post-queue', function (done) { | 
					
						
							|  |  |  | 		request(nconf.get('url') + '/api/post-queue', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							|  |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/manage/ip-blacklist', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/manage/ip-blacklist', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-10 16:27:44 -04:00
										 |  |  | 	it('/ip-blacklist should 404 for regular user', function (done) { | 
					
						
							|  |  |  | 		request(nconf.get('url') + '/api/ip-blacklist', { json: true }, function (err, res, body) { | 
					
						
							|  |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			assert.equal(res.statusCode, 404); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /ip-blacklist', function (done) { | 
					
						
							|  |  |  | 		request(nconf.get('url') + '/api/ip-blacklist', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							|  |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 	it('should load /admin/appearance/themes', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/appearance/themes', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it('should load /admin/appearance/customise', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/admin/appearance/customise', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-22 14:37:14 +03:00
										 |  |  | 	it('should load /recent in maintenance mode', function (done) { | 
					
						
							|  |  |  | 		meta.config.maintenanceMode = 1; | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/recent', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-11-22 14:37:14 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert.equal(res.statusCode, 200); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			meta.config.maintenanceMode = 0; | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2016-11-07 14:45:44 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-20 14:05:15 +03:00
										 |  |  | 	it('should load /posts/flags', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 		request(nconf.get('url') + '/api/posts/flags', { jar: jar, json: true }, function (err, res, body) { | 
					
						
							| 
									
										
										
										
											2016-12-20 14:05:15 +03:00
										 |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							|  |  |  | 			done(); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-12-20 14:06:19 +03:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2016-12-20 14:05:15 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-09 14:31:32 -04:00
										 |  |  | 	describe('mods page', function () { | 
					
						
							|  |  |  | 		var moderatorJar; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		before(function (done) { | 
					
						
							|  |  |  | 			helpers.loginUser('moderator', 'modmod', function (err, _jar) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				moderatorJar = _jar; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 23:21:46 -04:00
										 |  |  | 				groups.join('cid:' + cid + ':privileges:moderate', moderatorUid, done); | 
					
						
							| 
									
										
										
										
											2017-05-09 14:31:32 -04:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should error with no privileges', function (done) { | 
					
						
							|  |  |  | 			request(nconf.get('url') + '/api/flags', { json: true }, function (err, res, body) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(body.error, '[[error:no-privileges]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should load flags page data', function (done) { | 
					
						
							|  |  |  | 			request(nconf.get('url') + '/api/flags', { jar: moderatorJar, json: true }, function (err, res, body) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert(body); | 
					
						
							|  |  |  | 				assert(body.flags); | 
					
						
							|  |  |  | 				assert(body.categories); | 
					
						
							|  |  |  | 				assert(body.filters); | 
					
						
							|  |  |  | 				assert.equal(body.categories[cid], 'Test Category'); | 
					
						
							|  |  |  | 				assert.equal(body.filters.cid.indexOf(cid), -1); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return invalid data if flag does not exist', function (done) { | 
					
						
							|  |  |  | 			request(nconf.get('url') + '/api/flags/123123123', { jar: moderatorJar, json: true }, function (err, res, body) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(body.error, '[[error:invalid-data]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should error with not enough reputation to flag', function (done) { | 
					
						
							|  |  |  | 			var socketFlags = require('../src/socket.io/flags'); | 
					
						
							| 
									
										
										
										
											2018-01-12 17:29:47 -05:00
										 |  |  | 			var oldValue = meta.config['min:rep:flag']; | 
					
						
							|  |  |  | 			meta.config['min:rep:flag'] = 1000; | 
					
						
							| 
									
										
										
										
											2017-05-09 14:31:32 -04:00
										 |  |  | 			socketFlags.create({ uid: regularUid }, { id: pid, type: 'post', reason: 'spam' }, function (err) { | 
					
						
							|  |  |  | 				assert.equal(err.message, '[[error:not-enough-reputation-to-flag]]'); | 
					
						
							| 
									
										
										
										
											2018-01-12 17:29:47 -05:00
										 |  |  | 				meta.config['min:rep:flag'] = oldValue; | 
					
						
							| 
									
										
										
										
											2017-05-09 14:31:32 -04:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return flag details', function (done) { | 
					
						
							|  |  |  | 			var socketFlags = require('../src/socket.io/flags'); | 
					
						
							| 
									
										
										
										
											2018-01-12 17:29:47 -05:00
										 |  |  | 			var oldValue = meta.config['min:rep:flag']; | 
					
						
							|  |  |  | 			meta.config['min:rep:flag'] = 0; | 
					
						
							| 
									
										
										
										
											2017-05-09 14:31:32 -04:00
										 |  |  | 			socketFlags.create({ uid: regularUid }, { id: pid, type: 'post', reason: 'spam' }, function (err, data) { | 
					
						
							| 
									
										
										
										
											2018-01-12 17:29:47 -05:00
										 |  |  | 				meta.config['min:rep:flag'] = oldValue; | 
					
						
							| 
									
										
										
										
											2017-05-09 14:31:32 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				request(nconf.get('url') + '/api/flags/' + data.flagId, { jar: moderatorJar, json: true }, function (err, res, body) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert(body); | 
					
						
							|  |  |  | 					assert.equal(body.reporter.username, 'regular'); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2017-10-26 10:32:24 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	it('should escape special characters in config', function (done) { | 
					
						
							|  |  |  | 		var plugins = require('../src/plugins'); | 
					
						
							|  |  |  | 		function onConfigGet(config, callback) { | 
					
						
							|  |  |  | 			config.someValue = '"foo"'; | 
					
						
							|  |  |  | 			config.otherValue = "'123'"; | 
					
						
							|  |  |  | 			config.script = '</script>'; | 
					
						
							|  |  |  | 			callback(null, config); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		plugins.registerHook('somePlugin', { hook: 'filter:config.get', method: onConfigGet }); | 
					
						
							|  |  |  | 		request(nconf.get('url') + '/admin', { jar: jar }, function (err, res, body) { | 
					
						
							|  |  |  | 			assert.ifError(err); | 
					
						
							|  |  |  | 			assert.equal(res.statusCode, 200); | 
					
						
							|  |  |  | 			assert(body); | 
					
						
							| 
									
										
										
										
											2018-10-20 14:40:48 -04:00
										 |  |  | 			assert(body.includes('"someValue":"\\\\"foo\\\\""')); | 
					
						
							|  |  |  | 			assert(body.includes('"otherValue":"\\\'123\\\'"')); | 
					
						
							|  |  |  | 			assert(body.includes('"script":"<\\/script>"')); | 
					
						
							| 
									
										
										
										
											2017-10-26 10:32:24 -04:00
										 |  |  | 			request(nconf.get('url'), { jar: jar }, function (err, res, body) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(res.statusCode, 200); | 
					
						
							|  |  |  | 				assert(body); | 
					
						
							| 
									
										
										
										
											2018-10-20 14:40:48 -04:00
										 |  |  | 				assert(body.includes('"someValue":"\\\\"foo\\\\""')); | 
					
						
							|  |  |  | 				assert(body.includes('"otherValue":"\\\'123\\\'"')); | 
					
						
							|  |  |  | 				assert(body.includes('"script":"<\\/script>"')); | 
					
						
							| 
									
										
										
										
											2017-10-26 10:32:24 -04:00
										 |  |  | 				plugins.unregisterHook('somePlugin', 'filter:config.get', onConfigGet); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2016-10-31 13:52:26 +03:00
										 |  |  | }); |