@@ -1110,6 +1110,37 @@ def test_patch_invalid_email(self, bad_email):
11101110 field_errors ['email' ]['developer_message' ]
11111111 assert 'Valid e-mail address required.' == field_errors ['email' ]['user_message' ]
11121112
1113+ @override_settings (SECONDARY_EMAIL_RATE_LIMIT = '1/m' )
1114+ def test_patch_secondary_email_ratelimit (self ):
1115+ """
1116+ Tests if rate limit is applied on secondary_email patch
1117+ """
1118+ client = self .login_client ("client" , "user" )
1119+ self .send_patch (client , {"secondary_email" : "new_email_01@example.com" },
1120+ expected_status = status .HTTP_200_OK )
1121+ self .send_patch (client , {"secondary_email" : "new_email_02@example.com" },
1122+ expected_status = status .HTTP_429_TOO_MANY_REQUESTS )
1123+
1124+ @override_settings (SECONDARY_EMAIL_RATE_LIMIT = '' )
1125+ def test_ratelimit_is_disabled_on_secondary_email_patch_if_settings_is_empty (self ):
1126+ """
1127+ Tests rate limit doesn't applied on secondary_email patch if SECONDARY_EMAIL_RATE_LIMIT is empty string or None
1128+ """
1129+ client = self .login_client ("client" , "user" )
1130+ self .send_patch (client , {"secondary_email" : "email_new_01@example.com" },
1131+ expected_status = status .HTTP_200_OK )
1132+ self .send_patch (client , {"secondary_email" : "email_new_02@example.com" },
1133+ expected_status = status .HTTP_200_OK )
1134+
1135+ @override_settings (SECONDARY_EMAIL_RATE_LIMIT = '1/d' )
1136+ def test_ratelimit_is_only_on_secondary_email_change (self ):
1137+ """
1138+ Tests if rate limit is only applied for secondary_email attribute i.e. when user changes recovery email
1139+ """
1140+ client = self .login_client ("client" , "user" )
1141+ for i in range (5 ):
1142+ self .send_patch (client , {"name" : f"new_name_{ i } " }, expected_status = status .HTTP_200_OK )
1143+
11131144 @mock .patch ('common.djangoapps.student.views.management.do_email_change_request' )
11141145 def test_patch_duplicate_email (self , do_email_change_request ):
11151146 """
0 commit comments