boards.security.tests.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* eslint-env mocha */
  2. import { expect } from 'chai';
  3. import { Random } from 'meteor/random';
  4. import '../utils';
  5. // Unit tests for canUpdateBoardSort policy
  6. describe('boards security', function() {
  7. describe(canUpdateBoardSort.name, function() {
  8. it('denies anonymous updates even if fieldNames include sort', function() {
  9. const userId = null;
  10. const board = {
  11. hasMember: () => true,
  12. };
  13. const fieldNames = ['sort'];
  14. expect(canUpdateBoardSort(userId, board, fieldNames)).to.equal(false);
  15. });
  16. it('denies updates by non-members', function() {
  17. const userId = Random.id();
  18. const board = {
  19. hasMember: (id) => id === 'someone-else',
  20. };
  21. const fieldNames = ['sort'];
  22. expect(canUpdateBoardSort(userId, board, fieldNames)).to.equal(false);
  23. });
  24. it('allows updates when user is a member and updating sort', function() {
  25. const userId = Random.id();
  26. const board = {
  27. hasMember: (id) => id === userId,
  28. };
  29. const fieldNames = ['sort'];
  30. expect(canUpdateBoardSort(userId, board, fieldNames)).to.equal(true);
  31. });
  32. it('denies updates when not updating sort', function() {
  33. const userId = Random.id();
  34. const board = {
  35. hasMember: (id) => id === userId,
  36. };
  37. const fieldNames = ['title'];
  38. expect(canUpdateBoardSort(userId, board, fieldNames)).to.equal(false);
  39. });
  40. });
  41. });