[XAPID-1002] add X-Apigee-Consumer-Type header, add test
diff --git a/api_test.go b/api_test.go
index 86b3f76..4f6e265 100644
--- a/api_test.go
+++ b/api_test.go
@@ -772,6 +772,51 @@
Expect(strings.Contains(strings.ToLower(string(body)), strings.ToLower(expectedBody[i]))).To(BeTrue())
}
})
+
+ It("/register should reject invalid json, and marshal valid fields", func() {
+ // setup test data
+ dummyClient.code = http.StatusOK
+
+ testData := []string{
+ "invalid-json",
+ `{"reportedTime":"2017-08-09T13:30:03.987-07:00"}`,
+ `{"invalid-field1":"8eebdb60-be68-4380-a902-8cd0a2a0744c",
+ "invalid-field2":"2017-08-09T13:30:03.987-07:00"}`,
+ }
+
+ expectedCode := []int{
+ http.StatusBadRequest,
+ http.StatusBadRequest,
+ http.StatusBadRequest,
+ }
+
+ expectedBody := []string{
+ "json",
+ "",
+ "",
+ }
+
+ // setup http client
+ uri, err := url.Parse(apiTestUrl)
+ Expect(err).Should(Succeed())
+ for i, data := range testData {
+ uuid := "8eebdb60-be68-4380-a902-8cd0a2a0744c"
+ uri.Path = strings.Replace(testApiMan.registerEndpoint, "{uuid}", uuid, 1)
+ Expect(err).Should(Succeed())
+ log.Debug(uri.String())
+ req, err := http.NewRequest("PUT", uri.String(), strings.NewReader(data))
+ Expect(err).Should(Succeed())
+ // http put
+ res, err := testClient.Do(req)
+ Expect(err).Should(Succeed())
+ // parse response
+ defer res.Body.Close()
+ Expect(res.StatusCode).Should(Equal(expectedCode[i]))
+ body, err := ioutil.ReadAll(res.Body)
+ Expect(err).Should(Succeed())
+ Expect(strings.Contains(strings.ToLower(string(body)), strings.ToLower(expectedBody[i]))).To(BeTrue())
+ }
+ })
})
})
diff --git a/clients.go b/clients.go
index 7680029..6441446 100644
--- a/clients.go
+++ b/clients.go
@@ -45,6 +45,7 @@
req, err := http.NewRequest("PUT", uri.String(), bytes.NewReader(bodyBytes))
req.Header.Add("Authorization", getBearerToken())
+ req.Header.Set("X-Apigee-Consumer-Type", "apid")
r, err := t.httpclient.Do(req)
if err != nil {
@@ -79,6 +80,7 @@
req, err := http.NewRequest("PUT", uri.String(), bytes.NewReader(bodyBytes))
req.Header.Add("Authorization", getBearerToken())
+ req.Header.Set("X-Apigee-Consumer-Type", "apid")
r, err := t.httpclient.Do(req)
if err != nil {
@@ -98,6 +100,7 @@
req, err := http.NewRequest("PUT", uri.String(), nil)
req.Header.Add("Authorization", getBearerToken())
req.Header.Add("reportedTime", reported)
+ req.Header.Set("X-Apigee-Consumer-Type", "apid")
r, err := t.httpclient.Do(req)
if err != nil {
diff --git a/init.go b/init.go
index 3e8121a..deaf76f 100644
--- a/init.go
+++ b/init.go
@@ -128,7 +128,6 @@
}
apidClusterId = config.GetString(configApidClusterID)
-
client := &trackerClient{
trackerBaseUrl: configApiServerBaseURI,
clusterId: apidClusterId,
@@ -203,4 +202,3 @@
return pluginData, nil
}
-