1
1
use crate :: {
2
- builders:: { CrateBuilder , PublishBuilder , VersionBuilder } ,
3
- new_category, new_user, CrateMeta , OkBool , RequestHelper , TestApp ,
2
+ builders:: { CrateBuilder , VersionBuilder } ,
3
+ new_category, new_user, CrateMeta , RequestHelper , TestApp ,
4
4
} ;
5
5
use cargo_registry:: {
6
6
models:: Category ,
@@ -17,6 +17,7 @@ mod following;
17
17
mod publish;
18
18
mod summary;
19
19
mod versions;
20
+ mod yanking;
20
21
21
22
#[ derive( Deserialize ) ]
22
23
struct RevDeps {
@@ -32,42 +33,6 @@ impl crate::util::MockAnonymousUser {
32
33
}
33
34
}
34
35
35
- impl crate :: util:: MockTokenUser {
36
- /// Yank the specified version of the specified crate and run all pending background jobs
37
- fn yank ( & self , krate_name : & str , version : & str ) -> crate :: util:: Response < OkBool > {
38
- let url = format ! ( "/api/v1/crates/{}/{}/yank" , krate_name, version) ;
39
- let response = self . delete ( & url) ;
40
- self . app ( ) . run_pending_background_jobs ( ) ;
41
- response
42
- }
43
-
44
- /// Unyank the specified version of the specified crate and run all pending background jobs
45
- fn unyank ( & self , krate_name : & str , version : & str ) -> crate :: util:: Response < OkBool > {
46
- let url = format ! ( "/api/v1/crates/{}/{}/unyank" , krate_name, version) ;
47
- let response = self . put ( & url, & [ ] ) ;
48
- self . app ( ) . run_pending_background_jobs ( ) ;
49
- response
50
- }
51
- }
52
-
53
- impl crate :: util:: MockCookieUser {
54
- /// Yank the specified version of the specified crate and run all pending background jobs
55
- fn yank ( & self , krate_name : & str , version : & str ) -> crate :: util:: Response < OkBool > {
56
- let url = format ! ( "/api/v1/crates/{}/{}/yank" , krate_name, version) ;
57
- let response = self . delete ( & url) ;
58
- self . app ( ) . run_pending_background_jobs ( ) ;
59
- response
60
- }
61
-
62
- /// Unyank the specified version of the specified crate and run all pending background jobs
63
- fn unyank ( & self , krate_name : & str , version : & str ) -> crate :: util:: Response < OkBool > {
64
- let url = format ! ( "/api/v1/crates/{}/{}/unyank" , krate_name, version) ;
65
- let response = self . put ( & url, & [ ] ) ;
66
- self . app ( ) . run_pending_background_jobs ( ) ;
67
- response
68
- }
69
- }
70
-
71
36
#[ test]
72
37
fn index ( ) {
73
38
let ( app, anon) = TestApp :: init ( ) . empty ( ) ;
@@ -635,214 +600,6 @@ fn yanked_versions_are_not_considered_for_max_version() {
635
600
assert_eq ! ( json. crates[ 0 ] . max_version, "1.0.0" ) ;
636
601
}
637
602
638
- #[ test]
639
- fn yank_works_as_intended ( ) {
640
- let ( app, anon, cookie, token) = TestApp :: full ( ) . with_token ( ) ;
641
-
642
- // Upload a new crate, putting it in the git index
643
- let crate_to_publish = PublishBuilder :: new ( "fyk" ) ;
644
- token. enqueue_publish ( crate_to_publish) . good ( ) ;
645
- app. run_pending_background_jobs ( ) ;
646
-
647
- let crates = app. crates_from_index_head ( "3/f/fyk" ) ;
648
- assert_eq ! ( crates. len( ) , 1 ) ;
649
- assert_some_eq ! ( crates[ 0 ] . yanked, false ) ;
650
-
651
- // make sure it's not yanked
652
- let json = anon. show_version ( "fyk" , "1.0.0" ) ;
653
- assert ! ( !json. version. yanked) ;
654
-
655
- // yank it
656
- token. yank ( "fyk" , "1.0.0" ) . good ( ) ;
657
-
658
- let crates = app. crates_from_index_head ( "3/f/fyk" ) ;
659
- assert_eq ! ( crates. len( ) , 1 ) ;
660
- assert_some_eq ! ( crates[ 0 ] . yanked, true ) ;
661
-
662
- let json = anon. show_version ( "fyk" , "1.0.0" ) ;
663
- assert ! ( json. version. yanked) ;
664
-
665
- // un-yank it
666
- token. unyank ( "fyk" , "1.0.0" ) . good ( ) ;
667
-
668
- let crates = app. crates_from_index_head ( "3/f/fyk" ) ;
669
- assert_eq ! ( crates. len( ) , 1 ) ;
670
- assert_some_eq ! ( crates[ 0 ] . yanked, false ) ;
671
-
672
- let json = anon. show_version ( "fyk" , "1.0.0" ) ;
673
- assert ! ( !json. version. yanked) ;
674
-
675
- // yank it
676
- cookie. yank ( "fyk" , "1.0.0" ) . good ( ) ;
677
-
678
- let crates = app. crates_from_index_head ( "3/f/fyk" ) ;
679
- assert_eq ! ( crates. len( ) , 1 ) ;
680
- assert_some_eq ! ( crates[ 0 ] . yanked, true ) ;
681
-
682
- let json = anon. show_version ( "fyk" , "1.0.0" ) ;
683
- assert ! ( json. version. yanked) ;
684
-
685
- // un-yank it
686
- cookie. unyank ( "fyk" , "1.0.0" ) . good ( ) ;
687
-
688
- let crates = app. crates_from_index_head ( "3/f/fyk" ) ;
689
- assert_eq ! ( crates. len( ) , 1 ) ;
690
- assert_some_eq ! ( crates[ 0 ] . yanked, false ) ;
691
-
692
- let json = anon. show_version ( "fyk" , "1.0.0" ) ;
693
- assert ! ( !json. version. yanked) ;
694
- }
695
-
696
- #[ test]
697
- fn yank_by_a_non_owner_fails ( ) {
698
- let ( app, _, _, token) = TestApp :: full ( ) . with_token ( ) ;
699
-
700
- let another_user = app. db_new_user ( "bar" ) ;
701
- let another_user = another_user. as_model ( ) ;
702
- app. db ( |conn| {
703
- CrateBuilder :: new ( "foo_not" , another_user. id )
704
- . version ( "1.0.0" )
705
- . expect_build ( conn) ;
706
- } ) ;
707
-
708
- let json = token
709
- . yank ( "foo_not" , "1.0.0" )
710
- . bad_with_status ( StatusCode :: OK ) ;
711
- assert_eq ! (
712
- json. errors[ 0 ] . detail,
713
- "must already be an owner to yank or unyank"
714
- ) ;
715
- }
716
-
717
- #[ test]
718
- fn yank_max_version ( ) {
719
- let ( _, anon, _, token) = TestApp :: full ( ) . with_token ( ) ;
720
-
721
- // Upload a new crate
722
- let crate_to_publish = PublishBuilder :: new ( "fyk_max" ) ;
723
- token. enqueue_publish ( crate_to_publish) . good ( ) ;
724
-
725
- // double check the max version
726
- let json = anon. show_crate ( "fyk_max" ) ;
727
- assert_eq ! ( json. krate. max_version, "1.0.0" ) ;
728
-
729
- // add version 2.0.0
730
- let crate_to_publish = PublishBuilder :: new ( "fyk_max" ) . version ( "2.0.0" ) ;
731
- let json = token. enqueue_publish ( crate_to_publish) . good ( ) ;
732
- assert_eq ! ( json. krate. max_version, "2.0.0" ) ;
733
-
734
- // yank version 1.0.0
735
- token. yank ( "fyk_max" , "1.0.0" ) . good ( ) ;
736
-
737
- let json = anon. show_crate ( "fyk_max" ) ;
738
- assert_eq ! ( json. krate. max_version, "2.0.0" ) ;
739
-
740
- // unyank version 1.0.0
741
- token. unyank ( "fyk_max" , "1.0.0" ) . good ( ) ;
742
-
743
- let json = anon. show_crate ( "fyk_max" ) ;
744
- assert_eq ! ( json. krate. max_version, "2.0.0" ) ;
745
-
746
- // yank version 2.0.0
747
- token. yank ( "fyk_max" , "2.0.0" ) . good ( ) ;
748
-
749
- let json = anon. show_crate ( "fyk_max" ) ;
750
- assert_eq ! ( json. krate. max_version, "1.0.0" ) ;
751
-
752
- // yank version 1.0.0
753
- token. yank ( "fyk_max" , "1.0.0" ) . good ( ) ;
754
-
755
- let json = anon. show_crate ( "fyk_max" ) ;
756
- assert_eq ! ( json. krate. max_version, "0.0.0" ) ;
757
-
758
- // unyank version 2.0.0
759
- token. unyank ( "fyk_max" , "2.0.0" ) . good ( ) ;
760
-
761
- let json = anon. show_crate ( "fyk_max" ) ;
762
- assert_eq ! ( json. krate. max_version, "2.0.0" ) ;
763
-
764
- // unyank version 1.0.0
765
- token. unyank ( "fyk_max" , "1.0.0" ) . good ( ) ;
766
-
767
- let json = anon. show_crate ( "fyk_max" ) ;
768
- assert_eq ! ( json. krate. max_version, "2.0.0" ) ;
769
- }
770
-
771
- #[ test]
772
- fn publish_after_yank_max_version ( ) {
773
- let ( _, anon, _, token) = TestApp :: full ( ) . with_token ( ) ;
774
-
775
- // Upload a new crate
776
- let crate_to_publish = PublishBuilder :: new ( "fyk_max" ) ;
777
- token. enqueue_publish ( crate_to_publish) . good ( ) ;
778
-
779
- // double check the max version
780
- let json = anon. show_crate ( "fyk_max" ) ;
781
- assert_eq ! ( json. krate. max_version, "1.0.0" ) ;
782
-
783
- // yank version 1.0.0
784
- token. yank ( "fyk_max" , "1.0.0" ) . good ( ) ;
785
-
786
- let json = anon. show_crate ( "fyk_max" ) ;
787
- assert_eq ! ( json. krate. max_version, "0.0.0" ) ;
788
-
789
- // add version 2.0.0
790
- let crate_to_publish = PublishBuilder :: new ( "fyk_max" ) . version ( "2.0.0" ) ;
791
- let json = token. enqueue_publish ( crate_to_publish) . good ( ) ;
792
- assert_eq ! ( json. krate. max_version, "2.0.0" ) ;
793
-
794
- // unyank version 1.0.0
795
- token. unyank ( "fyk_max" , "1.0.0" ) . good ( ) ;
796
-
797
- let json = anon. show_crate ( "fyk_max" ) ;
798
- assert_eq ! ( json. krate. max_version, "2.0.0" ) ;
799
- }
800
-
801
- #[ test]
802
- fn yank_records_an_audit_action ( ) {
803
- let ( _, anon, _, token) = TestApp :: full ( ) . with_token ( ) ;
804
-
805
- // Upload a new crate, putting it in the git index
806
- let crate_to_publish = PublishBuilder :: new ( "fyk" ) ;
807
- token. enqueue_publish ( crate_to_publish) . good ( ) ;
808
-
809
- // Yank it
810
- token. yank ( "fyk" , "1.0.0" ) . good ( ) ;
811
-
812
- // Make sure it has one publish and one yank audit action
813
- let json = anon. show_version ( "fyk" , "1.0.0" ) ;
814
- let actions = json. version . audit_actions ;
815
-
816
- assert_eq ! ( actions. len( ) , 2 ) ;
817
- let action = & actions[ 1 ] ;
818
- assert_eq ! ( action. action, "yank" ) ;
819
- assert_eq ! ( action. user. id, token. as_model( ) . user_id) ;
820
- }
821
-
822
- #[ test]
823
- fn unyank_records_an_audit_action ( ) {
824
- let ( _, anon, _, token) = TestApp :: full ( ) . with_token ( ) ;
825
-
826
- // Upload a new crate
827
- let crate_to_publish = PublishBuilder :: new ( "fyk" ) ;
828
- token. enqueue_publish ( crate_to_publish) . good ( ) ;
829
-
830
- // Yank version 1.0.0
831
- token. yank ( "fyk" , "1.0.0" ) . good ( ) ;
832
-
833
- // Unyank version 1.0.0
834
- token. unyank ( "fyk" , "1.0.0" ) . good ( ) ;
835
-
836
- // Make sure it has one publish, one yank, and one unyank audit action
837
- let json = anon. show_version ( "fyk" , "1.0.0" ) ;
838
- let actions = json. version . audit_actions ;
839
-
840
- assert_eq ! ( actions. len( ) , 3 ) ;
841
- let action = & actions[ 2 ] ;
842
- assert_eq ! ( action. action, "unyank" ) ;
843
- assert_eq ! ( action. user. id, token. as_model( ) . user_id) ;
844
- }
845
-
846
603
#[ test]
847
604
fn reverse_dependencies ( ) {
848
605
let ( app, anon, user) = TestApp :: init ( ) . with_user ( ) ;
0 commit comments