Merge lp:~jameinel/goose/no-ssl-public into lp:goose

Proposed by John A Meinel
Status: Merged
Approved by: John A Meinel
Approved revision: 106
Merged at revision: 107
Proposed branch: lp:~jameinel/goose/no-ssl-public
Merge into: lp:goose
Diff against target: 55 lines (+37/-0)
2 files modified
client/client.go (+8/-0)
client/local_test.go (+29/-0)
To merge this branch: bzr merge lp:~jameinel/goose/no-ssl-public
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+184517@code.launchpad.net

Commit message

client.NewNonValidatingPublicClient: new API

While working on the juju-core side of the code, I discovered another path
where we try to connect to the HTTPS server (reading public buckets). So we
need a way to disable ssl validation there as well.

https://codereview.appspot.com/13396048/

Description of the change

client.NewNonValidatingPublicClient: new API

While working on the juju-core side of the code, I discovered another path
where we try to connect to the HTTPS server (reading public buckets). So we
need a way to disable ssl validation there as well.

https://codereview.appspot.com/13396048/

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

Reviewers: mp+184517_code.launchpad.net,

Message:
Please take a look.

Description:
client.NewNonValidatingPublicClient: new API

While working on the juju-core side of the code, I discovered another
path
where we try to connect to the HTTPS server (reading public buckets). So
we
need a way to disable ssl validation there as well.

https://code.launchpad.net/~jameinel/goose/no-ssl-public/+merge/184517

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/13396048/

Affected files (+39, -0 lines):
   A [revision details]
   M client/client.go
   M client/local_test.go

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-20130906034601-83yd6irnaucxwul4
+New revision: <email address hidden>

Index: client/client.go
=== modified file 'client/client.go'
--- client/client.go 2013-09-04 10:35:49 +0000
+++ client/client.go 2013-09-09 08:24:27 +0000
@@ -89,6 +89,14 @@
   return &client
  }

+func NewNonValidatingPublicClient(baseURL string, logger *log.Logger)
Client {
+ return &client{
+ baseURL: baseURL,
+ logger: logger,
+ httpClient: goosehttp.NewNonSSLValidating(),
+ }
+}
+
  var defaultRequiredServiceTypes = []string{"compute", "object-store"}

  func newClient(creds *identity.Credentials, auth_method identity.AuthMode,
httpClient *goosehttp.Client, logger *log.Logger) AuthenticatingClient {

Index: client/local_test.go
=== modified file 'client/local_test.go'
--- client/local_test.go 2013-09-04 10:35:49 +0000
+++ client/local_test.go 2013-09-09 08:24:27 +0000
@@ -396,3 +396,32 @@
   c.Assert(err, IsNil)
   c.Check(contents, DeepEquals, []swift.ContainerContents{})
  }
+
+func (s *localHTTPSSuite) setupPublicContainer(c *C) string {
+ // First set up a container that can be read publically
+ authClient := client.NewNonValidatingClient(s.cred,
identity.AuthUserPass, nil)
+ authSwift := swift.New(authClient)
+ err := authSwift.CreateContainer("test_container", swift.PublicRead)
+ c.Assert(err, IsNil)
+
+ baseURL, err := authClient.MakeServiceURL("object-store", nil)
+ c.Assert(err, IsNil)
+ c.Assert(baseURL[:8], Equals, "https://")
+ return baseURL
+}
+
+func (s *localHTTPSSuite) TestDefaultPublicClientRefusesSelfSigned(c *C) {
+ baseURL := s.setupPublicContainer(c)
+ swiftClient := swift.New(client.NewPublicClient(baseURL, nil))
+ contents, err := swiftClient.List("test_container", "", "", "", 0)
+ c.Assert(err, ErrorMatches, "(.|\n)*x509: certificate signed by unknown
authority")
+ c.Assert(contents, DeepEquals, []swift.ContainerContents(nil))
+}
+
+func (s *localHTTPSSuite) TestNonValidatingPublicClientAcceptsSelfSigned(c
*C) {
+ baseURL := s.setupPublicContainer(c)
+ swiftClient := swift.New(client.NewNonValidatingPublicClient(baseURL,
nil))
+ contents, err := swiftClient.List("test_container", "", "", "", 0)
+ c.Assert(err, IsNil)
+ c.Assert(contents, DeepEquals, []swift.ContainerContents{})
+}

Revision history for this message
Frank Mueller (themue) wrote :

LGTM, this cert validation stuff goes deeper than thought in the
beginning.

https://codereview.appspot.com/13396048/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'client/client.go'
2--- client/client.go 2013-09-04 10:35:49 +0000
3+++ client/client.go 2013-09-09 08:38:34 +0000
4@@ -89,6 +89,14 @@
5 return &client
6 }
7
8+func NewNonValidatingPublicClient(baseURL string, logger *log.Logger) Client {
9+ return &client{
10+ baseURL: baseURL,
11+ logger: logger,
12+ httpClient: goosehttp.NewNonSSLValidating(),
13+ }
14+}
15+
16 var defaultRequiredServiceTypes = []string{"compute", "object-store"}
17
18 func newClient(creds *identity.Credentials, auth_method identity.AuthMode, httpClient *goosehttp.Client, logger *log.Logger) AuthenticatingClient {
19
20=== modified file 'client/local_test.go'
21--- client/local_test.go 2013-09-04 10:35:49 +0000
22+++ client/local_test.go 2013-09-09 08:38:34 +0000
23@@ -396,3 +396,32 @@
24 c.Assert(err, IsNil)
25 c.Check(contents, DeepEquals, []swift.ContainerContents{})
26 }
27+
28+func (s *localHTTPSSuite) setupPublicContainer(c *C) string {
29+ // First set up a container that can be read publically
30+ authClient := client.NewNonValidatingClient(s.cred, identity.AuthUserPass, nil)
31+ authSwift := swift.New(authClient)
32+ err := authSwift.CreateContainer("test_container", swift.PublicRead)
33+ c.Assert(err, IsNil)
34+
35+ baseURL, err := authClient.MakeServiceURL("object-store", nil)
36+ c.Assert(err, IsNil)
37+ c.Assert(baseURL[:8], Equals, "https://")
38+ return baseURL
39+}
40+
41+func (s *localHTTPSSuite) TestDefaultPublicClientRefusesSelfSigned(c *C) {
42+ baseURL := s.setupPublicContainer(c)
43+ swiftClient := swift.New(client.NewPublicClient(baseURL, nil))
44+ contents, err := swiftClient.List("test_container", "", "", "", 0)
45+ c.Assert(err, ErrorMatches, "(.|\n)*x509: certificate signed by unknown authority")
46+ c.Assert(contents, DeepEquals, []swift.ContainerContents(nil))
47+}
48+
49+func (s *localHTTPSSuite) TestNonValidatingPublicClientAcceptsSelfSigned(c *C) {
50+ baseURL := s.setupPublicContainer(c)
51+ swiftClient := swift.New(client.NewNonValidatingPublicClient(baseURL, nil))
52+ contents, err := swiftClient.List("test_container", "", "", "", 0)
53+ c.Assert(err, IsNil)
54+ c.Assert(contents, DeepEquals, []swift.ContainerContents{})
55+}

Subscribers

People subscribed via source and target branches