@@ -717,6 +717,64 @@ public void gerritSubmit_success() throws Exception {
717
717
718
718
}
719
719
720
+ @ Test
721
+ public void gerritSubmit_plusTwoRestricted () throws Exception {
722
+ options .gerrit .gerritChangeId = null ;
723
+ fetch = "master" ;
724
+ writeFile (workdir , "file" , "some content" );
725
+ url = BASE_URL + "/foo/bar" ;
726
+ repoGitDir =
gitUtil .
mockRemoteRepo (
"user:[email protected] /foo/bar" ).
getGitDir ();
727
+ gitUtil .mockApi (eq ("GET" ), startsWith (BASE_URL + "/changes/" ),
728
+ mockResponse (
729
+ "["
730
+ + "{"
731
+ + " change_id : \" Iaaaaaaaaaabbbbbbbbbbccccccccccdddddddddd\" ,"
732
+ + " status : \" NEW\" "
733
+ + "}]" )
734
+ );
735
+ AtomicBoolean submitCalled = new AtomicBoolean (false );
736
+ AtomicBoolean reviewCalled = new AtomicBoolean (false );
737
+ gitUtil .mockApi (
738
+ eq ("POST" ),
739
+ matches (BASE_URL + "/changes/.*/revisions/.*/review" ),
740
+ mockResponseWithStatus ("Applying label \\ \" Code-Review\\ \" : 2 is restricted\\ n\\ n" , 401 ));
741
+
742
+ gitUtil .mockApi (
743
+ eq ("POST" ),
744
+ matches (BASE_URL + "/changes/.*/submit" ),
745
+ mockResponseAndValidateRequest (
746
+ "{"
747
+ + " change_id : \" Iaaaaaaaaaabbbbbbbbbbccccccccccdddddddddd\" ,"
748
+ + " status : \" submitted\" "
749
+ + "}" ,
750
+ new MockRequestAssertion ("Always true with side-effect" ,
751
+ s -> {
752
+ submitCalled .set (true );
753
+ return true ;
754
+ }))
755
+ );
756
+
757
+ options .setForce (true );
758
+ DummyRevision originRef = new DummyRevision ("origin_ref" );
759
+ GerritDestination destination = destination ("submit = True" , "gerrit_submit = True" );
760
+ Glob glob = Glob .createGlob (ImmutableList .of ("**" ), excludedDestinationPaths );
761
+ WriterContext writerContext =
762
+ new WriterContext ("GerritDestinationTest" , "test" , false , originRef ,
763
+ Glob .ALL_FILES .roots ());
764
+ ValidationException validationException =
765
+ assertThrows (ValidationException .class ,
766
+ () -> destination
767
+ .newWriter (writerContext )
768
+ .write (
769
+ TransformResults .of (workdir , originRef )
770
+ .withSummary ("Test message" )
771
+ .withIdentity (originRef .asString ()),
772
+ glob ,
773
+ console ));
774
+
775
+ assertThat (validationException ).hasMessageThat ().contains ("2 is restricted" );
776
+ }
777
+
720
778
@ Test
721
779
public void gerritSubmit_noChange () throws Exception {
722
780
options .gerrit .gerritChangeId = null ;
0 commit comments