@@ -1028,8 +1028,7 @@ fn publish_new_crate_rate_limited() {
10281028
10291029 // Uploading a second crate is limited
10301030 let crate_to_publish = PublishBuilder :: new ( "rate_limited2" ) ;
1031- let response = token. publish_crate ( crate_to_publish) ;
1032- assert_eq ! ( response. status( ) , StatusCode :: TOO_MANY_REQUESTS ) ;
1031+ token. publish_crate ( crate_to_publish) . assert_rate_limited ( ) ;
10331032
10341033 assert_eq ! ( app. stored_files( ) . len( ) , 2 ) ;
10351034
@@ -1049,9 +1048,9 @@ fn publish_new_crate_rate_limited() {
10491048}
10501049
10511050#[ test]
1052- fn publish_rate_limit_doesnt_affect_existing_crates ( ) {
1051+ fn publish_new_crate_rate_limit_doesnt_affect_existing_crates ( ) {
10531052 let ( _, _, _, token) = TestApp :: full ( )
1054- . with_rate_limit ( LimitedAction :: PublishNew , Duration :: from_millis ( 500 ) , 1 )
1053+ . with_rate_limit ( LimitedAction :: PublishNew , Duration :: from_secs ( 60 * 60 ) , 1 )
10551054 . with_token ( ) ;
10561055
10571056 // Upload a new crate
@@ -1062,6 +1061,67 @@ fn publish_rate_limit_doesnt_affect_existing_crates() {
10621061 token. publish_crate ( new_version) . good ( ) ;
10631062}
10641063
1064+ #[ test]
1065+ fn publish_existing_crate_rate_limited ( ) {
1066+ let ( app, anon, _, token) = TestApp :: full ( )
1067+ . with_rate_limit ( LimitedAction :: PublishUpdate , Duration :: from_millis ( 500 ) , 1 )
1068+ . with_token ( ) ;
1069+
1070+ // Upload a new crate
1071+ let crate_to_publish = PublishBuilder :: new ( "rate_limited1" ) ;
1072+ token. publish_crate ( crate_to_publish) . good ( ) ;
1073+
1074+ let json = anon. show_crate ( "rate_limited1" ) ;
1075+ assert_eq ! ( json. krate. max_version, "1.0.0" ) ;
1076+ assert_eq ! ( app. stored_files( ) . len( ) , 2 ) ;
1077+
1078+ // Uploading the first update to the crate works
1079+ let crate_to_publish = PublishBuilder :: new ( "rate_limited1" ) . version ( "1.0.1" ) ;
1080+ token. publish_crate ( crate_to_publish) . good ( ) ;
1081+
1082+ let json = anon. show_crate ( "rate_limited1" ) ;
1083+ assert_eq ! ( json. krate. max_version, "1.0.1" ) ;
1084+ assert_eq ! ( app. stored_files( ) . len( ) , 3 ) ;
1085+
1086+ // Uploading the second update to the crate is rate limited
1087+ let crate_to_publish = PublishBuilder :: new ( "rate_limited1" ) . version ( "1.0.2" ) ;
1088+ token. publish_crate ( crate_to_publish) . assert_rate_limited ( ) ;
1089+
1090+ // Check that version 1.0.2 was not published
1091+ let json = anon. show_crate ( "rate_limited1" ) ;
1092+ assert_eq ! ( json. krate. max_version, "1.0.1" ) ;
1093+ assert_eq ! ( app. stored_files( ) . len( ) , 3 ) ;
1094+
1095+ // Wait for the limit to be up
1096+ thread:: sleep ( Duration :: from_millis ( 500 ) ) ;
1097+
1098+ let crate_to_publish = PublishBuilder :: new ( "rate_limited1" ) . version ( "1.0.2" ) ;
1099+ token. publish_crate ( crate_to_publish) . good ( ) ;
1100+
1101+ let json = anon. show_crate ( "rate_limited1" ) ;
1102+ assert_eq ! ( json. krate. max_version, "1.0.2" ) ;
1103+ assert_eq ! ( app. stored_files( ) . len( ) , 4 ) ;
1104+ }
1105+
1106+ #[ test]
1107+ fn publish_existing_crate_rate_limit_doesnt_affect_new_crates ( ) {
1108+ let ( _, _, _, token) = TestApp :: full ( )
1109+ . with_rate_limit (
1110+ LimitedAction :: PublishUpdate ,
1111+ Duration :: from_secs ( 60 * 60 ) ,
1112+ 1 ,
1113+ )
1114+ . with_token ( ) ;
1115+
1116+ // Upload a new crate
1117+ let crate_to_publish = PublishBuilder :: new ( "rate_limited1" ) ;
1118+ token. publish_crate ( crate_to_publish) . good ( ) ;
1119+
1120+ // Upload a second new crate
1121+ let crate_to_publish = PublishBuilder :: new ( "rate_limited2" ) ;
1122+ token. publish_crate ( crate_to_publish) . good ( ) ;
1123+ }
1124+
10651125#[ test]
10661126fn features_version_2 ( ) {
10671127 let ( app, _, user, token) = TestApp :: full ( ) . with_token ( ) ;
0 commit comments