-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore!: Improve permissions check on mailer endpoints (#32336)
- Loading branch information
1 parent
fc2cea7
commit 2a26720
Showing
2 changed files
with
31 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
import { expect } from 'chai'; | ||
import { before, describe, it } from 'mocha'; | ||
import { before, after, describe, it } from 'mocha'; | ||
import type { Response } from 'supertest'; | ||
|
||
import { api, request, credentials, getCredentials } from '../../../data/api-data'; | ||
import { updatePermission } from '../../../data/permissions.helper'; | ||
|
||
describe('Mailer', () => { | ||
before((done) => getCredentials(done)); | ||
|
||
describe('POST mailer', () => { | ||
describe('POST mailer', async () => { | ||
before(async () => { | ||
return updatePermission('send-mail', ['admin']); | ||
}); | ||
|
||
after(async () => { | ||
return updatePermission('send-mail', ['admin']); | ||
}); | ||
|
||
it('should send an email if the payload is correct', async () => { | ||
await request | ||
.post(api('mailer')) | ||
|
@@ -58,6 +67,25 @@ describe('Mailer', () => { | |
expect(res.body).to.have.property('success', false); | ||
}); | ||
}); | ||
it('should throw an error if user does NOT have the send-mail permission', async () => { | ||
await updatePermission('send-mail', []); | ||
await request | ||
.post(api('mailer')) | ||
.set(credentials) | ||
.send({ | ||
from: '[email protected]', | ||
subject: 'Test email subject', | ||
body: 'Test email body', | ||
dryrun: true, | ||
query: '', | ||
}) | ||
.expect('Content-Type', 'application/json') | ||
.expect(403) | ||
.expect((res: Response) => { | ||
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]'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
|