Skip to content

Commit

Permalink
Handle new lines in CA provided as string
Browse files Browse the repository at this point in the history
[Finishes #146384923] User should be able to provide contents of CA instead of file reference (github CLI issue #4)
  • Loading branch information
Isobel Redelmeier committed Jul 21, 2017
1 parent 42f850f commit 3887f85
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"os"
"path"
"strings"
)

const AuthClient = "credhub_cli"
Expand Down Expand Up @@ -66,7 +67,7 @@ func (cfg *Config) UpdateTrustedCAs(caCerts []string) error {
_, err := os.Stat(cert)

if err != nil {
certs = append(certs, string(cert))
certs = append(certs, strings.Replace(cert, "\\n", "\n", -1))
} else {
certContents, err := ioutil.ReadFile(cert)

Expand Down
10 changes: 10 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ var _ = Describe("Config", func() {
Expect(cfg.CaCerts).To(ConsistOf([]string{string(ca1), ca2}))
})

It("handles new lines in certificate strings", func() {
caWithNewLines := `-----BEGIN CERTIFICATE-----\nFAKE CERTIFICATE CONTENTS\n-----END CERTIFICATE-----`
expectedCa := "-----BEGIN CERTIFICATE-----\nFAKE CERTIFICATE CONTENTS\n-----END CERTIFICATE-----"

err := cfg.UpdateTrustedCAs([]string{caWithNewLines})

Expect(err).To(BeNil())
Expect(cfg.CaCerts).To(ConsistOf([]string{expectedCa}))
})

It("returns an error if a file can't be read", func() {
invalidCaFile, err := ioutil.TempFile("", "no-read-access")
Expect(err).To(BeNil())
Expand Down

0 comments on commit 3887f85

Please sign in to comment.