Skip to content

Commit

Permalink
chore!: Improve permissions check on teams endpoints (#32351)
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusbsilva137 authored and ggazzo committed Jun 11, 2024
1 parent 903031c commit 1c6256b
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions apps/meteor/tests/end-to-end/api/25-teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,61 @@ describe('[Teams]', () => {
});
});

describe('/teams.listAll', () => {
before(async () => {
await updatePermission('view-all-teams', ['admin']);
const teamName = `test-team-${Date.now()}`;
await request.post(api('teams.create')).set(credentials).send({
name: teamName,
type: 0,
});
});

after(async () => {
return updatePermission('view-all-teams', ['admin']);
});

it('should list all teams', async () => {
await request
.get(api('teams.listAll'))
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('count');
expect(res.body).to.have.property('offset', 0);
expect(res.body).to.have.property('total');
expect(res.body).to.have.property('teams');
expect(res.body.teams).to.have.length.greaterThan(1);
expect(res.body.teams[0]).to.include.property('_id');
expect(res.body.teams[0]).to.include.property('_updatedAt');
expect(res.body.teams[0]).to.include.property('name');
expect(res.body.teams[0]).to.include.property('type');
expect(res.body.teams[0]).to.include.property('roomId');
expect(res.body.teams[0]).to.include.property('createdBy');
expect(res.body.teams[0].createdBy).to.include.property('_id');
expect(res.body.teams[0].createdBy).to.include.property('username');
expect(res.body.teams[0]).to.include.property('createdAt');
expect(res.body.teams[0]).to.include.property('rooms');
expect(res.body.teams[0]).to.include.property('numberOfUsers');
});
});

it('should return an error when the user does NOT have the view-all-teams permission', async () => {
await updatePermission('view-all-teams', []);
await request
.get(api('teams.listAll'))
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(403)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('error', 'User does not have the permissions required for this action [error-unauthorized]');
});
});
});

describe('/teams.updateMember', () => {
let testTeam;
const teamName = `test-team-update-member-${Date.now()}`;
Expand Down

0 comments on commit 1c6256b

Please sign in to comment.