Skip to content

Commit 4e10ff1

Browse files
committed
Add test for code emailing rate limit
1 parent 64621c6 commit 4e10ff1

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

api/test/auth.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,35 @@ describe("API auth endpoints", () => {
112112
expect(await pwStartEndpoint.getSeenRequests()).to.have.length(0);
113113
});
114114

115+
it("blocks sending more than 3 codes", async function () {
116+
this.timeout(5000); // SMTP can be a bit slow
117+
118+
const email = '[email protected]'
119+
120+
for (let i = 0; i < 3; i++) {
121+
const response = await fetch(`${apiAddress}/api/auth/send-code`, {
122+
method: 'POST',
123+
headers: { 'content-type': 'application/json' },
124+
body: JSON.stringify({ email, source: 'test' })
125+
});
126+
127+
expect(response.status).to.equal(200);
128+
}
129+
130+
// We have now received 3 codes:
131+
expect(await getReceivedEmails()).to.have.length(3);
132+
133+
const fourthResponse = await fetch(`${apiAddress}/api/auth/send-code`, {
134+
method: 'POST',
135+
headers: { 'content-type': 'application/json' },
136+
body: JSON.stringify({ email, source: 'test' })
137+
});
138+
139+
// Subsequent requests get a 429 and send no more emails:
140+
expect(fourthResponse.status).to.equal(429);
141+
expect(await getReceivedEmails()).to.have.length(3);
142+
});
143+
115144
});
116145

117146
describe("/auth/login", () => {

0 commit comments

Comments
 (0)