Merge branch 'master' into user-sort

Conflicts:
	client/coral-admin/src/reducers/moderation.js
	client/coral-embed-stream/src/actions/stream.js
	client/coral-embed-stream/src/components/Stream.js
	client/coral-framework/components/Slot.js
	plugin-api/beta/client/utils/index.js
	test/server/routes/api/account/index.js
This commit is contained in:
Chi Vinh Le
2017-08-25 21:55:00 +07:00
91 changed files with 1499 additions and 1222 deletions
+47
View File
@@ -0,0 +1,47 @@
const chai = require('chai');
const expect = chai.expect;
const authz = require('../../../middleware/authorization');
describe('middleware.authorization', () => {
describe('#has', () => {
it('allows if no roles are specified', () => {
expect(authz.has({roles: []})).to.be.true;
});
it('allows if the correct roles are met', () => {
expect(authz.has({roles: ['ADMIN']}, 'ADMIN', 'MODERATOR')).to.be.true;
});
it('disallows if the role required is missing', () => {
expect(authz.has({roles: []}, 'ADMIN', 'MODERATOR')).to.be.false;
});
});
describe('#needed', () => {
let needed = (...roles) => {
let middleware = authz.needed(...roles);
return middleware[middleware.length - 1];
};
it('allows if no roles are specified', () => {
needed()({user: {roles: []}}, {}, (err) => {
expect(err).to.be.undefined;
});
});
it('allows if the correct roles are met', () => {
needed()({user: {roles: ['ADMIN']}}, {}, (err) => {
expect(err).to.be.undefined;
});
});
it('disallows if the role required is missing', () => {
needed('ADMIN', 'MODERATOR')({user: {roles: []}}, {}, (err) => {
expect(err).to.not.be.undefined;
});
});
it('disallows if there is no user on the request', () => {
needed('ADMIN', 'MODERATOR')({}, {}, (err) => {
expect(err).to.not.be.undefined;
});
});
});
});
+26 -39
View File
@@ -2,6 +2,7 @@ const passport = require('../../../passport');
const app = require('../../../../../app');
const UsersService = require('../../../../../services/users');
const SettingsService = require('../../../../../services/settings');
const settings = {id: '1', moderation: 'PRE', wordlist: {banned: ['bad words'], suspect: ['suspect words']}};
@@ -10,61 +11,47 @@ chai.should();
chai.use(require('chai-http'));
const expect = chai.expect;
const UsersService = require('../../../../../services/users');
describe('/api/v1/account/username', () => {
let mockUser;
beforeEach(() => SettingsService.init(settings).then(() => {
return UsersService.createLocalUser('ana@gmail.com', '123321123', 'Ana');
})
.then((user) => {
mockUser = user;
}));
beforeEach(async () => {
await SettingsService.init(settings);
mockUser = await UsersService.createLocalUser('ana@gmail.com', '123321123', 'Ana');
});
describe('#put', () => {
it('it should enable a user to edit their username if canEditName is enabled', () => {
return chai.request(app)
it('it should enable a user to edit their username if canEditName is enabled', async () => {
await chai.request(app)
.post(`/api/v1/users/${mockUser.id}/username-enable`)
.set(passport.inject({id: '456', roles: ['ADMIN']}))
.then(() => chai.request(app)
.set(passport.inject({id: '456', roles: ['ADMIN']}));
const res = await chai.request(app)
.put('/api/v1/account/username')
.set(passport.inject({id: mockUser.id, roles: []}))
.send({username: 'MojoJojo'}))
.then((res) => {
expect(res).to.have.status(204);
});
.send({username: 'MojoJojo'});
expect(res).to.have.status(204);
});
it('it should return an error if the wrong user tries to edit a username', (done) => {
chai.request(app)
it('it should return an error if the wrong user tries to edit a username', async () => {
await chai.request(app)
.post(`/api/v1/users/${mockUser.id}/username-enable`)
.set(passport.inject({id: '456', roles: ['ADMIN']}))
.then(() => chai.request(app)
.set(passport.inject({id: '456', roles: ['ADMIN']}));
let res = chai.request(app)
.put('/api/v1/account/username')
.set(passport.inject({id: 'wrongid', roles: []}))
.send({username: 'MojoJojo'}))
.then(() => {
done(new Error('Expected Error'));
})
.catch((err) => {
expect(err).to.be.ok;
done();
});
.send({username: 'MojoJojo'});
return expect(res).to.eventually.be.rejected;
});
it('it should return an error when the user tries to edit their username if canEditName is disabled', (done) => {
chai.request(app)
it('it should return an error when the user tries to edit their username if canEditName is disabled', () => {
let res = chai.request(app)
.put('/api/v1/account/username')
.set(passport.inject({id: mockUser.id, roles: []}))
.send({username: 'MojoJojo'})
.then(() => {
done(new Error('Expected Error'));
})
.catch((err) => {
expect(err).to.be.ok;
done();
});
.send({username: 'MojoJojo'});
return expect(res).to.eventually.be.rejected;
});
});
});
+58 -7
View File
@@ -12,10 +12,13 @@ describe('services.Wordlist', () => {
'cookies',
'how to do bad things',
'how to do really bad things',
's h i t'
's h i t',
'$hit',
'p**ch',
'p*ch',
],
suspect: [
'do bad things'
'do bad things',
]
};
@@ -28,9 +31,19 @@ describe('services.Wordlist', () => {
before(() => wordlist.upsert(wordlists));
it('has entries', () => {
expect(wordlist.lists.banned).to.not.be.empty;
expect(wordlist.lists.suspect).to.not.be.empty;
it('parses the wordlists correctly', () => {
expect(wordlist.lists.banned).to.deep.equal([
[ 'cookies' ],
[ 'how', 'to', 'do', 'bad', 'things' ],
[ 'how', 'to', 'do', 'really', 'bad', 'things' ],
[ 's', 'h', 'i', 't' ],
[ '$hit' ],
[ 'p**ch' ],
[ 'p*ch' ],
]);
expect(wordlist.lists.suspect).to.deep.equal([
[ 'do', 'bad', 'things' ],
]);
});
});
@@ -59,7 +72,9 @@ describe('services.Wordlist', () => {
'cookies',
'COOKIES.',
'how to do bad things',
'How To do bad things!'
'How To do bad things!',
'This stuff is $hit!',
'That\'s a p**ch!',
].forEach((word) => {
expect(wordlist.match(bannedList, word)).to.be.true;
});
@@ -70,7 +85,10 @@ describe('services.Wordlist', () => {
'how to',
'cookie',
'how to be a great person?',
'how to not do really bad things?'
'how to not do really bad things?',
'i have $100 dollars.',
'I have bad $ hit lling',
'That\'s a p***ch!',
].forEach((word) => {
expect(wordlist.match(bannedList, word)).to.be.false;
});
@@ -78,6 +96,39 @@ describe('services.Wordlist', () => {
});
describe('#scan', () => {
it('does match on a bad word', () => {
[
'how to do really bad things',
'what is cookies',
'cookies',
'COOKIES.',
'how to do bad things',
'How To do bad things!',
'This stuff is $hit!',
'That\'s a p**ch!',
].forEach((word) => {
expect(wordlist.scan('body', word)).to.not.be.undefined;
});
});
it('does not match on a good word', () => {
[
'how to',
'cookie',
'how to be a great person?',
'how to not do really bad things?',
'i have $100 dollars.',
'I have bad $ hit lling',
'That\'s a p***ch!',
].forEach((word) => {
expect(wordlist.scan('body', word)).to.be.undefined;
});
});
});
describe('#checkName', () => {
[
'flowers',