-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#140 Only allow admins to get another user's communicators
- Loading branch information
1 parent
97a839a
commit 0bcbd49
Showing
4 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const request = require('supertest'); | ||
const server = require('../../app'); | ||
const helper = require('../helper'); | ||
|
||
describe('Communicator API calls', function () { | ||
describe('GET /communicator/byemail/:email', function() { | ||
it("only allows an admin to get another user's communicators", async function() { | ||
const adminEmail = helper.generateEmail(); | ||
const admin = await helper.prepareUser(server, { | ||
role: 'admin', | ||
email: adminEmail, | ||
}); | ||
|
||
const userEmail = helper.generateEmail(); | ||
const user = await helper.prepareUser(server, { | ||
role: 'user', | ||
email: userEmail, | ||
}); | ||
|
||
// Try to get another user's communicators as a regular user. | ||
// This should fail. | ||
await request(server) | ||
.get(`/communicator/byemail/${encodeURI(adminEmail)}`) | ||
.set('Authorization', `Bearer ${user.token}`) | ||
.expect({ | ||
message: "You are not authorized to get this user's communicators.", | ||
}) | ||
.expect(403); | ||
|
||
// Try to get another user's communicators as an admin user. | ||
// This should succeed. | ||
await request(server) | ||
.get(`/communicator/byemail/${encodeURI(userEmail)}`) | ||
.set('Authorization', `Bearer ${admin.token}`) | ||
.expect(200); | ||
|
||
|
||
// Try to get my own communicators as a regular user. | ||
// This should succeed. | ||
await request(server) | ||
.get(`/communicator/byemail/${encodeURI(userEmail)}`) | ||
.set('Authorization', `Bearer ${user.token}`) | ||
.expect(200); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters