mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	
		
			
	
	
		
			80 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
		
		
			
		
	
	
			80 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
|  | '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); | ||
|  | 	}); | ||
|  | }); |