diff --git a/credhub/get_test.go b/credhub/get_test.go index 1d5baf6b..4bb3e355 100644 --- a/credhub/get_test.go +++ b/credhub/get_test.go @@ -19,34 +19,17 @@ import ( var _ = Describe("Get", func() { Describe("GetLatestVersion()", func() { - Context("when the Credhub server version is 1.4.0 or newer", func() { - It("requests the credential by name using the 'versions' query parameter", func() { - dummyAuth := &DummyAuth{Response: &http.Response{ - Body: ioutil.NopCloser(bytes.NewBufferString("")), - }} - - ch, _ := New("https://example.com", Auth(dummyAuth.Builder()), ServerVersion("4.4.4")) - - ch.GetLatestVersion("/example-password") - url := dummyAuth.Request.URL.String() - Expect(url).To(Equal("https://example.com/api/v1/data?name=%2Fexample-password&versions=1")) - Expect(dummyAuth.Request.Method).To(Equal(http.MethodGet)) - }) - }) - - Context("when the Credhub server version is older than 1.4.0", func() { - It("requests the credential by name using the 'versions' query parameter", func() { - dummyAuth := &DummyAuth{Response: &http.Response{ - Body: ioutil.NopCloser(bytes.NewBufferString("")), - }} + It("requests the credential by name using the 'current' query parameter", func() { + dummyAuth := &DummyAuth{Response: &http.Response{ + Body: ioutil.NopCloser(bytes.NewBufferString("")), + }} - ch, _ := New("https://example.com", Auth(dummyAuth.Builder()), ServerVersion("1.1.1")) + ch, _ := New("https://example.com", Auth(dummyAuth.Builder()), ServerVersion("1.1.1")) - ch.GetLatestVersion("/example-password") - url := dummyAuth.Request.URL.String() - Expect(url).To(Equal("https://example.com/api/v1/data?current=true&name=%2Fexample-password")) - Expect(dummyAuth.Request.Method).To(Equal(http.MethodGet)) - }) + ch.GetLatestVersion("/example-password") + url := dummyAuth.Request.URL.String() + Expect(url).To(Equal("https://example.com/api/v1/data?current=true&name=%2Fexample-password")) + Expect(dummyAuth.Request.Method).To(Equal(http.MethodGet)) }) Context("when successful", func() { @@ -435,7 +418,7 @@ var _ = Describe("Get", func() { url := dummyAuth.Request.URL Expect(url.String()).To(ContainSubstring("https://example.com/api/v1/data")) Expect(url.String()).To(ContainSubstring("name=%2Fexample-password")) - Expect(url.String()).To(ContainSubstring("versions=1")) + Expect(url.String()).To(ContainSubstring("current=true")) Expect(dummyAuth.Request.Method).To(Equal(http.MethodGet)) }) @@ -486,7 +469,7 @@ var _ = Describe("Get", func() { url := dummyAuth.Request.URL Expect(url.String()).To(ContainSubstring("https://example.com/api/v1/data")) Expect(url.String()).To(ContainSubstring("name=%2Fexample-certificate")) - Expect(url.String()).To(ContainSubstring("versions=1")) + Expect(url.String()).To(ContainSubstring("current=true")) Expect(dummyAuth.Request.Method).To(Equal(http.MethodGet)) }) @@ -545,7 +528,7 @@ var _ = Describe("Get", func() { url := dummyAuth.Request.URL Expect(url.String()).To(ContainSubstring("https://example.com/api/v1/data")) Expect(url.String()).To(ContainSubstring("name=%2Fexample-user")) - Expect(url.String()).To(ContainSubstring("versions=1")) + Expect(url.String()).To(ContainSubstring("current=true")) Expect(dummyAuth.Request.Method).To(Equal(http.MethodGet)) }) @@ -608,7 +591,7 @@ var _ = Describe("Get", func() { url := dummyAuth.Request.URL Expect(url.String()).To(ContainSubstring("https://example.com/api/v1/data")) Expect(url.String()).To(ContainSubstring("name=%2Fexample-rsa")) - Expect(url.String()).To(ContainSubstring("versions=1")) + Expect(url.String()).To(ContainSubstring("current=true")) Expect(dummyAuth.Request.Method).To(Equal(http.MethodGet)) }) @@ -669,7 +652,7 @@ var _ = Describe("Get", func() { url := dummyAuth.Request.URL Expect(url.String()).To(ContainSubstring("https://example.com/api/v1/data")) Expect(url.String()).To(ContainSubstring("name=%2Fexample-ssh")) - Expect(url.String()).To(ContainSubstring("versions=1")) + Expect(url.String()).To(ContainSubstring("current=true")) Expect(dummyAuth.Request.Method).To(Equal(http.MethodGet)) }) @@ -732,7 +715,7 @@ var _ = Describe("Get", func() { url := dummyAuth.Request.URL Expect(url.String()).To(ContainSubstring("https://example.com/api/v1/data")) Expect(url.String()).To(ContainSubstring("name=%2Fexample-json")) - Expect(url.String()).To(ContainSubstring("versions=1")) + Expect(url.String()).To(ContainSubstring("current=true")) Expect(dummyAuth.Request.Method).To(Equal(http.MethodGet)) }) @@ -807,7 +790,7 @@ var _ = Describe("Get", func() { url := dummyAuth.Request.URL Expect(url.String()).To(ContainSubstring("https://example.com/api/v1/data")) Expect(url.String()).To(ContainSubstring("name=%2Fexample-value")) - Expect(url.String()).To(ContainSubstring("versions=1")) + Expect(url.String()).To(ContainSubstring("current=true")) Expect(dummyAuth.Request.Method).To(Equal(http.MethodGet)) }) diff --git a/credhub/new_test.go b/credhub/new_test.go index cfad48a9..fff2974f 100644 --- a/credhub/new_test.go +++ b/credhub/new_test.go @@ -7,7 +7,6 @@ import ( . "github.com/cloudfoundry-incubator/credhub-cli/credhub" "github.com/cloudfoundry-incubator/credhub-cli/credhub/auth" - version "github.com/hashicorp/go-version" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -106,46 +105,4 @@ var _ = Describe("New()", func() { _, err := New("https://example.com", CaCerts(caCerts...), ServerVersion("2.2.2")) Expect(err).To(HaveOccurred()) }) - - Context("With ServerVersion option provided", func() { - It("stores that server version in the client", func() { - ch, _ := New("https://example.com", ServerVersion("2.2.2")) - - Expect(ch.ServerVersion()).To(Equal(version.Must(version.NewVersion("2.2.2")))) - }) - }) - - Context("Without ServerVersion option provided", func() { - It("fetches the server version from the Credhub server", func() { - var apiHit bool - - credHubServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - apiHit = true - if req.URL.Path == "/info" { - w.Write([]byte(`{ - "auth-server": {"url": "https://uaa.example.com:8443"}, - "app": {"name": "CredHub"} - }`)) - } else if req.URL.Path == "/version" { - w.Write([]byte(`{ - "version": "4.4.4" - }`)) - } - })) - - defer credHubServer.Close() - - var authConfig auth.Config - - authBuilder := func(config auth.Config) (auth.Strategy, error) { - authConfig = config - return http.DefaultClient, nil - } - - ch, err := New(credHubServer.URL, AuthURL("https://some-auth-url.com"), Auth(authBuilder)) - Expect(err).ToNot(HaveOccurred()) - - Expect(ch.ServerVersion()).To(Equal(version.Must(version.NewVersion("4.4.4")))) - }) - }) }) diff --git a/credhub/options.go b/credhub/options.go index beba27cd..58bb3ffd 100644 --- a/credhub/options.go +++ b/credhub/options.go @@ -75,7 +75,6 @@ func ClientCert(certificate, key string) Option { // ServerVersion will set the version of server API to use (e.g. "1.2.3") func ServerVersion(serverVersion string) Option { return func(c *CredHub) error { - c.cachedServerVersion = serverVersion return nil } } diff --git a/credhub/options_test.go b/credhub/options_test.go deleted file mode 100644 index 3910974b..00000000 --- a/credhub/options_test.go +++ /dev/null @@ -1,17 +0,0 @@ -package credhub_test - -import ( - version "github.com/hashicorp/go-version" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - - . "github.com/cloudfoundry-incubator/credhub-cli/credhub" -) - -var _ = Describe("Options", func() { - It("", func() { - ch, _ := New("https://example.com", ServerVersion("2.2.2")) - - Expect(ch.ServerVersion()).To(Equal(version.Must(version.NewVersion("2.2.2")))) - }) -}) diff --git a/credhub/server_version_test.go b/credhub/server_version_test.go index d6e88d77..b8940a7a 100644 --- a/credhub/server_version_test.go +++ b/credhub/server_version_test.go @@ -35,7 +35,7 @@ var _ = Describe("ServerVersion()", func() { ) }) - It("should obtain the server version from the /version endpoint for the first request", func() { + It("should obtain the server version from the /info endpoint", func() { expectedVersion, err := version.NewVersion("1.2.3") Expect(err).To(BeNil()) @@ -45,12 +45,6 @@ var _ = Describe("ServerVersion()", func() { serverVersion, err := ch.ServerVersion() Expect(err).To(BeNil()) Expect(serverVersion).To(Equal(expectedVersion)) - - serverVersion, err = ch.ServerVersion() - Expect(err).To(BeNil()) - Expect(serverVersion).To(Equal(expectedVersion)) - - Expect(server.ReceivedRequests()).Should(HaveLen(1)) }) }) @@ -75,7 +69,7 @@ var _ = Describe("ServerVersion()", func() { ) }) - It("should obtain the server version from the /version endpoint for the first request", func() { + It("should obtain the server version from the /version endpoint", func() { expectedVersion, err := version.NewVersion("1.2.3") Expect(err).To(BeNil()) @@ -85,12 +79,6 @@ var _ = Describe("ServerVersion()", func() { serverVersion, err := ch.ServerVersion() Expect(err).To(BeNil()) Expect(serverVersion).To(Equal(expectedVersion)) - - serverVersion, err = ch.ServerVersion() - Expect(err).To(BeNil()) - Expect(serverVersion).To(Equal(expectedVersion)) - - Expect(server.ReceivedRequests()).Should(HaveLen(2)) }) })