mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
* Re-organize common folder * fix: Correct paths in tests * fix: move new content to proper folder * chore: Move audio folder to assets * Move sprites to sprites assets directory * Move css sprites to assets directory * Split out readmes for common code and sprites * Move images to assets directory * Move destinatin of shared browserified file * remove unused file * move compiled js to client-old * Fix karma tests * fix: Correct paths for sprites
58 lines
1.6 KiB
JavaScript
58 lines
1.6 KiB
JavaScript
/* eslint-disable global-require */
|
|
import {
|
|
generateRes,
|
|
generateReq,
|
|
generateNext,
|
|
} from '../../../../helpers/api-unit.helper';
|
|
import i18n from '../../../../../website/common/script/i18n';
|
|
import { ensureAdmin, ensureSudo } from '../../../../../website/server/middlewares/ensureAccessRight';
|
|
import { NotAuthorized } from '../../../../../website/server/libs/errors';
|
|
|
|
describe('ensure access middlewares', () => {
|
|
let res, req, next;
|
|
|
|
beforeEach(() => {
|
|
res = generateRes();
|
|
req = generateReq();
|
|
next = generateNext();
|
|
});
|
|
|
|
context('ensure admin', () => {
|
|
it('returns not authorized when user is not an admin', () => {
|
|
res.locals = {user: {contributor: {admin: false}}};
|
|
|
|
ensureAdmin(req, res, next);
|
|
|
|
expect(next).to.be.calledWith(new NotAuthorized(i18n.t('noAdminAccess')));
|
|
});
|
|
|
|
it('passes when user is an admin', () => {
|
|
res.locals = {user: {contributor: {admin: true}}};
|
|
|
|
ensureAdmin(req, res, next);
|
|
|
|
expect(next).to.be.calledOnce;
|
|
expect(next.args[0]).to.be.empty;
|
|
});
|
|
});
|
|
|
|
context('ensure sudo', () => {
|
|
it('returns not authorized when user is not a sudo user', () => {
|
|
res.locals = {user: {contributor: {sudo: false}}};
|
|
|
|
ensureSudo(req, res, next);
|
|
|
|
expect(next).to.be.calledWith(new NotAuthorized(i18n.t('noSudoAccess')));
|
|
});
|
|
|
|
it('passes when user is a sudo user', () => {
|
|
res.locals = {user: {contributor: {sudo: true}}};
|
|
|
|
ensureSudo(req, res, next);
|
|
|
|
expect(next).to.be.calledOnce;
|
|
expect(next.args[0]).to.be.empty;
|
|
});
|
|
});
|
|
});
|