aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/http
diff options
context:
space:
mode:
Diffstat (limited to 'plumbing/transport/http')
-rw-r--r--plumbing/transport/http/common.go18
-rw-r--r--plumbing/transport/http/common_test.go11
-rw-r--r--plumbing/transport/http/receive_pack.go4
-rw-r--r--plumbing/transport/http/upload_pack.go22
-rw-r--r--plumbing/transport/http/upload_pack_test.go2
5 files changed, 26 insertions, 31 deletions
diff --git a/plumbing/transport/http/common.go b/plumbing/transport/http/common.go
index 957fd07..a26cf0c 100644
--- a/plumbing/transport/http/common.go
+++ b/plumbing/transport/http/common.go
@@ -35,16 +35,16 @@ func NewClient(c *http.Client) transport.Transport {
}
}
-func (c *client) NewUploadPackSession(ep transport.Endpoint) (
+func (c *client) NewUploadPackSession(ep transport.Endpoint, auth transport.AuthMethod) (
transport.UploadPackSession, error) {
- return newUploadPackSession(c.c, ep), nil
+ return newUploadPackSession(c.c, ep, auth)
}
-func (c *client) NewReceivePackSession(ep transport.Endpoint) (
+func (c *client) NewReceivePackSession(ep transport.Endpoint, auth transport.AuthMethod) (
transport.ReceivePackSession, error) {
- return newReceivePackSession(c.c, ep), nil
+ return newReceivePackSession(c.c, ep, auth)
}
type session struct {
@@ -54,16 +54,6 @@ type session struct {
advRefs *packp.AdvRefs
}
-func (s *session) SetAuth(auth transport.AuthMethod) error {
- a, ok := auth.(AuthMethod)
- if !ok {
- return transport.ErrInvalidAuthMethod
- }
-
- s.auth = a
- return nil
-}
-
func (*session) Close() error {
return nil
}
diff --git a/plumbing/transport/http/common_test.go b/plumbing/transport/http/common_test.go
index 217999d..1fd0dd5 100644
--- a/plumbing/transport/http/common_test.go
+++ b/plumbing/transport/http/common_test.go
@@ -13,7 +13,8 @@ import (
func Test(t *testing.T) { TestingT(t) }
type ClientSuite struct {
- Endpoint transport.Endpoint
+ Endpoint transport.Endpoint
+ EmptyAuth transport.AuthMethod
}
var _ = Suite(&ClientSuite{})
@@ -76,9 +77,8 @@ func (s *ClientSuite) testNewHTTPError(c *C, code int, msg string) {
func (s *ClientSuite) TestSetAuth(c *C) {
auth := &BasicAuth{}
- r, err := DefaultClient.NewUploadPackSession(s.Endpoint)
+ r, err := DefaultClient.NewUploadPackSession(s.Endpoint, auth)
c.Assert(err, IsNil)
- r.SetAuth(auth)
c.Assert(auth, Equals, r.(*upSession).auth)
}
@@ -88,7 +88,6 @@ func (*mockAuth) Name() string { return "" }
func (*mockAuth) String() string { return "" }
func (s *ClientSuite) TestSetAuthWrongType(c *C) {
- r, err := DefaultClient.NewUploadPackSession(s.Endpoint)
- c.Assert(err, IsNil)
- c.Assert(r.SetAuth(&mockAuth{}), Equals, transport.ErrInvalidAuthMethod)
+ _, err := DefaultClient.NewUploadPackSession(s.Endpoint, &mockAuth{})
+ c.Assert(err, Equals, transport.ErrInvalidAuthMethod)
}
diff --git a/plumbing/transport/http/receive_pack.go b/plumbing/transport/http/receive_pack.go
index a8384c7..7a37049 100644
--- a/plumbing/transport/http/receive_pack.go
+++ b/plumbing/transport/http/receive_pack.go
@@ -14,8 +14,8 @@ type rpSession struct {
*session
}
-func newReceivePackSession(c *http.Client, ep transport.Endpoint) transport.ReceivePackSession {
- return &rpSession{&session{}}
+func newReceivePackSession(c *http.Client, ep transport.Endpoint, auth transport.AuthMethod) (transport.ReceivePackSession, error) {
+ return &rpSession{&session{}}, nil
}
func (s *rpSession) AdvertisedReferences() (*packp.AdvRefs, error) {
diff --git a/plumbing/transport/http/upload_pack.go b/plumbing/transport/http/upload_pack.go
index 26257f5..e828857 100644
--- a/plumbing/transport/http/upload_pack.go
+++ b/plumbing/transport/http/upload_pack.go
@@ -19,16 +19,22 @@ type upSession struct {
*session
}
-func newUploadPackSession(c *http.Client,
- ep transport.Endpoint) transport.UploadPackSession {
+func newUploadPackSession(c *http.Client, ep transport.Endpoint, auth transport.AuthMethod) (transport.UploadPackSession, error) {
+ s := &session{
+ auth: basicAuthFromEndpoint(ep),
+ client: c,
+ endpoint: ep,
+ }
+ if auth != nil {
+ a, ok := auth.(AuthMethod)
+ if !ok {
+ return nil, transport.ErrInvalidAuthMethod
+ }
- return &upSession{
- session: &session{
- auth: basicAuthFromEndpoint(ep),
- client: c,
- endpoint: ep,
- },
+ s.auth = a
}
+
+ return &upSession{session: s}, nil
}
func (s *upSession) AdvertisedReferences() (*packp.AdvRefs, error) {
diff --git a/plumbing/transport/http/upload_pack_test.go b/plumbing/transport/http/upload_pack_test.go
index d3e4989..13b7f75 100644
--- a/plumbing/transport/http/upload_pack_test.go
+++ b/plumbing/transport/http/upload_pack_test.go
@@ -35,7 +35,7 @@ func (s *UploadPackSuite) SetUpSuite(c *C) {
// Overwritten, different behaviour for HTTP.
func (s *UploadPackSuite) TestAdvertisedReferencesNotExists(c *C) {
- r, err := s.Client.NewUploadPackSession(s.NonExistentEndpoint)
+ r, err := s.Client.NewUploadPackSession(s.NonExistentEndpoint, s.EmptyAuth)
c.Assert(err, IsNil)
info, err := r.AdvertisedReferences()
c.Assert(err, Equals, transport.ErrAuthorizationRequired)