File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff 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+ 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" , ( ) => {
You can’t perform that action at this time.
0 commit comments