Skip to content

Commit 3b62c0b

Browse files
committed
add test for non org manager/owner updates to org team
1 parent 93538b9 commit 3b62c0b

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

app/tests/permissions/initialization.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ async function initializeContext (t) {
5252
sub: '101'
5353
})
5454

55+
introspectStub.withArgs('user102').returns({
56+
active: true,
57+
sub: '102'
58+
})
59+
5560
introspectStub.withArgs('invalidToken').returns({ active: false })
5661

5762
// Initialize context objects

app/tests/permissions/update-team.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,32 @@ test('a non-team moderator cannot update a team', async t => {
3939
t.is(res2.status, 401)
4040
})
4141

42+
test('an org team cannot be updated by non-org user', async t => {
43+
// Let's create an organization, user100 is the owner
44+
const res = await t.context.agent.post('/api/organizations')
45+
.send({ name: 'org team cannot be updated by non-org user' })
46+
.set('Authorization', 'Bearer user100')
47+
.expect(200)
48+
49+
// Let's set user101 to be a manager of this organization and create a
50+
// team in the organization
51+
await t.context.agent.put(`/api/organizations/${res.body.id}/addManager/101`)
52+
.set('Authorization', 'Bearer user100')
53+
.expect(200)
54+
55+
const res2 = await t.context.agent.post(`/api/organizations/${res.body.id}/teams`)
56+
.send({ name: 'org team cannot be updated by non-org user - team' })
57+
.set('Authorization', 'Bearer user101')
58+
.expect(200)
59+
60+
// Use a different user from 101 or 100 to update the team
61+
const res3 = await t.context.agent.put(`/api/teams/${res2.body.id}`)
62+
.send({ name: 'org team cannot be updated by non-org user - team2' })
63+
.set('Authorization', 'Bearer user102')
64+
65+
t.is(res3.status, 401)
66+
})
67+
4268
test('an org team can be updated by the the org manager', async t => {
4369
// Let's create an organization, user100 is the owner
4470
const res = await t.context.agent.post('/api/organizations')

0 commit comments

Comments
 (0)