Merge lp:~jtv/gwacl/unexport-x509 into lp:gwacl

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Jeroen T. Vermeulen
Approved revision: 62
Merged at revision: 63
Proposed branch: lp:~jtv/gwacl/unexport-x509
Merge into: lp:gwacl
Diff against target: 518 lines (+73/-73)
6 files modified
managementapi.go (+2/-2)
managementapi_test.go (+7/-7)
x509dispatcher.go (+20/-20)
x509dispatcher_test.go (+7/-7)
x509session.go (+9/-9)
x509session_test.go (+28/-28)
To merge this branch: bzr merge lp:~jtv/gwacl/unexport-x509
Reviewer Review Type Date Requested Status
Julian Edwards (community) Approve
Review via email: mp+155409@code.launchpad.net

Commit message

Un-export the X509 classes. They're an implementation detail, completely hidden from the gwacl API.

Description of the change

Cleaning up the public API that we expose for gwacl.

I regret the size of this diff. Just un-exporting some identifiers is a huge amount of pointless diff in Go. I figured for that very reason it'd be best to get this behind us as soon as possible, with a minimum of development going on for it to interfere with.

For what it's worth, the un-exporting of these items is the *only* thing that happens in this branch. It's a mechanical change: X509Request / X509Response / X509Session structs become x509Request / x509Response / x509Session respectively, and their constructors NewX509* become newX509* (insofar as they weren't lower-cased already).

Jeroen

To post a comment you must log in.
Revision history for this message
Julian Edwards (julian-edwards) wrote :

"Just un-exporting some identifiers is a huge amount of pointless diff in Go"

Sigh :/

review: Approve
Revision history for this message
Julian Edwards (julian-edwards) wrote :

Attempt to merge into lp:gwacl failed due to conflicts:

text conflict in managementapi_test.go

Revision history for this message
Julian Edwards (julian-edwards) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'managementapi.go'
--- managementapi.go 2013-03-25 02:10:02 +0000
+++ managementapi.go 2013-03-26 08:56:20 +0000
@@ -8,13 +8,13 @@
8)8)
99
10type ManagementAPI struct {10type ManagementAPI struct {
11 session *X509Session11 session *x509Session
12}12}
1313
14// NewManagementAPI creates an object used to interact with Windows Azure's API.14// NewManagementAPI creates an object used to interact with Windows Azure's API.
15// http://msdn.microsoft.com/en-us/library/windowsazure/ff800682.aspx15// http://msdn.microsoft.com/en-us/library/windowsazure/ff800682.aspx
16func NewManagementAPI(subscriptionId string, certFile string) (*ManagementAPI, error) {16func NewManagementAPI(subscriptionId string, certFile string) (*ManagementAPI, error) {
17 session, err := NewX509Session(subscriptionId, certFile)17 session, err := newX509Session(subscriptionId, certFile)
18 if err != nil {18 if err != nil {
19 return nil, err19 return nil, err
20 }20 }
2121
=== modified file 'managementapi_test.go'
--- managementapi_test.go 2013-03-26 07:00:46 +0000
+++ managementapi_test.go 2013-03-26 08:56:20 +0000
@@ -21,7 +21,7 @@
21 api, err := NewManagementAPI(subscriptionId, certFile)21 api, err := NewManagementAPI(subscriptionId, certFile)
2222
23 c.Assert(err, IsNil)23 c.Assert(err, IsNil)
24 session, err := NewX509Session(subscriptionId, certFile)24 session, err := newX509Session(subscriptionId, certFile)
25 c.Assert(api.session.subscriptionId, DeepEquals, session.subscriptionId)25 c.Assert(api.session.subscriptionId, DeepEquals, session.subscriptionId)
26 c.Assert(api.session.certFile, DeepEquals, session.certFile)26 c.Assert(api.session.certFile, DeepEquals, session.certFile)
27}27}
@@ -37,20 +37,20 @@
37// setUpDispatcher sets up a request dispatcher that:37// setUpDispatcher sets up a request dispatcher that:
38// - records requests38// - records requests
39// - returns empty responses39// - returns empty responses
40func (suite *managementAPISuite) setUpDispatcher() *[]*X509Request {40func (suite *managementAPISuite) setUpDispatcher() *[]*x509Request {
41 fixedResponse := X509Response{41 fixedResponse := x509Response{
42 StatusCode: http.StatusOK,42 StatusCode: http.StatusOK,
43 Body: []byte{},43 Body: []byte{},
44 }44 }
45 rigFixedResponseDispatcher(&fixedResponse)45 rigFixedResponseDispatcher(&fixedResponse)
46 recordedRequests := make([]*X509Request, 0)46 recordedRequests := make([]*x509Request, 0)
47 rigRecordingDispatcher(&recordedRequests)47 rigRecordingDispatcher(&recordedRequests)
48 return &recordedRequests48 return &recordedRequests
49}49}
5050
51// checkRequest asserts that the given slice contains one request, with the51// checkRequest asserts that the given slice contains one request, with the
52// given characteristics.52// given characteristics.
53func checkRequest(c *C, recordedRequests *[]*X509Request, URL string, payload []byte, Method string) {53func checkRequest(c *C, recordedRequests *[]*x509Request, URL string, payload []byte, Method string) {
54 requests := *recordedRequests54 requests := *recordedRequests
55 c.Assert(len(requests), Equals, 1)55 c.Assert(len(requests), Equals, 1)
56 request := requests[0]56 request := requests[0]
@@ -128,8 +128,8 @@
128128
129func (suite *managementAPISuite) TestAddStorageAccount(c *C) {129func (suite *managementAPISuite) TestAddStorageAccount(c *C) {
130 api := suite.makeAPI(c)130 api := suite.makeAPI(c)
131 rigFixedResponseDispatcher(&X509Response{StatusCode: http.StatusAccepted})131 rigFixedResponseDispatcher(&x509Response{StatusCode: http.StatusAccepted})
132 recordedRequests := make([]*X509Request, 0)132 recordedRequests := make([]*x509Request, 0)
133 rigRecordingDispatcher(&recordedRequests)133 rigRecordingDispatcher(&recordedRequests)
134 cssi := NewCreateStorageServiceInputWithLocation("name", "label", "East US")134 cssi := NewCreateStorageServiceInputWithLocation("name", "label", "East US")
135135
136136
=== modified file 'x509dispatcher.go'
--- x509dispatcher.go 2013-03-22 02:52:32 +0000
+++ x509dispatcher.go 2013-03-26 08:56:20 +0000
@@ -10,7 +10,7 @@
10 "net/textproto"10 "net/textproto"
11)11)
1212
13type X509Request struct {13type x509Request struct {
14 APIVersion string14 APIVersion string
15 Method string15 Method string
16 URL string16 URL string
@@ -28,20 +28,20 @@
28// baseAPIVersion is the default Azure API version to use.28// baseAPIVersion is the default Azure API version to use.
29const baseAPIVersion = "2012-03-01"29const baseAPIVersion = "2012-03-01"
3030
31// newX509RequestGET initializes an X509Request for a GET. You may still need31// newX509RequestGET initializes an x509Request for a GET. You may still need
32// to set further values.32// to set further values.
33func newX509RequestGET(url string) *X509Request {33func newX509RequestGET(url string) *x509Request {
34 return &X509Request{34 return &x509Request{
35 Method: "GET",35 Method: "GET",
36 URL: url,36 URL: url,
37 APIVersion: baseAPIVersion,37 APIVersion: baseAPIVersion,
38 }38 }
39}39}
4040
41// newX509RequestPOST initializes an X509Request for a POST. You may still41// newX509RequestPOST initializes an x509Request for a POST. You may still
42// need to set further values.42// need to set further values.
43func newX509RequestPOST(url string, payload []byte, contentType string) *X509Request {43func newX509RequestPOST(url string, payload []byte, contentType string) *x509Request {
44 return &X509Request{44 return &x509Request{
45 Method: "POST",45 Method: "POST",
46 URL: url,46 URL: url,
47 APIVersion: baseAPIVersion,47 APIVersion: baseAPIVersion,
@@ -50,19 +50,19 @@
50 }50 }
51}51}
5252
53// newX509RequestDELETE initializes an X509Request for a DELETE.53// newX509RequestDELETE initializes an x509Request for a DELETE.
54func newX509RequestDELETE(url string) *X509Request {54func newX509RequestDELETE(url string) *x509Request {
55 return &X509Request{55 return &x509Request{
56 Method: "DELETE",56 Method: "DELETE",
57 URL: url,57 URL: url,
58 APIVersion: baseAPIVersion,58 APIVersion: baseAPIVersion,
59 }59 }
60}60}
6161
62// newX509RequestPUT initializes an X509Request for a PUT. You may still62// newX509RequestPUT initializes an x509Request for a PUT. You may still
63// need to set further values.63// need to set further values.
64func newX509RequestPUT(url string, payload []byte) *X509Request {64func newX509RequestPUT(url string, payload []byte) *x509Request {
65 return &X509Request{65 return &x509Request{
66 Method: "PUT",66 Method: "PUT",
67 URL: url,67 URL: url,
68 APIVersion: baseAPIVersion,68 APIVersion: baseAPIVersion,
@@ -70,7 +70,7 @@
70 }70 }
71}71}
7272
73type X509Response struct {73type x509Response struct {
74 StatusCode int74 StatusCode int
75 // TODO: What exactly do we get back? How will we know its encoding?75 // TODO: What exactly do we get back? How will we know its encoding?
76 Body []byte76 Body []byte
@@ -78,8 +78,8 @@
78 Header http.Header78 Header http.Header
79}79}
8080
81func newX509Response() *X509Response {81func newX509Response() *x509Response {
82 return &X509Response{82 return &x509Response{
83 Body: make([]byte, 0),83 Body: make([]byte, 0),
84 RawHeader: make([]byte, 0),84 RawHeader: make([]byte, 0),
85 }85 }
@@ -120,7 +120,7 @@
120120
121// parseHeader parses the raw header as stored in RawHeader, and uses it to121// parseHeader parses the raw header as stored in RawHeader, and uses it to
122// initialize Header.122// initialize Header.
123func (response *X509Response) parseHeader() error {123func (response *x509Response) parseHeader() error {
124 rawHeader := stripPreliminaryResponses(response.RawHeader)124 rawHeader := stripPreliminaryResponses(response.RawHeader)
125 mimeHeader, err := stripResponseLine(rawHeader)125 mimeHeader, err := stripResponseLine(rawHeader)
126 if err != nil {126 if err != nil {
@@ -141,7 +141,7 @@
141 return nil141 return nil
142}142}
143143
144func performX509CurlRequest(session *X509Session, request *X509Request) (*X509Response, error) {144func performX509CurlRequest(session *x509Session, request *x509Request) (*x509Response, error) {
145 if verbose {145 if verbose {
146 log.Println("Performing request")146 log.Println("Performing request")
147 log.Println("Request url: " + request.URL)147 log.Println("Request url: " + request.URL)
@@ -181,7 +181,7 @@
181// makeCurlRequest produces a curl.CURL representing the request.181// makeCurlRequest produces a curl.CURL representing the request.
182// Clean up the request by calling its Cleanup() method after you're done182// Clean up the request by calling its Cleanup() method after you're done
183// with it.183// with it.
184func (request *X509Request) makeCurlRequest(session *X509Session, response *X509Response) *curl.CURL {184func (request *x509Request) makeCurlRequest(session *x509Session, response *x509Response) *curl.CURL {
185 ch := curl.EasyInit()185 ch := curl.EasyInit()
186186
187 ch.Setopt(curl.OPT_SSLCERT, session.certFile)187 ch.Setopt(curl.OPT_SSLCERT, session.certFile)
@@ -230,7 +230,7 @@
230230
231// setCurlHTTPMethod sets up a CURL object to perform an HTTP request of231// setCurlHTTPMethod sets up a CURL object to perform an HTTP request of
232// the HTTP method (GET, POST, etc.) appropriate for the request.232// the HTTP method (GET, POST, etc.) appropriate for the request.
233func (request *X509Request) setCurlHTTPMethod(ch *curl.CURL) {233func (request *x509Request) setCurlHTTPMethod(ch *curl.CURL) {
234 switch request.Method {234 switch request.Method {
235 case "GET":235 case "GET":
236 // Nothing to be done. This is the default.236 // Nothing to be done. This is the default.
237237
=== modified file 'x509dispatcher_test.go'
--- x509dispatcher_test.go 2013-03-22 02:06:22 +0000
+++ x509dispatcher_test.go 2013-03-26 08:56:20 +0000
@@ -30,7 +30,7 @@
30// An HTTP header contains a response line followed by a MIME header, which30// An HTTP header contains a response line followed by a MIME header, which
31// parseHeader processes.31// parseHeader processes.
32func (*X509DispatcherSuite) TestParseHeaderParsesHTTPHeader(c *C) {32func (*X509DispatcherSuite) TestParseHeaderParsesHTTPHeader(c *C) {
33 response := X509Response{}33 response := x509Response{}
34 text := "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\n\r\n"34 text := "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\n\r\n"
35 response.RawHeader = []byte(text)35 response.RawHeader = []byte(text)
3636
@@ -43,7 +43,7 @@
43// An HTTP response actually contains a sequence of HTTP headers, and43// An HTTP response actually contains a sequence of HTTP headers, and
44// parseHeader only uses the final one.44// parseHeader only uses the final one.
45func (*X509DispatcherSuite) TestParseHeaderParsesContinueResponse(c *C) {45func (*X509DispatcherSuite) TestParseHeaderParsesContinueResponse(c *C) {
46 response := X509Response{}46 response := x509Response{}
47 text := "HTTP/1.1 100 Continue\r\n\r\nHTTP/1.1 202 Accepted\r\nCache-Control: no-cache\r\n\r\n"47 text := "HTTP/1.1 100 Continue\r\n\r\nHTTP/1.1 202 Accepted\r\nCache-Control: no-cache\r\n\r\n"
48 response.RawHeader = []byte(text)48 response.RawHeader = []byte(text)
4949
@@ -58,7 +58,7 @@
58 server := makeRecordingHTTPServer(httpRequests, http.StatusOK, nil)58 server := makeRecordingHTTPServer(httpRequests, http.StatusOK, nil)
59 defer server.Close()59 defer server.Close()
60 // No real certificate needed since we're testing on http, not https.60 // No real certificate needed since we're testing on http, not https.
61 session, err := NewX509Session("subscriptionid", "cert.pem")61 session, err := newX509Session("subscriptionid", "cert.pem")
62 c.Assert(err, IsNil)62 c.Assert(err, IsNil)
63 path := "/foo/bar"63 path := "/foo/bar"
64 request := newX509RequestGET(server.URL + path)64 request := newX509RequestGET(server.URL + path)
@@ -80,7 +80,7 @@
80 server := makeRecordingHTTPServer(httpRequests, http.StatusOK, responseBody)80 server := makeRecordingHTTPServer(httpRequests, http.StatusOK, responseBody)
81 defer server.Close()81 defer server.Close()
82 // No real certificate needed since we're testing on http, not https.82 // No real certificate needed since we're testing on http, not https.
83 session, err := NewX509Session("subscriptionid", "cert.pem")83 session, err := newX509Session("subscriptionid", "cert.pem")
84 c.Assert(err, IsNil)84 c.Assert(err, IsNil)
85 path := "/foo/bar"85 path := "/foo/bar"
86 request := newX509RequestPOST(server.URL+path, requestBody, requestContentType)86 request := newX509RequestPOST(server.URL+path, requestBody, requestContentType)
@@ -102,7 +102,7 @@
102 server := makeRecordingHTTPServer(httpRequests, http.StatusOK, []byte{})102 server := makeRecordingHTTPServer(httpRequests, http.StatusOK, []byte{})
103 defer server.Close()103 defer server.Close()
104 // No real certificate needed since we're testing on http, not https.104 // No real certificate needed since we're testing on http, not https.
105 session, err := NewX509Session("subscriptionid", "cert.pem")105 session, err := newX509Session("subscriptionid", "cert.pem")
106 c.Assert(err, IsNil)106 c.Assert(err, IsNil)
107 path := "/foo/bar"107 path := "/foo/bar"
108 request := newX509RequestDELETE(server.URL + path)108 request := newX509RequestDELETE(server.URL + path)
@@ -123,7 +123,7 @@
123 server := makeRecordingHTTPServer(httpRequests, http.StatusOK, responseBody)123 server := makeRecordingHTTPServer(httpRequests, http.StatusOK, responseBody)
124 defer server.Close()124 defer server.Close()
125 // No real certificate needed since we're testing on http, not https.125 // No real certificate needed since we're testing on http, not https.
126 session, err := NewX509Session("subscriptionid", "cert.pem")126 session, err := newX509Session("subscriptionid", "cert.pem")
127 c.Assert(err, IsNil)127 c.Assert(err, IsNil)
128 path := "/foo/bar"128 path := "/foo/bar"
129 request := newX509RequestPUT(server.URL+path, requestBody)129 request := newX509RequestPUT(server.URL+path, requestBody)
@@ -149,7 +149,7 @@
149 serveMux.HandleFunc("/", returnRequest)149 serveMux.HandleFunc("/", returnRequest)
150 server := httptest.NewServer(serveMux)150 server := httptest.NewServer(serveMux)
151 defer server.Close()151 defer server.Close()
152 session, err := NewX509Session("subscriptionid", "cert.pem")152 session, err := newX509Session("subscriptionid", "cert.pem")
153 c.Assert(err, IsNil)153 c.Assert(err, IsNil)
154 path := "/foo/bar"154 path := "/foo/bar"
155 request := newX509RequestGET(server.URL + path)155 request := newX509RequestGET(server.URL + path)
156156
=== modified file 'x509session.go'
--- x509session.go 2013-03-20 23:53:03 +0000
+++ x509session.go 2013-03-26 08:56:20 +0000
@@ -8,15 +8,15 @@
8 "net/http"8 "net/http"
9)9)
1010
11type X509Session struct {11type x509Session struct {
12 subscriptionId string12 subscriptionId string
13 certFile string13 certFile string
14}14}
1515
16// NewX509Session creates and returns a new X509Session based on credentials16// newX509Session creates and returns a new x509Session based on credentials
17// and X509 certificate files.17// and X509 certificate files.
18func NewX509Session(subscriptionId string, certFile string) (*X509Session, error) {18func newX509Session(subscriptionId string, certFile string) (*x509Session, error) {
19 return &X509Session{subscriptionId: subscriptionId, certFile: certFile}, nil19 return &x509Session{subscriptionId: subscriptionId, certFile: certFile}, nil
20}20}
2121
22var AZURE_URL = "https://management.core.windows.net/"22var AZURE_URL = "https://management.core.windows.net/"
@@ -43,7 +43,7 @@
4343
44// getServerError returns a ServerError matching the given server response44// getServerError returns a ServerError matching the given server response
45// status, or nil if the server response indicates success.45// status, or nil if the server response indicates success.
46func (session *X509Session) getServerError(status int, description string) error {46func (session *x509Session) getServerError(status int, description string) error {
47 if status < http.StatusOK || status >= http.StatusMultipleChoices {47 if status < http.StatusOK || status >= http.StatusMultipleChoices {
48 failure := fmt.Errorf("%s (http status code %d)", description, status)48 failure := fmt.Errorf("%s (http status code %d)", description, status)
49 return &ServerError{error: failure, StatusCode: status}49 return &ServerError{error: failure, StatusCode: status}
@@ -55,7 +55,7 @@
55// It returns the response body and/or an error. If the error is a55// It returns the response body and/or an error. If the error is a
56// ServerError, the returned body will be the one received from the server.56// ServerError, the returned body will be the one received from the server.
57// For any other kind of error, the returned body will be nil.57// For any other kind of error, the returned body will be nil.
58func (session *X509Session) get(url string) ([]byte, error) {58func (session *x509Session) get(url string) ([]byte, error) {
59 fullUrl := composeURL(url, session.subscriptionId)59 fullUrl := composeURL(url, session.subscriptionId)
60 request := newX509RequestGET(fullUrl)60 request := newX509RequestGET(fullUrl)
61 response, err := _X509Dispatcher(session, request)61 response, err := _X509Dispatcher(session, request)
@@ -70,7 +70,7 @@
70// It returns the response body and/or an error. If the error is a70// It returns the response body and/or an error. If the error is a
71// ServerError, the returned body will be the one received from the server.71// ServerError, the returned body will be the one received from the server.
72// For any other kind of error, the returned body will be nil.72// For any other kind of error, the returned body will be nil.
73func (session *X509Session) post(url string, body []byte, contentType string) ([]byte, error) {73func (session *x509Session) post(url string, body []byte, contentType string) ([]byte, error) {
74 fullUrl := composeURL(url, session.subscriptionId)74 fullUrl := composeURL(url, session.subscriptionId)
75 request := newX509RequestPOST(fullUrl, body, contentType)75 request := newX509RequestPOST(fullUrl, body, contentType)
76 response, err := _X509Dispatcher(session, request)76 response, err := _X509Dispatcher(session, request)
@@ -82,7 +82,7 @@
82}82}
8383
84// delete performs a DELETE request to the Azure management API.84// delete performs a DELETE request to the Azure management API.
85func (session *X509Session) delete(url string) error {85func (session *x509Session) delete(url string) error {
86 fullUrl := composeURL(url, session.subscriptionId)86 fullUrl := composeURL(url, session.subscriptionId)
87 request := newX509RequestDELETE(fullUrl)87 request := newX509RequestDELETE(fullUrl)
88 response, err := _X509Dispatcher(session, request)88 response, err := _X509Dispatcher(session, request)
@@ -93,7 +93,7 @@
93}93}
9494
95// put performs a PUT request to the Azure management API.95// put performs a PUT request to the Azure management API.
96func (session *X509Session) put(url string, body []byte) error {96func (session *x509Session) put(url string, body []byte) error {
97 fullUrl := composeURL(url, session.subscriptionId)97 fullUrl := composeURL(url, session.subscriptionId)
98 request := newX509RequestPUT(fullUrl, body)98 request := newX509RequestPUT(fullUrl, body)
99 response, err := _X509Dispatcher(session, request)99 response, err := _X509Dispatcher(session, request)
100100
=== modified file 'x509session_test.go'
--- x509session_test.go 2013-03-20 23:53:03 +0000
+++ x509session_test.go 2013-03-26 08:56:20 +0000
@@ -18,7 +18,7 @@
18)18)
1919
20type X509SessionSuite struct {20type X509SessionSuite struct {
21 oldDispatcher func(*X509Session, *X509Request) (*X509Response, error)21 oldDispatcher func(*x509Session, *x509Request) (*x509Response, error)
22}22}
2323
24var _ = Suite(&X509SessionSuite{})24var _ = Suite(&X509SessionSuite{})
@@ -29,9 +29,9 @@
29// If you also want the dispatcher to return a particular result, rig it for29// If you also want the dispatcher to return a particular result, rig it for
30// that result first (using one of the other rig...Dispatcher functions) and30// that result first (using one of the other rig...Dispatcher functions) and
31// then chain the recording dispatcher in front of it.31// then chain the recording dispatcher in front of it.
32func rigRecordingDispatcher(record *[]*X509Request) {32func rigRecordingDispatcher(record *[]*x509Request) {
33 previousDispatcher := _X509Dispatcher33 previousDispatcher := _X509Dispatcher
34 _X509Dispatcher = func(session *X509Session, request *X509Request) (*X509Response, error) {34 _X509Dispatcher = func(session *x509Session, request *x509Request) (*x509Response, error) {
35 *record = append(*record, request)35 *record = append(*record, request)
36 return previousDispatcher(session, request)36 return previousDispatcher(session, request)
37 }37 }
@@ -39,8 +39,8 @@
3939
40// rigFixedResponseDispatcher sets up a request dispatcher that always returns40// rigFixedResponseDispatcher sets up a request dispatcher that always returns
41// a prepared response.41// a prepared response.
42func rigFixedResponseDispatcher(response *X509Response) {42func rigFixedResponseDispatcher(response *x509Response) {
43 _X509Dispatcher = func(*X509Session, *X509Request) (*X509Response, error) {43 _X509Dispatcher = func(*x509Session, *x509Request) (*x509Response, error) {
44 return response, nil44 return response, nil
45 }45 }
46}46}
@@ -48,7 +48,7 @@
48// rigFailingDispatcher sets up a request dispatcher that returns a given48// rigFailingDispatcher sets up a request dispatcher that returns a given
49// error.49// error.
50func rigFailingDispatcher(failure error) {50func rigFailingDispatcher(failure error) {
51 _X509Dispatcher = func(*X509Session, *X509Request) (*X509Response, error) {51 _X509Dispatcher = func(*x509Session, *x509Request) (*x509Response, error) {
52 return nil, failure52 return nil, failure
53 }53 }
54}54}
@@ -125,14 +125,14 @@
125}125}
126126
127func (suite *X509SessionSuite) TestNewX509SessionCreation(c *C) {127func (suite *X509SessionSuite) TestNewX509SessionCreation(c *C) {
128 _, err := NewX509Session("subscriptionid", "azure.pem")128 _, err := newX509Session("subscriptionid", "azure.pem")
129 c.Assert(err, IsNil)129 c.Assert(err, IsNil)
130}130}
131131
132func (suite *X509SessionSuite) TestGetServerErrorProducesServerError(c *C) {132func (suite *X509SessionSuite) TestGetServerErrorProducesServerError(c *C) {
133 msg := "huhwhat"133 msg := "huhwhat"
134 status := http.StatusNotFound134 status := http.StatusNotFound
135 session, err := NewX509Session("subscriptionid", "azure.pem")135 session, err := newX509Session("subscriptionid", "azure.pem")
136 c.Assert(err, IsNil)136 c.Assert(err, IsNil)
137137
138 err = session.getServerError(status, msg)138 err = session.getServerError(status, msg)
@@ -148,7 +148,7 @@
148 http.StatusOK,148 http.StatusOK,
149 http.StatusNoContent,149 http.StatusNoContent,
150 }150 }
151 session, err := NewX509Session("subscriptionid", "azure.pem")151 session, err := newX509Session("subscriptionid", "azure.pem")
152 c.Assert(err, IsNil)152 c.Assert(err, IsNil)
153153
154 for _, status := range goodCodes {154 for _, status := range goodCodes {
@@ -166,7 +166,7 @@
166 http.StatusInternalServerError,166 http.StatusInternalServerError,
167 http.StatusNotImplemented,167 http.StatusNotImplemented,
168 }168 }
169 session, err := NewX509Session("subscriptionid", "azure.pem")169 session, err := newX509Session("subscriptionid", "azure.pem")
170 c.Assert(err, IsNil)170 c.Assert(err, IsNil)
171171
172 for _, status := range badCodes {172 for _, status := range badCodes {
@@ -177,15 +177,15 @@
177func (suite *X509SessionSuite) TestGetIssuesRequest(c *C) {177func (suite *X509SessionSuite) TestGetIssuesRequest(c *C) {
178 subscriptionID := "subscriptionID"178 subscriptionID := "subscriptionID"
179 uri := "resource"179 uri := "resource"
180 session, err := NewX509Session(subscriptionID, "cert.pem")180 session, err := newX509Session(subscriptionID, "cert.pem")
181 c.Assert(err, IsNil)181 c.Assert(err, IsNil)
182 // Record incoming requests, and have them return a given reply.182 // Record incoming requests, and have them return a given reply.
183 fixedResponse := X509Response{183 fixedResponse := x509Response{
184 StatusCode: http.StatusOK,184 StatusCode: http.StatusOK,
185 Body: []byte("Response body"),185 Body: []byte("Response body"),
186 }186 }
187 rigFixedResponseDispatcher(&fixedResponse)187 rigFixedResponseDispatcher(&fixedResponse)
188 recordedRequests := make([]*X509Request, 0)188 recordedRequests := make([]*x509Request, 0)
189 rigRecordingDispatcher(&recordedRequests)189 rigRecordingDispatcher(&recordedRequests)
190190
191 receivedBody, err := session.get(uri)191 receivedBody, err := session.get(uri)
@@ -199,7 +199,7 @@
199}199}
200200
201func (suite *X509SessionSuite) TestGetReportsClientSideError(c *C) {201func (suite *X509SessionSuite) TestGetReportsClientSideError(c *C) {
202 session, err := NewX509Session("subscriptionid", "cert.pem")202 session, err := newX509Session("subscriptionid", "cert.pem")
203 msg := "could not dispatch request"203 msg := "could not dispatch request"
204 rigFailingDispatcher(fmt.Errorf(msg))204 rigFailingDispatcher(fmt.Errorf(msg))
205205
@@ -211,8 +211,8 @@
211}211}
212212
213func (suite *X509SessionSuite) TestGetReportsServerSideError(c *C) {213func (suite *X509SessionSuite) TestGetReportsServerSideError(c *C) {
214 session, err := NewX509Session("subscriptionid", "cert.pem")214 session, err := newX509Session("subscriptionid", "cert.pem")
215 fixedResponse := X509Response{215 fixedResponse := x509Response{
216 StatusCode: http.StatusForbidden,216 StatusCode: http.StatusForbidden,
217 Body: []byte("Body"),217 Body: []byte("Body"),
218 }218 }
@@ -231,15 +231,15 @@
231 uri := "resource"231 uri := "resource"
232 requestBody := []byte("Request body")232 requestBody := []byte("Request body")
233 requestContentType := "bogusContentType"233 requestContentType := "bogusContentType"
234 session, err := NewX509Session(subscriptionID, "cert.pem")234 session, err := newX509Session(subscriptionID, "cert.pem")
235 c.Assert(err, IsNil)235 c.Assert(err, IsNil)
236 // Record incoming requests, and have them return a given reply.236 // Record incoming requests, and have them return a given reply.
237 fixedResponse := X509Response{237 fixedResponse := x509Response{
238 StatusCode: http.StatusOK,238 StatusCode: http.StatusOK,
239 Body: []byte("Response body"),239 Body: []byte("Response body"),
240 }240 }
241 rigFixedResponseDispatcher(&fixedResponse)241 rigFixedResponseDispatcher(&fixedResponse)
242 recordedRequests := make([]*X509Request, 0)242 recordedRequests := make([]*x509Request, 0)
243 rigRecordingDispatcher(&recordedRequests)243 rigRecordingDispatcher(&recordedRequests)
244244
245 receivedBody, err := session.post(uri, requestBody, requestContentType)245 receivedBody, err := session.post(uri, requestBody, requestContentType)
@@ -255,7 +255,7 @@
255}255}
256256
257func (suite *X509SessionSuite) TestPostReportsClientSideError(c *C) {257func (suite *X509SessionSuite) TestPostReportsClientSideError(c *C) {
258 session, err := NewX509Session("subscriptionid", "cert.pem")258 session, err := newX509Session("subscriptionid", "cert.pem")
259 msg := "could not dispatch request"259 msg := "could not dispatch request"
260 rigFailingDispatcher(fmt.Errorf(msg))260 rigFailingDispatcher(fmt.Errorf(msg))
261261
@@ -267,8 +267,8 @@
267}267}
268268
269func (suite *X509SessionSuite) TestPostReportsServerSideError(c *C) {269func (suite *X509SessionSuite) TestPostReportsServerSideError(c *C) {
270 session, err := NewX509Session("subscriptionid", "cert.pem")270 session, err := newX509Session("subscriptionid", "cert.pem")
271 fixedResponse := X509Response{271 fixedResponse := x509Response{
272 StatusCode: http.StatusForbidden,272 StatusCode: http.StatusForbidden,
273 Body: []byte("Body"),273 Body: []byte("Body"),
274 }274 }
@@ -285,12 +285,12 @@
285func (suite *X509SessionSuite) TestDeleteIssuesRequest(c *C) {285func (suite *X509SessionSuite) TestDeleteIssuesRequest(c *C) {
286 subscriptionID := "subscriptionID"286 subscriptionID := "subscriptionID"
287 uri := "resource"287 uri := "resource"
288 session, err := NewX509Session(subscriptionID, "cert.pem")288 session, err := newX509Session(subscriptionID, "cert.pem")
289 c.Assert(err, IsNil)289 c.Assert(err, IsNil)
290 // Record incoming requests, and have them return a given reply.290 // Record incoming requests, and have them return a given reply.
291 fixedResponse := X509Response{StatusCode: http.StatusOK}291 fixedResponse := x509Response{StatusCode: http.StatusOK}
292 rigFixedResponseDispatcher(&fixedResponse)292 rigFixedResponseDispatcher(&fixedResponse)
293 recordedRequests := make([]*X509Request, 0)293 recordedRequests := make([]*x509Request, 0)
294 rigRecordingDispatcher(&recordedRequests)294 rigRecordingDispatcher(&recordedRequests)
295295
296 err = session.delete(uri)296 err = session.delete(uri)
@@ -306,14 +306,14 @@
306 subscriptionID := "subscriptionID"306 subscriptionID := "subscriptionID"
307 uri := "resource"307 uri := "resource"
308 requestBody := []byte("Request body")308 requestBody := []byte("Request body")
309 session, err := NewX509Session(subscriptionID, "cert.pem")309 session, err := newX509Session(subscriptionID, "cert.pem")
310 c.Assert(err, IsNil)310 c.Assert(err, IsNil)
311 // Record incoming requests, and have them return a given reply.311 // Record incoming requests, and have them return a given reply.
312 fixedResponse := X509Response{312 fixedResponse := x509Response{
313 StatusCode: http.StatusOK,313 StatusCode: http.StatusOK,
314 }314 }
315 rigFixedResponseDispatcher(&fixedResponse)315 rigFixedResponseDispatcher(&fixedResponse)
316 recordedRequests := make([]*X509Request, 0)316 recordedRequests := make([]*x509Request, 0)
317 rigRecordingDispatcher(&recordedRequests)317 rigRecordingDispatcher(&recordedRequests)
318318
319 err = session.put(uri, requestBody)319 err = session.put(uri, requestBody)

Subscribers

People subscribed via source and target branches