cards.security.tests.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* eslint-env mocha */
  2. import { expect } from 'chai';
  3. import '../utils';
  4. import '/models/cards';
  5. // Unit tests for canUpdateCard policy (deny direct vote updates)
  6. describe('cards security', function() {
  7. describe(canUpdateCard.name, function() {
  8. const userId = 'user1';
  9. const board = {
  10. hasMember: (id) => id === userId,
  11. };
  12. const doc = { boardId: 'board1' };
  13. // Patch ReactiveCache.getBoard for this unit test scope if not defined
  14. const origGetBoard = ReactiveCache && ReactiveCache.getBoard;
  15. before(function() {
  16. if (typeof ReactiveCache === 'object') {
  17. ReactiveCache.getBoard = () => board;
  18. }
  19. });
  20. after(function() {
  21. if (typeof ReactiveCache === 'object') {
  22. ReactiveCache.getBoard = origGetBoard;
  23. }
  24. });
  25. it('denies anonymous users', function() {
  26. expect(canUpdateCard(null, doc, ['title'])).to.equal(false);
  27. });
  28. it('denies direct vote updates', function() {
  29. expect(canUpdateCard(userId, doc, ['vote'])).to.equal(false);
  30. expect(canUpdateCard(userId, doc, ['vote', 'modifiedAt', 'dateLastActivity'])).to.equal(false);
  31. expect(canUpdateCard(userId, doc, ['vote.positive'])).to.equal(false);
  32. expect(canUpdateCard(userId, doc, ['vote.negative'])).to.equal(false);
  33. });
  34. it('denies direct poker updates', function() {
  35. expect(canUpdateCard(userId, doc, ['poker'])).to.equal(false);
  36. expect(canUpdateCard(userId, doc, ['poker.one'])).to.equal(false);
  37. expect(canUpdateCard(userId, doc, ['poker.allowNonBoardMembers'])).to.equal(false);
  38. expect(canUpdateCard(userId, doc, ['poker.end'])).to.equal(false);
  39. });
  40. it('allows member updates when not touching vote', function() {
  41. expect(canUpdateCard(userId, doc, ['title'])).to.equal(true);
  42. expect(canUpdateCard(userId, doc, ['description', 'modifiedAt'])).to.equal(true);
  43. });
  44. it('denies non-members even when not touching vote', function() {
  45. const nonMemberId = 'user2';
  46. expect(canUpdateCard(nonMemberId, doc, ['title'])).to.equal(false);
  47. });
  48. });
  49. });