File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -171,4 +171,43 @@ describe("Remote", function() {
171171 } ) ;
172172 } ) ;
173173
174+ it ( "cannot push to a repository" , function ( ) {
175+ this . timeout ( 5000 ) ;
176+ var repo = this . repository ;
177+ var branch = "should-not-exist" ;
178+ return Remote . lookup ( repo , "origin" )
179+ . then ( function ( remote ) {
180+ remote . setCallbacks ( {
181+ credentials : function ( url , userName ) {
182+ if ( url . indexOf ( "https" ) === - 1 ) {
183+ return NodeGit . Cred . sshKeyFromAgent ( userName ) ;
184+ } else {
185+ return NodeGit . Cred . userpassPlaintextNew ( userName , "" ) ;
186+ }
187+ } ,
188+ certificateCheck : function ( ) {
189+ return 1 ;
190+ }
191+ } ) ;
192+ return remote ;
193+ } )
194+ . then ( function ( remote ) {
195+ var ref = "refs/heads/" + branch ;
196+ var refs = [ ref + ":" + ref ] ;
197+ var signature = repo . defaultSignature ( ) ;
198+ return remote . push ( refs , null , signature ,
199+ "Pushed '" + branch + "' for test" ) ;
200+ } )
201+ . then ( function ( ) {
202+ return Promise . reject (
203+ new Error ( "should not be able to push to the repository" ) ) ;
204+ } , function ( err ) {
205+ if ( err . message . indexOf ( 401 ) === - 1 ) {
206+ return Promise . reject (
207+ new Error ( "failed to return unauthorized status code" ) ) ;
208+ } else {
209+ return Promise . resolve ( ) ;
210+ }
211+ } ) ;
212+ } ) ;
174213} ) ;
You can’t perform that action at this time.
0 commit comments