@@ -473,23 +473,45 @@ func TwoFactorAuthVerifySuccess(t *testing.T) {
473473}
474474
475475func TestGitLfsAuthenticateSuccess (t * testing.T ) {
476- handler := customHandler {
477- url : "/api/v4/internal/lfs_authenticate" ,
478- caller : func (w http.ResponseWriter , _ * http.Request ) {
479- fmt .Fprint (w , `{"username": "test-user", "lfs_token": "testlfstoken", "repo_path": "foo", "expires_in": 7200}` )
480- },
481- }
482- client := runSSHD (t , "ed25519" , successAPI (t , handler ))
476+ t .Run ("lfs is successfully authed when a correct user is provided" , func (t * testing.T ) {
477+ handler := customHandler {
478+ url : "/api/v4/internal/lfs_authenticate" ,
479+ caller : func (w http.ResponseWriter , _ * http.Request ) {
480+ fmt .Fprint (w , `{"username": "test-user", "lfs_token": "testlfstoken", "repo_path": "foo", "expires_in": 7200}` )
481+ },
482+ }
483+ client := runSSHD (t , "ed25519" , successAPI (t , handler ))
483484
484- session , err := client .NewSession ()
485- require .NoError (t , err )
486- defer session .Close ()
485+ session , err := client .NewSession ()
486+ require .NoError (t , err )
487+ defer session .Close ()
487488
488- output , err := session .Output ("git-lfs-authenticate test-user/repo.git download" )
489+ output , err := session .Output ("git-lfs-authenticate test-user/repo.git download" )
489490
490- require .NoError (t , err )
491- require .JSONEq (t , `{"header":{"Authorization":"Basic dGVzdC11c2VyOnRlc3RsZnN0b2tlbg=="},"href":"/info/lfs","expires_in":7200}
491+ require .NoError (t , err )
492+ require .JSONEq (t , `{"header":{"Authorization":"Basic dGVzdC11c2VyOnRlc3RsZnN0b2tlbg=="},"href":"/info/lfs","expires_in":7200}
492493` , string (output ))
494+ })
495+
496+ t .Run ("lfs is not authenticated when a user is not allowed to perform an action" , func (t * testing.T ) {
497+ handler := customHandler {
498+ url : "/api/v4/internal/lfs_authenticate" ,
499+ caller : func (w http.ResponseWriter , _ * http.Request ) {
500+ http .Error (w , "forbidden" , http .StatusForbidden )
501+ },
502+ }
503+ client := runSSHD (t , "ed25519" , successAPI (t , handler ))
504+ session , err := client .NewSession ()
505+ require .NoError (t , err )
506+ defer session .Close ()
507+
508+ output , err := session .Output ("git-lfs-authenticate test-user/repo.git download" )
509+
510+ // we don't send back an error
511+ require .NoError (t , err )
512+ // we also ensure that we don't send back any output
513+ require .Empty (t , string (output ))
514+ })
493515}
494516
495517func TestGitReceivePackSuccess (t * testing.T ) {
0 commit comments