-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
count with same email and ip address
- Loading branch information
mrkeksz
committed
Dec 21, 2023
1 parent
1755025
commit 3b1df36
Showing
4 changed files
with
96 additions
and
81 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -130,7 +130,7 @@ describe('sendVerificationCodeToEmail', () => { | |
}) | ||
}) | ||
|
||
it('should throw an error if sending attempts limit exceeded', async () => { | ||
it('should throw an error if sending attempts limit exceeded with same ip', async () => { | ||
const emailVerificationCodeSendingAttemptRepository = app.get( | ||
getRepositoryToken(EmailVerificationCodeSendingAttempt), | ||
) | ||
|
@@ -175,6 +175,96 @@ describe('sendVerificationCodeToEmail', () => { | |
expect(emailVerificationCodeSendingAttempts).toEqual([attempt1, attempt2, attempt3]) | ||
}) | ||
|
||
it('should throw an error if sending attempts limit exceeded with same email', async () => { | ||
const email = '[email protected]' | ||
|
||
const emailVerificationCodeSendingAttemptRepository = app.get( | ||
getRepositoryToken(EmailVerificationCodeSendingAttempt), | ||
) | ||
const attempt1 = await emailVerificationCodeSendingAttemptRepository.save({ | ||
email, | ||
senderIp: '::ffff:127.0.0.2', | ||
}) | ||
const attempt2 = await emailVerificationCodeSendingAttemptRepository.save({ | ||
email, | ||
senderIp: '::ffff:127.0.0.3', | ||
}) | ||
const attempt3 = await emailVerificationCodeSendingAttemptRepository.save({ | ||
email, | ||
senderIp: '::ffff:127.0.0.4', | ||
}) | ||
|
||
const result = await gqlService.sendRequest({ | ||
queryType: 'mutation', | ||
query: { | ||
operation: 'sendVerificationCodeToEmail', | ||
variables: {email: {type: 'String!', value: email}}, | ||
}, | ||
}) | ||
|
||
expect(result.body).toEqual({ | ||
errors: [ | ||
{ | ||
message: | ||
'You have exceeded the limit of email verification requests for the last 10 minutes.', | ||
locations: [{line: 2, column: 7}], | ||
path: ['sendVerificationCodeToEmail'], | ||
code: 'FORBIDDEN', | ||
}, | ||
], | ||
data: null, | ||
}) | ||
|
||
const emailVerificationCodeSendingAttempts = | ||
await emailVerificationCodeSendingAttemptRepository.find({order: {createdAt: 'ASC'}}) | ||
expect(emailVerificationCodeSendingAttempts).toHaveLength(3) | ||
expect(emailVerificationCodeSendingAttempts).toEqual([attempt1, attempt2, attempt3]) | ||
}) | ||
|
||
it('should throw an error if sending attempts limit exceeded with same email and ip', async () => { | ||
const emailVerificationCodeSendingAttemptRepository = app.get( | ||
getRepositoryToken(EmailVerificationCodeSendingAttempt), | ||
) | ||
const attempt1 = await emailVerificationCodeSendingAttemptRepository.save({ | ||
email: '[email protected]', | ||
senderIp: '::ffff:127.0.0.1', | ||
}) | ||
const attempt2 = await emailVerificationCodeSendingAttemptRepository.save({ | ||
email: '[email protected]', | ||
senderIp: '::ffff:127.0.0.2', | ||
}) | ||
const attempt3 = await emailVerificationCodeSendingAttemptRepository.save({ | ||
email: '[email protected]', | ||
senderIp: '::ffff:127.0.0.1', | ||
}) | ||
|
||
const result = await gqlService.sendRequest({ | ||
queryType: 'mutation', | ||
query: { | ||
operation: 'sendVerificationCodeToEmail', | ||
variables: {email: {type: 'String!', value: '[email protected]'}}, | ||
}, | ||
}) | ||
|
||
expect(result.body).toEqual({ | ||
errors: [ | ||
{ | ||
message: | ||
'You have exceeded the limit of email verification requests for the last 10 minutes.', | ||
locations: [{line: 2, column: 7}], | ||
path: ['sendVerificationCodeToEmail'], | ||
code: 'FORBIDDEN', | ||
}, | ||
], | ||
data: null, | ||
}) | ||
|
||
const emailVerificationCodeSendingAttempts = | ||
await emailVerificationCodeSendingAttemptRepository.find({order: {createdAt: 'ASC'}}) | ||
expect(emailVerificationCodeSendingAttempts).toHaveLength(3) | ||
expect(emailVerificationCodeSendingAttempts).toEqual([attempt1, attempt2, attempt3]) | ||
}) | ||
|
||
it('should throw InternalServerError', async () => { | ||
const emailVerificationSendingLimitService = app.get(EmailVerificationSendingLimitService) | ||
jest | ||
|
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