@@ -721,26 +721,22 @@ fn new_krate_twice() {
721
721
722
722
#[ test]
723
723
fn new_krate_wrong_user ( ) {
724
- let ( _b, app, middle) = app ( ) ;
725
-
726
- let mut req = new_req ( "foo_wrong" , "2.0.0" ) ;
724
+ let ( app, _, user) = TestApp :: init ( ) . with_user ( ) ;
727
725
728
- {
729
- // Create the 'foo' crate with one user
730
- let conn = app. diesel_database . get ( ) . unwrap ( ) ;
731
- let user = new_user ( "foo" ) . create_or_update ( & conn) . unwrap ( ) ;
732
- CrateBuilder :: new ( "foo_wrong" , user. id ) . expect_build ( & conn) ;
726
+ app. db ( |conn| {
727
+ // Create the foo_wrong crate with one user
728
+ CrateBuilder :: new ( "foo_wrong" , user. as_model ( ) . id ) . expect_build ( & conn) ;
729
+ } ) ;
733
730
734
- // But log in another
735
- let user = new_user ( "bar" ) . create_or_update ( & conn) . unwrap ( ) ;
736
- sign_in_as ( & mut req, & user) ;
737
- }
731
+ // Then try to publish with a different user
732
+ let another_user = app. db_new_user ( "another" ) . db_new_token ( "bar" ) ;
733
+ let crate_to_publish = PublishBuilder :: new ( "foo_wrong" ) . version ( "2.0.0" ) ;
738
734
739
- let json = bad_resp ! ( middle . call ( & mut req ) ) ;
735
+ let json = another_user . publish ( crate_to_publish ) . bad_with_status ( 200 ) ;
740
736
assert ! (
741
737
json. errors[ 0 ]
742
738
. detail
743
- . contains( "this crate exists but you don't seem to be an owner." , ) ,
739
+ . contains( "this crate exists but you don't seem to be an owner." ) ,
744
740
"{:?}" ,
745
741
json. errors
746
742
) ;
@@ -767,37 +763,43 @@ fn new_krate_too_big() {
767
763
assert ! (
768
764
json. errors[ 0 ]
769
765
. detail
770
- . contains( "uploaded tarball is malformed or too large when decompressed" )
766
+ . contains( "uploaded tarball is malformed or too large when decompressed" ) ,
767
+ "{:?}" ,
768
+ json. errors
771
769
) ;
772
770
}
773
771
774
772
#[ test]
775
773
fn new_krate_too_big_but_whitelisted ( ) {
776
- let ( _b, app, middle) = app ( ) ;
777
- let mut req = new_req ( "foo_whitelist" , "1.1.0" ) ;
778
- {
779
- let conn = app. diesel_database . get ( ) . unwrap ( ) ;
780
- let user = new_user ( "foo" ) . create_or_update ( & conn) . unwrap ( ) ;
781
- sign_in_as ( & mut req, & user) ;
782
- CrateBuilder :: new ( "foo_whitelist" , user. id )
774
+ let ( app, _, user, token) = TestApp :: with_proxy ( ) . with_token ( ) ;
775
+
776
+ app. db ( |conn| {
777
+ CrateBuilder :: new ( "foo_whitelist" , user. as_model ( ) . id )
783
778
. max_upload_size ( 2_000_000 )
784
779
. expect_build ( & conn) ;
785
- }
780
+ } ) ;
781
+
786
782
let files = [ ( "foo_whitelist-1.1.0/big" , & [ b'a' ; 2000 ] as & [ _ ] ) ] ;
787
- let body = new_crate_to_body ( & new_crate ( "foo_whitelist" , "1.1.0" ) , & files) ;
788
- let mut response = ok_resp ! ( middle. call( req. with_body( & body) ) ) ;
789
- :: json :: < GoodCrate > ( & mut response) ;
783
+ let crate_to_publish = PublishBuilder :: new ( "foo_whitelist" )
784
+ . version ( "1.1.0" )
785
+ . files ( & files) ;
786
+
787
+ token. publish ( crate_to_publish) . good ( ) ;
790
788
}
791
789
792
790
#[ test]
793
791
fn new_krate_wrong_files ( ) {
794
- let ( _b, app, middle) = app ( ) ;
795
- let mut req = new_req ( "foo" , "1.1.0" ) ;
796
- sign_in ( & mut req, & app) ;
792
+ let ( _, _, user) = TestApp :: init ( ) . with_user ( ) ;
797
793
let data: & [ u8 ] = & [ 1 ] ;
798
- let files = [ ( "foo-1.1.0/a" , data) , ( "bar-1.1.0/a" , data) ] ;
799
- let body = new_crate_to_body ( & new_crate ( "foo" , "1.1.0" ) , & files) ;
800
- bad_resp ! ( middle. call( req. with_body( & body) ) ) ;
794
+ let files = [ ( "foo-1.0.0/a" , data) , ( "bar-1.0.0/a" , data) ] ;
795
+ let builder = PublishBuilder :: new ( "foo" ) . files ( & files) ;
796
+
797
+ let json = user. publish ( builder) . bad_with_status ( 200 ) ;
798
+ assert ! (
799
+ json. errors[ 0 ] . detail. contains( "invalid tarball uploaded" ) ,
800
+ "{:?}" ,
801
+ json. errors
802
+ ) ;
801
803
}
802
804
803
805
#[ test]
@@ -823,18 +825,18 @@ fn new_krate_gzip_bomb() {
823
825
824
826
#[ test]
825
827
fn new_krate_duplicate_version ( ) {
826
- let ( _b, app, middle) = app ( ) ;
827
- let mut req = new_req ( "foo_dupe" , "1.0.0" ) ;
828
- {
829
- let conn = app. diesel_database . get ( ) . unwrap ( ) ;
830
- let user = new_user ( "foo" ) . create_or_update ( & conn) . unwrap ( ) ;
831
- sign_in_as ( & mut req, & user) ;
828
+ let ( app, _, user, token) = TestApp :: with_proxy ( ) . with_token ( ) ;
832
829
833
- CrateBuilder :: new ( "foo_dupe" , user. id )
834
- . version ( VersionBuilder :: new ( "1.0.0" ) )
830
+ app. db ( |conn| {
831
+ // Insert a crate directly into the database and then we'll try to publish the same version
832
+ CrateBuilder :: new ( "foo_dupe" , user. as_model ( ) . id )
833
+ . version ( "1.0.0" )
835
834
. expect_build ( & conn) ;
836
- }
837
- let json = bad_resp ! ( middle. call( & mut req) ) ;
835
+ } ) ;
836
+
837
+ let crate_to_publish = PublishBuilder :: new ( "foo_dupe" ) . version ( "1.0.0" ) ;
838
+ let json = token. publish ( crate_to_publish) . bad_with_status ( 200 ) ;
839
+
838
840
assert ! (
839
841
json. errors[ 0 ] . detail. contains( "already uploaded" ) ,
840
842
"{:?}" ,
0 commit comments